From 9edc8f6b58f71ec510ba36b838f115718d9a174d Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Queru Date: Fri, 8 Feb 2013 15:14:04 -0800 Subject: Snapshot of commit 84dc01e773388c2c72a1fc437f313dd5747e7809 from branch master of git://git.jetbrains.org/idea/community.git --- .../intellij/psi/infos/MethodCandidateInfo.java | 62 ++++++++++------------ 1 file changed, 28 insertions(+), 34 deletions(-) (limited to 'java/java-psi-api/src/com/intellij/psi/infos/MethodCandidateInfo.java') 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 8126582654f0..8c6f4c4ed477 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 @@ -41,7 +41,6 @@ public class MethodCandidateInfo extends CandidateInfo{ private final PsiType[] myTypeArguments; private PsiSubstitutor myCalcedSubstitutor = null; private final LanguageLevel myLanguageLevel; - private static final Object LOCK = new Object(); public MethodCandidateInfo(PsiElement candidate, PsiSubstitutor substitutor, @@ -99,27 +98,11 @@ public class MethodCandidateInfo extends CandidateInfo{ PsiSubstitutor incompleteSubstitutor = super.getSubstitutor(); PsiMethod method = getElement(); if (myTypeArguments == null) { - Map> map; - synchronized (LOCK) { - map = CURRENT_CANDIDATE.get(); - if (map == null) { - map = new ConcurrentWeakHashMap>(); - CURRENT_CANDIDATE.set(map); - } - } - map.put(myArgumentList, Pair.create(getElement(), incompleteSubstitutor)); - try { - - final Set lists = LambdaUtil.ourParams.get(); - if (lists != null && !lists.isEmpty()) { + final Set lists = LambdaUtil.ourParams.get(); + if (lists != null && !lists.isEmpty()) { return inferTypeArguments(DefaultParameterTypeInferencePolicy.INSTANCE); - } - - myCalcedSubstitutor = inferTypeArguments(DefaultParameterTypeInferencePolicy.INSTANCE); - } - finally { - map.remove(myArgumentList); - } + } + myCalcedSubstitutor = inferTypeArguments(DefaultParameterTypeInferencePolicy.INSTANCE); } else { PsiTypeParameter[] typeParams = method.getTypeParameters(); @@ -165,21 +148,32 @@ public class MethodCandidateInfo extends CandidateInfo{ } public PsiSubstitutor inferTypeArguments(final ParameterTypeInferencePolicy policy, final PsiExpression[] arguments) { - PsiMethod method = getElement(); - PsiTypeParameter[] typeParameters = method.getTypeParameters(); - - JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(method.getProject()); - if (!method.hasModifierProperty(PsiModifier.STATIC)) { - final PsiClass containingClass = method.getContainingClass(); - if (containingClass != null && PsiUtil.isRawSubstitutor(containingClass, mySubstitutor)) { - return javaPsiFacade.getElementFactory().createRawSubstitutor(mySubstitutor, typeParameters); - } + Map> map = CURRENT_CANDIDATE.get(); + if (map == null) { + map = new ConcurrentWeakHashMap>(); + CURRENT_CANDIDATE.set(map); } + final PsiMethod method = getElement(); + final Pair alreadyThere = map.put(myArgumentList, Pair.create(method, super.getSubstitutor())); + try { + PsiTypeParameter[] typeParameters = method.getTypeParameters(); + + JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(method.getProject()); + if (!method.hasModifierProperty(PsiModifier.STATIC)) { + final PsiClass containingClass = method.getContainingClass(); + if (containingClass != null && PsiUtil.isRawSubstitutor(containingClass, mySubstitutor)) { + return javaPsiFacade.getElementFactory().createRawSubstitutor(mySubstitutor, typeParameters); + } + } - final PsiElement parent = getParent(); - if (parent == null) return PsiSubstitutor.EMPTY; - return javaPsiFacade.getResolveHelper() - .inferTypeArguments(typeParameters, method.getParameterList().getParameters(), arguments, mySubstitutor, parent, policy); + final PsiElement parent = getParent(); + if (parent == null) return PsiSubstitutor.EMPTY; + return javaPsiFacade.getResolveHelper() + .inferTypeArguments(typeParameters, method.getParameterList().getParameters(), arguments, mySubstitutor, parent, policy); + } + finally { + if (alreadyThere == null) map.remove(myArgumentList); + } } public boolean isInferencePossible() { -- cgit v1.2.3