From a5f940d5e49a0c22c659f4806236c6a9f61881fd Mon Sep 17 00:00:00 2001 From: anna Date: Wed, 21 Nov 2012 12:12:19 +0100 Subject: [PATCH] method reference: proceed with class type when diamond static factory is used (IDEA-93099) --- .../source/resolve/PsiResolveHelperImpl.java | 8 ++++- .../methodRef/ConstructorWithoutParams.java | 31 +++++++++++++++++++ .../lambda/MethodRefHighlightingTest.java | 4 +++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/ConstructorWithoutParams.java diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/PsiResolveHelperImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/PsiResolveHelperImpl.java index 31945ae911b0..1fb4917113f5 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/PsiResolveHelperImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/PsiResolveHelperImpl.java @@ -663,7 +663,13 @@ public class PsiResolveHelperImpl implements PsiResolveHelper { PsiType functionalInterfaceReturnType = functionalInterfaceMethod.getReturnType(); if (functionalInterfaceReturnType != null && functionalInterfaceReturnType != PsiType.VOID) { functionalInterfaceReturnType = GenericsUtil.eliminateWildcards(subst.substitute(functionalInterfaceReturnType)); - return getSubstitutionForTypeParameterConstraint(typeParam, functionalInterfaceReturnType, methReferenceResolveResult.getSubstitutor().substitute(subst.substitute(method.getReturnType())), true, PsiUtil.getLanguageLevel(functionalInterfaceMethod)); + final PsiType argType; + if (method.isConstructor()) { + argType = JavaPsiFacade.getElementFactory(functionalInterfaceMethod.getProject()).createType(method.getContainingClass(), methReferenceResolveResult.getSubstitutor()); + } else { + argType = methReferenceResolveResult.getSubstitutor().substitute(subst.substitute(method.getReturnType())); + } + return getSubstitutionForTypeParameterConstraint(typeParam, functionalInterfaceReturnType, argType, true, PsiUtil.getLanguageLevel(functionalInterfaceMethod)); } } } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/ConstructorWithoutParams.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/ConstructorWithoutParams.java new file mode 100644 index 000000000000..10448a8c6aab --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/ConstructorWithoutParams.java @@ -0,0 +1,31 @@ +import java.util.*; + +interface Factory { + T create(); +} + +class LambdaTest { + + public void testR() { + Map> map = + new ComputeMap>(() -> + new ComputeMap<>(Counter::new)); + + } + + public static class ComputeMap extends HashMap { + public ComputeMap(Factory factory) { + } + } + + public static class Counter { + + public Counter() { + this(0); + } + + public Counter(int count) { + } + } + +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/MethodRefHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/MethodRefHighlightingTest.java index 4718e036b6d0..213c63d07789 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/MethodRefHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/MethodRefHighlightingTest.java @@ -133,6 +133,10 @@ public class MethodRefHighlightingTest extends LightDaemonAnalyzerTestCase { doTest(); } + public void testConstructorWithoutParams() throws Exception { + doTest(); + } + public void testInferenceFromReturnType() throws Exception { doTest(true); }