Search in sources :

Example 6 with GroovyResolveResultImpl

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

the class ResolverProcessorImpl method execute.

@Override
public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
    if (element instanceof PsiLocalVariableImpl) {
        // the debugger creates a Java code block context and our expressions to evaluate resolve there
        return true;
    }
    if (myResolveTargetKinds == null || myResolveTargetKinds.contains(getDeclarationKind(element))) {
        //don't check field for name because they can be aliased imported
        if (element instanceof PsiVariable && !(element instanceof PsiField) && myName != null && !myName.equals(((PsiVariable) element).getName())) {
            return true;
        }
        PsiNamedElement namedElement = (PsiNamedElement) element;
        PsiSubstitutor substitutor = state.get(PsiSubstitutor.KEY);
        if (substitutor == null)
            substitutor = PsiSubstitutor.EMPTY;
        if (myTypeArguments.length > 0 && namedElement instanceof PsiClass) {
            substitutor = substitutor.putAll((PsiClass) namedElement, myTypeArguments);
        }
        if (namedElement instanceof PsiClass && !(namedElement instanceof PsiTypeParameter)) {
            final PsiClass aClass = (PsiClass) namedElement;
            if (myProcessedClasses == null)
                myProcessedClasses = new HashSet<>();
            if (!myProcessedClasses.add(aClass.getQualifiedName())) {
                return true;
            }
        }
        boolean isAccessible = isAccessible(namedElement);
        final PsiElement resolveContext = state.get(RESOLVE_CONTEXT);
        final SpreadState spreadState = state.get(SpreadState.SPREAD_STATE);
        boolean isStaticsOK = isStaticsOK(namedElement, resolveContext, false);
        addCandidate(new GroovyResolveResultImpl(namedElement, resolveContext, spreadState, substitutor, isAccessible, isStaticsOK));
        return !(isAccessible && isStaticsOK);
    }
    return true;
}
Also used : PsiLocalVariableImpl(com.intellij.psi.impl.source.tree.java.PsiLocalVariableImpl) SpreadState(org.jetbrains.plugins.groovy.lang.psi.api.SpreadState) GroovyResolveResultImpl(org.jetbrains.plugins.groovy.lang.psi.impl.GroovyResolveResultImpl) HashSet(java.util.HashSet)

Example 7 with GroovyResolveResultImpl

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

the class GrDocParameterReferenceImpl method multiResolve.

@Override
@NotNull
public ResolveResult[] multiResolve(boolean incompleteCode) {
    final String name = getName();
    if (name == null)
        return ResolveResult.EMPTY_ARRAY;
    ArrayList<GroovyResolveResult> candidates = new ArrayList<>();
    final PsiElement owner = GrDocCommentUtil.findDocOwner(this);
    if (owner instanceof GrMethod) {
        final GrMethod method = (GrMethod) owner;
        final GrParameter[] parameters = method.getParameters();
        for (GrParameter parameter : parameters) {
            if (name.equals(parameter.getName())) {
                candidates.add(new GroovyResolveResultImpl(parameter, true));
            }
        }
        return candidates.toArray(new ResolveResult[candidates.size()]);
    } else {
        final PsiElement firstChild = getFirstChild();
        if (owner instanceof GrTypeParameterListOwner && firstChild != null) {
            final ASTNode node = firstChild.getNode();
            if (node != null && GroovyDocTokenTypes.mGDOC_TAG_VALUE_LT.equals(node.getElementType())) {
                final PsiTypeParameter[] typeParameters = ((PsiTypeParameterListOwner) owner).getTypeParameters();
                for (PsiTypeParameter typeParameter : typeParameters) {
                    if (name.equals(typeParameter.getName())) {
                        candidates.add(new GroovyResolveResultImpl(typeParameter, true));
                    }
                }
            }
        }
    }
    return ResolveResult.EMPTY_ARRAY;
}
Also used : ArrayList(java.util.ArrayList) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) GrParameter(org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter) GroovyResolveResultImpl(org.jetbrains.plugins.groovy.lang.psi.impl.GroovyResolveResultImpl) GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) ASTNode(com.intellij.lang.ASTNode) GrTypeParameterListOwner(org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeParameterListOwner) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with GroovyResolveResultImpl

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

