You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
c 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="NPathComplexity">
<property name="max" value="1"/>
</module>
</module>
</module>
➜ src cat Test.java
record ColoredPoint(int p, int x, boolean c) { }
record Rectangle(ColoredPoint upperLeft, ColoredPoint lowerRight) { }
public class Test {
void test(Object obj) {
switch (obj) {
case ColoredPoint(int a, int b, _) when (a >= b) : {} break;
case ColoredPoint(int a, int b, _) when (b > 100) : {} break;
case ColoredPoint(int a, int b, _) when (b != 1000) : {} break;
case ColoredPoint(int a, int b, _) when (b != 100000) : {} break;
case Rectangle(_,_) : {}
default : System.out.println("none");
};
}
void test2(Object obj) {
switch (obj) {
case ColoredPoint(int a, int b, _) when (a >= b) -> {}
case ColoredPoint(int a, int b, _) when (b > 100) -> {}
case ColoredPoint(int a, int b, _) when (b != 1000) -> {}
case ColoredPoint(int a, int b, _) when (b != 100000) -> {}
case Rectangle(_,_) -> {}
default -> System.out.println("none");
};
}
}
➜ src javac --enable-preview --release 21 Test.java
Note: Test.java uses preview features of Java SE 21.
Note: Recompile with -Xlint:preview for details.
➜ src java -jar checkstyle-10.18.1-SNAPSHOT-all.jar -c config.xml Test.java
Starting audit...
[ERROR] /home/nick/IdeaProjects/tester/src/Test.java:5:5: NPath Complexity is 6 (max allowed is 1). [NPathComplexity]
[ERROR] /home/nick/IdeaProjects/tester/src/Test.java:16:5: NPath Complexity is 2 (max allowed is 1). [NPathComplexity]
Audit done.
Checkstyle ends with 2 errors.
Describe what you want in detail
I expect both methods to have the same NPathComplexity. There is a problem in counting when case labels are in the switch rule (->)
The text was updated successfully, but these errors were encountered:
mahfouz72
changed the title
dd Check Support for Java 21 Pattern Matching for Switch Syntax: NPathComplexity
Add Check Support for Java 21 Pattern Matching for Switch Syntax: NPathComplexity
Jun 20, 2024
child of #14961
I have read check documentation:https://checkstyle.org/checks/metrics/npathcomplexity.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
Describe what you want in detail
I expect both methods to have the same NPathComplexity. There is a problem in counting when case labels are in the switch rule
(->)
The text was updated successfully, but these errors were encountered: