Search in sources :

Example 1 with NodeDescriptor

use of com.intellij.ide.util.treeView.NodeDescriptor in project intellij-community by JetBrains.

the class GrCallReferenceProcessor method process.

@Override
public boolean process(@NotNull PsiReference reference, @NotNull JavaCallHierarchyData data) {
    PsiClass originalClass = data.getOriginalClass();
    PsiMethod method = data.getMethod();
    Set<PsiMethod> methodsToFind = data.getMethodsToFind();
    PsiMethod methodToFind = data.getMethodToFind();
    PsiClassType originalType = data.getOriginalType();
    Map<PsiMember, NodeDescriptor> methodToDescriptorMap = data.getResultMap();
    Project project = data.getProject();
    if (reference instanceof GrReferenceExpression) {
        final GrExpression qualifier = ((GrReferenceExpression) reference).getQualifierExpression();
        if (org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil.isSuperReference(qualifier)) {
            // filter super.foo() call inside foo() and similar cases (bug 8411)
            assert qualifier != null;
            final PsiClass superClass = PsiUtil.resolveClassInType(qualifier.getType());
            if (originalClass == null || originalClass.isInheritor(superClass, true)) {
                return true;
            }
        }
        if (qualifier != null && !methodToFind.hasModifierProperty(PsiModifier.STATIC)) {
            final PsiType qualifierType = qualifier.getType();
            if (qualifierType instanceof PsiClassType && !TypeConversionUtil.isAssignable(qualifierType, originalType) && methodToFind != method) {
                final PsiClass psiClass = ((PsiClassType) qualifierType).resolve();
                if (psiClass != null) {
                    final PsiMethod callee = psiClass.findMethodBySignature(methodToFind, true);
                    if (callee != null && !methodsToFind.contains(callee)) {
                        // skip sibling methods
                        return true;
                    }
                }
            }
        }
    } else {
        if (!(reference instanceof PsiElement)) {
            return true;
        }
        final PsiElement parent = ((PsiElement) reference).getParent();
        if (parent instanceof PsiNewExpression) {
            if (((PsiNewExpression) parent).getClassReference() != reference) {
                return true;
            }
        } else if (parent instanceof GrAnonymousClassDefinition) {
            if (((GrAnonymousClassDefinition) parent).getBaseClassReferenceGroovy() != reference) {
                return true;
            }
        } else {
            return true;
        }
    }
    final PsiElement element = reference.getElement();
    final PsiMember key = CallHierarchyNodeDescriptor.getEnclosingElement(element);
    synchronized (methodToDescriptorMap) {
        CallHierarchyNodeDescriptor d = (CallHierarchyNodeDescriptor) methodToDescriptorMap.get(key);
        if (d == null) {
            d = new CallHierarchyNodeDescriptor(project, (CallHierarchyNodeDescriptor) data.getNodeDescriptor(), element, false, true);
            methodToDescriptorMap.put(key, d);
        } else if (!d.hasReference(reference)) {
            d.incrementUsageCount();
        }
        d.addReference(reference);
    }
    return true;
}
Also used : GrAnonymousClassDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrAnonymousClassDefinition) CallHierarchyNodeDescriptor(com.intellij.ide.hierarchy.call.CallHierarchyNodeDescriptor) NodeDescriptor(com.intellij.ide.util.treeView.NodeDescriptor) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression) Project(com.intellij.openapi.project.Project) CallHierarchyNodeDescriptor(com.intellij.ide.hierarchy.call.CallHierarchyNodeDescriptor)

Example 2 with NodeDescriptor

use of com.intellij.ide.util.treeView.NodeDescriptor in project intellij-community by JetBrains.

the class HierarchyBrowserBaseEx method changeView.

public final void changeView(@NotNull final String typeName) {
    setCurrentViewType(typeName);
    final PsiElement element = mySmartPsiElementPointer.getElement();
    if (element == null || !isApplicableElement(element)) {
        return;
    }
    if (myContent != null) {
        final String displayName = getContentDisplayName(typeName, element);
        if (displayName != null) {
            myContent.setDisplayName(displayName);
        }
    }
    myCardLayout.show(myTreePanel, typeName);
    if (!myType2BuilderMap.containsKey(typeName)) {
        try {
            setWaitCursor();
            // create builder
            final JTree tree = myType2TreeMap.get(typeName);
            final DefaultTreeModel model = new DefaultTreeModel(new DefaultMutableTreeNode(""));
            tree.setModel(model);
            final HierarchyTreeStructure structure = createHierarchyTreeStructure(typeName, element);
            if (structure == null) {
                return;
            }
            final Comparator<NodeDescriptor> comparator = getComparator();
            final HierarchyTreeBuilder builder = new HierarchyTreeBuilder(myProject, tree, model, structure, comparator);
            myType2BuilderMap.put(typeName, builder);
            Disposer.register(this, builder);
            Disposer.register(builder, () -> myType2BuilderMap.remove(typeName));
            final HierarchyNodeDescriptor descriptor = structure.getBaseDescriptor();
            builder.select(descriptor, () -> builder.expand(descriptor, null));
        } finally {
            restoreCursor();
        }
    }
    IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
        IdeFocusManager.getGlobalInstance().requestFocus(getCurrentTree(), true);
    });
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) NodeDescriptor(com.intellij.ide.util.treeView.NodeDescriptor) DefaultTreeModel(javax.swing.tree.DefaultTreeModel)

Example 3 with NodeDescriptor

use of com.intellij.ide.util.treeView.NodeDescriptor in project intellij-community by JetBrains.

the class ContentEntryTreeCellRenderer method customizeCellRenderer.

@Override
public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    super.customizeCellRenderer(tree, value, selected, expanded, leaf, row, hasFocus);
    final ContentEntryEditor editor = myTreeEditor.getContentEntryEditor();
    if (editor != null) {
        final Object userObject = ((DefaultMutableTreeNode) value).getUserObject();
        if (userObject instanceof NodeDescriptor) {
            final Object element = ((NodeDescriptor) userObject).getElement();
            if (element instanceof FileElement) {
                final VirtualFile file = ((FileElement) element).getFile();
                if (file != null && file.isDirectory()) {
                    final ContentEntry contentEntry = editor.getContentEntry();
                    if (contentEntry != null) {
                        final String prefix = getPresentablePrefix(contentEntry, file);
                        if (!prefix.isEmpty()) {
                            append(" (" + prefix + ")", new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, JBColor.GRAY));
                        }
                        setIcon(updateIcon(contentEntry, file, getIcon()));
                    }
                }
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ContentEntry(com.intellij.openapi.roots.ContentEntry) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) NodeDescriptor(com.intellij.ide.util.treeView.NodeDescriptor) FileElement(com.intellij.openapi.fileChooser.FileElement)

Example 4 with NodeDescriptor

use of com.intellij.ide.util.treeView.NodeDescriptor in project intellij-community by JetBrains.

the class ContentEntryTreeEditor method setContentEntryEditor.

/**
   * @param contentEntryEditor : null means to clear the editor
   */
public void setContentEntryEditor(final ContentEntryEditor contentEntryEditor) {
    if (myContentEntryEditor != null && myContentEntryEditor.equals(contentEntryEditor)) {
        return;
    }
    if (myFileSystemTree != null) {
        Disposer.dispose(myFileSystemTree);
        myFileSystemTree = null;
    }
    if (myContentEntryEditor != null) {
        myContentEntryEditor.removeContentEntryEditorListener(myContentEntryEditorListener);
        myContentEntryEditor = null;
    }
    if (contentEntryEditor == null) {
        ((DefaultTreeModel) myTree.getModel()).setRoot(EMPTY_TREE_ROOT);
        myTreePanel.setVisible(false);
        if (myFileSystemTree != null) {
            Disposer.dispose(myFileSystemTree);
        }
        return;
    }
    myTreePanel.setVisible(true);
    myContentEntryEditor = contentEntryEditor;
    myContentEntryEditor.addContentEntryEditorListener(myContentEntryEditorListener);
    final ContentEntry entry = contentEntryEditor.getContentEntry();
    assert entry != null : contentEntryEditor;
    final VirtualFile file = entry.getFile();
    if (file != null) {
        myDescriptor.setRoots(file);
    } else {
        String path = VfsUtilCore.urlToPath(entry.getUrl());
        myDescriptor.setTitle(FileUtil.toSystemDependentName(path));
    }
    final Runnable init = () -> {
        //noinspection ConstantConditions
        myFileSystemTree.updateTree();
        myFileSystemTree.select(file, null);
    };
    myFileSystemTree = new FileSystemTreeImpl(myProject, myDescriptor, myTree, getContentEntryCellRenderer(), init, null) {

        @Override
        protected AbstractTreeBuilder createTreeBuilder(JTree tree, DefaultTreeModel treeModel, AbstractTreeStructure treeStructure, Comparator<NodeDescriptor> comparator, FileChooserDescriptor descriptor, final Runnable onInitialized) {
            return new MyFileTreeBuilder(tree, treeModel, treeStructure, comparator, descriptor, onInitialized);
        }
    };
    myFileSystemTree.showHiddens(true);
    Disposer.register(myProject, myFileSystemTree);
    final NewFolderAction newFolderAction = new MyNewFolderAction();
    final DefaultActionGroup mousePopupGroup = new DefaultActionGroup();
    mousePopupGroup.add(myEditingActionsGroup);
    mousePopupGroup.addSeparator();
    mousePopupGroup.add(newFolderAction);
    myFileSystemTree.registerMouseListener(mousePopupGroup);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) AbstractTreeBuilder(com.intellij.ide.util.treeView.AbstractTreeBuilder) NodeDescriptor(com.intellij.ide.util.treeView.NodeDescriptor) FileSystemTreeImpl(com.intellij.openapi.fileChooser.ex.FileSystemTreeImpl) NewFolderAction(com.intellij.openapi.fileChooser.actions.NewFolderAction) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) ContentEntry(com.intellij.openapi.roots.ContentEntry) AbstractTreeStructure(com.intellij.ide.util.treeView.AbstractTreeStructure)

