refactor after review IDEA-CR-33048

This commit is contained in:
Anna Kozlova
2018-05-30 16:31:02 +03:00
parent a97212d845
commit f1862f7e01
3 changed files with 4 additions and 19 deletions
@@ -117,12 +117,7 @@ public abstract class BaseConvertToLocalQuickFix<V extends PsiVariable> implemen
variable,
refsSet,
delete,
declaration -> {
if (!mayBeFinal(firstElement, references)) {
PsiUtil.setModifierProperty((PsiModifierListOwner)declaration.getDeclaredElements()[0], PsiModifier.FINAL, false);
}
return anchor.replace(declaration);
}
declaration -> anchor.replace(declaration)
);
}
@@ -219,15 +214,6 @@ public abstract class BaseConvertToLocalQuickFix<V extends PsiVariable> implemen
@NotNull
protected abstract String suggestLocalName(@NotNull Project project, @NotNull V variable, @NotNull PsiCodeBlock scope);
private static boolean mayBeFinal(PsiElement firstElement, @NotNull Collection<PsiReference> references) {
for (PsiReference reference : references) {
final PsiElement element = reference.getElement();
if (element == firstElement) continue;
if (element instanceof PsiExpression && PsiUtil.isAccessedForWriting((PsiExpression)element)) return false;
}
return true;
}
private static void retargetReferences(PsiElementFactory elementFactory, String localName, Collection<PsiReference> refs)
throws IncorrectOperationException {
final PsiReferenceExpression refExpr = (PsiReferenceExpression)elementFactory.createExpressionFromText(localName, null);
@@ -2,8 +2,8 @@
class Test {
int getFoo1() {
int myFoo = 1;
myFoo = 5;
int myFoo;
while (true) myFoo = 1;
return myFoo;
}
}
@@ -3,8 +3,7 @@ class Test {
private int my<caret>Foo;
int getFoo1() {
myFoo = 1;
myFoo = 5;
while (true) myFoo = 1;
return myFoo;
}
}