new inference: standalong check with cached data (IDEA-128982)

This commit is contained in:
Anna Kozlova
2014-09-02 19:57:41 +04:00
parent 234a96abe6
commit 736f703bbf
3 changed files with 64 additions and 15 deletions

View File

@@ -275,11 +275,14 @@ public class InferenceSession {
additionalConstraints.add(new ExpressionCompatibilityConstraint(arg, parameterType));
}
additionalConstraints.add(new CheckedExceptionCompatibilityConstraint(arg, parameterType));
if (arg instanceof PsiCallExpression && PsiPolyExpressionUtil.isPolyExpression(arg)) {
if (arg instanceof PsiCallExpression) {
//If the expression is a poly class instance creation expression (15.9) or a poly method invocation expression (15.12),
//the set contains all constraint formulas that would appear in the set C when determining the poly expression's invocation type.
final PsiCallExpression callExpression = (PsiCallExpression)arg;
collectAdditionalConstraints(additionalConstraints, callExpression);
final JavaResolveResult resolveResult = getMethodResult((PsiCallExpression)arg);
final PsiMethod calledMethod = resolveResult instanceof MethodCandidateInfo ? (PsiMethod)resolveResult.getElement() : null;
if (PsiPolyExpressionUtil.isMethodCallPolyExpression(arg, calledMethod)) {
collectAdditionalConstraints(additionalConstraints, (PsiCallExpression)arg);
}
} else if (arg instanceof PsiLambdaExpression) {
collectLambdaReturnExpression(additionalConstraints, (PsiLambdaExpression)arg, parameterType);
}
@@ -303,7 +306,11 @@ public class InferenceSession {
PsiExpression returnExpression,
PsiType functionalType) {
if (returnExpression instanceof PsiCallExpression) {
collectAdditionalConstraints(additionalConstraints, (PsiCallExpression)returnExpression);
final JavaResolveResult resolveResult = getMethodResult((PsiCallExpression)returnExpression);
final PsiMethod calledMethod = resolveResult instanceof MethodCandidateInfo ? (PsiMethod)resolveResult.getElement() : null;
if (PsiPolyExpressionUtil.isMethodCallPolyExpression(returnExpression, calledMethod)) {
collectAdditionalConstraints(additionalConstraints, (PsiCallExpression)returnExpression);
}
}
else if (returnExpression instanceof PsiParenthesizedExpression) {
processReturnExpression(additionalConstraints, ((PsiParenthesizedExpression)returnExpression).getExpression(), functionalType);
@@ -321,18 +328,8 @@ public class InferenceSession {
final PsiCallExpression callExpression) {
PsiExpressionList argumentList = callExpression.getArgumentList();
if (argumentList != null) {
final PsiLambdaExpression expression = PsiTreeUtil.getParentOfType(argumentList, PsiLambdaExpression.class);
final Computable<JavaResolveResult> computableResolve = new Computable<JavaResolveResult>() {
@Override
public JavaResolveResult compute() {
return callExpression.resolveMethodGenerics();
}
};
final JavaResolveResult result = getMethodResult(callExpression);
MethodCandidateInfo.CurrentCandidateProperties properties = MethodCandidateInfo.getCurrentMethod(argumentList);
final JavaResolveResult result = properties != null ? null :
expression == null
? computableResolve.compute()
: PsiResolveHelper.ourGraphGuard.doPreventingRecursion(expression, false, computableResolve);
final PsiMethod method = result instanceof MethodCandidateInfo ? ((MethodCandidateInfo)result).getElement() : properties != null ? properties.getMethod() : null;
if (method != null) {
final PsiExpression[] newArgs = argumentList.getExpressions();
@@ -345,6 +342,23 @@ public class InferenceSession {
}
}
private static JavaResolveResult getMethodResult(final PsiCallExpression callExpression) {
final PsiExpressionList argumentList = callExpression.getArgumentList();
final PsiLambdaExpression expression = PsiTreeUtil.getParentOfType(argumentList, PsiLambdaExpression.class);
final Computable<JavaResolveResult> computableResolve = new Computable<JavaResolveResult>() {
@Override
public JavaResolveResult compute() {
return callExpression.resolveMethodGenerics();
}
};
MethodCandidateInfo.CurrentCandidateProperties properties = MethodCandidateInfo.getCurrentMethod(argumentList);
return properties != null ? null :
expression == null
? computableResolve.compute()
: PsiResolveHelper.ourGraphGuard.doPreventingRecursion(expression, false, computableResolve);
}
public PsiSubstitutor retrieveNonPrimitiveEqualsBounds(Collection<InferenceVariable> variables) {
PsiSubstitutor substitutor = mySiteSubstitutor;
for (InferenceVariable variable : variables) {

View File

@@ -0,0 +1,32 @@
import java.util.Map;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collector;
import java.util.stream.Stream;
class MultiDataPoint {
public MultiDataPoint(final Map<String, String> pCollect) {}
public static void convertValueResults(final Stream<Result> pStream) {
map(() -> new MultiDataPoint(collect(toMap(r -> r.event.substring(0)))));
}
static <R> R collect(Collector<? super Result, ?, R> collector) {return null;}
static <R> R map(Supplier<R> s) {
return null;
}
static <T, K> Collector<T, ?, Map<K,K>> toMap(Function< T, K> keyMapper) {
return null;
}
static class Result {
public String event;
public String getValue() {
return null;
}
}
}

View File

@@ -71,6 +71,7 @@ public class NewLambdaHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testIDEA121315() { doTest(); }
public void testIDEA118965comment() { doTest(); }
public void testIDEA122074() { doTest(); }
@Bombed(day = 30, month = Calendar.SEPTEMBER)
public void testIDEA122084() { doTest(); }
public void testAdditionalConstraintDependsOnNonMentionedVars() { doTest(); }
public void testIDEA122616() { doTest(); }
@@ -96,8 +97,10 @@ public class NewLambdaHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testIDEA124424() { doTest(); }
public void testNestedLambdaExpressions1() { doTest(); }
public void testNestedLambdaExpressionsNoFormalParams() { doTest(); }
@Bombed(day = 30, month = Calendar.SEPTEMBER)
public void testNestedLambdaExpressionsNoFormalParams1() { doTest(); }
public void testDeepNestedLambdaExpressionsNoFormalParams() { doTest(); }
public void testNestedLambdaExpressionsNoFormalParamsStopAtStandalone() { doTest(); }
public void testIDEA127596() throws Exception {
doTest();