Search in sources :

Example 1 with CoverageViewExtension

use of com.intellij.coverage.view.CoverageViewExtension in project intellij by bazelbuild.

the class BlazeCoverageEngine method createCoverageViewExtension.

@Nullable
@Override
public CoverageViewExtension createCoverageViewExtension(Project project, CoverageSuitesBundle suites, StateBean stateBean) {
    WorkspaceRoot root = WorkspaceRoot.fromProjectSafe(project);
    if (root == null) {
        return null;
    }
    Set<File> topLevelDirectories = getTopLevelDirectories(suites);
    if (topLevelDirectories.isEmpty()) {
        return null;
    }
    CoverageAnnotator annotator = getCoverageAnnotator(project);
    return new DirectoryCoverageViewExtension(project, annotator, suites, stateBean) {

        private List<AbstractTreeNode> topLevelNodes;

        @Override
        public AbstractTreeNode createRootNode() {
            if (topLevelDirectories.size() == 1) {
                File file = topLevelDirectories.iterator().next();
                return new CoverageListRootNode(project, resolveFile(project, file), suites, stateBean);
            }
            return new CoverageListRootNode(project, resolveFile(project, root.directory()), suites, stateBean) {

                @Override
                public Collection<? extends AbstractTreeNode> getChildren() {
                    return getRootChildren(this);
                }
            };
        }

        @Override
        public List<AbstractTreeNode> getChildrenNodes(AbstractTreeNode node) {
            if (node instanceof CoverageListRootNode && topLevelDirectories.size() != 1) {
                return getRootChildren((CoverageListRootNode) node);
            }
            return super.getChildrenNodes(node).stream().filter(treeNode -> !isLeaf(treeNode) || getPercentage(0, treeNode) != null).collect(Collectors.toList());
        }

        private List<AbstractTreeNode> getRootChildren(CoverageListRootNode root) {
            if (topLevelNodes == null) {
                topLevelNodes = ReadAction.compute(() -> getTopLevelNodes(project, suites, stateBean));
                for (AbstractTreeNode node : topLevelNodes) {
                    node.setParent(root);
                }
            }
            return topLevelNodes;
        }
    };
}
Also used : DirectoryCoverageViewExtension(com.intellij.coverage.view.DirectoryCoverageViewExtension) CoverageListRootNode(com.intellij.coverage.view.CoverageListRootNode) Arrays(java.util.Arrays) CoverageRunner(com.intellij.coverage.CoverageRunner) VirtualFile(com.intellij.openapi.vfs.VirtualFile) CoverageFileProvider(com.intellij.coverage.CoverageFileProvider) ReadAction(com.intellij.openapi.application.ReadAction) PsiManager(com.intellij.psi.PsiManager) CoverageUtils(com.google.idea.blaze.base.run.coverage.CoverageUtils) ImmutableList(com.google.common.collect.ImmutableList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) DirectoryCoverageViewExtension(com.intellij.coverage.view.DirectoryCoverageViewExtension) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) VirtualFileSystemProvider(com.google.idea.blaze.base.io.VirtualFileSystemProvider) Module(com.intellij.openapi.module.Module) CoverageEngine(com.intellij.coverage.CoverageEngine) CoverageEnabledConfiguration(com.intellij.execution.configurations.coverage.CoverageEnabledConfiguration) Nullable(javax.annotation.Nullable) Blaze(com.google.idea.blaze.base.settings.Blaze) Extensions(com.intellij.openapi.extensions.Extensions) CoverageSuitesBundle(com.intellij.coverage.CoverageSuitesBundle) ImmutableSet(com.google.common.collect.ImmutableSet) RunConfigurationBase(com.intellij.execution.configurations.RunConfigurationBase) Collection(java.util.Collection) Set(java.util.Set) CoverageListNode(com.intellij.coverage.view.CoverageListNode) AbstractTestProxy(com.intellij.execution.testframework.AbstractTestProxy) Collectors(java.util.stream.Collectors) File(java.io.File) Objects(java.util.Objects) CoverageSuite(com.intellij.coverage.CoverageSuite) List(java.util.List) CoverageViewExtension(com.intellij.coverage.view.CoverageViewExtension) StateBean(com.intellij.coverage.view.CoverageViewManager.StateBean) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) CoverageAnnotator(com.intellij.coverage.CoverageAnnotator) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) CoverageAnnotator(com.intellij.coverage.CoverageAnnotator) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) CoverageListRootNode(com.intellij.coverage.view.CoverageListRootNode) Nullable(javax.annotation.Nullable)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 VirtualFileSystemProvider (com.google.idea.blaze.base.io.VirtualFileSystemProvider)1 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)1 CoverageUtils (com.google.idea.blaze.base.run.coverage.CoverageUtils)1 Blaze (com.google.idea.blaze.base.settings.Blaze)1 CoverageAnnotator (com.intellij.coverage.CoverageAnnotator)1 CoverageEngine (com.intellij.coverage.CoverageEngine)1 CoverageFileProvider (com.intellij.coverage.CoverageFileProvider)1 CoverageRunner (com.intellij.coverage.CoverageRunner)1 CoverageSuite (com.intellij.coverage.CoverageSuite)1 CoverageSuitesBundle (com.intellij.coverage.CoverageSuitesBundle)1 CoverageListNode (com.intellij.coverage.view.CoverageListNode)1 CoverageListRootNode (com.intellij.coverage.view.CoverageListRootNode)1 CoverageViewExtension (com.intellij.coverage.view.CoverageViewExtension)1 StateBean (com.intellij.coverage.view.CoverageViewManager.StateBean)1 DirectoryCoverageViewExtension (com.intellij.coverage.view.DirectoryCoverageViewExtension)1 RunConfigurationBase (com.intellij.execution.configurations.RunConfigurationBase)1 CoverageEnabledConfiguration (com.intellij.execution.configurations.coverage.CoverageEnabledConfiguration)1 AbstractTestProxy (com.intellij.execution.testframework.AbstractTestProxy)1