From f3d0a39366b45632d19f17f6c6d2c9e99843edcb Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 4 May 2017 15:31:21 +0300 Subject: [PATCH] infer conditional expression type for incomplete calls (IDEA-171431) --- .../source/resolve/graphInference/InferenceSession.java | 9 +++++---- .../ConditionalExpressionInIncompleteCall.java | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java index 4fed6013b36d..85e41f823a27 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java @@ -890,7 +890,7 @@ public class InferenceSession { if (argumentList != null) { final MethodCandidateInfo.CurrentCandidateProperties properties = MethodCandidateInfo.getCurrentMethod(argumentList); if (properties != null && properties.isApplicabilityCheck()) { - return getTypeByMethod(context, argumentList, properties.getMethod(), properties.isVarargs(), properties.getSubstitutor()); + return getTypeByMethod(context, argumentList, properties.getMethod(), properties.isVarargs(), properties.getSubstitutor(), inferParent); } final JavaResolveResult result = ((PsiCall)gParent).resolveMethodGenerics(); @@ -901,7 +901,7 @@ public class InferenceSession { } if (element instanceof PsiMethod && (inferParent || !((PsiMethod)element).hasTypeParameters())) { final boolean varargs = result instanceof MethodCandidateInfo && ((MethodCandidateInfo)result).isVarargs(); - return getTypeByMethod(context, argumentList, result.getElement(), varargs, result.getSubstitutor()); + return getTypeByMethod(context, argumentList, result.getElement(), varargs, result.getSubstitutor(), inferParent); } } } @@ -946,12 +946,13 @@ public class InferenceSession { PsiExpressionList argumentList, PsiElement parentMethod, boolean varargs, - PsiSubstitutor substitutor) { + PsiSubstitutor substitutor, + boolean inferParent) { if (parentMethod instanceof PsiMethod) { final PsiParameter[] parameters = ((PsiMethod)parentMethod).getParameterList().getParameters(); if (parameters.length == 0) return null; final PsiExpression[] args = argumentList.getExpressions(); - if (!((PsiMethod)parentMethod).isVarArgs() && parameters.length != args.length) return null; + if (!((PsiMethod)parentMethod).isVarArgs() && parameters.length != args.length && !inferParent) return null; PsiElement arg = context; while (arg.getParent() instanceof PsiParenthesizedExpression) { arg = arg.getParent(); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting8/ConditionalExpressionInIncompleteCall.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting8/ConditionalExpressionInIncompleteCall.java index 6efc6cdc9ce5..316fba37f430 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting8/ConditionalExpressionInIncompleteCall.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting8/ConditionalExpressionInIncompleteCall.java @@ -1,7 +1,7 @@ class Test{ void test() { - B b = new B(true == false ? "bar" : null); + B b = new B(true == false ? "bar" : null); } class B {