mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java-inspections] IDEA-332812 Convert to old-style switch: produce incorrect code for null, default
GitOrigin-RevId: f0de0aee91d2b41e1ebb6e7a815851cbbf5b8447
This commit is contained in:
committed by
intellij-monorepo-bot
parent
5c3e92a137
commit
fbd8b70ca6
+5
-1
@@ -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;
|
||||
|
||||
+12
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Replace with old style 'switch' statement" "true"
|
||||
|
||||
class ReturnCaseNullDefault {
|
||||
int bar(Object o) {
|
||||
switch (o) {
|
||||
case null:
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user