[java-inspections] IDEA-332812 Convert to old-style switch: produce incorrect code for null, default

GitOrigin-RevId: f0de0aee91d2b41e1ebb6e7a815851cbbf5b8447
This commit is contained in:
Mikhail Pyltsin
2023-09-19 15:55:49 +00:00
committed by intellij-monorepo-bot
parent 5c3e92a137
commit fbd8b70ca6
5 changed files with 46 additions and 1 deletions
@@ -286,7 +286,11 @@ public final class EnhancedSwitchBackwardMigrationInspection extends AbstractBas
}
else {
PsiCaseLabelElement[] labelElements = labelElementList.getElements();
caseExpressionsText = StreamEx.of(labelElements).map(e -> "case " + ct.text(e) + ":").joining("\n");
caseExpressionsText = StreamEx.of(labelElements)
.map(e -> e instanceof PsiDefaultCaseLabelElement ?
(ct.text(e) + ":") :
("case " + ct.text(e) + ":"))
.joining("\n");
}
PsiStatement body = rule.getBody();
String finalBody;
@@ -0,0 +1,12 @@
// "Replace with old style 'switch' statement" "true"
class CaseNullDefault {
void bar(Object o) {
switch (o) {
case null:
default:
System.out.println("1");
break;
}
}
}
@@ -0,0 +1,11 @@
// "Replace with old style 'switch' statement" "true"
class ReturnCaseNullDefault {
int bar(Object o) {
switch (o) {
case null:
default:
return 1;
}
}
}
@@ -0,0 +1,9 @@
// "Replace with old style 'switch' statement" "true"
class CaseNullDefault {
void bar(Object o) {
switc<caret>h (o) {
case null, default -> System.out.println("1");
}
}
}
@@ -0,0 +1,9 @@
// "Replace with old style 'switch' statement" "true"
class ReturnCaseNullDefault {
int bar(Object o) {
return switc<caret>h (o) {
case null, default -> 1;
}
}
}