use of com.jetbrains.python.hierarchy.PyHierarchyNodeDescriptor in project intellij-community by JetBrains.
the class PySuperTypesHierarchyTreeStructure method buildChildren.
@NotNull
protected Object[] buildChildren(@NotNull HierarchyNodeDescriptor descriptor) {
final List<PyHierarchyNodeDescriptor> res = new ArrayList<>();
if (descriptor instanceof PyHierarchyNodeDescriptor) {
final PyHierarchyNodeDescriptor pyDescriptor = (PyHierarchyNodeDescriptor) descriptor;
final PsiElement element = pyDescriptor.getPsiElement();
if (element instanceof PyClass) {
final PyClass cls = (PyClass) element;
final PyClass[] superClasses = cls.getSuperClasses(null);
for (PyClass superClass : superClasses) {
res.add(new PyHierarchyNodeDescriptor(descriptor, superClass, false));
}
}
}
return res.toArray();
}
use of com.jetbrains.python.hierarchy.PyHierarchyNodeDescriptor in project intellij-community by JetBrains.
the class PySubTypesHierarchyTreeStructure method buildChildren.
@NotNull
protected Object[] buildChildren(@NotNull HierarchyNodeDescriptor descriptor) {
final List<PyHierarchyNodeDescriptor> res = new ArrayList<>();
final PsiElement element = ((PyHierarchyNodeDescriptor) descriptor).getPsiElement();
if (element instanceof PyClass) {
final PyClass cls = (PyClass) element;
Query<PyClass> subClasses = PyClassInheritorsSearch.search(cls, false);
for (PyClass subClass : subClasses) {
res.add(new PyHierarchyNodeDescriptor(descriptor, subClass, false));
}
}
return ArrayUtil.toObjectArray(res);
}
use of com.jetbrains.python.hierarchy.PyHierarchyNodeDescriptor in project intellij-community by JetBrains.
the class PyTypeHierarchyTreeStructure method buildHierarchyElement.
private static PyHierarchyNodeDescriptor buildHierarchyElement(@NotNull final PyClass cl) {
PyHierarchyNodeDescriptor descriptor = null;
List<PyClass> superClasses = PyUtil.getAllSuperClasses(cl);
for (int i = superClasses.size() - 1; i >= 0; --i) {
final PyClass superClass = superClasses.get(i);
final PyHierarchyNodeDescriptor newDescriptor = new PyHierarchyNodeDescriptor(descriptor, superClass, false);
if (descriptor != null) {
descriptor.setCachedChildren(new PyHierarchyNodeDescriptor[] { newDescriptor });
}
descriptor = newDescriptor;
}
final PyHierarchyNodeDescriptor newDescriptor = new PyHierarchyNodeDescriptor(descriptor, cl, true);
if (descriptor != null) {
descriptor.setCachedChildren(new HierarchyNodeDescriptor[] { newDescriptor });
}
return newDescriptor;
}
use of com.jetbrains.python.hierarchy.PyHierarchyNodeDescriptor in project intellij-community by JetBrains.
the class PyCallHierarchyTreeStructureBase method buildChildren.
@NotNull
@Override
protected Object[] buildChildren(@NotNull HierarchyNodeDescriptor descriptor) {
final List<PyHierarchyNodeDescriptor> descriptors = new ArrayList<>();
if (descriptor instanceof PyHierarchyNodeDescriptor) {
final PyHierarchyNodeDescriptor pyDescriptor = (PyHierarchyNodeDescriptor) descriptor;
final PsiElement element = pyDescriptor.getPsiElement();
final boolean isCallable = element instanceof PyFunction || element instanceof PyClass || element instanceof PyFile;
HierarchyNodeDescriptor nodeDescriptor = getBaseDescriptor();
if (!(element instanceof PyElement) || !isCallable || nodeDescriptor == null) {
return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
final List<PsiElement> children = getChildren((PyElement) element);
final HashMap<PsiElement, PyHierarchyNodeDescriptor> callerToDescriptorMap = new HashMap<>();
PsiElement baseClass = element instanceof PyFunction ? ((PyFunction) element).getContainingClass() : null;
for (PsiElement caller : children) {
if (isInScope(baseClass, caller, myScopeType)) {
PyHierarchyNodeDescriptor callerDescriptor = callerToDescriptorMap.get(caller);
if (callerDescriptor == null) {
callerDescriptor = new PyHierarchyNodeDescriptor(descriptor, caller, false);
callerToDescriptorMap.put(caller, callerDescriptor);
descriptors.add(callerDescriptor);
}
}
}
}
return ArrayUtil.toObjectArray(descriptors);
}
Aggregations