Java: Shortened text messages for highlighting of duplicate values and branches in enhanced 'switch' (IDEA-202629)

This commit is contained in:
Pavel Dolgov
2019-02-04 17:05:48 +03:00
parent 64d3c71276
commit e00ecc9156
37 changed files with 98 additions and 158 deletions
@@ -275,27 +275,23 @@ public class DuplicateBranchesInSwitchInspection extends LocalInspectionTool {
private static class MergeBranchesFix implements LocalQuickFix {
@NotNull private final String mySwitchLabelText;
private final boolean myInExpression;
MergeBranchesFix(@NotNull String switchLabelText, boolean inExpression) {
MergeBranchesFix(@NotNull String switchLabelText) {
mySwitchLabelText = switchLabelText;
myInExpression = inExpression;
}
@Nls(capitalization = Nls.Capitalization.Sentence)
@NotNull
@Override
public String getFamilyName() {
return myInExpression
? InspectionsBundle.message("inspection.duplicate.branches.in.switch.expression.fix.family.name")
: InspectionsBundle.message("inspection.duplicate.branches.in.switch.fix.family.name");
return InspectionsBundle.message("inspection.duplicate.branches.in.switch.merge.fix.family.name");
}
@Nls(capitalization = Nls.Capitalization.Sentence)
@NotNull
@Override
public String getName() {
return InspectionsBundle.message("inspection.duplicate.branches.in.switch.fix.name", mySwitchLabelText);
return InspectionsBundle.message("inspection.duplicate.branches.in.switch.merge.fix.name", mySwitchLabelText);
}
@Override
@@ -329,26 +325,19 @@ public class DuplicateBranchesInSwitchInspection extends LocalInspectionTool {
}
private static class DeleteRedundantBranchFix implements LocalQuickFix {
private final boolean myInExpression;
private DeleteRedundantBranchFix(boolean inExpression) {
myInExpression = inExpression;
}
@Nls(capitalization = Nls.Capitalization.Sentence)
@NotNull
@Override
public String getName() {
return InspectionsBundle.message("inspection.duplicate.branches.in.switch.redundant.fix.name");
return InspectionsBundle.message("inspection.duplicate.branches.in.switch.delete.fix.name");
}
@Nls(capitalization = Nls.Capitalization.Sentence)
@NotNull
@Override
public String getFamilyName() {
return myInExpression
? InspectionsBundle.message("inspection.duplicate.branches.in.switch.redundant.expression.fix.family.name")
: InspectionsBundle.message("inspection.duplicate.branches.in.switch.redundant.fix.family.name");
return InspectionsBundle.message("inspection.duplicate.branches.in.switch.delete.fix.family.name");
}
@Override
@@ -538,15 +527,11 @@ public class DuplicateBranchesInSwitchInspection extends LocalInspectionTool {
}
String getCaseBranchMessage() {
return myInExpression
? InspectionsBundle.message("inspection.duplicate.branches.in.switch.expression.message")
: InspectionsBundle.message("inspection.duplicate.branches.in.switch.statement.message");
return InspectionsBundle.message("inspection.duplicate.branches.in.switch.message");
}
String getDefaultBranchMessage() {
return myInExpression
? InspectionsBundle.message("inspection.duplicate.branches.in.switch.expression.default.message")
: InspectionsBundle.message("inspection.duplicate.branches.in.switch.statement.default.message");
return InspectionsBundle.message("inspection.duplicate.branches.in.switch.default.message");
}
@Override
@@ -681,7 +666,7 @@ public class DuplicateBranchesInSwitchInspection extends LocalInspectionTool {
@Override
LocalQuickFix newMergeCasesFix() {
String switchLabelText = getSwitchLabelText();
return switchLabelText != null ? new MergeBranchesFix(switchLabelText, myInExpression) : null;
return switchLabelText != null ? new MergeBranchesFix(switchLabelText) : null;
}
@Override
@@ -691,7 +676,7 @@ public class DuplicateBranchesInSwitchInspection extends LocalInspectionTool {
@Override
LocalQuickFix newDeleteCaseFix() {
return new DeleteRedundantBranchFix(myInExpression);
return new DeleteRedundantBranchFix();
}
/**
@@ -798,7 +783,6 @@ public class DuplicateBranchesInSwitchInspection extends LocalInspectionTool {
}
private static class Rule extends BranchBase<PsiSwitchLabeledRuleStatement> {
private final boolean myIsResult;
private final boolean myIsSimpleExit;
Rule(@NotNull PsiSwitchLabeledRuleStatement rule, @NotNull PsiStatement body, @NotNull String[] commentTexts) {
@@ -806,7 +790,6 @@ public class DuplicateBranchesInSwitchInspection extends LocalInspectionTool {
new PsiStatement[]{body},
commentTexts);
myIsResult = body instanceof PsiExpressionStatement;
myIsSimpleExit = body instanceof PsiExpressionStatement || body instanceof PsiThrowStatement;
}
@@ -820,31 +803,11 @@ public class DuplicateBranchesInSwitchInspection extends LocalInspectionTool {
return false;
}
@Override
String getCaseBranchMessage() {
if (myInExpression) {
return myIsResult
? InspectionsBundle.message("inspection.duplicate.branches.in.switch.result.message")
: InspectionsBundle.message("inspection.duplicate.branches.in.switch.expression.message");
}
return super.getCaseBranchMessage();
}
@Override
String getDefaultBranchMessage() {
if (myInExpression) {
return myIsResult
? InspectionsBundle.message("inspection.duplicate.branches.in.switch.default.result.message")
: InspectionsBundle.message("inspection.duplicate.branches.in.switch.expression.default.message");
}
return super.getDefaultBranchMessage();
}
@Nullable
@Override
LocalQuickFix newMergeCasesFix() {
String switchLabelText = getSwitchLabelText();
return switchLabelText != null ? new MergeRulesFix(switchLabelText, isResultExpression()) : null;
return switchLabelText != null ? new MergeRulesFix(switchLabelText) : null;
}
@Override
@@ -854,37 +817,29 @@ public class DuplicateBranchesInSwitchInspection extends LocalInspectionTool {
@Override
LocalQuickFix newDeleteCaseFix() {
return new DeleteRedundantRuleFix(isResultExpression());
}
private boolean isResultExpression() {
return myInExpression && myIsResult;
return new DeleteRedundantRuleFix();
}
}
private static class MergeRulesFix implements LocalQuickFix {
@NotNull private final String mySwitchLabelText;
private final boolean myIsResultExpression;
MergeRulesFix(@NotNull String switchLabelText, boolean isResultExpression) {
MergeRulesFix(@NotNull String switchLabelText) {
mySwitchLabelText = switchLabelText;
myIsResultExpression = isResultExpression;
}
@Nls(capitalization = Nls.Capitalization.Sentence)
@NotNull
@Override
public String getFamilyName() {
return myIsResultExpression
? InspectionsBundle.message("inspection.duplicate.branches.in.switch.expression.fix.family.name")
: InspectionsBundle.message("inspection.duplicate.branches.in.switch.fix.family.name");
return InspectionsBundle.message("inspection.duplicate.branches.in.switch.merge.fix.family.name");
}
@Nls(capitalization = Nls.Capitalization.Sentence)
@NotNull
@Override
public String getName() {
return InspectionsBundle.message("inspection.duplicate.branches.in.switch.fix.name", mySwitchLabelText);
return InspectionsBundle.message("inspection.duplicate.branches.in.switch.merge.fix.name", mySwitchLabelText);
}
@Override
@@ -898,28 +853,19 @@ public class DuplicateBranchesInSwitchInspection extends LocalInspectionTool {
}
private static class DeleteRedundantRuleFix implements LocalQuickFix {
private final boolean myIsResultExpression;
DeleteRedundantRuleFix(boolean isResultExpression) {
myIsResultExpression = isResultExpression;
}
@Nls(capitalization = Nls.Capitalization.Sentence)
@NotNull
@Override
public String getName() {
return myIsResultExpression
? InspectionsBundle.message("inspection.duplicate.branches.in.switch.redundant.expression.fix.name")
: InspectionsBundle.message("inspection.duplicate.branches.in.switch.redundant.fix.name");
return InspectionsBundle.message("inspection.duplicate.branches.in.switch.delete.fix.name");
}
@Nls(capitalization = Nls.Capitalization.Sentence)
@NotNull
@Override
public String getFamilyName() {
return myIsResultExpression
? InspectionsBundle.message("inspection.duplicate.branches.in.switch.redundant.expression.fix.family.name")
: InspectionsBundle.message("inspection.duplicate.branches.in.switch.redundant.fix.family.name");
return InspectionsBundle.message("inspection.duplicate.branches.in.switch.delete.fix.family.name");
}
@Override
@@ -6,7 +6,7 @@ class C {
case 2:
break "b";
case 3:
<weak_warning descr="Duplicate branch in 'switch' expression">break "a";</weak_warning>
<weak_warning descr="Duplicate branch in 'switch'">break "a";</weak_warning>
default:
break "";
};
@@ -7,7 +7,7 @@ class C {
case 2:
break "b";
case 3:
<weak_warning descr="Branch in 'switch' expression is a duplicate of the default branch">break "a";</weak_warning>
<weak_warning descr="Branch in 'switch' is a duplicate of the default branch">break "a";</weak_warning>
};
}
}
@@ -2,7 +2,7 @@ class C {
void test(int n) {
String s = switch (n) {
case 1:
<weak_warning descr="Branch in 'switch' expression is a duplicate of the default branch">break "a";</weak_warning>
<weak_warning descr="Branch in 'switch' is a duplicate of the default branch">break "a";</weak_warning>
case 2:
break "b";
case 3:
@@ -6,7 +6,7 @@ class C {
case 2:
break "b";
case 3:
<weak_warning descr="Duplicate branch in 'switch' expression">break "a"; // same comment</weak_warning>
<weak_warning descr="Duplicate branch in 'switch'">break "a"; // same comment</weak_warning>
default:
break "";
};
@@ -2,7 +2,7 @@ class C {
String test(int i) {
return switch (i) {
case 0 -> null;
case 1 -> <weak_warning descr="Duplicate result expression in 'switch' expression">(null);</weak_warning>
case 1 -> <weak_warning descr="Duplicate branch in 'switch'">(null);</weak_warning>
default -> "";
};
}
@@ -3,7 +3,7 @@ class C {
return switch (n) {
case 1 -> "A";
case 2 -> "B";
case 3 -> <weak_warning descr="Duplicate result expression in 'switch' expression">"A";</weak_warning>
case 3 -> <weak_warning descr="Duplicate branch in 'switch'">"A";</weak_warning>
default -> "";
};
}
@@ -3,7 +3,7 @@ class C {
String string = switch (n) {
case 1 -> bar("A");
case 2 -> bar("B");
case 3 -> <weak_warning descr="Duplicate result expression in 'switch' expression">bar("A");</weak_warning>
case 3 -> <weak_warning descr="Duplicate branch in 'switch'">bar("A");</weak_warning>
default -> "";
};
}
@@ -3,7 +3,7 @@ class C {
switch (n) {
case 1 -> bar("A");
case 2 -> bar("B");
case 3 -> <weak_warning descr="Duplicate branch in 'switch' statement">bar("A");</weak_warning>
case 3 -> <weak_warning descr="Duplicate branch in 'switch'">bar("A");</weak_warning>
}
}
void bar(String s){}
@@ -4,7 +4,7 @@ class C {
case 0 ->{
return null;
}
case 1 -><weak_warning descr="Duplicate branch in 'switch' statement">{
case 1 -><weak_warning descr="Duplicate branch in 'switch'">{
return (null);
}</weak_warning>
}
@@ -3,7 +3,7 @@ class C {
String string = switch (n) {
case 1 -> throw new IllegalArgumentException();
case 2 -> throw new IllegalStateException();
case 3 -> <weak_warning descr="Duplicate branch in 'switch' expression">throw new IllegalArgumentException();</weak_warning>
case 3 -> <weak_warning descr="Duplicate branch in 'switch'">throw new IllegalArgumentException();</weak_warning>
default -> "";
};
}
@@ -3,7 +3,7 @@ class C {
switch (n) {
case 1 -> throw new IllegalArgumentException();
case 2 -> throw new IllegalStateException();
case 3 -> <weak_warning descr="Duplicate branch in 'switch' statement">throw new IllegalArgumentException();</weak_warning>
case 3 -> <weak_warning descr="Duplicate branch in 'switch'">throw new IllegalArgumentException();</weak_warning>
}
}
}
@@ -1,4 +1,4 @@
// "Delete redundant 'switch' result expression" "GENERIC_ERROR_OR_WARNING"
// "Delete redundant 'switch' branch" "GENERIC_ERROR_OR_WARNING"
class C {
void foo(int n) {
String s = switch (n) {
@@ -1,4 +1,4 @@
// "Delete redundant 'switch' result expression" "GENERIC_ERROR_OR_WARNING"
// "Delete redundant 'switch' branch" "GENERIC_ERROR_OR_WARNING"
class C {
void foo(int n) {
String s = switch (n) {
@@ -1,4 +1,4 @@
// "Delete redundant 'switch' result expression" "GENERIC_ERROR_OR_WARNING"
// "Delete redundant 'switch' branch" "GENERIC_ERROR_OR_WARNING"
class C {
void foo(int n) {
String s = switch (n) {
@@ -1,4 +1,4 @@
// "Delete redundant 'switch' result expression" "GENERIC_ERROR_OR_WARNING"
// "Delete redundant 'switch' branch" "GENERIC_ERROR_OR_WARNING"
class C {
void foo(int n) {
String s = switch (n) {
@@ -1,4 +1,4 @@
// "Delete redundant 'switch' result expression" "GENERIC_ERROR_OR_WARNING"
// "Delete redundant 'switch' branch" "GENERIC_ERROR_OR_WARNING"
class C {
void foo(int n) {
String s = switch (n) {
@@ -1,4 +1,4 @@
// "Delete redundant 'switch' result expression" "GENERIC_ERROR_OR_WARNING"
// "Delete redundant 'switch' branch" "GENERIC_ERROR_OR_WARNING"
class C {
void foo(int n) {
String s = switch (n) {
@@ -3,8 +3,8 @@ class C {
String s;
switch (n) {
case 0: s = a(); break;
case 1: <weak_warning descr="Duplicate branch in 'switch' statement">s = a();</weak_warning> break;
case 2: <weak_warning descr="Branch in 'switch' statement is a duplicate of the default branch">s = b();</weak_warning> break;
case 1: <weak_warning descr="Duplicate branch in 'switch'">s = a();</weak_warning> break;
case 2: <weak_warning descr="Branch in 'switch' is a duplicate of the default branch">s = b();</weak_warning> break;
default: s = b();
}
}
@@ -14,7 +14,7 @@ class C {
break;
}
case 3:
<weak_warning descr="Duplicate branch in 'switch' statement">if(b) {
<weak_warning descr="Duplicate branch in 'switch'">if(b) {
return bar("A");
} else {
break;
@@ -18,7 +18,7 @@ class C {
bar("o");
break;
case 3:
<weak_warning descr="Duplicate branch in 'switch' statement">if(b) {
<weak_warning descr="Duplicate branch in 'switch'">if(b) {
bar("A");
} else {
bar("z");
@@ -9,7 +9,7 @@ class C {
case 2:
continue;
case 3:
<weak_warning descr="Duplicate branch in 'switch' statement">s += i;
<weak_warning descr="Duplicate branch in 'switch'">s += i;
continue;</weak_warning>
default:
s += i;
@@ -8,7 +8,7 @@ class C {
bar("A");
break;
case 1:
<weak_warning descr="Branch in 'switch' statement is a duplicate of the default branch">bar("A");</weak_warning>
<weak_warning descr="Branch in 'switch' is a duplicate of the default branch">bar("A");</weak_warning>
break;
}
}
@@ -6,10 +6,10 @@ class C {
case 2:
break;
case 3:
<weak_warning descr="Duplicate branch in 'switch' statement">bar("A");</weak_warning>
<weak_warning descr="Duplicate branch in 'switch'">bar("A");</weak_warning>
break;
case 4:
<weak_warning descr="Duplicate branch in 'switch' statement">bar("A");</weak_warning>
<weak_warning descr="Duplicate branch in 'switch'">bar("A");</weak_warning>
case 5:
}
}
@@ -13,7 +13,7 @@ class C {
case 6: bar("F");break;
case 7: bar("G");break;
case 8: bar("H");break;
case 9: <weak_warning descr="Duplicate branch in 'switch' statement">bar("A");</weak_warning>break;
case 9: <weak_warning descr="Duplicate branch in 'switch'">bar("A");</weak_warning>break;
case 11: return Collections.singletonMap(k + 1, Collections.singletonList("A"));
case 12: return Collections.singletonMap(k + 2, Collections.singletonList("B"));
@@ -23,7 +23,7 @@ class C {
case 16: return Collections.singletonMap(k + 6, Collections.singletonList("F"));
case 17: return Collections.singletonMap(k + 7, Collections.singletonList("G"));
case 18: return Collections.singletonMap(k + 8, Collections.singletonList("H"));
case 19: <weak_warning descr="Duplicate branch in 'switch' statement">return Collections.singletonMap(k + 1, Collections.singletonList("A"));</weak_warning>
case 19: <weak_warning descr="Duplicate branch in 'switch'">return Collections.singletonMap(k + 1, Collections.singletonList("A"));</weak_warning>
case 21: synchronized (lock) { bar("A"); }break;
case 22: synchronized (lock) { bar("B"); }break;
@@ -33,7 +33,7 @@ class C {
case 26: synchronized (lock) { bar("F"); }break;
case 27: synchronized (lock) { bar("G"); }break;
case 28: synchronized (lock) { bar("H"); }break;
case 29: <weak_warning descr="Duplicate branch in 'switch' statement">synchronized (lock) { bar("A"); }</weak_warning>break;
case 29: <weak_warning descr="Duplicate branch in 'switch'">synchronized (lock) { bar("A"); }</weak_warning>break;
case 31: assert k == 1;break;
case 32: assert k == 2;break;
@@ -43,36 +43,36 @@ class C {
case 36: assert k == 6;break;
case 37: assert k == 7;break;
case 38: assert k == 8;break;
case 39: <weak_warning descr="Duplicate branch in 'switch' statement">assert k == 1;</weak_warning>break;
case 39: <weak_warning descr="Duplicate branch in 'switch'">assert k == 1;</weak_warning>break;
case 41: if (k > 0) bar("A"); else bar("B");break;
case 42: <weak_warning descr="Duplicate branch in 'switch' statement">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 43: <weak_warning descr="Duplicate branch in 'switch' statement">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 44: <weak_warning descr="Duplicate branch in 'switch' statement">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 45: <weak_warning descr="Duplicate branch in 'switch' statement">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 46: <weak_warning descr="Duplicate branch in 'switch' statement">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 47: <weak_warning descr="Duplicate branch in 'switch' statement">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 48: <weak_warning descr="Duplicate branch in 'switch' statement">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 49: <weak_warning descr="Duplicate branch in 'switch' statement">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 50: <weak_warning descr="Duplicate branch in 'switch' statement">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 51: <weak_warning descr="Duplicate branch in 'switch' statement">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 52: <weak_warning descr="Duplicate branch in 'switch' statement">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 53: <weak_warning descr="Duplicate branch in 'switch' statement">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 54: <weak_warning descr="Duplicate branch in 'switch' statement">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 55: <weak_warning descr="Duplicate branch in 'switch' statement">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 56: <weak_warning descr="Duplicate branch in 'switch' statement">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 57: <weak_warning descr="Duplicate branch in 'switch' statement">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 58: <weak_warning descr="Duplicate branch in 'switch' statement">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 59: <weak_warning descr="Duplicate branch in 'switch' statement">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 61: <weak_warning descr="Duplicate branch in 'switch' statement">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 62: <weak_warning descr="Duplicate branch in 'switch' statement">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 63: <weak_warning descr="Duplicate branch in 'switch' statement">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 64: <weak_warning descr="Duplicate branch in 'switch' statement">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 65: <weak_warning descr="Duplicate branch in 'switch' statement">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 66: <weak_warning descr="Duplicate branch in 'switch' statement">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 67: <weak_warning descr="Duplicate branch in 'switch' statement">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 68: <weak_warning descr="Duplicate branch in 'switch' statement">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 69: <weak_warning descr="Duplicate branch in 'switch' statement">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 42: <weak_warning descr="Duplicate branch in 'switch'">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 43: <weak_warning descr="Duplicate branch in 'switch'">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 44: <weak_warning descr="Duplicate branch in 'switch'">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 45: <weak_warning descr="Duplicate branch in 'switch'">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 46: <weak_warning descr="Duplicate branch in 'switch'">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 47: <weak_warning descr="Duplicate branch in 'switch'">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 48: <weak_warning descr="Duplicate branch in 'switch'">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 49: <weak_warning descr="Duplicate branch in 'switch'">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 50: <weak_warning descr="Duplicate branch in 'switch'">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 51: <weak_warning descr="Duplicate branch in 'switch'">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 52: <weak_warning descr="Duplicate branch in 'switch'">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 53: <weak_warning descr="Duplicate branch in 'switch'">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 54: <weak_warning descr="Duplicate branch in 'switch'">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 55: <weak_warning descr="Duplicate branch in 'switch'">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 56: <weak_warning descr="Duplicate branch in 'switch'">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 57: <weak_warning descr="Duplicate branch in 'switch'">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 58: <weak_warning descr="Duplicate branch in 'switch'">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 59: <weak_warning descr="Duplicate branch in 'switch'">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 61: <weak_warning descr="Duplicate branch in 'switch'">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 62: <weak_warning descr="Duplicate branch in 'switch'">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 63: <weak_warning descr="Duplicate branch in 'switch'">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 64: <weak_warning descr="Duplicate branch in 'switch'">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 65: <weak_warning descr="Duplicate branch in 'switch'">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 66: <weak_warning descr="Duplicate branch in 'switch'">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 67: <weak_warning descr="Duplicate branch in 'switch'">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 68: <weak_warning descr="Duplicate branch in 'switch'">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
case 69: <weak_warning descr="Duplicate branch in 'switch'">if (k > 0) bar("A"); else bar("B");</weak_warning>break;
}
return Collections.emptyMap();
}
@@ -7,10 +7,10 @@ enum T {
return t.ordinal(); // comment 1
case B:
<weak_warning descr="Duplicate branch in 'switch' statement">return t.ordinal();</weak_warning>
<weak_warning descr="Duplicate branch in 'switch'">return t.ordinal();</weak_warning>
case C:
<weak_warning descr="Duplicate branch in 'switch' statement">return t.ordinal(); // comment 2</weak_warning>
<weak_warning descr="Duplicate branch in 'switch'">return t.ordinal(); // comment 2</weak_warning>
default:
return 0;
@@ -8,7 +8,7 @@ class C {
bar("B");
break;
case 3:
<weak_warning descr="Duplicate branch in 'switch' statement">bar("A");</weak_warning>
<weak_warning descr="Duplicate branch in 'switch'">bar("A");</weak_warning>
}
}
void bar(String s){}
@@ -2,7 +2,7 @@ class C {
String test(int i) {
switch (i) {
case 0: return null;
case 1: <weak_warning descr="Duplicate branch in 'switch' statement">return (null);</weak_warning>
case 1: <weak_warning descr="Duplicate branch in 'switch'">return (null);</weak_warning>
}
return "";
}
@@ -6,7 +6,7 @@ class C {
case 2:
return "B";
case 3:
<weak_warning descr="Duplicate branch in 'switch' statement">return "A";</weak_warning>
<weak_warning descr="Duplicate branch in 'switch'">return "A";</weak_warning>
}
return "";
}
@@ -13,24 +13,24 @@ enum C {
return "A";
case LINE_COMMENT:
// comment 1
<weak_warning descr="Duplicate branch in 'switch' statement">return "A";</weak_warning>
<weak_warning descr="Duplicate branch in 'switch'">return "A";</weak_warning>
case COMMENT_INSIDE_THE_CODE:
<weak_warning descr="Duplicate branch in 'switch' statement">return /* comment 1 */"A";</weak_warning>
<weak_warning descr="Duplicate branch in 'switch'">return /* comment 1 */"A";</weak_warning>
case JAVADOC_COMMENT:
/** comment 1 */
<weak_warning descr="Duplicate branch in 'switch' statement">return "A";</weak_warning>
<weak_warning descr="Duplicate branch in 'switch'">return "A";</weak_warning>
case COMMENT_WITH_NEW_LINES:
/*
comment 1
*/
<weak_warning descr="Duplicate branch in 'switch' statement">return "A";</weak_warning>
<weak_warning descr="Duplicate branch in 'switch'">return "A";</weak_warning>
case EMPTY_COMMENTS_ARE_IGNORED:
/* comment 1 */
//
<weak_warning descr="Duplicate branch in 'switch' statement">return "A";</weak_warning>
<weak_warning descr="Duplicate branch in 'switch'">return "A";</weak_warning>
// comment 1
case COMMENT_RIGHT_BEFORE_A_CASE_IS_ATTACHED_TO_THAT_CASE:
<weak_warning descr="Duplicate branch in 'switch' statement">return "A";</weak_warning>
<weak_warning descr="Duplicate branch in 'switch'">return "A";</weak_warning>
}
return "";
}
@@ -8,7 +8,7 @@ class C {
bar("B");
break;
case 3:
<weak_warning descr="Duplicate branch in 'switch' statement">bar("A");</weak_warning>
<weak_warning descr="Duplicate branch in 'switch'">bar("A");</weak_warning>
break;
}
}
@@ -8,10 +8,10 @@ class C {
bar("B");
break;
case 3:
<weak_warning descr="Duplicate branch in 'switch' statement">bar("A");</weak_warning>
<weak_warning descr="Duplicate branch in 'switch'">bar("A");</weak_warning>
break;
case 4:
<weak_warning descr="Duplicate branch in 'switch' statement">bar("A");</weak_warning>
<weak_warning descr="Duplicate branch in 'switch'">bar("A");</weak_warning>
break;
}
}
@@ -2,13 +2,13 @@ class C {
void foo(int n) {
switch (n) {
case 1:
<weak_warning descr="Branch in 'switch' statement is a duplicate of the default branch">bar("A");</weak_warning>
<weak_warning descr="Branch in 'switch' is a duplicate of the default branch">bar("A");</weak_warning>
break;
case 2:
bar("B");
break;
case 3:
<weak_warning descr="Branch in 'switch' statement is a duplicate of the default branch">bar("A");</weak_warning>
<weak_warning descr="Branch in 'switch' is a duplicate of the default branch">bar("A");</weak_warning>
break;
default:
bar("A");
@@ -6,7 +6,7 @@ class C {
case 2:
throw new IllegalStateException("A");
case 3:
<weak_warning descr="Duplicate branch in 'switch' statement">throw new IllegalArgumentException("A");</weak_warning>
<weak_warning descr="Duplicate branch in 'switch'">throw new IllegalArgumentException("A");</weak_warning>
}
return "";
}
@@ -6,7 +6,7 @@ class C {
bar("A");
break;
case 3:
<weak_warning descr="Duplicate branch in 'switch' statement">bar("A");</weak_warning>
<weak_warning descr="Duplicate branch in 'switch'">bar("A");</weak_warning>
break;
case 4:
bar("B");
@@ -5,6 +5,7 @@ import org.junit.runner.RunWith;
import org.junit.runners.Suite;
/**
* Tests for {@link com.intellij.codeInspection.DuplicateBranchesInSwitchInspection}
* @author Pavel.Dolgov
*/
@RunWith(Suite.class)
@@ -1051,20 +1051,13 @@ inspection.switch.expression.backward.expression.migration.inspection.name='swit
inspection.switch.expression.backward.statement.migration.inspection.name='switch' statement can be replaced with old style 'switch' statement
inspection.replace.with.old.style.switch.statement.fix.name=Replace with old style 'switch' statement
inspection.duplicate.branches.in.switch.display.name=Duplicate branches in 'switch' statement
inspection.duplicate.branches.in.switch.statement.message=Duplicate branch in 'switch' statement
inspection.duplicate.branches.in.switch.expression.message=Duplicate branch in 'switch' expression
inspection.duplicate.branches.in.switch.result.message=Duplicate result expression in 'switch' expression
inspection.duplicate.branches.in.switch.statement.default.message=Branch in 'switch' statement is a duplicate of the default branch
inspection.duplicate.branches.in.switch.expression.default.message=Branch in 'switch' expression is a duplicate of the default branch
inspection.duplicate.branches.in.switch.default.result.message=Result expression in 'switch' expression is a duplicate of the default result
inspection.duplicate.branches.in.switch.fix.family.name=Merge duplicate branches of 'switch' statement
inspection.duplicate.branches.in.switch.expression.fix.family.name=Merge duplicate results of 'switch' expression
inspection.duplicate.branches.in.switch.fix.name=Merge with ''{0}''
inspection.duplicate.branches.in.switch.redundant.fix.family.name=Delete redundant branches of 'switch' statement
inspection.duplicate.branches.in.switch.redundant.expression.fix.family.name=Delete redundant branches of 'switch' expression
inspection.duplicate.branches.in.switch.redundant.fix.name=Delete redundant 'switch' branch
inspection.duplicate.branches.in.switch.redundant.expression.fix.name=Delete redundant 'switch' result expression
inspection.duplicate.branches.in.switch.display.name=Duplicate branches in 'switch'
inspection.duplicate.branches.in.switch.message=Duplicate branch in 'switch'
inspection.duplicate.branches.in.switch.default.message=Branch in 'switch' is a duplicate of the default branch
inspection.duplicate.branches.in.switch.merge.fix.family.name=Merge duplicate branches in 'switch'
inspection.duplicate.branches.in.switch.merge.fix.name=Merge with ''{0}''
inspection.duplicate.branches.in.switch.delete.fix.family.name=Delete redundant 'switch' branches
inspection.duplicate.branches.in.switch.delete.fix.name=Delete redundant 'switch' branch
inspection.duplicate.branches.in.switch.merge.with.default.fix.name=Merge with the default 'switch' branch
inspection.switch.labeled.rule.can.be.code.block.display.name=Labeled switch rule can have code block