override from multiple interfaces with throws lists: intersect throws lists

This commit is contained in:
Anna Kozlova
2013-06-25 20:15:27 +04:00
parent 6c3d6d2caa
commit 59af6284bd
5 changed files with 53 additions and 11 deletions
@@ -15,6 +15,7 @@
*/
package com.intellij.codeInsight.generation;
import com.intellij.codeInsight.ExceptionUtil;
import com.intellij.codeInsight.daemon.impl.quickfix.CreateFromUsageUtils;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.diagnostic.Logger;
@@ -42,10 +43,7 @@ import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.*;
public class GenerateMembersUtil {
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.generation.GenerateMembersUtil");
@@ -266,7 +264,17 @@ public class GenerateMembersUtil {
substituteTypeParameters(factory, target, sourceMethod.getTypeParameterList(), resultMethod.getTypeParameterList(), substitutor, sourceMethod);
substituteReturnType(PsiManager.getInstance(project), resultMethod, sourceMethod.getReturnType(), collisionResolvedSubstitutor);
substituteParameters(factory, codeStyleManager, sourceMethod.getParameterList(), resultMethod.getParameterList(), collisionResolvedSubstitutor, target);
substituteThrows(factory, sourceMethod.getThrowsList(), resultMethod.getThrowsList(), collisionResolvedSubstitutor, sourceMethod);
final List<PsiClassType> thrownTypes = ExceptionUtil.collectSubstituted(collisionResolvedSubstitutor, sourceMethod.getThrowsList().getReferencedTypes());
if (target instanceof PsiClass) {
final PsiClass[] supers = ((PsiClass)target).getSupers();
for (PsiClass aSuper : supers) {
final PsiMethod psiMethod = aSuper.findMethodBySignature(sourceMethod, true);
if (psiMethod != null && psiMethod != sourceMethod) {
ExceptionUtil.retainExceptions(thrownTypes, ExceptionUtil.collectSubstituted(TypeConversionUtil.getSuperClassSubstitutor(aSuper, (PsiClass)target, PsiSubstitutor.EMPTY), psiMethod.getThrowsList().getReferencedTypes()));
}
}
}
substituteThrows(factory, resultMethod.getThrowsList(), collisionResolvedSubstitutor, sourceMethod, thrownTypes);
return resultMethod;
}
catch (IncorrectOperationException e) {
@@ -400,11 +408,11 @@ public class GenerateMembersUtil {
}
private static void substituteThrows(@NotNull JVMElementFactory factory,
@NotNull PsiReferenceList sourceThrowsList,
@NotNull PsiReferenceList targetThrowsList,
@NotNull PsiSubstitutor substitutor,
@NotNull PsiMethod sourceMethod) {
for (PsiClassType thrownType : sourceThrowsList.getReferencedTypes()) {
@NotNull PsiSubstitutor substitutor,
@NotNull PsiMethod sourceMethod,
List<PsiClassType> thrownTypes) {
for (PsiClassType thrownType : thrownTypes) {
targetThrowsList.add(factory.createReferenceElementByType((PsiClassType)substituteType(substitutor, thrownType, sourceMethod)));
}
}
@@ -439,7 +439,7 @@ public class ExceptionUtil {
return getUnhandledExceptions(method, methodCall, topElement, substitutor);
}
private static void retainExceptions(List<PsiClassType> ex, List<PsiClassType> thrownEx) {
public static void retainExceptions(List<PsiClassType> ex, List<PsiClassType> thrownEx) {
final List<PsiClassType> replacement = new ArrayList<PsiClassType>();
for (Iterator<PsiClassType> iterator = ex.iterator(); iterator.hasNext(); ) {
PsiClassType classType = iterator.next();
@@ -462,7 +462,7 @@ public class ExceptionUtil {
ex.addAll(replacement);
}
private static List<PsiClassType> collectSubstituted(PsiSubstitutor substitutor, PsiClassType[] thrownExceptions) {
public static List<PsiClassType> collectSubstituted(PsiSubstitutor substitutor, PsiClassType[] thrownExceptions) {
final List<PsiClassType> ex = new ArrayList<PsiClassType>();
for (PsiClassType thrownException : thrownExceptions) {
final PsiType psiType = substitutor.substitute(thrownException);
@@ -0,0 +1,17 @@
import java.io.*;
interface A {
void close() throws Exception;
}
interface B {
void close() throws IOException;
}
interface C<T extends Exception> {
void close() throws T;
}
interface AB extends A, C, B {
@Override
void close() throws IOException;
}
@@ -0,0 +1,16 @@
import java.io.*;
interface A {
void close() throws Exception;
}
interface B {
void close() throws IOException;
}
interface C<T extends Exception> {
void close() throws T;
}
interface AB extends A, C, B {
<caret>
}
@@ -73,6 +73,7 @@ public class OverrideImplementTest extends LightCodeInsightTestCase {
public void testOverrideInInterface() { doTest8(false, false); }
public void testMultipleInheritedThrows() {doTest8(false, false);}
public void testLongFinalParameterList() {
CodeStyleSettings codeStyleSettings = CodeStyleSettingsManager.getSettings(getProject()).clone();