IDEA-79290 Inline Local Variable does not qualify accesses to obscured types
authorAnna Kozlova <anna.kozlova@jetbrains.com>
Wed, 25 Jan 2012 10:48:59 +0000 (14:48 +0400)
committerAnna Kozlova <anna.kozlova@jetbrains.com>
Wed, 25 Jan 2012 11:26:11 +0000 (15:26 +0400)
java/java-impl/src/com/intellij/psi/impl/source/codeStyle/ReferenceAdjuster.java
java/java-tests/testData/refactoring/inlineLocal/Qualified.java [new file with mode: 0644]
java/java-tests/testData/refactoring/inlineLocal/Qualified.java.after [new file with mode: 0644]
java/java-tests/testSrc/com/intellij/refactoring/inline/InlineLocalTest.java

index bbabfc85fc859ecbd18a95d3b1ca4401703ddc67..f223dd2262193f922492233e6ab963953aa02cea 100644 (file)
@@ -221,7 +221,8 @@ public class ReferenceAdjuster {
   private static boolean isSafeToShortenReference(final String referenceText, final PsiElement psiReference, final PsiClass refClass) {
     final PsiManager manager = refClass.getManager();
     final JavaPsiFacade facade = JavaPsiFacade.getInstance(manager.getProject());
-    return manager.areElementsEquivalent(refClass, facade.getResolveHelper().resolveReferencedClass(referenceText, psiReference));
+    final PsiResolveHelper helper = facade.getResolveHelper();
+    return manager.areElementsEquivalent(refClass, helper.resolveReferencedClass(referenceText, psiReference)) && helper.resolveReferencedVariable(referenceText, psiReference) == null;
   }
 
   @NotNull
diff --git a/java/java-tests/testData/refactoring/inlineLocal/Qualified.java b/java/java-tests/testData/refactoring/inlineLocal/Qualified.java
new file mode 100644 (file)
index 0000000..dc626e0
--- /dev/null
@@ -0,0 +1,17 @@
+public class A {
+  int f = 23;
+
+  static class B {
+    static int f = 42;
+  }
+
+  int foo() {
+    int r = B.f;
+    A B = this;
+    return r<caret>;
+  }
+
+  public static void main(String[] args) {
+    System.out.println(new A().foo());
+  }
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/refactoring/inlineLocal/Qualified.java.after b/java/java-tests/testData/refactoring/inlineLocal/Qualified.java.after
new file mode 100644 (file)
index 0000000..102be05
--- /dev/null
@@ -0,0 +1,16 @@
+public class A {
+  int f = 23;
+
+  static class B {
+    static int f = 42;
+  }
+
+  int foo() {
+      A B = this;
+    return A.B.f;
+  }
+
+  public static void main(String[] args) {
+    System.out.println(new A().foo());
+  }
+}
\ No newline at end of file
index c0e4cb1784b34210767b776efa0ac4da821806ed..e4bde4df16c0c4ac6dea4399d6c5fe41b4003442 100644 (file)
@@ -4,8 +4,6 @@ import com.intellij.JavaTestUtil;
 import com.intellij.codeInsight.TargetElementUtilBase;
 import com.intellij.openapi.editor.Editor;
 import com.intellij.openapi.project.Project;
-import com.intellij.openapi.projectRoots.Sdk;
-import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
 import com.intellij.psi.PsiElement;
 import com.intellij.psi.PsiLocalVariable;
 import com.intellij.psi.PsiReference;
@@ -130,6 +128,11 @@ public class InlineLocalTest extends LightCodeInsightTestCase {
     doTest(true);
   }
 
+  public void testQualified() throws Exception {
+    doTest(true);
+  }
+
+
   private void doTest(final boolean inlineDef, String conflictMessage) throws Exception {
     try {
       doTest(inlineDef);