Search in sources :

Example 1 with GroovyMethodSignatureInsertHandler

use of org.jetbrains.plugins.groovy.lang.completion.handlers.GroovyMethodSignatureInsertHandler 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)

Aggregations

LookupElement (com.intellij.codeInsight.lookup.LookupElement)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 GrCodeReferenceElement (org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement)1 ResolverProcessor (org.jetbrains.plugins.groovy.lang.resolve.processors.ResolverProcessor)1