Search in sources :

Example 1 with HierarchyNodeDescriptor

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

the class PyCallHierarchyTest method dump.

private static void dump(final HierarchyTreeStructure treeStructure, @Nullable HierarchyNodeDescriptor descriptor, int level, StringBuilder b) {
    if (level > 10) {
        for (int i = 0; i < level; i++) b.append("  ");
        b.append("<Probably infinite part skipped>\n");
        return;
    }
    if (descriptor == null)
        descriptor = (HierarchyNodeDescriptor) treeStructure.getRootElement();
    for (int i = 0; i < level; i++) b.append("  ");
    descriptor.update();
    b.append("<node text=\"").append(descriptor.getHighlightedText().getText()).append("\"").append(treeStructure.getBaseDescriptor() == descriptor ? " base=\"true\"" : "");
    final Object[] children = treeStructure.getChildElements(descriptor);
    if (children.length > 0) {
        b.append(">\n");
        for (Object o : children) {
            HierarchyNodeDescriptor d = (HierarchyNodeDescriptor) o;
            dump(treeStructure, d, level + 1, b);
        }
        for (int i = 0; i < level; i++) b.append("  ");
        b.append("</node>\n");
    } else {
        b.append("/>\n");
    }
}
Also used : HierarchyNodeDescriptor(com.intellij.ide.hierarchy.HierarchyNodeDescriptor)

Example 2 with HierarchyNodeDescriptor

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

the class KotlinCallTreeStructure method addNodeDescriptorForElement.

protected static void addNodeDescriptorForElement(PsiReference reference, PsiElement element, Map<PsiElement, HierarchyNodeDescriptor> declarationToDescriptorMap, HierarchyNodeDescriptor descriptor, boolean wrapAsLightElements) {
    HierarchyNodeDescriptor d = declarationToDescriptorMap.get(element);
    if (d == null) {
        d = createNodeDescriptor(element.getProject(), element, descriptor, true, wrapAsLightElements);
        if (d == null)
            return;
        declarationToDescriptorMap.put(element, d);
    } else if (d instanceof CallHierarchyNodeDescriptor) {
        ((CallHierarchyNodeDescriptor) d).incrementUsageCount();
    }
    if (d instanceof CallHierarchyNodeDescriptor) {
        ((CallHierarchyNodeDescriptor) d).addReference(reference);
    } else if (d instanceof KotlinCallHierarchyNodeDescriptor) {
        ((KotlinCallHierarchyNodeDescriptor) d).addReference(reference);
    }
}
Also used : HierarchyNodeDescriptor(com.intellij.ide.hierarchy.HierarchyNodeDescriptor) CallHierarchyNodeDescriptor(com.intellij.ide.hierarchy.call.CallHierarchyNodeDescriptor) CallHierarchyNodeDescriptor(com.intellij.ide.hierarchy.call.CallHierarchyNodeDescriptor)

Example 3 with HierarchyNodeDescriptor

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

the class HierarchyViewTestBase method checkHierarchyTreeStructure.

private static void checkHierarchyTreeStructure(final HierarchyTreeStructure treeStructure, final Element rootElement) {
    final HierarchyNodeDescriptor rootNodeDescriptor = (HierarchyNodeDescriptor) treeStructure.getRootElement();
    rootNodeDescriptor.update();
    if (rootElement == null || !NODE_ELEMENT_NAME.equals(rootElement.getName())) {
        throw new IllegalArgumentException("Incorrect root element in verification resource");
    }
    checkNodeDescriptorRecursively(treeStructure, rootNodeDescriptor, rootElement);
}
Also used : HierarchyNodeDescriptor(com.intellij.ide.hierarchy.HierarchyNodeDescriptor)

Example 4 with HierarchyNodeDescriptor

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

the class HierarchyViewTestBase method dump.

private static void dump(final HierarchyTreeStructure treeStructure, @Nullable HierarchyNodeDescriptor descriptor, int level, StringBuilder b) {
    if (level > 10) {
        for (int i = 0; i < level; i++) b.append("  ");
        b.append("<Probably infinite part skipped>\n");
        return;
    }
    if (descriptor == null)
        descriptor = (HierarchyNodeDescriptor) treeStructure.getRootElement();
    for (int i = 0; i < level; i++) b.append("  ");
    descriptor.update();
    b.append("<node text=\"").append(descriptor.getHighlightedText().getText()).append("\"").append(treeStructure.getBaseDescriptor() == descriptor ? " base=\"true\"" : "");
    final Object[] children = treeStructure.getChildElements(descriptor);
    if (children.length > 0) {
        b.append(">\n");
        for (Object o : children) {
            HierarchyNodeDescriptor d = (HierarchyNodeDescriptor) o;
            dump(treeStructure, d, level + 1, b);
        }
        for (int i = 0; i < level; i++) b.append("  ");
        b.append("</node>\n");
    } else {
        b.append("/>\n");
    }
}
Also used : HierarchyNodeDescriptor(com.intellij.ide.hierarchy.HierarchyNodeDescriptor)

Example 5 with HierarchyNodeDescriptor

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

the class OverrideImplementMethodAction method actionPerformed.

public final void actionPerformed(final AnActionEvent event) {
    final DataContext dataContext = event.getDataContext();
    final MethodHierarchyBrowser methodHierarchyBrowser = (MethodHierarchyBrowser) MethodHierarchyBrowserBase.DATA_KEY.getData(dataContext);
    if (methodHierarchyBrowser == null)
        return;
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    if (project == null)
        return;
    final String commandName = event.getPresentation().getText();
    ApplicationManager.getApplication().runWriteAction(() -> CommandProcessor.getInstance().executeCommand(project, () -> {
        try {
            final HierarchyNodeDescriptor[] selectedDescriptors = methodHierarchyBrowser.getSelectedDescriptors();
            if (selectedDescriptors.length > 0) {
                final List<VirtualFile> files = new ArrayList<>(selectedDescriptors.length);
                for (HierarchyNodeDescriptor selectedDescriptor : selectedDescriptors) {
                    final PsiFile containingFile = ((MethodHierarchyNodeDescriptor) selectedDescriptor).getPsiClass().getContainingFile();
                    if (containingFile != null) {
                        final VirtualFile vFile = containingFile.getVirtualFile();
                        if (vFile != null) {
                            files.add(vFile);
                        }
                    }
                }
                final ReadonlyStatusHandler.OperationStatus status = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(VfsUtil.toVirtualFileArray(files));
                if (!status.hasReadonlyFiles()) {
                    for (HierarchyNodeDescriptor selectedDescriptor : selectedDescriptors) {
                        final PsiElement aClass = ((MethodHierarchyNodeDescriptor) selectedDescriptor).getPsiClass();
                        if (aClass instanceof PsiClass) {
                            OverrideImplementUtil.overrideOrImplement((PsiClass) aClass, methodHierarchyBrowser.getBaseMethod());
                        }
                    }
                    ToolWindowManager.getInstance(project).activateEditorComponent();
                } else {
                    ApplicationManager.getApplication().invokeLater(() -> Messages.showErrorDialog(project, status.getReadonlyFilesMessage(), commandName));
                }
            }
        } catch (IncorrectOperationException e) {
            LOG.error(e);
        }
    }, commandName, null));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) ArrayList(java.util.ArrayList) List(java.util.List) IncorrectOperationException(com.intellij.util.IncorrectOperationException) HierarchyNodeDescriptor(com.intellij.ide.hierarchy.HierarchyNodeDescriptor)

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