Skip to content

Add Check Support for Java 21 Record Pattern Syntax: GenericWhitespace #15008

@mahfouz72

Description

@mahfouz72

child of #14890
I have read check documentation: https://checkstyle.org/checks/whitespace/genericwhitespace.html#GenericWhitespace
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> cat src/Test2.java                                                
record ColoredPoint(int p, int x, String c) { }
record Rectangle(ColoredPoint upperLeft, ColoredPoint lowerRight) { }
record Pair<T>(T x, T y) {
    }
public class Test2 {
    void test(Object obj) {
        if (obj instanceof Pair < ? > (var s, var y)) {  // 4 violations
        }
    }

}
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="GenericWhitespaceCheck">

        </module>

    </module>
</module>
PS D:\CS\test> java  -jar checkstyle-10.17.0-all.jar -c config.xml src/Test2.java
Starting audit...
[ERROR] D:\CS\test\src\Test2.java:7:33: '<' is followed by whitespace. [GenericWhitespace]
[ERROR] D:\CS\test\src\Test2.java:7:33: '<' is preceded with whitespace. [GenericWhitespace]
[ERROR] D:\CS\test\src\Test2.java:7:37: '>' is followed by whitespace. [GenericWhitespace]
[ERROR] D:\CS\test\src\Test2.java:7:37: '>' is preceded with whitespace. [GenericWhitespace]
Audit done.
Checkstyle ends with 4 errors.
PS D:\CS\test> 

Describe what you expect in detail.

this can be closed and no need for an input file because we already have one in favor of #14502

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions