Search in sources :

Example 11 with HierarchyNodeDescriptor

use of com.intellij.ide.hierarchy.HierarchyNodeDescriptor in project intellij-community by JetBrains.

the class HierarchyViewTestBase method checkBaseNode.

private static void checkBaseNode(final HierarchyTreeStructure treeStructure, final HierarchyNodeDescriptor descriptor, final Element expectedElement) {
    final String baseAttrValue = expectedElement.getAttributeValue(BASE_ATTR_NAME);
    final HierarchyNodeDescriptor baseDescriptor = treeStructure.getBaseDescriptor();
    final boolean mustBeBase = "true".equalsIgnoreCase(baseAttrValue);
    assertTrue("Incorrect base node", mustBeBase ? baseDescriptor == descriptor : baseDescriptor != descriptor);
}
Also used : HierarchyNodeDescriptor(com.intellij.ide.hierarchy.HierarchyNodeDescriptor)

Example 12 with HierarchyNodeDescriptor

use of com.intellij.ide.hierarchy.HierarchyNodeDescriptor in project intellij-community by JetBrains.

the class HierarchyViewTestBase method checkChildren.

private static void checkChildren(final HierarchyTreeStructure treeStructure, final HierarchyNodeDescriptor descriptor, final Element element) {
    if (element.getChild(ANY_NODES_ELEMENT_NAME) != null) {
        return;
    }
    final Object[] children = treeStructure.getChildElements(descriptor);
    //noinspection unchecked
    final List<Element> expectedChildren = new ArrayList<>(element.getChildren(NODE_ELEMENT_NAME));
    final StringBuilder messageBuilder = new StringBuilder("Actual children of [" + descriptor.getHighlightedText().getText() + "]:\n");
    for (Object child : children) {
        final HierarchyNodeDescriptor nodeDescriptor = (HierarchyNodeDescriptor) child;
        nodeDescriptor.update();
        messageBuilder.append("    [").append(nodeDescriptor.getHighlightedText().getText()).append("]\n");
    }
    assertEquals(messageBuilder.toString(), expectedChildren.size(), children.length);
    Arrays.sort(children, (first, second) -> ((HierarchyNodeDescriptor) first).getHighlightedText().getText().compareTo(((HierarchyNodeDescriptor) second).getHighlightedText().getText()));
    Collections.sort(expectedChildren, (first, second) -> first.getAttributeValue(TEXT_ATTR_NAME).compareTo(second.getAttributeValue(TEXT_ATTR_NAME)));
    //noinspection unchecked
    final Iterator<Element> iterator = expectedChildren.iterator();
    for (Object child : children) {
        checkNodeDescriptorRecursively(treeStructure, ((HierarchyNodeDescriptor) child), iterator.next());
    }
}
Also used : Element(org.jdom.Element) HierarchyNodeDescriptor(com.intellij.ide.hierarchy.HierarchyNodeDescriptor)

Example 13 with HierarchyNodeDescriptor

use of com.intellij.ide.hierarchy.HierarchyNodeDescriptor in project intellij-community by JetBrains.

the class CallerMethodsTreeStructure method buildChildren.

