new inference: do not use nested call args to infer on the top level

This commit is contained in:
anna
2013-11-07 20:49:32 +01:00
parent 465762a96e
commit 38e2991f54
3 changed files with 9 additions and 14 deletions
@@ -69,16 +69,15 @@ public class InferenceSession {
}
public InferenceSession(PsiTypeParameter[] typeParams,
PsiParameter[] parameters,
PsiExpression[] args,
PsiSubstitutor siteSubstitutor,
PsiElement parent,
PsiManager manager) {
myManager = manager;
mySiteSubstitutor = siteSubstitutor;
initBounds(typeParams);
}
public void initExpressionConstraints(PsiParameter[] parameters, PsiExpression[] args, PsiElement parent) {
final Pair<PsiMethod, PsiCallExpression> pair = getPair(parent);
if (parameters.length > 0) {
for (int i = 0; i < args.length; i++) {
@@ -38,8 +38,8 @@ public class PsiGraphInferenceHelper implements PsiInferenceHelper {
@NotNull PsiSubstitutor partialSubstitutor,
@Nullable PsiElement parent,
@NotNull ParameterTypeInferencePolicy policy) {
final InferenceSession inferenceSession =
new InferenceSession(new PsiTypeParameter[]{typeParameter}, parameters, arguments, partialSubstitutor, parent, myManager);
final InferenceSession inferenceSession = new InferenceSession(new PsiTypeParameter[]{typeParameter}, partialSubstitutor, myManager);
inferenceSession.initExpressionConstraints(parameters, arguments, parent);
return inferenceSession.infer(parameters, arguments, parent).substitute(typeParameter);
}
@@ -53,8 +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, partialSubstitutor, myManager);
inferenceSession.initExpressionConstraints(parameters, arguments, parent);
return inferenceSession.infer(parameters, arguments, parent);
}
@@ -83,11 +83,9 @@ public class ExpressionCompatibilityConstraint extends InputOutputConstraintForm
InferenceSession callSession = null;
if (method != null && !method.isConstructor()) {
returnType = method.getReturnType();
final PsiParameter[] parameters = method.getParameterList().getParameters();
if (returnType != null) {
callSession = new InferenceSession(method.getTypeParameters(), parameters,
argumentList.getExpressions(),
PsiSubstitutor.EMPTY, null, myExpression.getManager());
callSession = new InferenceSession(method.getTypeParameters(),
PsiSubstitutor.EMPTY, myExpression.getManager());
}
} else if (myExpression instanceof PsiNewExpression) { //default constructor
@@ -97,9 +95,7 @@ public class ExpressionCompatibilityConstraint extends InputOutputConstraintForm
if (psiClass instanceof PsiClass) {
returnType = JavaPsiFacade.getElementFactory(argumentList.getProject()).createType((PsiClass)psiClass, PsiSubstitutor.EMPTY);
callSession = new InferenceSession(((PsiClass)psiClass).getTypeParameters(),
PsiParameter.EMPTY_ARRAY,
argumentList.getExpressions(),
PsiSubstitutor.EMPTY, null, myExpression.getManager());
PsiSubstitutor.EMPTY, myExpression.getManager());
}
}
}