mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-49425 Groovy: completion for special property ('.@') and method ('.&') access syntax shows irrelevant choices
This commit is contained in:
+20
-7
@@ -342,6 +342,8 @@ public class CompleteReferenceExpression {
|
||||
private final Set<String> myPropertyNames = new HashSet<String>();
|
||||
private final Set<String> myLocalVars = new HashSet<String>();
|
||||
private final Set<GrMethod> myProcessedMethodWithOptionalParams = new HashSet<GrMethod>();
|
||||
private final boolean myFieldPointerOperator;
|
||||
private final boolean myMethodPointerOperator;
|
||||
|
||||
protected CompleteReferenceProcessor(GrReferenceExpression place, Consumer<Object> consumer, @NotNull PrefixMatcher matcher, CompletionParameters parameters) {
|
||||
super(null, EnumSet.allOf(ResolveKind.class), place, PsiType.EMPTY_ARRAY);
|
||||
@@ -352,6 +354,9 @@ public class CompleteReferenceExpression {
|
||||
mySkipPackages = PsiImplUtil.getRuntimeQualifier(place) == null;
|
||||
myEventListener = JavaPsiFacade.getInstance(place.getProject()).findClass("java.util.EventListener", place.getResolveScope());
|
||||
myPropertyNames.addAll(addAllRestrictedProperties(place));
|
||||
|
||||
myFieldPointerOperator = place.hasAt();
|
||||
myMethodPointerOperator = place.getDotTokenType() == GroovyTokenTypes.mMEMBER_POINTER;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -396,17 +401,25 @@ public class CompleteReferenceExpression {
|
||||
result.isInvokedOnProperty());
|
||||
}
|
||||
|
||||
if (myFieldPointerOperator && !(element instanceof PsiVariable)) {
|
||||
return;
|
||||
}
|
||||
if (myMethodPointerOperator && !(element instanceof PsiMethod)) {
|
||||
return;
|
||||
}
|
||||
addCandidate(result);
|
||||
|
||||
if (element instanceof PsiMethod) {
|
||||
processProperty((PsiMethod)element, result);
|
||||
}
|
||||
else if (element instanceof GrField) {
|
||||
if (((GrField)element).isProperty()) {
|
||||
processPropertyFromField((GrField)element, result);
|
||||
if (!myFieldPointerOperator && !myMethodPointerOperator) {
|
||||
if (element instanceof PsiMethod) {
|
||||
processProperty((PsiMethod)element, result);
|
||||
}
|
||||
else if (element instanceof GrField) {
|
||||
if (((GrField)element).isProperty()) {
|
||||
processPropertyFromField((GrField)element, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (element instanceof GrVariable) {
|
||||
if (element instanceof GrVariable && !(element instanceof GrField)) {
|
||||
myLocalVars.add(((GrVariable)element).getName());
|
||||
}
|
||||
}
|
||||
|
||||
+42
-3
@@ -18,13 +18,13 @@ package org.jetbrains.plugins.groovy.completion;
|
||||
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightSettings
|
||||
import com.intellij.codeInsight.completion.CompletionType
|
||||
import com.intellij.codeInsight.lookup.LookupElement
|
||||
import com.intellij.codeInsight.lookup.LookupElementPresentation
|
||||
import org.jetbrains.plugins.groovy.GroovyFileType
|
||||
import org.jetbrains.plugins.groovy.util.TestUtils
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager
|
||||
import org.jetbrains.plugins.groovy.GroovyFileType
|
||||
import org.jetbrains.plugins.groovy.formatter.GroovyCodeStyleSettings
|
||||
import com.intellij.codeInsight.completion.CompletionType
|
||||
import org.jetbrains.plugins.groovy.util.TestUtils
|
||||
|
||||
/**
|
||||
* @author Maxim.Medvedev
|
||||
@@ -1133,4 +1133,43 @@ Util.foo()<caret>'''
|
||||
}
|
||||
|
||||
public void testPropertyChain() { doBasicTest() }
|
||||
|
||||
public void testMethodPointer() {
|
||||
myFixture.configureByText('_a.groovy', '''\
|
||||
class Base {
|
||||
def prefixMethod(){}
|
||||
def prefixField
|
||||
}
|
||||
|
||||
new Base().&prefix<caret>''')
|
||||
myFixture.completeBasic()
|
||||
assertNull(myFixture.lookupElements)
|
||||
myFixture.checkResult('''\
|
||||
class Base {
|
||||
def prefixMethod(){}
|
||||
def prefixField
|
||||
}
|
||||
|
||||
new Base().&prefixMethod<caret>''')
|
||||
}
|
||||
|
||||
public void testFieldPointer() {
|
||||
myFixture.configureByText('_a.groovy', '''\
|
||||
class Base {
|
||||
def prefixMethod(){}
|
||||
def prefixField
|
||||
}
|
||||
|
||||
new Base().@prefix<caret>''')
|
||||
myFixture.completeBasic()
|
||||
assertNull(myFixture.lookupElements)
|
||||
myFixture.checkResult('''\
|
||||
class Base {
|
||||
def prefixMethod(){}
|
||||
def prefixField
|
||||
}
|
||||
|
||||
new Base().@prefixField<caret>''')
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user