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 4ef60491bdf2..9bf61545d4dd 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 @@ -866,7 +866,7 @@ public class InferenceSession { return getTypeByMethod(context, argumentList, properties.getMethod(), properties.isVarargs(), properties.getSubstitutor(), inferParent); } - final JavaResolveResult result = ((PsiCall)gParent).resolveMethodGenerics(); + final JavaResolveResult result = PsiDiamondType.getDiamondsAwareResolveResult((PsiCall)gParent); final PsiElement element = result.getElement(); if (element == null) { errorMessage.set("Overload resolution failed"); diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSessionContainer.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSessionContainer.java index ff0dbaf147e9..6ccff5f705af 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSessionContainer.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSessionContainer.java @@ -172,7 +172,7 @@ public class InferenceSessionContainer { if (initialInferenceState != null) { final PsiExpressionList argumentList = call.getArgumentList(); final int idx = LambdaUtil.getLambdaIdx(argumentList, gParent); - final JavaResolveResult result = call.resolveMethodGenerics(); + final JavaResolveResult result = PsiDiamondType.getDiamondsAwareResolveResult(call); final PsiElement method = result.getElement(); if (method instanceof PsiMethod && idx > -1) { LOG.assertTrue(argumentList != null); @@ -244,7 +244,7 @@ public class InferenceSessionContainer { @Nullable private static InferenceSession startTopLevelInference(final PsiCall topLevelCall, final ParameterTypeInferencePolicy policy) { - final JavaResolveResult result = topLevelCall.resolveMethodGenerics(); + final JavaResolveResult result = PsiDiamondType.getDiamondsAwareResolveResult(topLevelCall); if (result instanceof MethodCandidateInfo) { final PsiMethod method = ((MethodCandidateInfo)result).getElement(); final PsiParameter[] topLevelParameters = method.getParameterList().getParameters(); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/diamond/DetectStaticFactoryForTopLevelCall.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/diamond/DetectStaticFactoryForTopLevelCall.java new file mode 100644 index 000000000000..9c6228e77e32 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/diamond/DetectStaticFactoryForTopLevelCall.java @@ -0,0 +1,23 @@ + +import java.util.Optional; +import java.util.stream.Collector; +import java.util.stream.Collectors; + +class Collectinator { + + private Collectinator(Collector collector) { } + + { + + Collectinator> lastDate = + new Collectinator<>(Collectors.maxBy(Foo::compareTo)); + + } + + static class Bar {} + static class Foo extends Bar{ + public int compareTo(Bar other) { + return -1; + } + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/diamond/EraseTypeForNewExpressionWithDiamondsIfUncheckedConversionWasPerformedDuringApplicabilityCheck.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/diamond/EraseTypeForNewExpressionWithDiamondsIfUncheckedConversionWasPerformedDuringApplicabilityCheck.java index 28300272b653..c61a57f6127c 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/diamond/EraseTypeForNewExpressionWithDiamondsIfUncheckedConversionWasPerformedDuringApplicabilityCheck.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/diamond/EraseTypeForNewExpressionWithDiamondsIfUncheckedConversionWasPerformedDuringApplicabilityCheck.java @@ -9,15 +9,14 @@ inference variable K has incompatible bounds: lower bounds: Holder">Result.create(h); Holder dataHolder = null; - Result r3 = new Result<>(new Holder<>(dataHolder)); + Result r3 = new Result<>(new Holder<>(dataHolder)); Result r4 = Result.create(new Holder<>(dataHolder)); - Result r5 = new Result<>(Holder.create(dataHolder)); + Result r5 = new Result<>(Holder.create(dataHolder)); Result r6 = <>(f, consumer, arg(c.getOp())); + return new CImpl<>(f, consumer, arg(c.getOp())); } static > BiOp arg(BiOp op) { diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/Diamond8HighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/Diamond8HighlightingTest.java index b6b4e620673e..5fcee7b35172 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/Diamond8HighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/Diamond8HighlightingTest.java @@ -97,6 +97,10 @@ public class Diamond8HighlightingTest extends LightDaemonAnalyzerTestCase { doTest(); } + public void testDetectStaticFactoryForTopLevelCall() throws Exception { + doTest(); + } + private void doTest() throws Exception { doTest(BASE_PATH + "/" + getTestName(false) + ".java", false, false); }