mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
ExpectedTypesProvider and CreateLocalFromUsageFix updated for Java 12 (IDEA-204006)
This commit is contained in:
@@ -305,11 +305,26 @@ public class ExpectedTypesProvider {
|
||||
|
||||
@Override
|
||||
public void visitExpressionStatement(PsiExpressionStatement statement) {
|
||||
if (statement.getParent() instanceof PsiSwitchLabeledRuleStatement) {
|
||||
PsiSwitchBlock block = ((PsiSwitchLabeledRuleStatement)statement.getParent()).getEnclosingSwitchBlock();
|
||||
if (block instanceof PsiSwitchExpression) {
|
||||
block.getParent().accept(this);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (myVoidable) {
|
||||
myResult.add(VOID_EXPECTED);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitBreakStatement(PsiBreakStatement statement) {
|
||||
PsiElement exitedElement = statement.findExitedElement();
|
||||
if (exitedElement instanceof PsiSwitchExpression) {
|
||||
exitedElement.getParent().accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitMethodCallExpression(@NotNull PsiMethodCallExpression expression) {
|
||||
myExpr = (PsiExpression)myExpr.getParent();
|
||||
@@ -469,6 +484,15 @@ public class ExpectedTypesProvider {
|
||||
|
||||
@Override
|
||||
public void visitSwitchStatement(@NotNull PsiSwitchStatement statement) {
|
||||
processSwitchBlock(statement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitSwitchExpression(@NotNull PsiSwitchExpression expression) {
|
||||
processSwitchBlock(expression);
|
||||
}
|
||||
|
||||
public void processSwitchBlock(@NotNull PsiSwitchBlock statement) {
|
||||
myResult.add(createInfoImpl(PsiType.LONG, PsiType.INT));
|
||||
if (!PsiUtil.isLanguageLevel5OrHigher(statement)) {
|
||||
return;
|
||||
|
||||
+11
-1
@@ -175,7 +175,17 @@ public class CreateLocalFromUsageFix extends CreateVarFromUsageFix {
|
||||
minOffset = Math.min(minOffset, expressionOccurences[i].getTextRange().getStartOffset());
|
||||
}
|
||||
|
||||
final PsiCodeBlock block = PsiTreeUtil.getParentOfType(parent, PsiCodeBlock.class, false);
|
||||
PsiCodeBlock block = null;
|
||||
while (parent != null) {
|
||||
if (parent instanceof PsiCodeBlock) {
|
||||
block = (PsiCodeBlock)parent;
|
||||
break;
|
||||
} else if (parent instanceof PsiSwitchLabeledRuleStatement) {
|
||||
parent = ((PsiSwitchLabeledRuleStatement)parent).getEnclosingSwitchBlock();
|
||||
} else {
|
||||
parent = parent.getParent();
|
||||
}
|
||||
}
|
||||
LOG.assertTrue(block != null && !block.isEmpty(), "block: " + block +"; parent: " + parent);
|
||||
PsiStatement[] statements = block.getStatements();
|
||||
for (int i = 1; i < statements.length; i++) {
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Create local variable 'foo'" "true"
|
||||
class Foo {
|
||||
String test(int i) {
|
||||
return switch (i) {
|
||||
default -> {
|
||||
String foo;
|
||||
break foo;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Create local variable 'foo'" "true"
|
||||
class Foo {
|
||||
String test(int i) {
|
||||
String foo;
|
||||
return switch (i) {
|
||||
default -> foo;
|
||||
};
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Create local variable 'foo'" "true"
|
||||
class Foo {
|
||||
String test(int i) {
|
||||
int foo;
|
||||
return switch (foo) {
|
||||
default -> {
|
||||
break i;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Create local variable 'foo'" "true"
|
||||
class Foo {
|
||||
String test(int i) {
|
||||
return switch (i) {
|
||||
default -> {
|
||||
break fo<caret>o;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Create local variable 'foo'" "true"
|
||||
class Foo {
|
||||
String test(int i) {
|
||||
return switch (i) {
|
||||
default -> fo<caret>o;
|
||||
};
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Create local variable 'foo'" "true"
|
||||
class Foo {
|
||||
String test(int i) {
|
||||
return switch (f<caret>oo) {
|
||||
default -> {
|
||||
break i;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user