use of com.intellij.psi.scope.PsiScopeProcessor in project intellij-community by JetBrains.
the class PyModuleType method getVisibleImports.
@NotNull
public static List<PyImportElement> getVisibleImports(@NotNull ScopeOwner owner) {
final List<PyImportElement> visibleImports = new ArrayList<>();
PyResolveUtil.scopeCrawlUp(new PsiScopeProcessor() {
@Override
public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
if (element instanceof PyImportElement) {
visibleImports.add((PyImportElement) element);
}
return true;
}
@Nullable
@Override
public <T> T getHint(@NotNull Key<T> hintKey) {
return null;
}
@Override
public void handleEvent(@NotNull Event event, @Nullable Object associated) {
}
}, owner, null, null);
return visibleImports;
}
use of com.intellij.psi.scope.PsiScopeProcessor in project intellij-community by JetBrains.
the class PyDebugProcess method resolveInCurrentFrame.
@NotNull
private static Ref<PsiElement> resolveInCurrentFrame(final String name, XSourcePosition currentPosition, PsiFile file) {
final Ref<PsiElement> elementRef = Ref.create();
PsiElement currentElement = file.findElementAt(currentPosition.getOffset());
if (currentElement == null) {
return elementRef;
}
PyResolveUtil.scopeCrawlUp(new PsiScopeProcessor() {
@Override
public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
if ((element instanceof PyImportElement)) {
PyImportElement importElement = (PyImportElement) element;
if (name.equals(importElement.getVisibleName())) {
if (elementRef.isNull()) {
elementRef.set(element);
}
return false;
}
return true;
} else {
if (elementRef.isNull()) {
elementRef.set(element);
}
return false;
}
}
@Nullable
@Override
public <T> T getHint(@NotNull Key<T> hintKey) {
return null;
}
@Override
public void handleEvent(@NotNull Event event, @Nullable Object associated) {
}
}, currentElement, name, null);
return elementRef;
}
Aggregations