mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
getUnhandledExceptions: make potentially expensive substitutor calculation a bit lazier
This commit is contained in:
@@ -24,6 +24,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* @author mike
|
||||
@@ -352,7 +353,7 @@ public class ExceptionUtil {
|
||||
final PsiElement resolve = resolveResult.getElement();
|
||||
if (resolve instanceof PsiMethod) {
|
||||
final PsiElement referenceNameElement = methodReferenceExpression.getReferenceNameElement();
|
||||
return getUnhandledExceptions((PsiMethod)resolve, referenceNameElement, topElement, resolveResult.getSubstitutor());
|
||||
return getUnhandledExceptions((PsiMethod)resolve, referenceNameElement, topElement, resolveResult::getSubstitutor);
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -409,7 +410,7 @@ public class ExceptionUtil {
|
||||
if (element instanceof PsiEnumConstant) {
|
||||
final PsiMethod method = ((PsiEnumConstant)element).resolveMethod();
|
||||
if (method != null) {
|
||||
return getUnhandledExceptions(method, element, null, PsiSubstitutor.EMPTY);
|
||||
return getUnhandledExceptions(method, element, null, () -> PsiSubstitutor.EMPTY);
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -466,7 +467,6 @@ public class ExceptionUtil {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
final PsiSubstitutor substitutor = result.getSubstitutor();
|
||||
if (!isArrayClone(method, methodCall) && methodCall instanceof PsiMethodCallExpression) {
|
||||
PsiFile containingFile = methodCall.getContainingFile();
|
||||
MethodResolverProcessor processor = new MethodResolverProcessor((PsiMethodCallExpression)methodCall, containingFile);
|
||||
@@ -486,11 +486,11 @@ public class ExceptionUtil {
|
||||
});
|
||||
if (!candidates.isEmpty()) {
|
||||
GlobalSearchScope scope = methodCall.getResolveScope();
|
||||
final List<PsiClassType> ex = collectSubstituted(substitutor, thrownExceptions, scope);
|
||||
List<PsiClassType> ex = collectSubstituted(result.getSubstitutor(), thrownExceptions, scope);
|
||||
for (Pair<PsiMethod, PsiSubstitutor> pair : candidates) {
|
||||
final PsiClassType[] exceptions = pair.first.getThrowsList().getReferencedTypes();
|
||||
if (exceptions.length == 0) {
|
||||
return getUnhandledExceptions(methodCall, topElement, PsiSubstitutor.EMPTY, PsiClassType.EMPTY_ARRAY);
|
||||
return Collections.emptyList();
|
||||
}
|
||||
retainExceptions(ex, collectSubstituted(pair.second, exceptions, scope));
|
||||
}
|
||||
@@ -502,7 +502,7 @@ public class ExceptionUtil {
|
||||
}
|
||||
}
|
||||
|
||||
return getUnhandledExceptions(method, methodCall, topElement, substitutor);
|
||||
return getUnhandledExceptions(method, methodCall, topElement, result::getSubstitutor);
|
||||
}
|
||||
|
||||
public static void retainExceptions(List<PsiClassType> ex, List<? extends PsiClassType> thrownEx) {
|
||||
@@ -646,15 +646,19 @@ public class ExceptionUtil {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<PsiClassType> getUnhandledExceptions(@NotNull PsiMethod method,
|
||||
private static List<PsiClassType> getUnhandledExceptions(@NotNull PsiMethod method,
|
||||
PsiElement element,
|
||||
PsiElement topElement,
|
||||
@NotNull PsiSubstitutor substitutor) {
|
||||
@NotNull Supplier<PsiSubstitutor> substitutor) {
|
||||
if (isArrayClone(method, element)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
final PsiClassType[] referencedTypes = method.getThrowsList().getReferencedTypes();
|
||||
return getUnhandledExceptions(element, topElement, substitutor, referencedTypes);
|
||||
if (referencedTypes.length == 0) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return getUnhandledExceptions(element, topElement, substitutor.get(), referencedTypes);
|
||||
}
|
||||
|
||||
private static List<PsiClassType> getUnhandledExceptions(PsiElement element,
|
||||
|
||||
Reference in New Issue
Block a user