use of com.intellij.psi.scope.PsiScopeProcessor in project intellij-plugins by JetBrains.
the class FlexResolveHelper method importClass.
public boolean importClass(final PsiScopeProcessor processor, final PsiNamedElement file) {
// there is no need to process package stuff at function level
if (file instanceof JSFunction)
return true;
if (file instanceof XmlBackedJSClassImpl) {
if (!processInlineComponentsInScope((XmlBackedJSClassImpl) file, inlineComponent -> processor.execute(inlineComponent, ResolveState.initial()))) {
return false;
}
}
final String packageQualifierText = JSResolveUtil.findPackageStatementQualifier(file);
final Project project = file.getProject();
GlobalSearchScope scope = JSResolveUtil.getResolveScope(file);
final MxmlAndFxgFilesProcessor filesProcessor = new MxmlAndFxgFilesProcessor() {
final PsiManager manager = PsiManager.getInstance(project);
public void addDependency(final PsiDirectory directory) {
}
public boolean processFile(final VirtualFile file, final VirtualFile root) {
final PsiFile xmlFile = manager.findFile(file);
if (!(xmlFile instanceof XmlFile))
return true;
return processor.execute(XmlBackedJSClassFactory.getXmlBackedClass((XmlFile) xmlFile), ResolveState.initial());
}
};
PsiFile containingFile = file.getContainingFile();
boolean completion = containingFile.getOriginalFile() != containingFile;
if (completion) {
return processAllMxmlAndFxgFiles(scope, project, filesProcessor, null);
} else {
if (packageQualifierText != null && packageQualifierText.length() > 0) {
if (!processMxmlAndFxgFilesInPackage(scope, project, packageQualifierText, filesProcessor))
return false;
}
return processMxmlAndFxgFilesInPackage(scope, project, "", filesProcessor);
}
}
use of com.intellij.psi.scope.PsiScopeProcessor in project intellij-community by JetBrains.
the class PsiDocParamRef method getReference.
@Override
public PsiReference getReference() {
final PsiDocComment comment = PsiTreeUtil.getParentOfType(this, PsiDocComment.class);
if (comment == null)
return null;
final PsiJavaDocumentedElement owner = comment.getOwner();
if (!(owner instanceof PsiMethod) && !(owner instanceof PsiClass))
return null;
final ASTNode valueToken = findChildByType(JavaDocTokenType.DOC_TAG_VALUE_TOKEN);
if (valueToken == null)
return null;
final String name = valueToken.getText();
PsiElement reference = null;
final PsiElement firstChild = getFirstChild();
if (firstChild instanceof PsiDocToken && ((PsiDocToken) firstChild).getTokenType().equals(JavaDocTokenType.DOC_TAG_VALUE_LT)) {
final PsiTypeParameter[] typeParameters = ((PsiTypeParameterListOwner) owner).getTypeParameters();
for (PsiTypeParameter typeParameter : typeParameters) {
if (typeParameter.getName().equals(name)) {
reference = typeParameter;
}
}
} else if (owner instanceof PsiMethod) {
final PsiParameter[] parameters = ((PsiMethod) owner).getParameterList().getParameters();
for (PsiParameter parameter : parameters) {
if (parameter.getName().equals(name)) {
reference = parameter;
}
}
}
final PsiElement resultReference = reference;
return new PsiJavaReference() {
@Override
public PsiElement resolve() {
return resultReference;
}
@Override
@NotNull
public String getCanonicalText() {
return valueToken.getText();
}
@Override
public PsiElement handleElementRename(String newElementName) {
final CharTable charTableByTree = SharedImplUtil.findCharTableByTree(getNode());
LeafElement newElement = Factory.createSingleLeafElement(JavaDocTokenType.DOC_TAG_VALUE_TOKEN, newElementName, charTableByTree, getManager());
replaceChild(valueToken, newElement);
return PsiDocParamRef.this;
}
@Override
public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
if (isReferenceTo(element))
return PsiDocParamRef.this;
if (!(element instanceof PsiParameter)) {
throw new IncorrectOperationException("Unsupported operation");
}
return handleElementRename(((PsiParameter) element).getName());
}
@Override
public boolean isReferenceTo(PsiElement element) {
if (!(element instanceof PsiNamedElement))
return false;
PsiNamedElement namedElement = (PsiNamedElement) element;
if (!getCanonicalText().equals(namedElement.getName()))
return false;
return getManager().areElementsEquivalent(resolve(), element);
}
@Override
@NotNull
public PsiElement[] getVariants() {
final PsiElement firstChild = getFirstChild();
Set<String> usedNames = new HashSet<>();
for (PsiDocTag tag : comment.getTags()) {
if (tag.getName().equals("param")) {
PsiDocTagValue valueElement = tag.getValueElement();
if (valueElement != null) {
usedNames.add(valueElement.getText());
}
}
}
PsiNamedElement[] result = PsiNamedElement.EMPTY_ARRAY;
if (firstChild instanceof PsiDocToken && ((PsiDocToken) firstChild).getTokenType().equals(JavaDocTokenType.DOC_TAG_VALUE_LT)) {
result = ((PsiTypeParameterListOwner) owner).getTypeParameters();
} else if (owner instanceof PsiMethod) {
result = ((PsiMethod) owner).getParameterList().getParameters();
}
List<PsiElement> filtered = new ArrayList<>();
for (PsiNamedElement namedElement : result) {
if (!usedNames.contains(namedElement.getName())) {
filtered.add(namedElement);
}
}
return filtered.toArray(new PsiElement[filtered.size()]);
}
@Override
public boolean isSoft() {
return false;
}
@Override
public TextRange getRangeInElement() {
final int startOffsetInParent = valueToken.getPsi().getStartOffsetInParent();
return new TextRange(startOffsetInParent, startOffsetInParent + valueToken.getTextLength());
}
@Override
public PsiElement getElement() {
return PsiDocParamRef.this;
}
@Override
public void processVariants(@NotNull PsiScopeProcessor processor) {
for (final PsiElement element : getVariants()) {
if (!processor.execute(element, ResolveState.initial())) {
return;
}
}
}
@Override
@NotNull
public JavaResolveResult advancedResolve(boolean incompleteCode) {
return resultReference == null ? JavaResolveResult.EMPTY : new CandidateInfo(resultReference, PsiSubstitutor.EMPTY);
}
@Override
@NotNull
public JavaResolveResult[] multiResolve(boolean incompleteCode) {
return resultReference == null ? JavaResolveResult.EMPTY_ARRAY : new JavaResolveResult[] { new CandidateInfo(resultReference, PsiSubstitutor.EMPTY) };
}
};
}
use of com.intellij.psi.scope.PsiScopeProcessor in project intellij-community by JetBrains.
the class GdkMethodUtil method processMixinToMetaclass.
public static boolean processMixinToMetaclass(GrStatementOwner run, final PsiScopeProcessor processor, ResolveState state, PsiElement lastParent, PsiElement place) {
GrStatement[] statements = run.getStatements();
for (GrStatement statement : statements) {
if (statement == lastParent)
break;
final Trinity<PsiClassType, GrReferenceExpression, PsiClass> result = getMixinTypes(statement);
if (result != null) {
final PsiClassType subjectType = result.first;
final GrReferenceExpression qualifier = result.second;
final PsiClass mixin = result.third;
for (PsiScopeProcessor each : GroovyResolverProcessor.allProcessors(processor)) {
if (!mixin.processDeclarations(new MixinMemberContributor.MixinProcessor(each, subjectType, qualifier), state, null, place)) {
return false;
}
}
} else {
Trinity<PsiClassType, GrReferenceExpression, List<GrMethod>> closureResult = getClosureMixins(statement);
if (closureResult != null) {
final PsiClassType subjectType = closureResult.first;
final GrReferenceExpression qualifier = closureResult.second;
final List<GrMethod> methods = closureResult.third;
final DelegatingScopeProcessor delegate = new MixinMemberContributor.MixinProcessor(processor, subjectType, qualifier);
for (GrMethod method : methods) {
ResolveUtil.processElement(delegate, method, state);
}
}
}
}
return true;
}
use of com.intellij.psi.scope.PsiScopeProcessor in project intellij-community by JetBrains.
the class GrCollectionTypeMembersProvider method processDynamicElements.
@Override
public void processDynamicElements(@NotNull final PsiType qualifierType, PsiClass aClass, @NotNull final PsiScopeProcessor processor, @NotNull final PsiElement place, @NotNull final ResolveState state) {
final PsiType collectionType = PsiUtil.extractIterableTypeParameter(qualifierType, true);
if (collectionType == null)
return;
PsiClass collectionClass = JavaPsiFacade.getInstance(place.getProject()).findClass(CommonClassNames.JAVA_UTIL_COLLECTION, place.getResolveScope());
final PsiScopeProcessor fieldSearcher = new FieldSearcher(processor, collectionClass);
ResolveUtil.processAllDeclarations(collectionType, fieldSearcher, state, place);
}
use of com.intellij.psi.scope.PsiScopeProcessor in project intellij-community by JetBrains.
the class GdkMethodDslProvider method processCategoryMethods.
private static void processCategoryMethods(final String className, final GdslMembersHolderConsumer consumer, final boolean isStatic) {
final GlobalSearchScope scope = consumer.getResolveScope();
final PsiClass categoryClass = JavaPsiFacade.getInstance(consumer.getProject()).findClass(className, scope);
if (categoryClass == null) {
return;
}
final VolatileNotNullLazyValue<GdkMethodHolder> methodsMap = new VolatileNotNullLazyValue<GdkMethodHolder>() {
@NotNull
@Override
protected GdkMethodHolder compute() {
return GdkMethodHolder.getHolderForClass(categoryClass, isStatic, scope);
}
};
consumer.addMemberHolder(new CustomMembersHolder() {
@Override
public boolean processMembers(GroovyClassDescriptor descriptor, PsiScopeProcessor _processor, ResolveState state) {
for (PsiScopeProcessor each : GroovyResolverProcessor.allProcessors(_processor)) {
if (ResolveUtil.shouldProcessMethods(each.getHint(ElementClassHint.KEY)) && !methodsMap.getValue().processMethods(each, state, descriptor.getPsiType(), descriptor.getProject())) {
return false;
}
}
return true;
}
});
}
Aggregations