[java-inspections] DuplicateBranchesInSwitch: fix a comment

IJ-CR-101312

GitOrigin-RevId: 11e80499c55677cea9ba2c2c3d1dc0dd0f83124d
This commit is contained in:
Andrey Cherkasov
2023-03-01 18:12:37 +00:00
committed by intellij-monorepo-bot
parent ad49d42f5a
commit 4cd808e3b0
3 changed files with 39 additions and 5 deletions
@@ -385,19 +385,19 @@ public final class DuplicateBranchesInSwitchInspection extends LocalInspectionTo
case R():
case null:
case S():
<caret>System.out.println(42); // Branch in 'switch' is a duplicate of the default branch
break;
<caret>return 42; // Branch in 'switch' is a duplicate of the default branch
case String s:
System.out.println(0);
break;
return 0;
default:
System.out.println(42);
return 42;
}
The 'case R():' and 'case S():' statements can be removed as redundant,
because the corresponding branch is a duplicate of the default branch.
But the 'default' case does not handle null values, so we cannot delete
the 'case null:' and the 'return 42;' statement.
See com.intellij.java.codeInspection.DuplicateBranchesInSwitchFixTest [DeleteRedundantBranch7.java]
*/
context.deleteStatements();
}
@@ -0,0 +1,16 @@
// "Delete redundant 'switch' branch" "GENERIC_ERROR_OR_WARNING"
class Test {
record R() {}
record S() {}
void foo(Object obj) {
switch (obj) {
case null:
return 42;
case String s:
return 0;
default:
return 42;
}
}
}
@@ -0,0 +1,18 @@
// "Delete redundant 'switch' branch" "GENERIC_ERROR_OR_WARNING"
class Test {
record R() {}
record S() {}
void foo(Object obj) {
switch (obj) {
case R():
case null:
case S():
<caret>return 42;
case String s:
return 0;
default:
return 42;
}
}
}