rename: do not qualify refs to fields with this in static context

This commit is contained in:
Anna Kozlova
2013-01-24 21:18:51 +04:00
parent 5379de1358
commit f5abe71123
4 changed files with 21 additions and 2 deletions
@@ -43,8 +43,9 @@ class JavaResolveSnapshot extends ResolveSnapshotProvider.ResolveSnapshot {
scope.accept(new JavaRecursiveElementWalkingVisitor() {
@Override public void visitReferenceExpression(PsiReferenceExpression refExpr) {
if (!refExpr.isQualified()) {
PsiElement resolved = refExpr.resolve();
if (resolved instanceof PsiField) {
JavaResolveResult resolveResult = refExpr.advancedResolve(false);
final PsiElement resolved = resolveResult.getElement();
if (resolved instanceof PsiField && resolveResult.isStaticsScopeCorrect()) {
SmartPsiElementPointer key = pointerManager.createSmartPsiElementPointer(refExpr);
SmartPsiElementPointer value = pointers.get(resolved);
if (value == null) {
@@ -0,0 +1,7 @@
class Test {
String myFoo;
static {
String f<caret>oo = "";
System.out.println(myFoo);
}
}
@@ -0,0 +1,7 @@
class Test {
String myFoo;
static {
String myFoo = "";
System.out.println(myFoo);
}
}
@@ -109,6 +109,10 @@ public class RenameLocalTest extends LightRefactoringTestCase {
doTestInplaceRename("r1");
}
public void testRenameToFieldNameInStaticContext() throws Exception {
doTestInplaceRename("myFoo");
}
public void testRenameInPlaceInStaticContextWithConflictingField() throws Exception {
doTestInplaceRename("s");
}