mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java-inspections] IDEA-287311 Bug: Inspection 'bring variable into scope' introduces Compilation error when used with 'var'
GitOrigin-RevId: 85f7f526ec1cee6533f441bf42bc43b1b0bb8be1
This commit is contained in:
committed by
intellij-monorepo-bot
parent
eea5b2207e
commit
c7ed6477fb
+4
@@ -123,6 +123,10 @@ public final class BringVariableIntoScopeFix implements IntentionAction, HighPri
|
||||
PsiDeclarationStatement newDeclaration = (PsiDeclarationStatement)JavaPsiFacade.getElementFactory(manager.getProject()).createStatementFromText("int i = 0", null);
|
||||
PsiVariable variable = (PsiVariable)newDeclaration.getDeclaredElements()[0].replace(outOfScopeVariable);
|
||||
if (variable.getInitializer() != null) {
|
||||
PsiTypeElement typeElement = variable.getTypeElement();
|
||||
if (typeElement != null && typeElement.isInferredType()) {
|
||||
PsiTypesUtil.replaceWithExplicitType(typeElement);
|
||||
}
|
||||
variable.getInitializer().delete();
|
||||
}
|
||||
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Bring 'String msg' into scope" "true"
|
||||
public class BringVarIntoScope {
|
||||
public void moveVariableDeclarationOutOfBlock(boolean b) {
|
||||
String msg;
|
||||
if (b) {
|
||||
msg = "Leap year";
|
||||
} else {
|
||||
msg = "Not a leap year";
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Bring 'String msg' into scope" "true"
|
||||
public class BringVarIntoScope {
|
||||
public void moveVariableDeclarationOutOfBlock(boolean b) {
|
||||
if (b) {
|
||||
var msg = "Leap year";
|
||||
} else {
|
||||
<caret>msg = "Not a leap year";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user