IDEA-CR-12743, IDEA-157088 The autocomplete to offer not only the implementation of the interface, but the interface itself (when Object arrays are expected)

This commit is contained in:
peter
2016-08-17 16:24:56 +02:00
parent fa1e9e3704
commit 1368f7e7bb
3 changed files with 16 additions and 1 deletions
@@ -84,7 +84,8 @@ public class JavaInheritorsGetter extends CompletionProvider<CompletionParameter
addArrayTypes(parameters.getPosition(), infos, consumer);
List<PsiClassType> classTypes = extractClassTypes(infos);
boolean arraysWelcome = classTypes.stream().anyMatch(t -> t.equalsToText(CommonClassNames.JAVA_LANG_OBJECT));
boolean arraysWelcome = ContainerUtil.exists(ExpectedTypesGetter.extractTypes(infos, true),
t -> t.getDeepComponentType().equalsToText(CommonClassNames.JAVA_LANG_OBJECT));
processInheritors(parameters, classTypes, prefixMatcher, type -> {
final LookupElement element = addExpectedType(type, parameters);
if (element != null) {
@@ -0,0 +1,8 @@
interface MyIntf {}
void foo(MyIntf i){}
void foo(Object[] array){}
void test() {
foo(new MyIntf<caret>)
}
@@ -1603,4 +1603,10 @@ class Bar {
assert LookupElementPresentation.renderElement(myFixture.lookup.items[0]).tailText.contains('{...}')
assert LookupElementPresentation.renderElement(myFixture.lookup.items[1]).tailText.contains('[]')
}
public void testSuggestInterfaceArrayWhenObjectArrayIsExpected() {
configure()
assert LookupElementPresentation.renderElement(myFixture.lookup.items[0]).tailText.contains('{...}')
assert LookupElementPresentation.renderElement(myFixture.lookup.items[1]).tailText.contains('[]')
}
}