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