Fix ExpectedTypesProvider for completion inside switch expressions (IDEA-204680)

Review ID: IDEA-CR-41558
This commit is contained in:
Tagir Valeev
2018-12-25 12:50:07 +07:00
parent 3f224f0fcd
commit 36fee2ff50
6 changed files with 48 additions and 0 deletions

View File

@@ -308,6 +308,9 @@ public class ExpectedTypesProvider {
if (statement.getParent() instanceof PsiSwitchLabeledRuleStatement) {
PsiSwitchBlock block = ((PsiSwitchLabeledRuleStatement)statement.getParent()).getEnclosingSwitchBlock();
if (block instanceof PsiSwitchExpression) {
if (myForCompletion) {
myExpr = (PsiSwitchExpression)block;
}
block.getParent().accept(this);
return;
}
@@ -321,6 +324,9 @@ public class ExpectedTypesProvider {
public void visitBreakStatement(PsiBreakStatement statement) {
PsiElement exitedElement = statement.findExitedElement();
if (exitedElement instanceof PsiSwitchExpression) {
if (myForCompletion) {
myExpr = (PsiExpression)exitedElement;
}
exitedElement.getParent().accept(this);
}
}

View File

@@ -0,0 +1,11 @@
public class ConstConfig {
int test(boolean aaaaaaaa) {
Boolean b;
if ((b = switch (0) {
case 1: {
break aaaa<caret>;
}
default: break false;
}));
}
}

View File

@@ -0,0 +1,11 @@
public class ConstConfig {
int test(boolean aaaaaaaa) {
Boolean b;
if ((b = switch (0) {
case 1: {
break aaaaaaaa<caret>;
}
default: break false;
}));
}
}

View File

@@ -0,0 +1,9 @@
public class ConstConfig {
int test(boolean aaaaaaaa) {
Boolean b;
if ((b = switch (0) {
case 1 -> aaaa<caret>;
default -> break false;
}));
}
}

View File

@@ -0,0 +1,9 @@
public class ConstConfig {
int test(boolean aaaaaaaa) {
Boolean b;
if ((b = switch (0) {
case 1 -> aaaaaaaa<caret>;
default -> break false;
}));
}
}

View File

@@ -21,4 +21,6 @@ class Normal12CompletionTest extends NormalCompletionTestCase {
void testSecondLabelInRuleSwitch() throws Throwable { doTest() }
void testSwitchExpressionStart() throws Throwable { doTest() }
void testBreakInSwitchExpression() throws Throwable { doTest() }
void testInsideBreakInSwitchExpression() throws Throwable { doTest() }
void testInsideRuleInSwitchExpression() throws Throwable { doTest() }
}