IDEA-112567 Don't show any completion variants after method reference and dot

This commit is contained in:
peter
2013-09-06 17:31:32 +02:00
parent 6b3d77c6b3
commit 1952eeec4f
2 changed files with 13 additions and 1 deletions
@@ -35,6 +35,7 @@ import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.patterns.ElementPattern;
import com.intellij.patterns.PatternCondition;
import com.intellij.patterns.PsiJavaElementPattern;
import com.intellij.patterns.PsiNameValuePairPattern;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.*;
@@ -78,6 +79,8 @@ public class JavaCompletionContributor extends CompletionContributor {
public static final ElementPattern<PsiElement> ANNOTATION_NAME = psiElement().
withParents(PsiJavaCodeReferenceElement.class, PsiAnnotation.class).afterLeaf("@");
private static final PsiJavaElementPattern.Capture<PsiElement> UNEXPECTED_REFERENCE_AFTER_DOT =
psiElement().afterLeaf(".").insideStarting(psiExpressionStatement());
private static JavaCompletionData getCompletionData(LanguageLevel level) {
final Set<Map.Entry<LanguageLevel, JavaCompletionData>> entries = ourCompletionData.entrySet();
@@ -203,7 +206,7 @@ public class JavaCompletionContributor extends CompletionContributor {
return;
}
if (AFTER_NUMBER_LITERAL.accepts(position)) {
if (AFTER_NUMBER_LITERAL.accepts(position) || UNEXPECTED_REFERENCE_AFTER_DOT.accepts(position)) {
_result.stopHere();
return;
}
@@ -50,4 +50,13 @@ class Foo {{ Object o = Fo<caret>x }}
class Foo {{ Object o = Foo::<caret>x }}
"""
}
public void testNoSuggestionsAfterMethodReferenceAndDot() {
String text = """
class Foo {{ Object o = StringBuilder::append.<caret> }}
"""
myFixture.configureByText "a.java", text
assertEmpty(myFixture.completeBasic())
myFixture.checkResult(text)
}
}