intersect thrown types when implementing 2 interfaces with same method signature (IDEA-82426)

This commit is contained in:
Anna Kozlova
2015-09-03 20:06:32 +03:00
parent b22c0040f7
commit 788d7d0e3c
4 changed files with 37 additions and 5 deletions

View 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));
}
}
}
}

View File

@@ -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() {
}
}

View File

@@ -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>
}

View 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 """\