use of com.intellij.coverage.view.CoverageViewManager.StateBean 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;
}
};
}
Aggregations