Skip to content

Add Check Support for Java 21 Record Pattern Syntax: Indentation #15055

@mahfouz72

Description

@mahfouz72

child of #14890

I have read check documentation:https://checkstyle.org/checks/misc/indentation.html#Indentation
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


PS D:\CS\test> javac src/Test.java                                              
PS D:\CS\test> cat src/Test.java                                                
record ColoredPoint(boolean p, int x, int c) { }
record Rectangle(ColoredPoint upperLeft, ColoredPoint lowerRight) { }

public class Test {
    void test(Object obj) {
        boolean b = obj instanceof
                ColoredPoint(_,_,_);
        boolean bb = obj instanceof
        ColoredPoint(_,_,_);  // violation
        if (obj instanceof ColoredPoint(_,_,_)) {}
        if (obj instanceof
                ColoredPoint(_,_,_)) {}
        if (obj instanceof
        ColoredPoint(_,_,_)) {  // violation

        }
        if (obj instanceof
ColoredPoint(_,_,_)) {  // violation

        }
        if (obj instanceof
ColoredPoint( // violation
_,  // violation
_,  // violation
_)) // violation
        {

        }

        if (obj instanceof
                Rectangle(
                ColoredPoint(
                        boolean x,
                int y,
                        _),
                ColoredPoint(_,_,_)
                )) {

        }

        if (obj instanceof
Rectangle(  // violation
ColoredPoint(  // violation
        boolean x, // violation
        int y, // violation
        _), // violation
ColoredPoint(_,_,_) // violation
        )) {  // violation

        }
    }

    void testSwitch(Object obj) {
        switch (obj) {
            case Rectangle(
        ColoredPoint _,  // violation
        ColoredPoint _) -> System.out.println("Rectangle");  // violation
            default -> {}
        }
    }
}
PS D:\CS\test> cat config.xml                                                   
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
        "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
        "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
    <property name="charset" value="UTF-8"/>
    <module name="TreeWalker">
               <module name="Indentation">

        </module>
    </module>
</module>
PS D:\CS\test> java  -jar checkstyle-10.17.0-all.jar -c config.xml src/Test.java
Starting audit...
[ERROR] D:\CS\test\src\Test.java:9:9: 'ColoredPoint' has incorrect indentation level 8, expected level should be 12. [Indentation]
[ERROR] D:\CS\test\src\Test.java:14:9: 'if' child has incorrect indentation level 8, expected level should be 12. [Indentation]
[ERROR] D:\CS\test\src\Test.java:18:1: 'if' child has incorrect indentation level 0, expected level should be 12. [Indentation]
[ERROR] D:\CS\test\src\Test.java:22:1: 'if' child has incorrect indentation level 0, expected level should be 12. [Indentation]
[ERROR] D:\CS\test\src\Test.java:23:1: 'if' child has incorrect indentation level 0, expected level should be 12. [Indentation]
[ERROR] D:\CS\test\src\Test.java:24:1: 'if' child has incorrect indentation level 0, expected level should be 12. [Indentation]
[ERROR] D:\CS\test\src\Test.java:25:1: 'if' child has incorrect indentation level 0, expected level should be 12. [Indentation]
[ERROR] D:\CS\test\src\Test.java:42:1: 'if' child has incorrect indentation level 0, expected level should be 12. [Indentation]
[ERROR] D:\CS\test\src\Test.java:43:1: 'if' child has incorrect indentation level 0, expected level should be 12. [Indentation]
[ERROR] D:\CS\test\src\Test.java:44:9: 'if' child has incorrect indentation level 8, expected level should be 12. [Indentation]
[ERROR] D:\CS\test\src\Test.java:45:9: 'if' child has incorrect indentation level 8, expected level should be 12. [Indentation]
[ERROR] D:\CS\test\src\Test.java:46:9: 'if' child has incorrect indentation level 8, expected level should be 12. [Indentation]
[ERROR] D:\CS\test\src\Test.java:47:1: 'if' child has incorrect indentation level 0, expected level should be 12. [Indentation]
[ERROR] D:\CS\test\src\Test.java:48:9: 'if' child has incorrect indentation level 8, expected level should be 12. [Indentation]
[ERROR] D:\CS\test\src\Test.java:56:9: 'case' child has incorrect indentation level 8, expected level should be 16. [Indentation]
[ERROR] D:\CS\test\src\Test.java:57:9: 'case' child has incorrect indentation level 8, expected level should be 16. [Indentation]
Audit done.
Checkstyle ends with 16 errors.
PS D:\CS\test> 


Describe what you want in detail.

looks good to me.

Metadata

Metadata

Assignees

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions