Search in sources :

Example 1 with CurrentFileTodosTreeBuilder

use of com.intellij.ide.todo.CurrentFileTodosTreeBuilder in project intellij-community by JetBrains.

the class SummaryNode method getChildren.

@Override
@NotNull
public Collection<AbstractTreeNode> getChildren() {
    ArrayList<AbstractTreeNode> children = new ArrayList<>();
    final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(getProject()).getFileIndex();
    if (myToDoSettings.isModulesShown()) {
        for (Iterator i = myBuilder.getAllFiles(); i.hasNext(); ) {
            final PsiFile psiFile = (PsiFile) i.next();
            if (psiFile == null) {
                // skip invalid PSI files
                continue;
            }
            final VirtualFile virtualFile = psiFile.getVirtualFile();
            createModuleTodoNodeForFile(children, projectFileIndex, virtualFile);
        }
    } else {
        if (myToDoSettings.getIsPackagesShown()) {
            if (myBuilder instanceof CurrentFileTodosTreeBuilder) {
                final Iterator allFiles = myBuilder.getAllFiles();
                if (allFiles.hasNext()) {
                    children.add(new TodoFileNode(myProject, (PsiFile) allFiles.next(), myBuilder, false));
                }
            } else {
                TodoTreeHelper.getInstance(getProject()).addPackagesToChildren(children, null, myBuilder);
            }
        } else {
            for (Iterator i = myBuilder.getAllFiles(); i.hasNext(); ) {
                final PsiFile psiFile = (PsiFile) i.next();
                if (psiFile == null) {
                    // skip invalid PSI files
                    continue;
                }
                TodoFileNode fileNode = new TodoFileNode(getProject(), psiFile, myBuilder, false);
                if (getTreeStructure().accept(psiFile) && !children.contains(fileNode)) {
                    children.add(fileNode);
                }
            }
        }
    }
    Collections.sort(children, TodoFileDirAndModuleComparator.INSTANCE);
    return children;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiFile(com.intellij.psi.PsiFile) CurrentFileTodosTreeBuilder(com.intellij.ide.todo.CurrentFileTodosTreeBuilder) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with CurrentFileTodosTreeBuilder

use of com.intellij.ide.todo.CurrentFileTodosTreeBuilder in project intellij-community by JetBrains.

the class ToDoTreeStructureTest method testToDo.

//todo kirillk
public void testToDo() throws Exception {
    AllTodosTreeBuilder all = new AllTodosTreeBuilder(new Tree(), new DefaultTreeModel(new DefaultMutableTreeNode()), myProject);
    all.init();
    AbstractTreeStructure structure = all.getTreeStructure();
    ProjectViewTestUtil.assertStructureEqual(structure, "Root\n" + " Summary\n" + "  toDo\n" + "   xmlFile.xml\n" + "    Item: (12,16)\n" + "  package1 toDoFileCount=2,toDoItemCount=4\n" + "   package2 toDoFileCount=1,toDoItemCount=2\n" + "    JavaClass.java\n" + "     Item: (62,78)\n" + "     Item: (145,162)\n" + "   JavaClass.java\n" + "    Item: (52,68)\n" + "    Item: (134,151)\n" + "  package3 toDoFileCount=1,toDoItemCount=2\n" + "   JavaClass.java\n" + "    Item: (53,69)\n" + "    Item: (136,153)\n", myPrintInfo);
    checkOccurrences(all, new String[] { "Item: (12,16)", "Item: (62,78)", "Item: (145,162)", "Item: (52,68)", "Item: (134,151)", "Item: (53,69)", "Item: (136,153)" });
    final DefaultTreeModel treeModel = new DefaultTreeModel(new DefaultMutableTreeNode());
    final JTree currentFileTree = new Tree(treeModel);
    CurrentFileTodosTreeBuilder builder = new CurrentFileTodosTreeBuilder(currentFileTree, treeModel, myProject);
    builder.init();
    builder.setFile(getSrcDirectory().findSubdirectory("package1").findFile("JavaClass.java"));
    builder.updateFromRoot();
    ProjectViewTestUtil.assertStructureEqual(builder.getTreeStructure(), "JavaClass.java\n" + " JavaClass.java\n" + "  Item: (52,68)\n" + "  Item: (134,151)\n", myPrintInfo);
    Disposer.dispose(builder);
    Disposer.dispose(all);
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) AllTodosTreeBuilder(com.intellij.ide.todo.AllTodosTreeBuilder) Tree(com.intellij.ui.treeStructure.Tree) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) AbstractTreeStructure(com.intellij.ide.util.treeView.AbstractTreeStructure) CurrentFileTodosTreeBuilder(com.intellij.ide.todo.CurrentFileTodosTreeBuilder)

Aggregations

CurrentFileTodosTreeBuilder (com.intellij.ide.todo.CurrentFileTodosTreeBuilder)2 AllTodosTreeBuilder (com.intellij.ide.todo.AllTodosTreeBuilder)1 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)1 AbstractTreeStructure (com.intellij.ide.util.treeView.AbstractTreeStructure)1 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 Tree (com.intellij.ui.treeStructure.Tree)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)1 NotNull (org.jetbrains.annotations.NotNull)1