compose throws list on override: ignore supers of super method, ensure same thrown types do not appear in the list (IDEA-166623)

This commit is contained in:
Anna Kozlova
2017-01-18 11:13:43 +03:00
parent 5a23cba5fa
commit 326ad95830
7 changed files with 82 additions and 8 deletions

View File

@@ -34,10 +34,7 @@ import com.intellij.psi.impl.source.codeStyle.JavaCodeStyleManagerImpl;
import com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl;
import com.intellij.psi.javadoc.PsiDocComment;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.PropertyUtil;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtil;
import com.intellij.psi.util.TypeConversionUtil;
import com.intellij.psi.util.*;
import com.intellij.refactoring.util.RefactoringUtil;
import com.intellij.util.Function;
import com.intellij.util.IncorrectOperationException;
@@ -297,7 +294,7 @@ public class GenerateMembersUtil {
if (target instanceof PsiClass) {
final PsiMethod[] methods = ((PsiClass)target).findMethodsBySignature(sourceMethod, true);
for (PsiMethod psiMethod : methods) {
if (psiMethod != null && psiMethod != sourceMethod) {
if (psiMethod != null && psiMethod != sourceMethod && !MethodSignatureUtil.isSuperMethod(psiMethod, sourceMethod)) {
PsiClass aSuper = psiMethod.getContainingClass();
if (aSuper != null && aSuper != target) {
PsiSubstitutor superClassSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(aSuper, (PsiClass)target, PsiSubstitutor.EMPTY);

View File

@@ -515,16 +515,14 @@ public class ExceptionUtil {
} else if (classType.isAssignableFrom(psiClassType)) {
if (isUncheckedException(classType) == isUncheckedException(psiClassType)) {
replacement.add(psiClassType);
iterator.remove();
}
found = true;
break;
}
}
if (!found) {
iterator.remove();
}
}
ex.removeAll(replacement);
ex.addAll(replacement);
}

View File

@@ -0,0 +1,21 @@
import java.io.FileNotFoundException;
import java.io.IOException;
class Outer {
private interface IA {
void print() throws FileNotFoundException, IOException;
}
private static class A implements IA {
public void print() throws FileNotFoundException, IOException {
}
}
private static class B extends A {
@Override
public void print() throws FileNotFoundException, IOException {
super.print();
}
}
}

View File

@@ -0,0 +1,20 @@
import java.io.FileNotFoundException;
import java.io.IOException;
class Outer {
private interface IA {
void print() throws FileNotFoundException, IOException;
}
private static class A {
public void print() throws FileNotFoundException, IOException {
}
}
private static class B extends A implements IA {
public void print() throws IOException, FileNotFoundException {
}
}
}

View File

@@ -0,0 +1,18 @@
import java.io.FileNotFoundException;
import java.io.IOException;
class Outer {
private interface IA {
void print() throws FileNotFoundException, IOException;
}
private static class A implements IA {
public void print() throws FileNotFoundException, IOException {
}
}
private static class B extends A {
<caret>
}
}

View File

@@ -0,0 +1,18 @@
import java.io.FileNotFoundException;
import java.io.IOException;
class Outer {
private interface IA {
void print() throws FileNotFoundException, IOException;
}
private static class A {
public void print() throws FileNotFoundException, IOException {
}
}
private static class B extends A implements IA {
<caret>
}
}

View File

@@ -54,6 +54,8 @@ public class OverrideImplement15Test extends LightCodeInsightTestCase {
public void testSimple() { doTest(true); }
public void testAnnotation() { doTest(true); }
public void testJavadocForChangedParamName() { doTest(true); }
public void testThrowsListFromMethodHierarchy() { doTest(true); }
public void testThrowsListUnrelatedMethods() { doTest(true); }
public void testIncomplete() { doTest(false); }
public void testSubstitutionInTypeParametersList() { doTest(false); }
public void testTestMissed() { doTest(false); }