mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
java completion: remove irrelevant suggestions after Unresolved:: (IDEA-201798)
to enable chain completion, which only works when there are no other suggestions
This commit is contained in:
@@ -34,6 +34,7 @@ import static com.intellij.psi.SyntaxTraverser.psiApi;
|
||||
|
||||
public class JavaKeywordCompletion {
|
||||
public static final ElementPattern<PsiElement> AFTER_DOT = psiElement().afterLeaf(".");
|
||||
private static final ElementPattern<PsiElement> AFTER_DOUBLE_COLON = psiElement().afterLeaf("::");
|
||||
|
||||
static final ElementPattern<PsiElement> VARIABLE_AFTER_FINAL = psiElement().afterLeaf(PsiKeyword.FINAL).inside(PsiDeclarationStatement.class);
|
||||
|
||||
@@ -417,10 +418,12 @@ public class JavaKeywordCompletion {
|
||||
}
|
||||
|
||||
private void addExpressionKeywords(boolean statementPosition) {
|
||||
if (psiElement(JavaTokenType.DOUBLE_COLON).accepts(myPrevLeaf)) {
|
||||
if (AFTER_DOUBLE_COLON.accepts(myPosition)) {
|
||||
PsiMethodReferenceExpression parent = PsiTreeUtil.getParentOfType(myPosition, PsiMethodReferenceExpression.class);
|
||||
TailType tail = parent != null && !LambdaHighlightingUtil.insertSemicolon(parent.getParent()) ? TailType.SEMICOLON : TailType.NONE;
|
||||
addKeyword(new OverridableSpace(createKeyword(PsiKeyword.NEW), tail));
|
||||
if (parent != null && canUseConstructorReference(parent)) {
|
||||
TailType tail = !LambdaHighlightingUtil.insertSemicolon(parent.getParent()) ? TailType.SEMICOLON : TailType.NONE;
|
||||
addKeyword(new OverridableSpace(createKeyword(PsiKeyword.NEW), tail));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -442,6 +445,17 @@ public class JavaKeywordCompletion {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean canUseConstructorReference(PsiMethodReferenceExpression ref) {
|
||||
PsiTypeElement qualifierType = ref.getQualifierType();
|
||||
if (qualifierType == null) {
|
||||
PsiElement qualifier = ref.getQualifier();
|
||||
return qualifier instanceof PsiJavaCodeReferenceElement && ((PsiJavaCodeReferenceElement)qualifier).resolve() != null;
|
||||
}
|
||||
|
||||
if (qualifierType instanceof PsiClassType) return ((PsiClassType)qualifierType).resolve() != null;
|
||||
return qualifierType instanceof PsiArrayType;
|
||||
}
|
||||
|
||||
private boolean isQualifiedNewContext() {
|
||||
if (myPosition.getParent() instanceof PsiReferenceExpression) {
|
||||
PsiExpression qualifier = ((PsiReferenceExpression)myPosition.getParent()).getQualifierExpression();
|
||||
@@ -644,6 +658,7 @@ public class JavaKeywordCompletion {
|
||||
|
||||
static void addPrimitiveTypes(Consumer<? super LookupElement> result, PsiElement position, JavaCompletionSession session) {
|
||||
if (AFTER_DOT.accepts(position) ||
|
||||
AFTER_DOUBLE_COLON.accepts(position) ||
|
||||
psiElement().inside(psiAnnotation()).accepts(position) && !expectsClassLiteral(position)) {
|
||||
return;
|
||||
}
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
class A {
|
||||
{
|
||||
Runnable r = Strings::<caret>
|
||||
}
|
||||
}
|
||||
+7
@@ -340,6 +340,13 @@ class Test88 {
|
||||
checkResultByFileName()
|
||||
}
|
||||
|
||||
void testChainedMethodReferenceWithNoPrefix() {
|
||||
myFixture.addClass("package bar; public class Strings {}")
|
||||
myFixture.addClass("package foo; public class Strings { public static void goo() {} }")
|
||||
configureByTestName()
|
||||
myFixture.assertPreferredCompletionItems 0, 'Strings::goo'
|
||||
}
|
||||
|
||||
void testPreferVariableToLambda() {
|
||||
configureByTestName()
|
||||
myFixture.assertPreferredCompletionItems 0, 'output', 'out -> '
|
||||
|
||||
Reference in New Issue
Block a user