mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
completion of constructor refs (IDEA-145281)
This commit is contained in:
+25
@@ -134,6 +134,23 @@ public class FunctionalExpressionCompletionProvider extends CompletionProvider<C
|
||||
collectVariantsByReceiver(prioritize, functionalInterfaceType, params, originalPosition, substitutor, expectedReturnType, result);
|
||||
}
|
||||
collectThisVariants(functionalInterfaceType, params, originalPosition, substitutor, expectedReturnType, result);
|
||||
final PsiClass psiClass = PsiUtil.resolveClassInType(expectedReturnType);
|
||||
if (psiClass != null) {
|
||||
if (expectedReturnType.getArrayDimensions() == 0) {
|
||||
final PsiMethod[] constructors = psiClass.getConstructors();
|
||||
for (PsiMethod psiMethod : constructors) {
|
||||
if (areParameterTypesAppropriate(psiMethod, params, substitutor, 0)) {
|
||||
result.add(createConstructorReferenceLookup(functionalInterfaceType, expectedReturnType));
|
||||
}
|
||||
}
|
||||
if (constructors.length == 0 && params.length == 0) {
|
||||
result.add(createConstructorReferenceLookup(functionalInterfaceType, expectedReturnType));
|
||||
}
|
||||
}
|
||||
else if (params.length == 1 && PsiType.INT.equals(params[0].getType())){
|
||||
result.add(createConstructorReferenceLookup(functionalInterfaceType, expectedReturnType));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -141,6 +158,14 @@ public class FunctionalExpressionCompletionProvider extends CompletionProvider<C
|
||||
return result;
|
||||
}
|
||||
|
||||
private static LookupElement createConstructorReferenceLookup(PsiType functionalInterfaceType, PsiType expectedReturnType) {
|
||||
return LookupElementBuilder
|
||||
.create(expectedReturnType.getPresentableText() + "::new")
|
||||
.withTypeText(functionalInterfaceType.getPresentableText())
|
||||
.withIcon(AllIcons.Nodes.MethodReference)
|
||||
.withAutoCompletionPolicy(AutoCompletionPolicy.NEVER_AUTOCOMPLETE);
|
||||
}
|
||||
|
||||
private static void collectThisVariants(PsiType functionalInterfaceType,
|
||||
PsiParameter[] params,
|
||||
PsiElement originalPosition,
|
||||
|
||||
+36
@@ -148,6 +148,42 @@ class Test88 {
|
||||
}
|
||||
"""
|
||||
}
|
||||
|
||||
public void "test constructor ref without start"() {
|
||||
myFixture.configureByText "a.java", """
|
||||
interface Foo9 {
|
||||
Bar test(int p);
|
||||
}
|
||||
|
||||
class Bar {
|
||||
public Bar(int p) {}
|
||||
}
|
||||
|
||||
class Test88 {
|
||||
{
|
||||
Foo9 f = <caret>;
|
||||
}
|
||||
}
|
||||
"""
|
||||
def items = myFixture.completeBasic()
|
||||
assert items.find {LookupElementPresentation.renderElement(it).itemText.contains('Bar::new')}
|
||||
}
|
||||
|
||||
public void "test new array ref"() {
|
||||
myFixture.configureByText "a.java", """
|
||||
interface Foo9<T> {
|
||||
T test(int p);
|
||||
}
|
||||
|
||||
class Test88 {
|
||||
{
|
||||
Foo9<String[]> f = <caret>;
|
||||
}
|
||||
}
|
||||
"""
|
||||
def items = myFixture.completeBasic()
|
||||
assert items.find {LookupElementPresentation.renderElement(it).itemText.contains('String[]::new')}
|
||||
}
|
||||
|
||||
public void testCollectorsToList() {
|
||||
configureByTestName()
|
||||
|
||||
Reference in New Issue
Block a user