diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java index df75fdf060e8..1892c2df2a8d 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java @@ -608,7 +608,9 @@ public class HighlightUtil { if (isIncorrect) { String description = JavaErrorMessages.message("variable.already.defined", name); HighlightInfo highlightInfo = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, identifier, description); - QuickFixAction.registerQuickFixAction(highlightInfo, new ReuseVariableDeclarationFix(variable, identifier)); + if (!(variable instanceof PsiResourceVariable)) { + QuickFixAction.registerQuickFixAction(highlightInfo, new ReuseVariableDeclarationFix(variable, identifier)); + } return highlightInfo; } return null; diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ReuseVariableDeclarationFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ReuseVariableDeclarationFix.java index 2a681620886f..bd36c7434f41 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ReuseVariableDeclarationFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ReuseVariableDeclarationFix.java @@ -57,7 +57,6 @@ public class ReuseVariableDeclarationFix implements IntentionAction { return myVariable != null && myVariable.isValid() && myVariable instanceof PsiLocalVariable && - !(myVariable.getParent() instanceof PsiResourceVariable && myVariable.getInitializer() == null) && previousVariable != null && Comparing.equal(previousVariable.getType(), myVariable.getType()) && myIdentifier != null && @@ -78,17 +77,9 @@ public class ReuseVariableDeclarationFix implements IntentionAction { } PsiUtil.setModifierProperty(refVariable, PsiModifier.FINAL, false); - final PsiElementFactory factory = JavaPsiFacade.getInstance(myVariable.getProject()).getElementFactory(); - final PsiElement replacement; - final PsiElement parent = myVariable.getParent(); - if (parent instanceof PsiResourceVariable) { - replacement = factory.createResourceFromText(myVariable.getName() + " = " + initializer.getText(), null); - } - else { - replacement = factory.createStatementFromText(myVariable.getName() + " = " + initializer.getText() + ";", null); - } - parent.replace(replacement); + final PsiElement statement = factory.createStatementFromText(myVariable.getName() + " = " + initializer.getText() + ";", null); + myVariable.getParent().replace(statement); } @Nullable diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/reuseVariableDeclaration/after7.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/reuseVariableDeclaration/after7.java deleted file mode 100644 index 5b655ed5ba30..000000000000 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/reuseVariableDeclaration/after7.java +++ /dev/null @@ -1,14 +0,0 @@ -// "Reuse previous variable 'r' declaration" "true" -import java.io.*; - -class a { - static class MyResource implements AutoCloseable { - public void close() { } - } - - void m() { - MyResource r; - try (r = new MyResource()) { - } - } -} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/reuseVariableDeclaration/before7.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/reuseVariableDeclaration/before7.java deleted file mode 100644 index dab83655490c..000000000000 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/reuseVariableDeclaration/before7.java +++ /dev/null @@ -1,14 +0,0 @@ -// "Reuse previous variable 'r' declaration" "true" -import java.io.*; - -class a { - static class MyResource implements AutoCloseable { - public void close() { } - } - - void m() { - MyResource r; - try (MyResource r = new MyResource()) { - } - } -}