Search in sources :

Example 21 with HierarchyNodeDescriptor

use of com.intellij.ide.hierarchy.HierarchyNodeDescriptor 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

HierarchyNodeDescriptor (com.intellij.ide.hierarchy.HierarchyNodeDescriptor)21 NotNull (org.jetbrains.annotations.NotNull)6 DartHierarchyUtil.findDartClass (com.jetbrains.lang.dart.ide.hierarchy.DartHierarchyUtil.findDartClass)4 DartClass (com.jetbrains.lang.dart.psi.DartClass)4 ArrayList (java.util.ArrayList)4 TypeHierarchyItem (org.dartlang.analysis.server.protocol.TypeHierarchyItem)4 PsiElement (com.intellij.psi.PsiElement)3 SearchScope (com.intellij.psi.search.SearchScope)3 HashMap (com.intellij.util.containers.HashMap)3 CallHierarchyNodeDescriptor (com.intellij.ide.hierarchy.call.CallHierarchyNodeDescriptor)2 Project (com.intellij.openapi.project.Project)2 PsiClass (com.intellij.psi.PsiClass)2 HashMap (java.util.HashMap)2 HierarchyBrowserManager (com.intellij.ide.hierarchy.HierarchyBrowserManager)1 NodeDescriptor (com.intellij.ide.util.treeView.NodeDescriptor)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiAnonymousClass (com.intellij.psi.PsiAnonymousClass)1 PsiReference (com.intellij.psi.PsiReference)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 DartComponent (com.jetbrains.lang.dart.psi.DartComponent)1