Search in sources :

Example 1 with PyHierarchyNodeDescriptor

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();
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) ArrayList(java.util.ArrayList) PsiElement(com.intellij.psi.PsiElement) PyHierarchyNodeDescriptor(com.jetbrains.python.hierarchy.PyHierarchyNodeDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with PyHierarchyNodeDescriptor

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);
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) ArrayList(java.util.ArrayList) PsiElement(com.intellij.psi.PsiElement) PyHierarchyNodeDescriptor(com.jetbrains.python.hierarchy.PyHierarchyNodeDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with PyHierarchyNodeDescriptor

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;
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) PyHierarchyNodeDescriptor(com.jetbrains.python.hierarchy.PyHierarchyNodeDescriptor)

Example 4 with PyHierarchyNodeDescriptor

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);
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PyFile(com.jetbrains.python.psi.PyFile) PyHierarchyNodeDescriptor(com.jetbrains.python.hierarchy.PyHierarchyNodeDescriptor) PyFunction(com.jetbrains.python.psi.PyFunction) HierarchyNodeDescriptor(com.intellij.ide.hierarchy.HierarchyNodeDescriptor) PyHierarchyNodeDescriptor(com.jetbrains.python.hierarchy.PyHierarchyNodeDescriptor) PsiElement(com.intellij.psi.PsiElement) PyElement(com.jetbrains.python.psi.PyElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PyHierarchyNodeDescriptor (com.jetbrains.python.hierarchy.PyHierarchyNodeDescriptor)4 PyClass (com.jetbrains.python.psi.PyClass)4 PsiElement (com.intellij.psi.PsiElement)3 ArrayList (java.util.ArrayList)3 NotNull (org.jetbrains.annotations.NotNull)3 HierarchyNodeDescriptor (com.intellij.ide.hierarchy.HierarchyNodeDescriptor)1 PyElement (com.jetbrains.python.psi.PyElement)1 PyFile (com.jetbrains.python.psi.PyFile)1 PyFunction (com.jetbrains.python.psi.PyFunction)1 HashMap (java.util.HashMap)1