[java-analysis] PsiSubstitutor.hasRawSubstitution

Optimize partially IDEA-353780 Syntax Analysis hangs forever with complex use of Java generic parameters

GitOrigin-RevId: 3b6d77db8353c21e0d09c9c28d551c1edd6c5e1d
This commit is contained in:
Tagir Valeev
2024-05-21 18:48:36 +02:00
committed by intellij-monorepo-bot
parent efea905a99
commit 3f46270d18
5 changed files with 22 additions and 3 deletions

View File

@@ -41,6 +41,11 @@ public final class EmptySubstitutor implements PsiSubstitutor {
return type;
}
@Override
public boolean hasRawSubstitution() {
return false;
}
@Override
public PsiType substituteWithBoundsPromotion(@NotNull PsiTypeParameter typeParameter) {
return JavaPsiFacade.getElementFactory(typeParameter.getProject()).createType(typeParameter);

View File

@@ -51,6 +51,13 @@ public interface PsiSubstitutor {
@Contract(pure = true, value = "null -> null")
PsiType substitute(@Nullable PsiType type);
/**
* @return true if this substitutor has at least one raw substitution
*/
default boolean hasRawSubstitution() {
return getSubstitutionMap().containsValue(null);
}
//Should be used with great care, be sure to prevent infinite recursion that could arise
// from the use of recursively bounded type parameters
@Contract(pure = true)

View File

@@ -1057,7 +1057,7 @@ public final class PsiUtil extends PsiUtilCore {
}
public static boolean isRawSubstitutor(@NotNull PsiTypeParameterListOwner owner, @NotNull PsiSubstitutor substitutor) {
if (substitutor == PsiSubstitutor.EMPTY) return false;
if (!substitutor.hasRawSubstitution()) return false;
for (PsiTypeParameter parameter : typeParametersIterable(owner)) {
if (substitutor.substitute(parameter) == null) return true;