@NotNull
@Override
protected final Object[] buildChildren(@NotNull final HierarchyNodeDescriptor descriptor) {
    PsiMember enclosingElement = ((CallHierarchyNodeDescriptor) descriptor).getEnclosingElement();
    HierarchyNodeDescriptor nodeDescriptor = getBaseDescriptor();
    if (enclosingElement instanceof PsiMethod) {
        PsiClass clazz = enclosingElement.getContainingClass();
        if (isLocalOrAnonymousClass(clazz)) {
            PsiElement parent = clazz.getParent();
            PsiElement grandParent = parent instanceof PsiNewExpression ? parent.getParent() : null;
            if (grandParent instanceof PsiExpressionList) {
                // for created anonymous class that immediately passed as argument use instantiation point as next call point (IDEA-73312)
                enclosingElement = CallHierarchyNodeDescriptor.getEnclosingElement(grandParent);
            }
        }
    }
    if (!(enclosingElement instanceof PsiMethod) || nodeDescriptor == null) {
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    }
    final PsiMethod baseMethod = (PsiMethod) ((CallHierarchyNodeDescriptor) nodeDescriptor).getTargetElement();
    if (baseMethod == null) {
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    }
    final SearchScope searchScope = getSearchScope(myScopeType, baseMethod.getContainingClass());
    final PsiMethod method = (PsiMethod) enclosingElement;
    final PsiClass originalClass = method.getContainingClass();
    assert originalClass != null;
    final PsiClassType originalType = JavaPsiFacade.getElementFactory(myProject).createType(originalClass);
    final Set<PsiMethod> methodsToFind = new HashSet<>();
    methodsToFind.add(method);
    ContainerUtil.addAll(methodsToFind, method.findDeepestSuperMethods());
    final Map<PsiMember, NodeDescriptor> methodToDescriptorMap = new HashMap<>();
    for (final PsiMethod methodToFind : methodsToFind) {
        final JavaCallHierarchyData data = new JavaCallHierarchyData(originalClass, methodToFind, originalType, method, methodsToFind, descriptor, methodToDescriptorMap, myProject);
        MethodReferencesSearch.search(methodToFind, searchScope, true).forEach(reference -> {
            for (CallReferenceProcessor processor : CallReferenceProcessor.EP_NAME.getExtensions()) {
                if (!processor.process(reference, data))
                    break;
            }
            return true;
        });
    }
    return methodToDescriptorMap.values().toArray(new Object[methodToDescriptorMap.size()]);
}
Also used : HashMap(com.intellij.util.containers.HashMap) HierarchyNodeDescriptor(com.intellij.ide.hierarchy.HierarchyNodeDescriptor) NodeDescriptor(com.intellij.ide.util.treeView.NodeDescriptor) SearchScope(com.intellij.psi.search.SearchScope) HierarchyNodeDescriptor(com.intellij.ide.hierarchy.HierarchyNodeDescriptor) HashSet(java.util.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with HierarchyNodeDescriptor

use of com.intellij.ide.hierarchy.HierarchyNodeDescriptor in project intellij-community by JetBrains.

the class MethodHierarchyTreeStructure method buildHierarchyElement.

private HierarchyNodeDescriptor buildHierarchyElement(final Project project, final PsiMethod method) {
    final PsiClass suitableBaseClass = findSuitableBaseClass(method);
    HierarchyNodeDescriptor descriptor = null;
    final ArrayList<PsiClass> superClasses = createSuperClasses(suitableBaseClass);
    if (!suitableBaseClass.equals(method.getContainingClass())) {
        superClasses.add(0, suitableBaseClass);
    }
    // remove from the top of the branch the classes that contain no 'method'
    for (int i = superClasses.size() - 1; i >= 0; i--) {
        final PsiClass psiClass = superClasses.get(i);
        if (MethodHierarchyUtil.findBaseMethodInClass(method, psiClass, false) == null) {
            superClasses.remove(i);
        } else {
            break;
        }
    }
    for (int i = superClasses.size() - 1; i >= 0; i--) {
        final PsiClass superClass = superClasses.get(i);
        final HierarchyNodeDescriptor newDescriptor = new MethodHierarchyNodeDescriptor(project, descriptor, superClass, false, this);
        if (descriptor != null) {
            descriptor.setCachedChildren(new HierarchyNodeDescriptor[] { newDescriptor });
        }
        descriptor = newDescriptor;
    }
    final HierarchyNodeDescriptor newDescriptor = new MethodHierarchyNodeDescriptor(project, descriptor, method.getContainingClass(), true, this);
    if (descriptor != null) {
        descriptor.setCachedChildren(new HierarchyNodeDescriptor[] { newDescriptor });
    }
    return newDescriptor;
}
Also used : HierarchyNodeDescriptor(com.intellij.ide.hierarchy.HierarchyNodeDescriptor)

Example 15 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