EnhancedSwitchMigrationInspection: proper condition for non-exhaustive switch

GitOrigin-RevId: 7e0310220f13821a87cc0e231d12f403af65b4e1
This commit is contained in:
Roman.Ivanov
2020-02-20 09:19:30 +00:00
committed by intellij-monorepo-bot
parent 5c186cba88
commit 620b2c353f
4 changed files with 7 additions and 6 deletions
@@ -480,11 +480,12 @@ public class EnhancedSwitchMigrationInspection extends AbstractBaseJavaLocalInsp
}
if (assignedVariable == null || !hasAssignedBranch) return null;
boolean isRightAfterDeclaration = isRightAfterDeclaration(anchor, assignedVariable);
if (!wasDefault || !isExhaustive) {
if (!wasDefault) {
SwitchExpressionBranch defaultBranch = getVariableAssigningDefaultBranch(assignedVariable, isRightAfterDeclaration, statement);
if (defaultBranch == null) {
} else {
if (defaultBranch != null) {
newBranches.add(defaultBranch);
} else if (!isExhaustive) {
return null;
}
}
return new SwitchExistingVariableReplacer(assignedVariable, statement, expressionBeingSwitched, newBranches, isRightAfterDeclaration);
@@ -2,7 +2,7 @@
import java.util.*;
class SwitchExpressionMigration {
private static void m() {
private static void m(String s) {
int result = switch (s) {
case "a" -> 1;
case "b" -> 2;
@@ -2,7 +2,7 @@
import java.util.*;
class SwitchExpressionMigration {
private static void m() {
private static void m(String s) {
int result = 0;
switch<caret>(s) {
case "a": result = 1; break;
@@ -2,7 +2,7 @@
import java.util.*;
class SwitchExpressionMigration {
private static void m() {
private static void m(String s) {
int result;
switch<caret>(s) {
case "a": result = 1; break;