method duplicates: correctly process qualifiers (IDEA-79954)
authoranna <Anna.Kozlova@jetbrains.com>
Mon, 16 Jan 2012 16:10:11 +0000 (17:10 +0100)
committeranna <Anna.Kozlova@jetbrains.com>
Mon, 16 Jan 2012 16:12:19 +0000 (17:12 +0100)
java/java-impl/src/com/intellij/refactoring/util/duplicates/DuplicatesFinder.java
java/java-tests/testData/refactoring/methodDuplicatesMisc/Qualifiers.java [new file with mode: 0644]
java/java-tests/testData/refactoring/methodDuplicatesMisc/Qualifiers.java.after [new file with mode: 0644]
java/java-tests/testSrc/com/intellij/refactoring/FindMethodDuplicatesMiscTest.java

index cf1ca752b9d94118579913e17754eabfaba75264..251118af279768fc8eac1896abee1ab713da1926 100644 (file)
@@ -395,7 +395,7 @@ public class DuplicatesFinder {
         PsiClass contextClass = PsiTreeUtil.getParentOfType(pattern, PsiClass.class);
         if (candidateQualifier instanceof PsiReferenceExpression) {
           final PsiElement resolved = ((PsiReferenceExpression)candidateQualifier).resolve();
-          if (resolved instanceof PsiClass && contextClass != null && contextClass.isInheritor((PsiClass)resolved, true)) {
+          if (resolved instanceof PsiClass && contextClass != null && InheritanceUtil.isInheritorOrSelf(contextClass, (PsiClass)resolved, true)) {
             return true;
           }
         }
@@ -430,7 +430,7 @@ public class DuplicatesFinder {
                 final PsiElement resolved = ((PsiReferenceExpression)patternQualifier).resolve();
                 if (resolved instanceof PsiClass) {
                   final PsiClass classContext = PsiTreeUtil.getParentOfType(candidate, PsiClass.class);
-                  if (classContext != null && classContext.isInheritor((PsiClass)resolved, true)) {
+                  if (classContext != null && InheritanceUtil.isInheritorOrSelf(classContext, (PsiClass)resolved, true)) {
                     return true;
                   }
                 }
diff --git a/java/java-tests/testData/refactoring/methodDuplicatesMisc/Qualifiers.java b/java/java-tests/testData/refactoring/methodDuplicatesMisc/Qualifiers.java
new file mode 100644 (file)
index 0000000..33d05b3
--- /dev/null
@@ -0,0 +1,20 @@
+class Utilz {
+    static int func(){
+        return 1;
+    }
+
+    static int foo1(){
+        return 2*Utilz.func();
+    }
+
+    static int fo<caret>o2(){
+        return 2*func();
+    }
+
+}
+
+class Something {
+    Something(){
+        int x = 2*Utilz.func();
+    }
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/refactoring/methodDuplicatesMisc/Qualifiers.java.after b/java/java-tests/testData/refactoring/methodDuplicatesMisc/Qualifiers.java.after
new file mode 100644 (file)
index 0000000..aebe8e7
--- /dev/null
@@ -0,0 +1,20 @@
+class Utilz {
+    static int func(){
+        return 1;
+    }
+
+    static int foo1(){
+        return foo2();
+    }
+
+    static int foo2(){
+        return 2*func();
+    }
+
+}
+
+class Something {
+    Something(){
+        int x = Utilz.foo2();
+    }
+}
\ No newline at end of file
index 08cf2792a90bba7ea85a4b541b4f0237a2dd26ec..fa0fbcbb3f569e5e043780e2eb4d8d3246b716d6 100644 (file)
@@ -89,4 +89,8 @@ public class FindMethodDuplicatesMiscTest extends FindMethodDuplicatesBaseTest {
   public void testSkipNotAccessible() throws Exception {
     doTest(false);
   }
+  
+  public void testQualifiers() throws Exception {
+    doTest();
+  }
 }
\ No newline at end of file