From ddeea16f5bc372ced15a9f6948bb659b6cdc6193 Mon Sep 17 00:00:00 2001 From: anna Date: Fri, 4 Oct 2013 19:15:07 +0200 Subject: [PATCH] new inference: infer from type pair with PsiType.NULL when not enough data is provided --- .../PsiGraphInferenceHelper.java | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/PsiGraphInferenceHelper.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/PsiGraphInferenceHelper.java index 82bd1215df4f..84c8b7cef80f 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/PsiGraphInferenceHelper.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/PsiGraphInferenceHelper.java @@ -18,7 +18,6 @@ package com.intellij.psi.impl.source.resolve.graphInference; import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.*; import com.intellij.psi.impl.source.resolve.ParameterTypeInferencePolicy; -import com.intellij.psi.impl.source.resolve.PsiOldInferenceHelper; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -54,7 +53,8 @@ public class PsiGraphInferenceHelper implements PsiInferenceHelper { @NotNull ParameterTypeInferencePolicy policy, @NotNull LanguageLevel languageLevel) { if (typeParameters.length == 0) return partialSubstitutor; - final InferenceSession inferenceSession = new InferenceSession(typeParameters, parameters, arguments, partialSubstitutor, parent, myManager); + final InferenceSession inferenceSession = + new InferenceSession(typeParameters, parameters, arguments, partialSubstitutor, parent, myManager); return inferenceSession.infer(parameters, arguments, parent); } @@ -74,6 +74,31 @@ public class PsiGraphInferenceHelper implements PsiInferenceHelper { PsiType arg, boolean isContraVariantPosition, LanguageLevel languageLevel) { - return new PsiOldInferenceHelper(myManager).getSubstitutionForTypeParameter(typeParam, param, arg, isContraVariantPosition, languageLevel); + if (arg == PsiType.VOID || param == PsiType.VOID) return PsiType.NULL; + final PsiType[] leftTypes; + final PsiType[] rightTypes; + if (isContraVariantPosition) { + leftTypes = new PsiType[] {param}; + rightTypes = new PsiType[]{arg}; + } + else { + leftTypes = new PsiType[] {arg}; + rightTypes = new PsiType[]{param}; + } + final InferenceSession inferenceSession = new InferenceSession(new PsiTypeParameter[]{typeParam}, leftTypes, rightTypes, PsiSubstitutor.EMPTY, myManager); + if (inferenceSession.isProperType(param) && inferenceSession.isProperType(arg)) { + boolean proceed = false; + for (PsiClassType classType : typeParam.getExtendsListTypes()) { + if (!inferenceSession.isProperType(classType)) { + proceed = true; + break; + } + } + if (!proceed) { + return PsiType.NULL; + } + } + final PsiSubstitutor substitutor = inferenceSession.infer(); + return substitutor.substitute(typeParam); } }