mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java-inspections] DuplicateBranchesInSwitch: fix a comment
IJ-CR-101312 GitOrigin-RevId: 11e80499c55677cea9ba2c2c3d1dc0dd0f83124d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
ad49d42f5a
commit
4cd808e3b0
+5
-5
@@ -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();
|
||||
}
|
||||
|
||||
+16
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user