use of org.jetbrains.plugins.groovy.lang.psi.impl.GroovyResolveResultImpl in project intellij-community by JetBrains.
the class GrAnnotationNameValuePairImpl method multiResolveFromAlias.
private static GroovyResolveResult[] multiResolveFromAlias(@NotNull GrAnnotation alias, @NotNull String name, @NotNull PsiAnnotation annotationCollector) {
List<GroovyResolveResult> result = ContainerUtilRt.newArrayList();
List<GrAnnotation> annotations = ContainerUtilRt.newArrayList();
GrAnnotationCollector.collectAnnotations(annotations, alias, annotationCollector);
for (GrAnnotation annotation : annotations) {
final PsiElement clazz = annotation.getClassReference().resolve();
if (clazz instanceof PsiClass && ((PsiClass) clazz).isAnnotationType()) {
if (GroovyCommonClassNames.GROOVY_TRANSFORM_ANNOTATION_COLLECTOR.equals(((PsiClass) clazz).getQualifiedName()))
continue;
for (PsiMethod method : ((PsiClass) clazz).findMethodsByName(name, false)) {
result.add(new GroovyResolveResultImpl(method, true));
}
}
}
return result.toArray(new GroovyResolveResult[result.size()]);
}
use of org.jetbrains.plugins.groovy.lang.psi.impl.GroovyResolveResultImpl in project intellij-community by JetBrains.
the class GrSuperReferenceResolver method resolveSuperExpression.
@Nullable("null if ref is not 'super' reference")
public static GroovyResolveResult[] resolveSuperExpression(@NotNull GrReferenceExpression ref) {
GrExpression qualifier = ref.getQualifier();
if (qualifier == null) {
final PsiElement parent = ref.getParent();
if (parent instanceof GrConstructorInvocation) {
return ((GrConstructorInvocation) parent).multiResolve(false);
}
PsiClass aClass = PsiUtil.getContextClass(ref);
if (aClass != null) {
return getSuperClass(aClass);
}
} else if (qualifier instanceof GrReferenceExpression) {
GroovyResolveResult result = ((GrReferenceExpression) qualifier).advancedResolve();
PsiElement resolved = result.getElement();
if (resolved instanceof PsiClass) {
PsiClass superClass = (PsiClass) resolved;
GrTypeDefinition scopeClass = PsiTreeUtil.getParentOfType(ref, GrTypeDefinition.class, true);
if (scopeClass != null && GrTraitUtil.isTrait(superClass) && scopeClass.isInheritor(superClass, false)) {
PsiSubstitutor superClassSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(superClass, scopeClass, PsiSubstitutor.EMPTY);
return new GroovyResolveResultImpl[] { new GroovyResolveResultImpl(superClass, null, null, superClassSubstitutor, true, true) };
}
if (PsiUtil.hasEnclosingInstanceInScope(superClass, ref, false)) {
return getSuperClass(superClass);
}
}
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.impl.GroovyResolveResultImpl in project intellij-community by JetBrains.
the class GrArgumentLabelImpl method multiResolve.
@NotNull
@Override
public GroovyResolveResult[] multiResolve(boolean incompleteCode) {
final ResolveResult[] results = getRealReference().multiResolve(incompleteCode);
if (results instanceof GroovyResolveResult[]) {
return (GroovyResolveResult[]) results;
} else {
final GroovyResolveResult[] results1 = new GroovyResolveResult[results.length];
for (int i = 0; i < results.length; i++) {
ResolveResult result = results[i];
final PsiElement element = result.getElement();
if (element == null) {
results1[i] = GroovyResolveResult.EMPTY_RESULT;
} else {
results1[i] = new GroovyResolveResultImpl(element, true);
}
}
return results1;
}
}
use of org.jetbrains.plugins.groovy.lang.psi.impl.GroovyResolveResultImpl in project intellij-community by JetBrains.
the class ResolveUtil method getConstructorResolveResult.
private static GroovyResolveResult[] getConstructorResolveResult(PsiMethod[] constructors, PsiElement place) {
GroovyResolveResult[] variants = new GroovyResolveResult[constructors.length];
for (int i = 0; i < constructors.length; i++) {
final boolean isAccessible = PsiUtil.isAccessible(constructors[i], place, null);
variants[i] = new GroovyResolveResultImpl(constructors[i], isAccessible);
}
return variants;
}
use of org.jetbrains.plugins.groovy.lang.psi.impl.GroovyResolveResultImpl in project intellij-community by JetBrains.
the class GroovyResolverProcessor method execute.
@Override
public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
if (!(element instanceof PsiNamedElement))
return true;
final PsiNamedElement namedElement = (PsiNamedElement) element;
final PsiElement resolveContext = state.get(ClassHint.RESOLVE_CONTEXT);
final GroovyResolveKind kind = computeKindAndCheckName(namedElement, resolveContext);
if (!myAcceptableKinds.contains(kind))
return true;
if (kind == GroovyResolveKind.METHOD && myStopExecutingMethods) {
return true;
} else if (kind != GroovyResolveKind.PROPERTY && kind != GroovyResolveKind.METHOD) {
if (!myCandidates.get(kind).isEmpty())
return true;
}
final GroovyResolveResultImpl candidate;
{
final PsiSubstitutor substitutor = getSubstitutor(state);
final SpreadState spreadState = state.get(SpreadState.SPREAD_STATE);
final boolean isAccessible = isAccessible(myRef, namedElement);
final boolean isStaticsOK = isStaticsOK(myRef, namedElement, resolveContext, false);
if (kind == GroovyResolveKind.METHOD || kind == GroovyResolveKind.PROPERTY) {
final PsiMethod method = (PsiMethod) namedElement;
final boolean isApplicable = kind == GroovyResolveKind.PROPERTY && !myIsLValue || isApplicable(myArgumentTypes.getValue(), method, substitutor, myRef, true);
final NotNullComputable<PsiSubstitutor> substitutorComputer;
if (kind == GroovyResolveKind.METHOD) {
substitutorComputer = () -> myMethodSubstitutorComputer.getValue().obtainSubstitutor(substitutor, method, resolveContext);
} else {
substitutorComputer = () -> myPropertySubstitutorComputer.getValue().obtainSubstitutor(substitutor, method, resolveContext);
}
candidate = new GroovyMethodResult(method, resolveContext, spreadState, substitutor, substitutorComputer, kind == GroovyResolveKind.PROPERTY, isAccessible, isStaticsOK, isApplicable);
} else {
candidate = new GroovyResolveResultImpl(namedElement, resolveContext, spreadState, substitutor, isAccessible, isStaticsOK, false, true);
}
}
(candidate.isValidResult() ? myCandidates : myInapplicableCandidates).putValue(kind, candidate);
if (candidate.isValidResult() && kind == GroovyResolveKind.VARIABLE) {
myStopExecutingMethods = true;
}
return true;
}
Aggregations