new inference: throws clause processed

This commit is contained in:
anna
2013-10-31 16:35:37 +01:00
parent eebe810bf4
commit 47fee8e129
@@ -445,14 +445,18 @@ public class InferenceSession {
}
else if (acceptObject || upperBounds.size() > 1 || !upperBounds.get(0).equalsToText(CommonClassNames.JAVA_LANG_OBJECT)) {
PsiType glb = null;
for (PsiType upperBound : upperBounds) {
upperBound = acceptBoundsWithRecursiveDependencies(typeParameter, upperBound, substitutor);
if (isProperType(upperBound, false)) {
if (glb == null) {
glb = upperBound;
}
else {
glb = GenericsUtil.getGreatestLowerBound(glb, upperBound);
if (isThrowable(upperBounds)) {
glb = PsiType.getJavaLangRuntimeException(myManager, GlobalSearchScope.allScope(myManager.getProject()));
} else {
for (PsiType upperBound : upperBounds) {
upperBound = acceptBoundsWithRecursiveDependencies(typeParameter, upperBound, substitutor);
if (isProperType(upperBound, false)) {
if (glb == null) {
glb = upperBound;
}
else {
glb = GenericsUtil.getGreatestLowerBound(glb, upperBound);
}
}
}
}
@@ -473,6 +477,20 @@ public class InferenceSession {
return substitutor;
}
private static boolean isThrowable(List<PsiType> upperBounds) {
boolean commonThrowable = false;
for (PsiType upperBound : upperBounds) {
if (upperBound.equalsToText(CommonClassNames.JAVA_LANG_OBJECT)) continue;
if (upperBound.equalsToText(CommonClassNames.JAVA_LANG_EXCEPTION) ||
upperBound.equalsToText(CommonClassNames.JAVA_LANG_THROWABLE)) {
commonThrowable = true;
} else {
return false;
}
}
return commonThrowable;
}
private PsiType acceptBoundsWithRecursiveDependencies(PsiTypeParameter typeParameter, PsiType bound, PsiSubstitutor substitutor) {
if (!isProperType(bound)) {
final PsiSubstitutor subst = PsiUtil.resolveClassInType(bound) != typeParameter ? substitutor.put(typeParameter, null) : substitutor;