Search in sources :

Example 1 with PackageElement

use of com.intellij.ide.projectView.impl.nodes.PackageElement in project intellij-community by JetBrains.

the class TodoJavaTreeHelper method getSelectedElement.

@Override
public PsiElement getSelectedElement(final Object userObject) {
    if (userObject instanceof TodoPackageNode) {
        TodoPackageNode descriptor = (TodoPackageNode) userObject;
        final PackageElement packageElement = descriptor.getValue();
        return packageElement != null ? packageElement.getPackage() : null;
    }
    return super.getSelectedElement(userObject);
}
Also used : PackageElement(com.intellij.ide.projectView.impl.nodes.PackageElement)

Example 2 with PackageElement

use of com.intellij.ide.projectView.impl.nodes.PackageElement in project intellij-community by JetBrains.

the class TodoJavaTreeHelper method traverseSubPackages.

private static void traverseSubPackages(PsiPackage psiPackage, Module module, TodoTreeBuilder builder, Project project, Set<PsiPackage> packages) {
    if (!isPackageEmpty(new PackageElement(module, psiPackage, false), builder, project)) {
        packages.add(psiPackage);
    }
    GlobalSearchScope scope = module != null ? GlobalSearchScope.moduleScope(module) : GlobalSearchScope.projectScope(project);
    final PsiPackage[] subPackages = psiPackage.getSubPackages(scope);
    for (PsiPackage subPackage : subPackages) {
        traverseSubPackages(subPackage, module, builder, project, packages);
    }
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PackageElement(com.intellij.ide.projectView.impl.nodes.PackageElement)

Example 3 with PackageElement

use of com.intellij.ide.projectView.impl.nodes.PackageElement in project intellij-community by JetBrains.

the class PackageViewPane method getSelectedPackageElement.

@Nullable
private PackageElement getSelectedPackageElement() {
    PackageElement result = null;
    final DefaultMutableTreeNode selectedNode = getSelectedNode();
    if (selectedNode != null) {
        Object o = selectedNode.getUserObject();
        if (o instanceof AbstractTreeNode) {
            Object selected = ((AbstractTreeNode) o).getValue();
            result = selected instanceof PackageElement ? (PackageElement) selected : null;
        }
    }
    return result;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PackageElement(com.intellij.ide.projectView.impl.nodes.PackageElement) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with PackageElement

use of com.intellij.ide.projectView.impl.nodes.PackageElement in project intellij-community by JetBrains.

the class CoverageProjectViewClassNodeDecorator method decorate.

public void decorate(ProjectViewNode node, PresentationData data) {
    final CoverageDataManager coverageDataManager = getCoverageDataManager();
    final CoverageSuitesBundle currentSuite = coverageDataManager.getCurrentSuitesBundle();
    final Project project = node.getProject();
    final JavaCoverageAnnotator javaCovAnnotator = getCovAnnotator(currentSuite, project);
    // This decorator is applicable only to JavaCoverageAnnotator
    if (javaCovAnnotator == null) {
        return;
    }
    final Object value = node.getValue();
    PsiElement element = null;
    if (value instanceof PsiElement) {
        element = (PsiElement) value;
    } else if (value instanceof SmartPsiElementPointer) {
        element = ((SmartPsiElementPointer) value).getElement();
    } else if (value instanceof PackageElement) {
        PackageElement packageElement = (PackageElement) value;
        final String coverageString = javaCovAnnotator.getPackageCoverageInformationString(packageElement.getPackage(), packageElement.getModule(), coverageDataManager);
        data.setLocationString(coverageString);
    }
    if (element instanceof PsiClass) {
        final GlobalSearchScope searchScope = currentSuite.getSearchScope(project);
        final VirtualFile vFile = PsiUtilCore.getVirtualFile(element);
        if (vFile != null && searchScope.contains(vFile)) {
            final String qName = ((PsiClass) element).getQualifiedName();
            if (qName != null) {
                data.setLocationString(javaCovAnnotator.getClassCoverageInformationString(qName, coverageDataManager));
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) SmartPsiElementPointer(com.intellij.psi.SmartPsiElementPointer) PsiClass(com.intellij.psi.PsiClass) PackageElement(com.intellij.ide.projectView.impl.nodes.PackageElement) PsiElement(com.intellij.psi.PsiElement)

Example 5 with PackageElement

use of com.intellij.ide.projectView.impl.nodes.PackageElement in project intellij-community by JetBrains.

the class TodoJavaTreeHelper method addPackagesToChildren.

@Override
public void addPackagesToChildren(final ArrayList<AbstractTreeNode> children, final Module module, final TodoTreeBuilder builder) {
    Project project = getProject();
    final PsiManager psiManager = PsiManager.getInstance(project);
    final List<VirtualFile> sourceRoots = new ArrayList<>();
    if (module == null) {
        final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(project);
        ContainerUtil.addAll(sourceRoots, projectRootManager.getContentSourceRoots());
    } else {
        ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
        ContainerUtil.addAll(sourceRoots, moduleRootManager.getSourceRoots());
    }
    final Set<PsiPackage> topLevelPackages = new HashSet<>();
    for (final VirtualFile root : sourceRoots) {
        final PsiDirectory directory = psiManager.findDirectory(root);
        if (directory == null) {
            continue;
        }
        final PsiPackage directoryPackage = JavaDirectoryService.getInstance().getPackage(directory);
        if (directoryPackage == null || PackageUtil.isPackageDefault(directoryPackage)) {
            // add subpackages
            final PsiDirectory[] subdirectories = directory.getSubdirectories();
            for (PsiDirectory subdirectory : subdirectories) {
                final PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(subdirectory);
                if (aPackage != null && !PackageUtil.isPackageDefault(aPackage)) {
                    topLevelPackages.add(aPackage);
                } else {
                    final Iterator<PsiFile> files = builder.getFiles(subdirectory);
                    if (!files.hasNext())
                        continue;
                    TodoDirNode dirNode = new TodoDirNode(project, subdirectory, builder);
                    if (!children.contains(dirNode)) {
                        children.add(dirNode);
                    }
                }
            }
            // add non-dir items
            final Iterator<PsiFile> filesUnderDirectory = builder.getFilesUnderDirectory(directory);
            for (; filesUnderDirectory.hasNext(); ) {
                final PsiFile file = filesUnderDirectory.next();
                TodoFileNode todoFileNode = new TodoFileNode(project, file, builder, false);
                if (!children.contains(todoFileNode)) {
                    children.add(todoFileNode);
                }
            }
        } else {
            // this is the case when a source root has pakage prefix assigned
            topLevelPackages.add(directoryPackage);
        }
    }
    GlobalSearchScope scope = module != null ? GlobalSearchScope.moduleScope(module) : GlobalSearchScope.projectScope(project);
    ArrayList<PsiPackage> packages = new ArrayList<>();
    for (PsiPackage psiPackage : topLevelPackages) {
        final PsiPackage aPackage = findNonEmptyPackage(psiPackage, module, project, builder, scope);
        if (aPackage != null) {
            packages.add(aPackage);
        }
    }
    for (PsiPackage psiPackage : packages) {
        if (!builder.getTodoTreeStructure().getIsFlattenPackages()) {
            PackageElement element = new PackageElement(module, psiPackage, false);
            TodoPackageNode packageNode = new TodoPackageNode(project, element, builder, psiPackage.getQualifiedName());
            if (!children.contains(packageNode)) {
                children.add(packageNode);
            }
        } else {
            Set<PsiPackage> allPackages = new HashSet<>();
            traverseSubPackages(psiPackage, module, builder, project, allPackages);
            for (PsiPackage aPackage : allPackages) {
                TodoPackageNode packageNode = new TodoPackageNode(project, new PackageElement(module, aPackage, false), builder);
                if (!children.contains(packageNode)) {
                    children.add(packageNode);
                }
            }
        }
    }
    final List<VirtualFile> roots = collectContentRoots(module);
    roots.removeAll(sourceRoots);
    addDirsToChildren(roots, children, builder);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PackageElement(com.intellij.ide.projectView.impl.nodes.PackageElement) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager)

Aggregations

PackageElement (com.intellij.ide.projectView.impl.nodes.PackageElement)10 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)5 Module (com.intellij.openapi.module.Module)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 PsiDirectory (com.intellij.psi.PsiDirectory)4 Project (com.intellij.openapi.project.Project)3 PsiPackage (com.intellij.psi.PsiPackage)3 NotNull (org.jetbrains.annotations.NotNull)3 DirectoryGroupNode (com.android.tools.idea.navigator.nodes.DirectoryGroupNode)2 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)2 NodeDescriptor (com.intellij.ide.util.treeView.NodeDescriptor)2 PsiElement (com.intellij.psi.PsiElement)2 PsiFile (com.intellij.psi.PsiFile)2 FileGroupNode (com.android.tools.idea.navigator.nodes.FileGroupNode)1 PackageElementNode (com.intellij.ide.projectView.impl.nodes.PackageElementNode)1 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)1 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)1 IndexNotReadyException (com.intellij.openapi.project.IndexNotReadyException)1 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)1 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)1