mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
"Reuse variable declaration" no more suitable for resource variables
This commit is contained in:
@@ -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;
|
||||
|
||||
+2
-11
@@ -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
|
||||
|
||||
-14
@@ -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()) {
|
||||
}
|
||||
}
|
||||
}
|
||||
-14
@@ -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 <caret>r = new MyResource()) {
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user