mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java-inspections] IDEA-333228 AIOOBE: EnhancedSwitchMigrationInspection.inspectReturningSwitch
- fix case, when `default` is not last GitOrigin-RevId: 93d12d7a0d4a929c58630a4a6f1f5b2c9a10d039
This commit is contained in:
committed by
intellij-monorepo-bot
parent
b128380722
commit
0c27b276dc
+4
-1
@@ -486,7 +486,7 @@ public class EnhancedSwitchMigrationInspection extends AbstractBaseJavaLocalInsp
|
||||
statements = psiCodeBlock.getCodeBlock().getStatements();
|
||||
}
|
||||
if (statements.length == 0) {
|
||||
if (i == branches.size() - 1) {
|
||||
if ((i == branches.size() - 1) || branch.isDefault()) {
|
||||
if (returnAfterSwitch != null) {
|
||||
statements = new PsiStatement[]{returnAfterSwitch};
|
||||
}
|
||||
@@ -497,6 +497,9 @@ public class EnhancedSwitchMigrationInspection extends AbstractBaseJavaLocalInsp
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (maxLines < statements.length) {
|
||||
maxLines = statements.length;
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Replace with 'switch' expression" "true-preview"
|
||||
|
||||
class X {
|
||||
enum State {
|
||||
CANCELLED, INTERRUPTING, NORMAL
|
||||
}
|
||||
|
||||
String test(State state, String outcome) {
|
||||
return switch (state) {
|
||||
default -> "1";
|
||||
case CANCELLED, INTERRUPTED -> "2";
|
||||
};
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// "Replace with 'switch' expression" "true-preview"
|
||||
|
||||
class X {
|
||||
enum State {
|
||||
CANCELLED, INTERRUPTING, NORMAL
|
||||
}
|
||||
|
||||
String test(State state, String outcome) {
|
||||
sw<caret>itch (state){
|
||||
default:
|
||||
break;
|
||||
case CANCELLED:
|
||||
case INTERRUPTED:
|
||||
return "2";
|
||||
}
|
||||
return "1";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user