intersect thrown types when implementing 2 interfaces with same method signature...
authorAnna Kozlova <anna.kozlova@jetbrains.com>
Thu, 3 Sep 2015 17:06:32 +0000 (20:06 +0300)
committerAnna Kozlova <anna.kozlova@jetbrains.com>
Thu, 3 Sep 2015 17:31:03 +0000 (20:31 +0300)
java/java-impl/src/com/intellij/codeInsight/generation/GenerateMembersUtil.java
java/java-tests/testData/codeInsight/overrideImplement/afterMultipleInheritanceWithThrowables.java [new file with mode: 0644]
java/java-tests/testData/codeInsight/overrideImplement/beforeMultipleInheritanceWithThrowables.java [new file with mode: 0644]
java/java-tests/testSrc/com/intellij/codeInsight/OverrideImplementTest.groovy

index 317b3db20dce52fb5c1f0087ebb9ec4694e46699..fc144a98927dcd1568193c4895f6216093c069ca 100644 (file)
@@ -282,12 +282,14 @@ public class GenerateMembersUtil {
       final List<PsiClassType> thrownTypes = ExceptionUtil.collectSubstituted(collisionResolvedSubstitutor, sourceMethod.getThrowsList().getReferencedTypes(),
                                                                               scope);
       if (target instanceof PsiClass) {
-        final PsiClass[] supers = ((PsiClass)target).getSupers();
-        for (PsiClass aSuper : supers) {
-          final PsiMethod psiMethod = aSuper.findMethodBySignature(sourceMethod, true);
+        final PsiMethod[] methods = ((PsiClass)target).findMethodsBySignature(sourceMethod, true);
+        for (PsiMethod psiMethod : methods) {
           if (psiMethod != null && psiMethod != sourceMethod) {
-            PsiSubstitutor superClassSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(aSuper, (PsiClass)target, PsiSubstitutor.EMPTY);
-            ExceptionUtil.retainExceptions(thrownTypes, ExceptionUtil.collectSubstituted(superClassSubstitutor, psiMethod.getThrowsList().getReferencedTypes(), scope));
+            PsiClass aSuper = psiMethod.getContainingClass();
+            if (aSuper != null && aSuper != target) {
+              PsiSubstitutor superClassSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(aSuper, (PsiClass)target, PsiSubstitutor.EMPTY);
+              ExceptionUtil.retainExceptions(thrownTypes, ExceptionUtil.collectSubstituted(superClassSubstitutor, psiMethod.getThrowsList().getReferencedTypes(), scope));
+            }
           }
         }
       }
diff --git a/java/java-tests/testData/codeInsight/overrideImplement/afterMultipleInheritanceWithThrowables.java b/java/java-tests/testData/codeInsight/overrideImplement/afterMultipleInheritanceWithThrowables.java
new file mode 100644 (file)
index 0000000..f652912
--- /dev/null
@@ -0,0 +1,16 @@
+interface A {
+    void a() throws java.io.IOException;
+}
+
+interface B {
+    void a() throws InstantiationException;
+}
+
+interface C extends A, B {}
+
+class D implements C {
+    @Override
+    public void a() {
+        
+    }
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/codeInsight/overrideImplement/beforeMultipleInheritanceWithThrowables.java b/java/java-tests/testData/codeInsight/overrideImplement/beforeMultipleInheritanceWithThrowables.java
new file mode 100644 (file)
index 0000000..f45cdc4
--- /dev/null
@@ -0,0 +1,13 @@
+interface A {
+    void a() throws java.io.IOException;
+}
+
+interface B {
+    void a() throws InstantiationException;
+}
+
+interface C extends A, B {}
+
+class D implements C {
+    <caret>
+}
\ No newline at end of file
index 1fc816e173325be18f7091f10334488261e0ac87..4dd320974f5b09609d98657f9369d9a56b384137 100644 (file)
@@ -39,6 +39,7 @@ class OverrideImplementTest extends LightCodeInsightFixtureTestCase {
   public void testSkipUnknownAnnotations() { doTest(true) }
   public void testMultipleInheritedThrows() { doTest(false) }
   public void testOverrideInInterface() { doTest(false) }
+  public void testMultipleInheritanceWithThrowables() { doTest(true) }
 
   public void testImplementInInterface() {
     myFixture.addClass """\