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);
}
}
}
Aggregations