Search in sources :

Example 1 with ResolverProcessor

use of org.jetbrains.plugins.groovy.lang.resolve.processors.ResolverProcessor in project intellij-community by JetBrains.

the class GroovyDocCompletionProvider method addCompletions.

@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
    final PsiElement position = parameters.getPosition();
    GrDocMemberReference reference = PsiTreeUtil.getParentOfType(position, GrDocMemberReference.class);
    if (reference == null)
        return;
    GrDocReferenceElement holder = reference.getReferenceHolder();
    PsiElement resolved;
    if (holder != null) {
        GrCodeReferenceElement referenceElement = holder.getReferenceElement();
        resolved = referenceElement != null ? referenceElement.resolve() : null;
    } else {
        resolved = PsiUtil.getContextClass(reference);
    }
    if (resolved instanceof PsiClass) {
        ResolverProcessor propertyProcessor = CompletionProcessor.createPropertyCompletionProcessor(reference);
        resolved.processDeclarations(propertyProcessor, ResolveState.initial(), null, reference);
        PsiElement[] propertyCandidates = ResolveUtil.mapToElements(propertyProcessor.getCandidates());
        ResolverProcessor methodProcessor = CompletionProcessor.createPropertyCompletionProcessor(reference);
        resolved.processDeclarations(methodProcessor, ResolveState.initial(), null, reference);
        PsiElement[] methodCandidates = ResolveUtil.mapToElements(methodProcessor.getCandidates());
        PsiElement[] elements = ArrayUtil.mergeArrays(propertyCandidates, methodCandidates);
        for (PsiElement psiElement : elements) {
            LookupElement element = GroovyCompletionUtil.createLookupElement((PsiNamedElement) psiElement);
            if (psiElement instanceof PsiMethod) {
                element = ((LookupElementBuilder) element).withInsertHandler(new GroovyMethodSignatureInsertHandler());
            }
            result.addElement(element);
        }
    }
}
Also used : GrCodeReferenceElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement) ResolverProcessor(org.jetbrains.plugins.groovy.lang.resolve.processors.ResolverProcessor) GroovyMethodSignatureInsertHandler(org.jetbrains.plugins.groovy.lang.completion.handlers.GroovyMethodSignatureInsertHandler) GrDocReferenceElement(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocReferenceElement) GrDocMemberReference(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocMemberReference) LookupElement(com.intellij.codeInsight.lookup.LookupElement)

Example 2 with ResolverProcessor

use of org.jetbrains.plugins.groovy.lang.resolve.processors.ResolverProcessor in project intellij-community by JetBrains.

the class RenameAliasedUsagesUtil method findAliasedName.

private static String findAliasedName(Map<GroovyFile, String> map, GroovyFile containingFile, PsiElement elementToResolve) {
    final String s = map.get(containingFile);
    if (s != null)
        return s;
    final GrImportStatement[] imports = containingFile.getImportStatements();
    final PsiManager manager = elementToResolve.getManager();
    for (GrImportStatement anImport : imports) {
        if (anImport.isAliasedImport()) {
            final ResolverProcessor processor = getProcessor(elementToResolve, containingFile);
            anImport.processDeclarations(processor, ResolveState.initial(), null, containingFile);
            final GroovyResolveResult[] results = processor.getCandidates();
            for (GroovyResolveResult result : results) {
                if (manager.areElementsEquivalent(elementToResolve, result.getElement())) {
                    final String importedName = anImport.getImportedName();
                    if (importedName != null) {
                        map.put(containingFile, importedName);
                        return importedName;
                    }
                }
            }
        }
    }
    map.put(containingFile, EMPTY_ALIAS);
    return EMPTY_ALIAS;
}
Also used : GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) MethodResolverProcessor(org.jetbrains.plugins.groovy.lang.resolve.processors.MethodResolverProcessor) PropertyResolverProcessor(org.jetbrains.plugins.groovy.lang.resolve.processors.PropertyResolverProcessor) ClassResolverProcessor(org.jetbrains.plugins.groovy.lang.resolve.processors.ClassResolverProcessor) ResolverProcessor(org.jetbrains.plugins.groovy.lang.resolve.processors.ResolverProcessor) GrImportStatement(org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement)

Example 3 with ResolverProcessor

use of org.jetbrains.plugins.groovy.lang.resolve.processors.ResolverProcessor in project intellij-community by JetBrains.

