[java-highlighting] [java-inspections] IDEA-327632

Conversion to enhanced switch produces incorrect code.

- Added checks that branches don't have a fast exit

GitOrigin-RevId: 33c6cffa421a3b0c3c5b9f9f1ea29127c7a99d29
This commit is contained in:
Mikhail Pyltsin
2023-08-05 21:56:58 +02:00
committed by intellij-monorepo-bot
parent 23e26fa546
commit 2ba4582735
3 changed files with 46 additions and 1 deletions

View File

@@ -0,0 +1,18 @@
// "Replace with enhanced 'switch' expression" "false"
class SwitchToExpressionWithBreak {
public int test(Object o) {
int i;
sw<caret>itch (o) {
case String s:
if (s.length() == 1) {
break;
}
i = 1;
break;
default:
i = 2;
}
return i;
}
}

View File

@@ -0,0 +1,18 @@
// "Replace with enhanced 'switch' expression" "false"
class SwitchToExpressionWithReturn {
public int test(Object o) {
int i;
sw<caret>itch (o) {
case String s:
if (s.length() == 1) {
return 1;
}
i = 1;
break;
default:
i = 2;
}
return i;
}
}