mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
lambda: no need to store params to compute anymore - return values are checked not to depend on params inference anyway
This commit is contained in:
@@ -37,7 +37,6 @@ import java.util.*;
|
||||
*/
|
||||
public class LambdaUtil {
|
||||
private static final Logger LOG = Logger.getInstance("#" + LambdaUtil.class.getName());
|
||||
public static ThreadLocal<Set<PsiParameterList>> ourParams = new ThreadLocal<Set<PsiParameterList>>();
|
||||
@NonNls public static final String JAVA_LANG_FUNCTIONAL_INTERFACE = "java.lang.FunctionalInterface";
|
||||
|
||||
@Nullable
|
||||
@@ -525,34 +524,22 @@ public class LambdaUtil {
|
||||
final PsiLambdaExpression lambdaExpression = PsiTreeUtil.getParentOfType(param, PsiLambdaExpression.class);
|
||||
if (lambdaExpression != null) {
|
||||
|
||||
Set<PsiParameterList> currentStack = ourParams.get();
|
||||
if (currentStack == null) {
|
||||
currentStack = new HashSet<PsiParameterList>();
|
||||
ourParams.set(currentStack);
|
||||
}
|
||||
|
||||
final PsiParameterList parameterList = lambdaExpression.getParameterList();
|
||||
final boolean add = currentStack.add(parameterList);
|
||||
try {
|
||||
PsiType type = getFunctionalInterfaceType(lambdaExpression, true, parameterIndex);
|
||||
if (type == null) {
|
||||
type = getFunctionalInterfaceType(lambdaExpression, false);
|
||||
}
|
||||
if (type instanceof PsiIntersectionType) {
|
||||
final PsiType[] conjuncts = ((PsiIntersectionType)type).getConjuncts();
|
||||
for (PsiType conjunct : conjuncts) {
|
||||
final PsiType lambdaParameterFromType = getLambdaParameterFromType(parameterIndex, lambdaExpression, conjunct);
|
||||
if (lambdaParameterFromType != null) return lambdaParameterFromType;
|
||||
}
|
||||
} else {
|
||||
final PsiType lambdaParameterFromType = getLambdaParameterFromType(parameterIndex, lambdaExpression, type);
|
||||
if (lambdaParameterFromType != null) {
|
||||
return lambdaParameterFromType;
|
||||
}
|
||||
}
|
||||
PsiType type = getFunctionalInterfaceType(lambdaExpression, true, parameterIndex);
|
||||
if (type == null) {
|
||||
type = getFunctionalInterfaceType(lambdaExpression, false);
|
||||
}
|
||||
finally {
|
||||
if (add) currentStack.remove(parameterList);
|
||||
if (type instanceof PsiIntersectionType) {
|
||||
final PsiType[] conjuncts = ((PsiIntersectionType)type).getConjuncts();
|
||||
for (PsiType conjunct : conjuncts) {
|
||||
final PsiType lambdaParameterFromType = getLambdaParameterFromType(parameterIndex, lambdaExpression, conjunct);
|
||||
if (lambdaParameterFromType != null) return lambdaParameterFromType;
|
||||
}
|
||||
} else {
|
||||
final PsiType lambdaParameterFromType = getLambdaParameterFromType(parameterIndex, lambdaExpression, type);
|
||||
if (lambdaParameterFromType != null) {
|
||||
return lambdaParameterFromType;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ import org.intellij.lang.annotations.MagicConstant;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author ik, dsl
|
||||
@@ -103,8 +102,7 @@ public class MethodCandidateInfo extends CandidateInfo{
|
||||
|
||||
final PsiSubstitutor inferredSubstitutor = inferTypeArguments(DefaultParameterTypeInferencePolicy.INSTANCE);
|
||||
|
||||
final Set<PsiParameterList> lists = LambdaUtil.ourParams.get();
|
||||
if (lists != null && !lists.isEmpty() || !stackStamp.mayCacheNow()) {
|
||||
if (!stackStamp.mayCacheNow()) {
|
||||
return inferredSubstitutor;
|
||||
}
|
||||
|
||||
|
||||
+4
-8
@@ -18,7 +18,10 @@ package com.intellij.psi.impl.source.resolve;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.projectRoots.JavaSdkVersion;
|
||||
import com.intellij.openapi.projectRoots.JavaVersionService;
|
||||
import com.intellij.openapi.util.*;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.RecursionGuard;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
@@ -40,7 +43,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class PsiResolveHelperImpl implements PsiResolveHelper {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.resolve.PsiResolveHelperImpl");
|
||||
@@ -719,12 +721,6 @@ public class PsiResolveHelperImpl implements PsiResolveHelper {
|
||||
final Pair<PsiType, ConstraintType> constraintFromFormalParams = inferConstraintFromLambdaFormalParams(typeParam, subst, method, lambdaExpression);
|
||||
if (constraintFromFormalParams != null) return constraintFromFormalParams;
|
||||
|
||||
final Set<PsiParameterList> lists = LambdaUtil.ourParams.get();
|
||||
if (lists != null && lists.contains(lambdaExpression.getParameterList()) &&
|
||||
ourGraphGuard.currentStack().isEmpty()){
|
||||
return null;
|
||||
}
|
||||
|
||||
final PsiParameter[] methodParameters = method.getParameterList().getParameters();
|
||||
if (methodParamsDependOn(typeParam, lambdaExpression, functionalInterfaceType, methodParameters, subst)) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user