the class GrAnnotationNameValuePairImpl method multiResolveFromAnnotationType.

private static GroovyResolveResult[] multiResolveFromAnnotationType(@NotNull PsiClass resolved, @NotNull String name) {
    PsiMethod[] methods = resolved.findMethodsByName(name, false);
    if (methods.length == 0)
        return GroovyResolveResult.EMPTY_ARRAY;
    final GroovyResolveResult[] results = new GroovyResolveResult[methods.length];
    for (int i = 0; i < methods.length; i++) {
        PsiMethod method = methods[i];
        results[i] = new GroovyResolveResultImpl(method, true);
    }
    return results;
}
Also used : GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) GroovyResolveResultImpl(org.jetbrains.plugins.groovy.lang.psi.impl.GroovyResolveResultImpl)

Example 9 with GroovyResolveResultImpl

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

the class AnnotationAttributeCompletionResultProcessor method process.

public void process(@NotNull Consumer<LookupElement> consumer, @NotNull PrefixMatcher matcher) {
    GrCodeReferenceElement ref = myAnnotation.getClassReference();
    PsiElement resolved = ref.resolve();
    if (resolved instanceof PsiClass) {
        final PsiAnnotation annotationCollector = GrAnnotationCollector.findAnnotationCollector((PsiClass) resolved);
        if (annotationCollector != null) {
            final ArrayList<GrAnnotation> annotations = ContainerUtil.newArrayList();
            GrAnnotationCollector.collectAnnotations(annotations, myAnnotation, annotationCollector);
            Set<String> usedNames = ContainerUtil.newHashSet();
            for (GrAnnotation annotation : annotations) {
                final PsiElement resolvedAliased = annotation.getClassReference().resolve();
                if (resolvedAliased instanceof PsiClass && ((PsiClass) resolvedAliased).isAnnotationType()) {
                    for (PsiMethod method : ((PsiClass) resolvedAliased).getMethods()) {
                        if (usedNames.add(method.getName())) {
                            for (LookupElement element : GroovyCompletionUtil.createLookupElements(new GroovyResolveResultImpl(method, true), false, matcher, null)) {
                                consumer.consume(element);
                            }
                        }
                    }
                }
            }
        } else if (((PsiClass) resolved).isAnnotationType()) {
            for (PsiMethod method : ((PsiClass) resolved).getMethods()) {
                for (LookupElement element : GroovyCompletionUtil.createLookupElements(new GroovyResolveResultImpl(method, true), false, matcher, null)) {
                    consumer.consume(element);
                }
            }
        }
    }
}
Also used : GrCodeReferenceElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement) GrAnnotation(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation) PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) PsiAnnotation(com.intellij.psi.PsiAnnotation) LookupElement(com.intellij.codeInsight.lookup.LookupElement) PsiElement(com.intellij.psi.PsiElement) GroovyResolveResultImpl(org.jetbrains.plugins.groovy.lang.psi.impl.GroovyResolveResultImpl)

Example 10 with GroovyResolveResultImpl

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

the class CompleteCodeReferenceElement method feedLookupElements.

private void feedLookupElements(@NotNull PsiNamedElement psi, boolean afterNew) {
    GroovyResolveResultImpl candidate = new GroovyResolveResultImpl(psi, true);
    List<? extends LookupElement> elements = GroovyCompletionUtil.createLookupElements(candidate, afterNew, myMatcher, null);
    for (LookupElement element : elements) {
        myConsumer.consume(element);
    }
}
Also used : LookupElement(com.intellij.codeInsight.lookup.LookupElement) GroovyResolveResultImpl(org.jetbrains.plugins.groovy.lang.psi.impl.GroovyResolveResultImpl)

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