Skip to content

Add Check Support for Java 21 Unnamed Variables & Patterns Syntax: WhitespaceAfter #15057

@mahfouz72

Description

@mahfouz72

child of #14942

I have read check documentation: https://checkstyle.sourceforge.io/checks/whitespace/whitespaceafter.html#WhitespaceAfter
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 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="WhitespaceAfter">
        </module>
    </module>
</module>
PS D:\CS\test> cat src/Test.java                                                
import java.util.List;

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

public class Test {
    void test(Object obj) {

        switch (obj) {
            case ColoredPoint(int x, _, int c) when c == 0 -> { // expected violation

            }
            case ColoredPoint(int x, _ , int c) -> {}
            default -> { }
        }
    }
}

PS D:\CS\test> java  -jar checkstyle-10.17.0-all.jar -c config.xml src/Test.java
Starting audit...
Audit done.
PS D:\CS\test> 

Describe what you want in detail.

I think the check should support UNNAMED_PATTERN_DEF. IMO, it is visually cleaner when we have a space after the underscore. do you think it should be no white space as someone suggested before?

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions