Skip to content

Add Check Support for Java 21 Pattern Matching for Switch Syntax: RightCurly #15033

@mahfouz72

Description

@mahfouz72

child of #14961

I have read check documentation: https://checkstyle.org/checks/blocks/rightcurly.html
I have downloaded the latest checkstyle from: https://checkstyle.org/cmdline.html#Download_and_Run
I have executed the cli and showed it below, as cli describes the problem better than 1,000 words

record ColoredPoint(int p, int x, String c) { }
record Rectangle(ColoredPoint upperLeft, ColoredPoint lowerRight) { }

public class Test {

    void test(Object obj) {
        int y = 0;
        switch (obj) {
            case ColoredPoint(int x, _, _) when(x >= 2) ->
            {
            }case ColoredPoint(int x, _, _) // violation
                    when(x >= 2) ->
            {

            }case ColoredPoint(int x, _, _)  // violation
                    when(x == 1)
                    ->
            {

            }
           case ColoredPoint(int x, _, _)
                    when(x == 0) -> {

            }
            default -> { }
        }
        switch (obj) {
            case ColoredPoint(int x, _, _) when(x >= 2) :
            { } break;  // violation
            case ColoredPoint(int x, _, _)
                    when(x >= 2) :
            { } break; // violation
             case ColoredPoint(int x, _, _)
                    when(x >= 2) : { }
            default : { }
        }
    }
}

Describe what you want in detail

we are ok here. This can be closed or add an input file for cases with when

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions