mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
completion: completion of constructor ref should insert new instead of class name (IDEA-137350)
(cherry picked from commit f98061b83147b69eed33fa86c4817bcbe67e26f4)
This commit is contained in:
@@ -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<ExpectedTypeInfo[], CompletionLocation> EXPECTED_TYPES = NullableLazyKey.create("expectedTypes", new NullableFunction<CompletionLocation, ExpectedTypeInfo[]>() {
|
||||
@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<ExpectedTypeInfo[], CompletionLocation> EXPECTED_TYPES = NullableLazyKey.create("expectedTypes",
|
||||
new NullableFunction<CompletionLocation, ExpectedTypeInfo[]>() {
|
||||
@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<PsiElement> LEFT_PAREN = psiElement(JavaTokenType.LPARENTH).andOr(psiElement().withParent(
|
||||
PsiExpressionList.class), psiElement().afterLeaf(".", PsiKeyword.NEW));
|
||||
PsiExpressionList.class), psiElement().afterLeaf(".", PsiKeyword.NEW));
|
||||
|
||||
public static final Key<Boolean> SUPER_METHOD_PARAMETERS = Key.create("SUPER_METHOD_PARAMETERS");
|
||||
|
||||
@@ -550,6 +562,10 @@ public class JavaCompletionUtil {
|
||||
Conditions.<PsiClass>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();
|
||||
|
||||
+36
@@ -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::<caret>;
|
||||
}
|
||||
}
|
||||
"""
|
||||
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;
|
||||
}
|
||||
}
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user