Example 5 with NodeDescriptor

use of com.intellij.ide.util.treeView.NodeDescriptor in project intellij-community by JetBrains.

the class AbstractListBuilder method updateList.

protected final void updateList() {
    if (myIsDisposed || myCurrentParent == null) {
        return;
    }
    if (myTreeStructure.hasSomethingToCommit()) {
        myTreeStructure.commit();
    }
    AbstractTreeNode parentDescriptor = myCurrentParent;
    while (true) {
        parentDescriptor.update();
        if (parentDescriptor.getValue() != null)
            break;
        parentDescriptor = parentDescriptor.getParent();
    }
    final Object[] children = getChildren(parentDescriptor);
    final HashMap<Object, Integer> elementToIndexMap = new HashMap<>();
    for (int i = 0; i < children.length; i++) {
        elementToIndexMap.put(children[i], Integer.valueOf(i));
    }
    final List<NodeDescriptor> resultDescriptors = new ArrayList<>();
    final Object[] listChildren = myModel.toArray();
    for (final Object child : listChildren) {
        if (!(child instanceof NodeDescriptor)) {
            continue;
        }
        final NodeDescriptor descriptor = (NodeDescriptor) child;
        descriptor.update();
        final Object newElement = descriptor.getElement();
        final Integer index = newElement != null ? elementToIndexMap.get(newElement) : null;
        if (index != null) {
            resultDescriptors.add(descriptor);
            descriptor.setIndex(index.intValue());
            elementToIndexMap.remove(newElement);
        }
    }
    for (final Object child : elementToIndexMap.keySet()) {
        final Integer index = elementToIndexMap.get(child);
        if (index != null) {
            final NodeDescriptor childDescr = myTreeStructure.createDescriptor(child, parentDescriptor);
            childDescr.setIndex(index.intValue());
            childDescr.update();
            resultDescriptors.add(childDescr);
        }
    }
    final SelectionInfo selection = storeSelection();
    if (myComparator != null) {
        Collections.sort(resultDescriptors, myComparator);
    } else {
        Collections.sort(resultDescriptors, IndexComparator.INSTANCE);
    }
    if (shouldAddTopElement()) {
        final List elems = new ArrayList();
        elems.add(new TopLevelNode(myProject, parentDescriptor.getValue()));
        elems.addAll(resultDescriptors);
        myModel.replaceElements(elems);
    } else {
        myModel.replaceElements(resultDescriptors);
    }
    restoreSelection(selection);
    updateParentTitle();
}
Also used : HashMap(com.intellij.util.containers.HashMap) NodeDescriptor(com.intellij.ide.util.treeView.NodeDescriptor) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) List(java.util.List)

Aggregations

NodeDescriptor (com.intellij.ide.util.treeView.NodeDescriptor)25 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 PsiFile (com.intellij.psi.PsiFile)4 SimpleTextAttributes (com.intellij.ui.SimpleTextAttributes)4 TreePath (javax.swing.tree.TreePath)4 TodoItemNode (com.intellij.ide.todo.nodes.TodoItemNode)3 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)3 DirectoryGroupNode (com.android.tools.idea.navigator.nodes.DirectoryGroupNode)2 PackageElement (com.intellij.ide.projectView.impl.nodes.PackageElement)2 FileElement (com.intellij.openapi.fileChooser.FileElement)2 Module (com.intellij.openapi.module.Module)2 Project (com.intellij.openapi.project.Project)2 ContentEntry (com.intellij.openapi.roots.ContentEntry)2 PsiDirectory (com.intellij.psi.PsiDirectory)2 PsiElement (com.intellij.psi.PsiElement)2 ArrayList (java.util.ArrayList)2 Nullable (org.jetbrains.annotations.Nullable)2 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)1 FileGroupNode (com.android.tools.idea.navigator.nodes.FileGroupNode)1