IDEA-175672 Duplicate "new char[]" suggestions

This commit is contained in:
peter
2017-07-12 22:02:38 +02:00
parent 4ce6e7c0df
commit 3cd5240969
5 changed files with 25 additions and 3 deletions

View File

@@ -308,12 +308,24 @@ public class JavaCompletionContributor extends CompletionContributor {
if (JavaSmartCompletionContributor.AFTER_NEW.accepts(position)) {
session.flushBatchItems();
new JavaInheritorsGetter(ConstructorInsertHandler.BASIC_INSTANCE).generateVariants(parameters, matcher, session::addClassItem);
new JavaInheritorsGetter(ConstructorInsertHandler.BASIC_INSTANCE).generateVariants(parameters, matcher, lookupElement -> {
if (!isSuggestedByKeywordCompletion(lookupElement)) {
session.addClassItem(lookupElement);
}
});
}
suggestSmartCast(parameters, session, false, result);
}
private static boolean isSuggestedByKeywordCompletion(LookupElement lookupElement) {
if (lookupElement instanceof PsiTypeLookupItem) {
PsiType type = ((PsiTypeLookupItem)lookupElement).getType();
return type instanceof PsiArrayType && ((PsiArrayType)type).getComponentType() instanceof PsiPrimitiveType;
}
return false;
}
private static void suggestSmartCast(CompletionParameters parameters, JavaCompletionSession session, boolean quick, Consumer<LookupElement> result) {
if (SmartCastProvider.shouldSuggestCast(parameters)) {
session.flushBatchItems();

View File

@@ -0,0 +1,5 @@
class Foo {
{
char[] cc = new cha<caret>x
}
}

View File

@@ -1,5 +1,5 @@
public class Bar {
{
int[] a = new in<caret>
int[] a = new in<caret>x
}
}

View File

@@ -1,5 +1,5 @@
public class Bar {
{
int[] a = new int[<caret>]
int[] a = new int[<caret>]x
}
}

View File

@@ -683,6 +683,11 @@ public class ListUtils {
assert myFixture.lookupElementStrings == ['void']
}
void testNoExpectedArrayTypeDuplication() {
configure()
assert myFixture.lookupElementStrings == ['char']
}
void testMethodReturnType() throws Throwable {
doTest()
}