Search in sources :

Example 1 with GrReferenceExpressionImpl

use of org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.GrReferenceExpressionImpl in project intellij-community by JetBrains.

the class GroovyResolverProcessorImpl method getCandidates.

@NotNull
public List<GroovyResolveResult> getCandidates() {
    List<GroovyResolveResult> candidates;
    // return package if whole ref text is valid class name
    if (myAcceptableKinds.contains(GroovyResolveKind.PACKAGE) && myIsPartOfFqn) {
        candidates = getCandidates(GroovyResolveKind.PACKAGE);
        if (!candidates.isEmpty()) {
            final GroovyResolveResult candidate = candidates.get(0);
            final PsiElement element = candidate.getElement();
            assert element instanceof PsiPackage;
            final GrReferenceExpressionImpl topRef = getContextReferenceExpression(myRef);
            if (topRef != null) {
                final String fqn = topRef.getTextSkipWhiteSpaceAndComments();
                if (JavaPsiFacade.getInstance(myRef.getProject()).findClass(fqn, myRef.getResolveScope()) != null) {
                    return candidates;
                }
            }
        }
    }
    candidates = getCandidates(GroovyResolveKind.VARIABLE);
    if (!candidates.isEmpty()) {
        return candidates;
    }
    candidates = getCandidates(GroovyResolveKind.METHOD);
    if (!candidates.isEmpty()) {
        final List<GroovyResolveResult> results = filterMethodCandidates(candidates);
        return myRef.hasMemberPointer() ? collapseReflectedMethods(results) : results;
    }
    candidates = getCandidates(GroovyResolveKind.ENUM_CONST);
    if (!candidates.isEmpty()) {
        return candidates;
    }
    candidates = getCandidates(GroovyResolveKind.FIELD);
    if (!candidates.isEmpty()) {
        assert candidates.size() == 1;
        final GroovyResolveResult candidate = candidates.get(0);
        final PsiElement element = candidate.getElement();
        if (element instanceof PsiField) {
            final PsiClass containingClass = ((PsiField) element).getContainingClass();
            if (containingClass != null && PsiUtil.getContextClass(myRef) == containingClass)
                return candidates;
        } else if (!(element instanceof GrBindingVariable)) {
            return candidates;
        }
    }
    if (myIsPartOfFqn) {
        candidates = getCandidates(GroovyResolveKind.PACKAGE, GroovyResolveKind.CLASS);
        if (!candidates.isEmpty()) {
            return candidates;
        }
    }
    candidates = getCandidates(GroovyResolveKind.PROPERTY);
    if (!candidates.isEmpty()) {
        return candidates.size() <= 1 ? candidates : ContainerUtil.newSmartList(candidates.get(0));
    }
    candidates = getCandidates(GroovyResolveKind.FIELD);
    if (!candidates.isEmpty()) {
        return candidates;
    }
    candidates = getCandidates(GroovyResolveKind.PACKAGE, GroovyResolveKind.CLASS);
    if (!candidates.isEmpty()) {
        return candidates;
    }
    candidates = getCandidates(GroovyResolveKind.PROPERTY);
    if (!candidates.isEmpty()) {
        return candidates;
    }
    candidates = getCandidates(GroovyResolveKind.BINDING);
    if (!candidates.isEmpty()) {
        return candidates;
    }
    for (GroovyResolveKind kind : myAcceptableKinds) {
        Collection<GroovyResolveResult> results = myInapplicableCandidates.get(kind);
        if (!results.isEmpty()) {
            return ContainerUtil.newArrayList(ResolveUtil.filterSameSignatureCandidates(filterCorrectParameterCount(results)));
        }
    }
    return Collections.emptyList();
}
Also used : GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) GrBindingVariable(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrBindingVariable) GrReferenceExpressionImpl(org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.GrReferenceExpressionImpl) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

NotNull (org.jetbrains.annotations.NotNull)1 GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)1 GrReferenceExpressionImpl (org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.GrReferenceExpressionImpl)1 GrBindingVariable (org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrBindingVariable)1