IDEA-167807 Completion inside wildcard type suggests equals

This commit is contained in:
peter
2017-02-08 17:12:32 +01:00
parent 990d8f5498
commit 030b38fd76
4 changed files with 45 additions and 12 deletions

View File

@@ -59,10 +59,7 @@ import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
import static com.intellij.patterns.PsiJavaPatterns.*;
import static com.intellij.util.ObjectUtils.assertNotNull;
@@ -236,6 +233,10 @@ public class JavaCompletionContributor extends CompletionContributor {
addIdentifierVariants(parameters, position, result, matcher, parent, session);
}
if (JavaMemberNameCompletionContributor.INSIDE_TYPE_PARAMS_PATTERN.accepts(position)) {
return;
}
Set<String> usedWords = addReferenceVariants(parameters, result, session);
if (psiElement().inside(PsiLiteralExpression.class).accepts(position)) {
@@ -478,7 +479,9 @@ public class JavaCompletionContributor extends CompletionContributor {
boolean isSecondCompletion = parameters.getInvocationCount() >= 2;
PsiElement position = parameters.getPosition();
if (JavaKeywordCompletion.isInstanceofPlace(position)) return false;
if (JavaKeywordCompletion.isInstanceofPlace(position) || JavaMemberNameCompletionContributor.INSIDE_TYPE_PARAMS_PATTERN.accepts(position)) {
return false;
}
final PsiElement parent = position.getParent();
if (!(parent instanceof PsiJavaCodeReferenceElement)) return isSecondCompletion;

View File

@@ -260,6 +260,10 @@ public class JavaKeywordCompletion {
return;
}
if (addWildcardExtendsSuper(result, position)) {
return;
}
PsiElement prevLeaf = PsiTreeUtil.prevVisibleLeaf(position);
addFinal(result, position, prevLeaf);
@@ -292,7 +296,16 @@ public class JavaKeywordCompletion {
addUnfinishedMethodTypeParameters(position, result);
addExtendsSuperImplements(result, position, prevLeaf);
addExtendsImplements(result, position, prevLeaf);
}
private static boolean addWildcardExtendsSuper(Consumer<LookupElement> result, PsiElement position) {
if (JavaMemberNameCompletionContributor.INSIDE_TYPE_PARAMS_PATTERN.accepts(position)) {
result.consume(new OverrideableSpace(createKeyword(position, PsiKeyword.EXTENDS), TailType.HUMBLE_SPACE_BEFORE_WORD));
result.consume(new OverrideableSpace(createKeyword(position, PsiKeyword.SUPER), TailType.HUMBLE_SPACE_BEFORE_WORD));
return true;
}
return false;
}
private static void addMethodHeaderKeywords(Consumer<LookupElement> result, PsiElement position, @Nullable PsiElement prevLeaf) {
@@ -499,12 +512,7 @@ public class JavaKeywordCompletion {
}
}
private static void addExtendsSuperImplements(Consumer<LookupElement> result, PsiElement position, @Nullable PsiElement prevLeaf) {
if (JavaMemberNameCompletionContributor.INSIDE_TYPE_PARAMS_PATTERN.accepts(position)) {
result.consume(new OverrideableSpace(createKeyword(position, PsiKeyword.EXTENDS), TailType.HUMBLE_SPACE_BEFORE_WORD));
result.consume(new OverrideableSpace(createKeyword(position, PsiKeyword.SUPER), TailType.HUMBLE_SPACE_BEFORE_WORD));
}
private static void addExtendsImplements(Consumer<LookupElement> result, PsiElement position, @Nullable PsiElement prevLeaf) {
if (prevLeaf == null || !(prevLeaf instanceof PsiIdentifier || prevLeaf.textMatches(">"))) return;
PsiClass psiClass = null;

View File

@@ -0,0 +1,9 @@
package abcdef;
public class Foo {
void foo() {
Class<String> classOfString = (Class<? <caret>>)aClass.cast(Long.class);
}
static class NClass {}
}

View File

@@ -1745,4 +1745,17 @@ class Bar {
void testSuggestClassNamesForLambdaParameterTypes() { doTest('\n') }
void testOnlyExtendsSuperInWildcard() {
CodeInsightSettings.instance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.NONE
configure()
assert myFixture.lookupElementStrings == ['extends', 'super']
LookupManager.getInstance(project).hideActiveLookup()
myFixture.type('n')
assert !myFixture.completeBasic()
myFixture.type('\b')
checkResultByFile(getTestName(false) + ".java")
}
}