use of com.intellij.coverage.CoverageSuitesBundle in project intellij-community by JetBrains.
the class HideCoverageInfoAction method update.
@Override
public void update(AnActionEvent e) {
final Presentation presentation = e.getPresentation();
presentation.setEnabled(false);
presentation.setVisible(ActionPlaces.isToolbarPlace(e.getPlace()));
final Project project = e.getData(CommonDataKeys.PROJECT);
if (project != null) {
final CoverageSuitesBundle suitesBundle = CoverageDataManager.getInstance(project).getCurrentSuitesBundle();
presentation.setEnabled(suitesBundle != null);
presentation.setVisible(suitesBundle != null);
}
}
use of com.intellij.coverage.CoverageSuitesBundle in project intellij-community by JetBrains.
the class ShowCoveringTestsAction method actionPerformed.
public void actionPerformed(final AnActionEvent e) {
final DataContext context = e.getDataContext();
final Project project = e.getProject();
LOG.assertTrue(project != null);
final Editor editor = e.getData(CommonDataKeys.EDITOR);
LOG.assertTrue(editor != null);
final CoverageSuitesBundle currentSuite = CoverageDataManager.getInstance(project).getCurrentSuitesBundle();
LOG.assertTrue(currentSuite != null);
final File[] traceFiles = getTraceFiles(project);
final Set<String> tests = new HashSet<>();
Runnable runnable = () -> {
for (File traceFile : traceFiles) {
DataInputStream in = null;
try {
in = new DataInputStream(new FileInputStream(traceFile));
extractTests(traceFile, in, tests);
} catch (Exception ex) {
LOG.error(traceFile.getName(), ex);
} finally {
try {
in.close();
} catch (IOException ex) {
LOG.error(ex);
}
}
}
};
if (ProgressManager.getInstance().runProcessWithProgressSynchronously(runnable, "Extract information about tests", false, project)) {
//todo cache them? show nothing found message
final String[] testNames = ArrayUtil.toStringArray(tests);
Arrays.sort(testNames);
if (testNames.length == 0) {
HintManager.getInstance().showErrorHint(editor, "Failed to load covered tests");
return;
}
final List<PsiElement> elements = currentSuite.getCoverageEngine().findTestsByNames(testNames, project);
final ImplementationViewComponent component;
final String title = "Tests covering line " + myClassFQName + ":" + myLineData.getLineNumber();
final ComponentPopupBuilder popupBuilder;
if (!elements.isEmpty()) {
component = new ImplementationViewComponent(PsiUtilCore.toPsiElementArray(elements), 0);
popupBuilder = JBPopupFactory.getInstance().createComponentPopupBuilder(component, component.getPreferredFocusableComponent()).setDimensionServiceKey(project, "ShowTestsPopup", false).setCouldPin(popup -> {
component.showInUsageView();
popup.cancel();
return false;
});
} else {
component = null;
final JPanel panel = new PanelWithText("Following test" + (testNames.length > 1 ? "s" : "") + " could not be found: " + StringUtil.join(testNames, "<br/>").replace("_", "."));
popupBuilder = JBPopupFactory.getInstance().createComponentPopupBuilder(panel, null);
}
final JBPopup popup = popupBuilder.setRequestFocusCondition(project, NotLookupOrSearchCondition.INSTANCE).setProject(project).setResizable(true).setMovable(true).setTitle(title).createPopup();
popup.showInBestPositionFor(editor);
if (component != null) {
component.setHint(popup, title);
}
}
}
Aggregations