From 45b1217485bb712dd89c15077b98a4042975d226 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 24 Oct 2024 12:51:42 +0200 Subject: [PATCH] [java] TooFewBranchesForSwitch: don't report empty switch Empty switch statements are already reported by EmptyControlStatement --- docs/pages/release_notes.md | 2 ++ pmd-java/src/main/resources/category/java/performance.xml | 2 +- .../java/rule/performance/xml/TooFewBranchesForSwitch.xml | 6 +++--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 19769b9943..6fb4e5bdef 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -24,6 +24,8 @@ See [PR #5040](https://github.com/pmd/pmd/pull/5040) for details. ### 🌟 Rule Changes #### Changed Rules +* {% rule java/performance/TooFewBranchesForSwitch %} (Java Performance) doesn't report empty switches anymore. + To detect these, use {% rule java/codestyle/EmptyControlStatement %}. * {% rule java/bestpractices/UnitTestShouldUseAfterAnnotation %} (Java Best Practices) now also considers JUnit 5 and TestNG tests. * {% rule java/bestpractices/UnitTestShouldUseBeforeAnnotation %} (Java Best Practices) now also considers JUnit 5 and TestNG tests. diff --git a/pmd-java/src/main/resources/category/java/performance.xml b/pmd-java/src/main/resources/category/java/performance.xml index f2e7eef431..a8e4c37142 100644 --- a/pmd-java/src/main/resources/category/java/performance.xml +++ b/pmd-java/src/main/resources/category/java/performance.xml @@ -631,7 +631,7 @@ Note: This rule was named TooFewBranchesForASwitchStatement before PMD 7.7.0. //(SwitchStatement | SwitchExpression) [ (count(*) - 1) < $minimumNumberCaseForASwitch ] (: only consider if no pattern matching is used :) - [not(*/SwitchLabel[@PatternLabel = true()])] + [*/SwitchLabel[@PatternLabel = false()]] ]]> diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/performance/xml/TooFewBranchesForSwitch.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/performance/xml/TooFewBranchesForSwitch.xml index 239aebbb12..e603390ec6 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/performance/xml/TooFewBranchesForSwitch.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/performance/xml/TooFewBranchesForSwitch.xml @@ -5,13 +5,13 @@ xsi:schemaLocation="http://pmd.sourceforge.net/rule-tests http://pmd.sourceforge.net/rule-tests_1_0_0.xsd"> - Switch Statement with no case, not ok + Switch Statement with no case, ok 3 - 1 + 0