new inference: infer from type pair with PsiType.NULL when not enough data is provided

This commit is contained in:
anna
2013-10-04 20:37:06 +02:00
parent ad4eead64a
commit ddeea16f5b
@@ -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);
}
}