diff --git a/java/java-psi-api/src/com/intellij/psi/infos/MethodCandidateInfo.java b/java/java-psi-api/src/com/intellij/psi/infos/MethodCandidateInfo.java index 415f32e86fd3..706fd116e6e6 100644 --- a/java/java-psi-api/src/com/intellij/psi/infos/MethodCandidateInfo.java +++ b/java/java-psi-api/src/com/intellij/psi/infos/MethodCandidateInfo.java @@ -155,7 +155,7 @@ public class MethodCandidateInfo extends CandidateInfo{ } return level; } - }, substitutor); + }, substitutor, isVarargs(), true); if (level > ApplicabilityLevel.NOT_APPLICABLE && !isTypeArgumentsApplicable(new Computable() { @Override public PsiSubstitutor compute() { @@ -236,15 +236,17 @@ public class MethodCandidateInfo extends CandidateInfo{ return true; } - private T computeForOverloadedCandidate(final Computable computable, final PsiSubstitutor substitutor) { + private T computeForOverloadedCandidate(final Computable computable, + final PsiSubstitutor substitutor, + boolean varargs, boolean applicabilityCheck) { Map map = CURRENT_CANDIDATE.get(); if (map == null) { map = ContainerUtil.createConcurrentWeakMap(); CURRENT_CANDIDATE.set(map); } final PsiElement argumentList = getMarkerList(); - final CurrentCandidateProperties alreadyThere = map.put(argumentList, - new CurrentCandidateProperties(this, substitutor, isVarargs(), true)); + final CurrentCandidateProperties alreadyThere = + map.put(argumentList, new CurrentCandidateProperties(this, substitutor, varargs, applicabilityCheck)); try { return computable.compute(); } @@ -370,39 +372,28 @@ public class MethodCandidateInfo extends CandidateInfo{ } @NotNull - public PsiSubstitutor inferTypeArguments(@NotNull ParameterTypeInferencePolicy policy, - @NotNull PsiExpression[] arguments, + public PsiSubstitutor inferTypeArguments(@NotNull final ParameterTypeInferencePolicy policy, + @NotNull final PsiExpression[] arguments, boolean includeReturnConstraint) { - Map map = CURRENT_CANDIDATE.get(); - if (map == null) { - map = ContainerUtil.createConcurrentWeakMap(); - CURRENT_CANDIDATE.set(map); - } - final PsiMethod method = getElement(); - final PsiElement argumentList = getMarkerList(); - final CurrentCandidateProperties alreadyThere = - map.put(argumentList, new CurrentCandidateProperties(this, super.getSubstitutor(), policy.isVarargsIgnored() || isVarargs(), !includeReturnConstraint)); - try { - PsiTypeParameter[] typeParameters = method.getTypeParameters(); + return computeForOverloadedCandidate(new Computable() { + @Override + public PsiSubstitutor compute() { + final PsiMethod method = MethodCandidateInfo.this.getElement(); + PsiTypeParameter[] typeParameters = method.getTypeParameters(); - if (isRawSubstitution()) { - return JavaPsiFacade.getInstance(method.getProject()).getElementFactory().createRawSubstitutor(mySubstitutor, typeParameters); - } + if (MethodCandidateInfo.this.isRawSubstitution()) { + return JavaPsiFacade.getInstance(method.getProject()).getElementFactory().createRawSubstitutor(mySubstitutor, typeParameters); + } - final PsiElement parent = getParent(); - if (parent == null) return PsiSubstitutor.EMPTY; - Project project = method.getProject(); - JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(project); - return javaPsiFacade.getResolveHelper() - .inferTypeArguments(typeParameters, method.getParameterList().getParameters(), arguments, mySubstitutor, parent, policy, myLanguageLevel); - } - finally { - if (alreadyThere == null) { - map.remove(argumentList); - } else { - map.put(argumentList, alreadyThere); + final PsiElement parent = MethodCandidateInfo.this.getParent(); + if (parent == null) return PsiSubstitutor.EMPTY; + Project project = method.getProject(); + JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(project); + return javaPsiFacade.getResolveHelper() + .inferTypeArguments(typeParameters, method.getParameterList().getParameters(), arguments, mySubstitutor, parent, policy, + myLanguageLevel); } - } + }, super.getSubstitutor(), policy.isVarargsIgnored() || isVarargs(), !includeReturnConstraint); } private boolean isRawSubstitution() {