[java] TooFewBranchesForSwitch - also ignore record pattern

This commit is contained in:
Andreas Dangel 2024-10-05 10:36:39 +02:00
parent d9db4dbcab
commit 13cc79af62
No known key found for this signature in database
GPG Key ID: 93450DF2DF9A3FA3
2 changed files with 18 additions and 2 deletions

View File

@ -630,7 +630,7 @@ Note: This rule was named TooFewBranchesForASwitchStatement before PMD 7.7.0.
<![CDATA[
//(SwitchStatement | SwitchExpression)[ (count(*) - 1) < $minimumNumberCaseForASwitch ]
(: exclude pattern matching :)
[not(*/SwitchLabel/TypePattern)]
[not(*/SwitchLabel/(TypePattern|RecordPattern))]
]]>
</value>
</property>

View File

@ -89,7 +89,7 @@ public class ValidSwitch {
</test-code>
<test-code>
<description>[java] TooFewBranchesForASwitchStatement false positive for Pattern Matching</description>
<description>[java] TooFewBranchesForASwitchStatement false positive for Pattern Matching #5249</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
sealed interface S permits A {}
@ -107,6 +107,22 @@ public class Sample {
};
}
}
]]></code>
</test-code>
<test-code>
<description>Record patterns are ignored, too #5249</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
record R(int i) {}
public class SwitchWithRecordPattern {
public void check(R r) {
switch(r) {
case R(int a) -> System.out.println(a);
}
}
}
]]></code>
</test-code>
</test-data>