use of com.intellij.psi.scope.DelegatingScopeProcessor in project intellij-community by JetBrains.
the class PyFileImpl method processDeclarations.
@Override
public boolean processDeclarations(@NotNull final PsiScopeProcessor processor, @NotNull ResolveState resolveState, PsiElement lastParent, @NotNull PsiElement place) {
final List<String> dunderAll = getDunderAll();
final List<String> remainingDunderAll = dunderAll == null ? null : new ArrayList<>(dunderAll);
PsiScopeProcessor wrapper = new DelegatingScopeProcessor(processor) {
@Override
public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
if (!super.execute(element, state))
return false;
if (remainingDunderAll != null && element instanceof PyElement) {
remainingDunderAll.remove(((PyElement) element).getName());
}
return true;
}
};
Set<PyFile> pyFiles = resolveState.get(PROCESSED_FILES);
if (pyFiles == null) {
pyFiles = new HashSet<>();
resolveState = resolveState.put(PROCESSED_FILES, pyFiles);
}
if (pyFiles.contains(this))
return true;
pyFiles.add(this);
for (PyClass c : getTopLevelClasses()) {
if (c == lastParent)
continue;
if (!wrapper.execute(c, resolveState))
return false;
}
for (PyFunction f : getTopLevelFunctions()) {
if (f == lastParent)
continue;
if (!wrapper.execute(f, resolveState))
return false;
}
for (PyTargetExpression e : getTopLevelAttributes()) {
if (e == lastParent)
continue;
if (!wrapper.execute(e, resolveState))
return false;
}
for (PyImportElement e : getImportTargets()) {
if (e == lastParent)
continue;
if (!wrapper.execute(e, resolveState))
return false;
}
for (PyFromImportStatement e : getFromImports()) {
if (e == lastParent)
continue;
if (!e.processDeclarations(wrapper, resolveState, null, this))
return false;
}
if (remainingDunderAll != null) {
for (String s : remainingDunderAll) {
if (!PyNames.isIdentifier(s)) {
continue;
}
if (!processor.execute(new LightNamedElement(myManager, PythonLanguage.getInstance(), s), resolveState))
return false;
}
}
return true;
}
use of com.intellij.psi.scope.DelegatingScopeProcessor in project intellij-community by JetBrains.
the class PsiReferenceExpressionImpl method processVariants.
@Override
public void processVariants(@NotNull PsiScopeProcessor processor) {
DelegatingScopeProcessor filterProcessor = new DelegatingScopeProcessor(processor) {
private PsiElement myResolveContext;
private final Set<String> myVarNames = new THashSet<>();
@Override
public boolean execute(@NotNull final PsiElement element, @NotNull final ResolveState state) {
return !shouldProcess(element) || super.execute(element, state);
}
private boolean shouldProcess(@NotNull PsiElement element) {
if (element instanceof PsiVariable)
return ensureNonShadowedVariable((PsiVariable) element);
if (element instanceof PsiClass)
return !seemsScrambled((PsiClass) element);
if (element instanceof PsiPackage)
return isQualified();
if (element instanceof PsiMethod)
return shouldProcessMethod((PsiMethod) element);
return false;
}
private boolean ensureNonShadowedVariable(@NotNull PsiVariable element) {
if (element instanceof PsiLocalVariable || element instanceof PsiParameter) {
myVarNames.add(element.getName());
}
if (element instanceof PsiField && myVarNames.contains(element.getName())) {
return false;
}
return true;
}
private boolean shouldProcessMethod(@NotNull PsiMethod method) {
PsiReferenceExpressionImpl ref = PsiReferenceExpressionImpl.this;
return !method.isConstructor() && hasValidQualifier(method, ref, myResolveContext);
}
@Override
public void handleEvent(@NotNull Event event, Object associated) {
if (event == JavaScopeProcessorEvent.SET_CURRENT_FILE_CONTEXT) {
myResolveContext = (PsiElement) associated;
}
super.handleEvent(event, associated);
}
};
PsiScopesUtil.resolveAndWalk(filterProcessor, this, null, true);
}
use of com.intellij.psi.scope.DelegatingScopeProcessor in project intellij-community by JetBrains.
the class GrImportStatementImpl method processDeclarationsForMultipleElements.
private boolean processDeclarationsForMultipleElements(@NotNull final PsiScopeProcessor processor, @Nullable PsiElement lastParent, @NotNull PsiElement place, @NotNull ResolveState state) {
GrCodeReferenceElement ref = getImportReference();
if (ref == null)
return true;
if (isStatic()) {
final PsiElement resolved = ref.resolve();
if (resolved instanceof PsiClass) {
state = state.put(ClassHint.RESOLVE_CONTEXT, this);
final PsiClass clazz = (PsiClass) resolved;
for (final PsiScopeProcessor each : GroovyResolverProcessor.allProcessors(processor)) {
if (!clazz.processDeclarations(new DelegatingScopeProcessor(each) {
@Override
public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
if (element instanceof PsiMember && ((PsiMember) element).hasModifierProperty(PsiModifier.STATIC)) {
return super.execute(element, state);
}
return true;
}
}, state, lastParent, place))
return false;
}
}
} else {
if (ResolveUtil.shouldProcessClasses(processor.getHint(ElementClassHint.KEY))) {
String qName = PsiUtil.getQualifiedReferenceText(ref);
if (qName != null) {
PsiPackage aPackage = JavaPsiFacade.getInstance(getProject()).findPackage(qName);
if (aPackage != null && !((GroovyFile) getContainingFile()).getPackageName().equals(aPackage.getQualifiedName())) {
state = state.put(ClassHint.RESOLVE_CONTEXT, this);
if (!aPackage.processDeclarations(processor, state, lastParent, place))
return false;
}
}
}
}
return true;
}
use of com.intellij.psi.scope.DelegatingScopeProcessor 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;
}
Aggregations