Search in sources :

Example 1 with GroovyResolveResultImpl

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()]);
}
Also used : GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) GrAnnotation(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation) GroovyResolveResultImpl(org.jetbrains.plugins.groovy.lang.psi.impl.GroovyResolveResultImpl)

Example 2 with GroovyResolveResultImpl

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;
}
Also used : GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) GrConstructorInvocation(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrConstructorInvocation) GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) PsiClass(com.intellij.psi.PsiClass) PsiSubstitutor(com.intellij.psi.PsiSubstitutor) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) PsiElement(com.intellij.psi.PsiElement) GroovyResolveResultImpl(org.jetbrains.plugins.groovy.lang.psi.impl.GroovyResolveResultImpl) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with GroovyResolveResultImpl

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;
    }
}
Also used : GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) GroovyResolveResultImpl(org.jetbrains.plugins.groovy.lang.psi.impl.GroovyResolveResultImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with GroovyResolveResultImpl

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;
}
Also used : GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) ElementClassHint(com.intellij.psi.scope.ElementClassHint) NameHint(com.intellij.psi.scope.NameHint) GroovyResolveResultImpl(org.jetbrains.plugins.groovy.lang.psi.impl.GroovyResolveResultImpl)

Example 5 with GroovyResolveResultImpl

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;
}
Also used : NotNullComputable(com.intellij.openapi.util.NotNullComputable) GroovyMethodResult(org.jetbrains.plugins.groovy.lang.psi.impl.GroovyMethodResult) GroovyResolveResultImpl(org.jetbrains.plugins.groovy.lang.psi.impl.GroovyResolveResultImpl) SpreadState(org.jetbrains.plugins.groovy.lang.psi.api.SpreadState)

Aggregations

GroovyResolveResultImpl (org.jetbrains.plugins.groovy.lang.psi.impl.GroovyResolveResultImpl)10 GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)6 LookupElement (com.intellij.codeInsight.lookup.LookupElement)2 PsiClass (com.intellij.psi.PsiClass)2 PsiElement (com.intellij.psi.PsiElement)2 NotNull (org.jetbrains.annotations.NotNull)2 SpreadState (org.jetbrains.plugins.groovy.lang.psi.api.SpreadState)2 GrAnnotation (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation)2 ASTNode (com.intellij.lang.ASTNode)1 NotNullComputable (com.intellij.openapi.util.NotNullComputable)1 PsiAnnotation (com.intellij.psi.PsiAnnotation)1 PsiMethod (com.intellij.psi.PsiMethod)1 PsiSubstitutor (com.intellij.psi.PsiSubstitutor)1 LeafPsiElement (com.intellij.psi.impl.source.tree.LeafPsiElement)1 PsiLocalVariableImpl (com.intellij.psi.impl.source.tree.java.PsiLocalVariableImpl)1 ElementClassHint (com.intellij.psi.scope.ElementClassHint)1 NameHint (com.intellij.psi.scope.NameHint)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Nullable (org.jetbrains.annotations.Nullable)1