[java] TooFewBranchesForSwitch: report empty switch
This fixes a false negative
This commit is contained in:
@ -631,7 +631,7 @@ Note: This rule was named TooFewBranchesForASwitchStatement before PMD 7.7.0.
|
|||||||
//(SwitchStatement | SwitchExpression)
|
//(SwitchStatement | SwitchExpression)
|
||||||
[ (count(*) - 1) < $minimumNumberCaseForASwitch ]
|
[ (count(*) - 1) < $minimumNumberCaseForASwitch ]
|
||||||
(: only consider if no pattern matching is used :)
|
(: only consider if no pattern matching is used :)
|
||||||
[*/SwitchLabel[@PatternLabel = false()]]
|
[not(*/SwitchLabel[@PatternLabel = true()])]
|
||||||
]]>
|
]]>
|
||||||
</value>
|
</value>
|
||||||
</property>
|
</property>
|
||||||
|
@ -4,6 +4,19 @@
|
|||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://pmd.sourceforge.net/rule-tests http://pmd.sourceforge.net/rule-tests_1_0_0.xsd">
|
xsi:schemaLocation="http://pmd.sourceforge.net/rule-tests http://pmd.sourceforge.net/rule-tests_1_0_0.xsd">
|
||||||
|
|
||||||
|
<test-code>
|
||||||
|
<description>Switch Statement with no case, not ok</description>
|
||||||
|
<rule-property name="minimumNumberCaseForASwitch">3</rule-property>
|
||||||
|
<expected-problems>1</expected-problems>
|
||||||
|
<code><![CDATA[
|
||||||
|
public class DumbSwitch {
|
||||||
|
public void foo(int i) {
|
||||||
|
switch (i) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]]></code>
|
||||||
|
</test-code>
|
||||||
|
|
||||||
<test-code>
|
<test-code>
|
||||||
<description>Switch Statement with only one case, not ok</description>
|
<description>Switch Statement with only one case, not ok</description>
|
||||||
<rule-property name="minimumNumberCaseForASwitch">3</rule-property>
|
<rule-property name="minimumNumberCaseForASwitch">3</rule-property>
|
||||||
|
Reference in New Issue
Block a user