push down: show conflict if method already exist in target class when super signature...
authorAnna.Kozlova <anna.kozlova@jetbrains.com>
Wed, 4 May 2016 17:27:10 +0000 (19:27 +0200)
committerAnna.Kozlova <anna.kozlova@jetbrains.com>
Wed, 4 May 2016 18:18:45 +0000 (20:18 +0200)
java/java-impl/src/com/intellij/refactoring/memberPushDown/PushDownConflicts.java
java/java-tests/testData/refactoring/pushDown/AlreadyContainsMethodWithTheSignatureForGenericsSuperclass.java [new file with mode: 0644]
java/java-tests/testData/refactoring/pushDown/AlreadyContainsMethodWithTheSignatureForGenericsSuperclass_after.java [new file with mode: 0644]
java/java-tests/testSrc/com/intellij/refactoring/PushDownTest.java

index 21b0b9c49afb5265a9c176a065b05268ca1feb9d..ba2974df4f1c1a1db7c119668e15ffe68b0e8ade 100644 (file)
@@ -19,6 +19,7 @@ import com.intellij.codeInsight.AnnotationUtil;
 import com.intellij.psi.*;
 import com.intellij.psi.search.searches.ReferencesSearch;
 import com.intellij.psi.util.InheritanceUtil;
+import com.intellij.psi.util.MethodSignatureUtil;
 import com.intellij.refactoring.RefactoringBundle;
 import com.intellij.refactoring.util.CommonRefactoringUtil;
 import com.intellij.refactoring.util.RefactoringConflictsUtil;
@@ -157,7 +158,7 @@ public class PushDownConflicts {
       assert modifierList != null;
       if (!modifierList.hasModifierProperty(PsiModifier.ABSTRACT)) {
         PsiMethod method = (PsiMethod)movedMember;
-        final PsiMethod overrider = targetClass.findMethodBySignature(method, false);
+        final PsiMethod overrider = MethodSignatureUtil.findMethodBySuperMethod(targetClass, method, false);
         if (overrider != null) {
           String message = RefactoringBundle.message("0.is.already.overridden.in.1",
                                                      RefactoringUIUtil.getDescription(method, true), RefactoringUIUtil.getDescription(targetClass, false));
diff --git a/java/java-tests/testData/refactoring/pushDown/AlreadyContainsMethodWithTheSignatureForGenericsSuperclass.java b/java/java-tests/testData/refactoring/pushDown/AlreadyContainsMethodWithTheSignatureForGenericsSuperclass.java
new file mode 100644 (file)
index 0000000..3a0cb00
--- /dev/null
@@ -0,0 +1,11 @@
+class Parent<T> {
+  public void fo<caret>o(T p) {
+    System.out.println("a");
+  }
+}
+
+class Child extends Parent {
+  public void foo(Object p) {
+    System.out.println("b");
+  }
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/refactoring/pushDown/AlreadyContainsMethodWithTheSignatureForGenericsSuperclass_after.java b/java/java-tests/testData/refactoring/pushDown/AlreadyContainsMethodWithTheSignatureForGenericsSuperclass_after.java
new file mode 100644 (file)
index 0000000..4ea9146
--- /dev/null
@@ -0,0 +1,8 @@
+class Parent<T> {
+}
+
+class Child extends Parent {
+  public void foo(Object p) {
+    System.out.println("b");
+  }
+}
\ No newline at end of file
index 8ed1bf5cac0a024c7ac47da582dba0768707f90a..0aa5fe9e93e602f71f7c3a41889060bc00c7da7b 100644 (file)
@@ -83,6 +83,10 @@ public class PushDownTest extends LightRefactoringTestCase {
     doTest();
   }
 
+  public void testAlreadyContainsMethodWithTheSignatureForGenericsSuperclass() throws Exception {
+    doTest(true);
+  }
+
   private void doTest() {
     doTest(false);
   }