mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
IDEA-167807 Completion inside wildcard type suggests equals
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package abcdef;
|
||||
|
||||
public class Foo {
|
||||
void foo() {
|
||||
Class<String> classOfString = (Class<? <caret>>)aClass.cast(Long.class);
|
||||
}
|
||||
|
||||
static class NClass {}
|
||||
}
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user