[java] TooFewBranchesForSwitch should ignore Pattern Matching
Fixes #5249
This commit is contained in:
@@ -34,6 +34,9 @@ The old rule names still work but are deprecated.
|
|||||||
* [#4532](https://github.com/pmd/pmd/issues/4532): \[java] Rule misnomer for JUnit* rules
|
* [#4532](https://github.com/pmd/pmd/issues/4532): \[java] Rule misnomer for JUnit* rules
|
||||||
* java-errorprone
|
* java-errorprone
|
||||||
* [#5067](https://github.com/pmd/pmd/issues/5067): \[java] CloseResource: False positive for FileSystems.getDefault()
|
* [#5067](https://github.com/pmd/pmd/issues/5067): \[java] CloseResource: False positive for FileSystems.getDefault()
|
||||||
|
* java-performance
|
||||||
|
* [#5249](https://github.com/pmd/pmd/issues/5249): \[java] TooFewBranchesForASwitchStatement false positive for Pattern Matching
|
||||||
|
* [#....](https://github.com/pmd/pmd/issues/....): \[java] TooFewBranchesForASwitchStatement should consider Switch Expressions
|
||||||
|
|
||||||
### 🚨 API Changes
|
### 🚨 API Changes
|
||||||
* java-bestpractices
|
* java-bestpractices
|
||||||
|
@@ -625,6 +625,8 @@ if-else statement to increase code readability.
|
|||||||
<value>
|
<value>
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
//SwitchStatement[ (count(*) - 1) < $minimumNumberCaseForASwitch ]
|
//SwitchStatement[ (count(*) - 1) < $minimumNumberCaseForASwitch ]
|
||||||
|
(: exclude pattern matching :)
|
||||||
|
[not(*/SwitchLabel/TypePattern)]
|
||||||
]]>
|
]]>
|
||||||
</value>
|
</value>
|
||||||
</property>
|
</property>
|
||||||
|
@@ -69,4 +69,26 @@ public class ValidSwitch {
|
|||||||
}
|
}
|
||||||
]]></code>
|
]]></code>
|
||||||
</test-code>
|
</test-code>
|
||||||
|
|
||||||
|
<test-code>
|
||||||
|
<description>[java] TooFewBranchesForASwitchStatement false positive for Pattern Matching</description>
|
||||||
|
<expected-problems>0</expected-problems>
|
||||||
|
<code><![CDATA[
|
||||||
|
sealed interface S permits A {}
|
||||||
|
final class A implements S {}
|
||||||
|
public class Sample {
|
||||||
|
public void simpleSwitchStatment(S s) {
|
||||||
|
switch(s) {
|
||||||
|
case A a -> System.out.println("a");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void simpleSwitchExpression(S s) {
|
||||||
|
String result = switch(s) {
|
||||||
|
case A a -> "a";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]]></code>
|
||||||
|
</test-code>
|
||||||
</test-data>
|
</test-data>
|
||||||
|
Reference in New Issue
Block a user