diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionUtil.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionUtil.java index 6eb89184e6b0..f552c0ac768e 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionUtil.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionUtil.java @@ -75,20 +75,32 @@ public class JavaCompletionUtil { public static final OffsetKey LPAREN_OFFSET = OffsetKey.create("lparen"); public static final OffsetKey RPAREN_OFFSET = OffsetKey.create("rparen"); public static final OffsetKey ARG_LIST_END_OFFSET = OffsetKey.create("argListEnd"); - static final NullableLazyKey EXPECTED_TYPES = NullableLazyKey.create("expectedTypes", new NullableFunction() { - @Override - @Nullable - public ExpectedTypeInfo[] fun(final CompletionLocation location) { - if (PsiJavaPatterns.psiElement().beforeLeaf(PsiJavaPatterns.psiElement().withText(".")) - .accepts(location.getCompletionParameters().getPosition())) { - return ExpectedTypeInfo.EMPTY_ARRAY; - } + static final NullableLazyKey EXPECTED_TYPES = NullableLazyKey.create("expectedTypes", + new NullableFunction() { + @Override + @Nullable + public ExpectedTypeInfo[] fun( + final CompletionLocation location) { + if (PsiJavaPatterns + .psiElement() + .beforeLeaf( + PsiJavaPatterns + .psiElement() + .withText(".")) + .accepts(location + .getCompletionParameters() + .getPosition())) { + return ExpectedTypeInfo.EMPTY_ARRAY; + } - return JavaSmartCompletionContributor.getExpectedTypes(location.getCompletionParameters()); - } - }); + return JavaSmartCompletionContributor + .getExpectedTypes( + location + .getCompletionParameters()); + } + }); private static final ElementPattern LEFT_PAREN = psiElement(JavaTokenType.LPARENTH).andOr(psiElement().withParent( - PsiExpressionList.class), psiElement().afterLeaf(".", PsiKeyword.NEW)); + PsiExpressionList.class), psiElement().afterLeaf(".", PsiKeyword.NEW)); public static final Key SUPER_METHOD_PARAMETERS = Key.create("SUPER_METHOD_PARAMETERS"); @@ -550,6 +562,10 @@ public class JavaCompletionUtil { Conditions.alwaysTrue()); } } + + if (reference instanceof PsiMethodReferenceExpression && completion instanceof PsiMethod && ((PsiMethod)completion).isConstructor()) { + return Arrays.asList(JavaLookupElementBuilder.forMethod((PsiMethod)completion, "new", PsiSubstitutor.EMPTY, null)); + } LookupElement _ret = LookupItemUtil.objectToLookupItem(completion); if (_ret == null || !(_ret instanceof LookupItem)) return Collections.emptyList(); diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/Normal8CompletionTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/Normal8CompletionTest.groovy index 135fc3a6bf47..45456bbc045d 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/Normal8CompletionTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/Normal8CompletionTest.groovy @@ -74,4 +74,40 @@ class Test { assert LookupElementPresentation.renderElement(items[0]).itemText == 'x -> {}' } + + public void "test constructor ref"() { + myFixture.configureByText "a.java", """ +interface Foo9 { + Bar test(int p); +} + +class Bar { + public Bar(int p) {} +} + +class Test88 { + { + Foo9 f = Bar::; + } +} +""" + myFixture.completeBasic() + myFixture.type('\n') + + myFixture.checkResult """ +interface Foo9 { + Bar test(int p); +} + +class Bar { + public Bar(int p) {} +} + +class Test88 { + { + Foo9 f = Bar::new; + } +} +""" + } }