Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Check Support for Java 21 Pattern Matching for Switch Syntax: IllegalToken #15293

Closed
mahfouz72 opened this issue Jul 17, 2024 · 1 comment

Comments

@mahfouz72
Copy link
Member

mahfouz72 commented Jul 17, 2024

child of #14961

I have read check documentation: https://checkstyle.org/checks/coding/illegaltoken.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

PS D:\CS\test> javac src/Test.java                                               
PS D:\CS\test> cat config.xml                                                                                     
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
          "https://checkstyle.org/dtds/configuration_1_3.dtd">

<module name="Checker">
  <module name="TreeWalker">
    <module name="IllegalToken">
       <property name="tokens" value="LITERAL_WHEN"/>
    </module>
  </module>
</module>
PS D:\CS\test> cat src/Test.java                                                 
public class Test {
    void test(Object o) {
        switch (o) {
            case Integer i when i == 5 -> {} // violation
            default -> {}
        }
    }
}
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:4:28: Using 'when' is not allowed. [IllegalToken]
Audit done.
Checkstyle ends with 1 errors.


Describe what you expect in detail.

I expected the check to work for any token and it works correctly. no update is needed for this check


@mahfouz72 mahfouz72 changed the title Add Check Support for Java 21 Pattern Matching for Switch Syntax: IllegalType Add Check Support for Java 21 Pattern Matching for Switch Syntax: IllegalToken Jul 17, 2024
@nrmancuso
Copy link
Member

Yep, looks good, we can close this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

No branches or pull requests

2 participants