the class GroovyDslDefaultMembers method delegatesTo.

/**
   * **********************************************************************************
   * Methods and properties of the GroovyDSL language
   * **********************************************************************************
   */
public void delegatesTo(@Nullable PsiElement elem, GdslMembersHolderConsumer consumer) {
    if (elem instanceof PsiClass) {
        final PsiClass clazz = (PsiClass) elem;
        final NonCodeMembersHolder holder = new NonCodeMembersHolder();
        if (clazz instanceof GrTypeDefinition) {
            final PsiClassType type = JavaPsiFacade.getElementFactory(consumer.getProject()).createType(clazz);
            final ResolverProcessor processor = CompletionProcessor.createPropertyCompletionProcessor(clazz);
            final GroovyPsiElement context = (GroovyPsiElement) clazz;
            ResolveUtil.processAllDeclarations(type, processor, ResolveState.initial(), context);
            for (GroovyResolveResult result : processor.getCandidates()) {
                final PsiElement element = result.getElement();
                if (element instanceof PsiMethod && !((PsiMethod) element).isConstructor() || element instanceof PsiField) {
                    holder.addDeclaration(element);
                }
            }
        } else {
            for (PsiMethod method : clazz.getAllMethods()) {
                if (!method.isConstructor())
                    holder.addDeclaration(method);
            }
            for (PsiField field : clazz.getAllFields()) {
                holder.addDeclaration(field);
            }
        }
        consumer.addMemberHolder(holder);
    } else if (elem instanceof GrExpression) {
        GrExpression expr = (GrExpression) elem;
        final PsiType type = expr.getType();
        if (type instanceof PsiClassType) {
            PsiClassType ctype = (PsiClassType) type;
            delegatesTo(ctype.resolve(), consumer);
        }
    }
}
Also used : GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) ResolverProcessor(org.jetbrains.plugins.groovy.lang.resolve.processors.ResolverProcessor) NonCodeMembersHolder(org.jetbrains.plugins.groovy.dsl.holders.NonCodeMembersHolder) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)

Example 4 with ResolverProcessor

use of org.jetbrains.plugins.groovy.lang.resolve.processors.ResolverProcessor in project intellij-community by JetBrains.

the class ControlFlowBuilderUtil method resolveNonQualifiedRefWithoutFlow.

@NotNull
public static GroovyResolveResult[] resolveNonQualifiedRefWithoutFlow(@NotNull GrReferenceExpression ref) {
    LOG.assertTrue(!ref.isQualified());
    final String referenceName = ref.getReferenceName();
    final ResolverProcessor processor = new PropertyResolverProcessor(referenceName, ref);
    treeWalkUp(ref, processor);
    final GroovyResolveResult[] candidates = processor.getCandidates();
    if (candidates.length != 0) {
        return candidates;
    }
    return GroovyResolveResult.EMPTY_ARRAY;
}
Also used : GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) PropertyResolverProcessor(org.jetbrains.plugins.groovy.lang.resolve.processors.PropertyResolverProcessor) ResolverProcessor(org.jetbrains.plugins.groovy.lang.resolve.processors.ResolverProcessor) PropertyResolverProcessor(org.jetbrains.plugins.groovy.lang.resolve.processors.PropertyResolverProcessor) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ResolverProcessor (org.jetbrains.plugins.groovy.lang.resolve.processors.ResolverProcessor)4 GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)3 PropertyResolverProcessor (org.jetbrains.plugins.groovy.lang.resolve.processors.PropertyResolverProcessor)2 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 NotNull (org.jetbrains.annotations.NotNull)1 NonCodeMembersHolder (org.jetbrains.plugins.groovy.dsl.holders.NonCodeMembersHolder)1 GroovyMethodSignatureInsertHandler (org.jetbrains.plugins.groovy.lang.completion.handlers.GroovyMethodSignatureInsertHandler)1 GrDocMemberReference (org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocMemberReference)1 GrDocReferenceElement (org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocReferenceElement)1 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)1 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)1 GrTypeDefinition (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition)1 GrImportStatement (org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement)1 GrCodeReferenceElement (org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement)1 ClassResolverProcessor (org.jetbrains.plugins.groovy.lang.resolve.processors.ClassResolverProcessor)1 MethodResolverProcessor (org.jetbrains.plugins.groovy.lang.resolve.processors.MethodResolverProcessor)1