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();
}
Aggregations