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 15ea2af284cb..23e8101f1efb 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 @@ -278,8 +278,7 @@ public class InferenceSession { 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 JavaResolveResult resolveResult = getMethodResult((PsiCallExpression)arg); - final PsiMethod calledMethod = resolveResult instanceof MethodCandidateInfo ? (PsiMethod)resolveResult.getElement() : null; + final PsiMethod calledMethod = getCalledMethod((PsiCallExpression)arg); if (PsiPolyExpressionUtil.isMethodCallPolyExpression(arg, calledMethod)) { collectAdditionalConstraints(additionalConstraints, (PsiCallExpression)arg); } @@ -290,6 +289,20 @@ public class InferenceSession { } } + private static PsiMethod getCalledMethod(PsiCallExpression arg) { + final PsiExpressionList argumentList = arg.getArgumentList(); + if (argumentList == null || argumentList.getExpressions().length == 0) { + return null; + } + + MethodCandidateInfo.CurrentCandidateProperties properties = MethodCandidateInfo.getCurrentMethod(argumentList); + if (properties != null) { + return properties.getMethod(); + } + final JavaResolveResult resolveResult = getMethodResult(arg); + return resolveResult instanceof MethodCandidateInfo ? (PsiMethod)resolveResult.getElement() : null; + } + private void collectLambdaReturnExpression(Set additionalConstraints, PsiLambdaExpression lambdaExpression, PsiType parameterType) { @@ -306,8 +319,7 @@ public class InferenceSession { PsiExpression returnExpression, PsiType functionalType) { if (returnExpression instanceof PsiCallExpression) { - final JavaResolveResult resolveResult = getMethodResult((PsiCallExpression)returnExpression); - final PsiMethod calledMethod = resolveResult instanceof MethodCandidateInfo ? (PsiMethod)resolveResult.getElement() : null; + final PsiMethod calledMethod = getCalledMethod((PsiCallExpression)returnExpression); if (PsiPolyExpressionUtil.isMethodCallPolyExpression(returnExpression, calledMethod)) { collectAdditionalConstraints(additionalConstraints, (PsiCallExpression)returnExpression); }