[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
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[ <![CDATA[
//(SwitchStatement | SwitchExpression)[ (count(*) - 1) < $minimumNumberCaseForASwitch ] //(SwitchStatement | SwitchExpression)[ (count(*) - 1) < $minimumNumberCaseForASwitch ]
(: exclude pattern matching :) (: exclude pattern matching :)
[not(*/SwitchLabel/TypePattern)] [not(*/SwitchLabel/(TypePattern|RecordPattern))]
]]> ]]>
</value> </value>
</property> </property>

View File

@@ -89,7 +89,7 @@ public class ValidSwitch {
</test-code> </test-code>
<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> <expected-problems>0</expected-problems>
<code><![CDATA[ <code><![CDATA[
sealed interface S permits A {} 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> ]]></code>
</test-code> </test-code>
</test-data> </test-data>