Search in sources :

Example 6 with CoverageSuitesBundle

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);
    }
}
Also used : Project(com.intellij.openapi.project.Project) CoverageSuitesBundle(com.intellij.coverage.CoverageSuitesBundle)

Example 7 with CoverageSuitesBundle

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);
        }
    }
}
Also used : DataInputStream(java.io.DataInputStream) java.util(java.util) ArrayUtil(com.intellij.util.ArrayUtil) HashSet(com.intellij.util.containers.HashSet) LineCoverage(com.intellij.rt.coverage.data.LineCoverage) Comparing(com.intellij.openapi.util.Comparing) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) PlatformIcons(com.intellij.util.PlatformIcons) ProgressManager(com.intellij.openapi.progress.ProgressManager) LineData(com.intellij.rt.coverage.data.LineData) CoverageSuitesBundle(com.intellij.coverage.CoverageSuitesBundle) ComponentPopupBuilder(com.intellij.openapi.ui.popup.ComponentPopupBuilder) StringUtil(com.intellij.openapi.util.text.StringUtil) PanelWithText(com.intellij.openapi.ui.PanelWithText) CoverageDataManager(com.intellij.coverage.CoverageDataManager) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Editor(com.intellij.openapi.editor.Editor) JBPopup(com.intellij.openapi.ui.popup.JBPopup) File(java.io.File) CoverageSuite(com.intellij.coverage.CoverageSuite) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) Nullable(org.jetbrains.annotations.Nullable) PsiUtilCore(com.intellij.psi.util.PsiUtilCore) NotLookupOrSearchCondition(com.intellij.ui.popup.NotLookupOrSearchCondition) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) HintManager(com.intellij.codeInsight.hint.HintManager) ImplementationViewComponent(com.intellij.codeInsight.hint.ImplementationViewComponent) javax.swing(javax.swing) ImplementationViewComponent(com.intellij.codeInsight.hint.ImplementationViewComponent) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) CoverageSuitesBundle(com.intellij.coverage.CoverageSuitesBundle) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) Project(com.intellij.openapi.project.Project) PanelWithText(com.intellij.openapi.ui.PanelWithText) ComponentPopupBuilder(com.intellij.openapi.ui.popup.ComponentPopupBuilder) Editor(com.intellij.openapi.editor.Editor) JBPopup(com.intellij.openapi.ui.popup.JBPopup) File(java.io.File) PsiElement(com.intellij.psi.PsiElement) HashSet(com.intellij.util.containers.HashSet)

Aggregations

CoverageSuitesBundle (com.intellij.coverage.CoverageSuitesBundle)7 Project (com.intellij.openapi.project.Project)4 CoverageDataManager (com.intellij.coverage.CoverageDataManager)3 CoverageEngine (com.intellij.coverage.CoverageEngine)2 CoverageSuite (com.intellij.coverage.CoverageSuite)2 DataContext (com.intellij.openapi.actionSystem.DataContext)2 PsiElement (com.intellij.psi.PsiElement)2 File (java.io.File)2 Nullable (org.jetbrains.annotations.Nullable)2 HintManager (com.intellij.codeInsight.hint.HintManager)1 ImplementationViewComponent (com.intellij.codeInsight.hint.ImplementationViewComponent)1 ExportToHTMLDialog (com.intellij.codeInspection.export.ExportToHTMLDialog)1 Location (com.intellij.execution.Location)1 AbstractTestProxy (com.intellij.execution.testframework.AbstractTestProxy)1 com.intellij.openapi.actionSystem (com.intellij.openapi.actionSystem)1 Presentation (com.intellij.openapi.actionSystem.Presentation)1 Logger (com.intellij.openapi.diagnostic.Logger)1 Editor (com.intellij.openapi.editor.Editor)1 ProgressManager (com.intellij.openapi.progress.ProgressManager)1 PanelWithText (com.intellij.openapi.ui.PanelWithText)1