Search in sources :

Example 11 with LineData

use of com.intellij.rt.coverage.data.LineData in project intellij by bazelbuild.

the class BlazeCoverageRunner method fromFileData.

private static LineData[] fromFileData(FileData fileData) {
    LineData[] lines = new LineData[maxLineNumber(fileData) + 1];
    fileData.lineHits.forEachEntry((line, hits) -> {
        LineData newLine = new LineData(line, null);
        newLine.setHits(hits);
        lines[line] = newLine;
        return true;
    });
    return lines;
}
Also used : LineData(com.intellij.rt.coverage.data.LineData)

Example 12 with LineData

use of com.intellij.rt.coverage.data.LineData in project intellij-plugins by JetBrains.

the class JstdCoverageEngine method convertClassDataToLineHits.

private static List<CoverageReport.LineHits> convertClassDataToLineHits(@NotNull ClassData classData) {
    int lineCount = classData.getLines().length;
    List<CoverageReport.LineHits> lineHitsList = ContainerUtil.newArrayListWithCapacity(lineCount);
    for (int lineInd = 0; lineInd < lineCount; lineInd++) {
        LineData lineData = classData.getLineData(lineInd);
        if (lineData != null) {
            CoverageReport.LineHits lineHits = new CoverageReport.LineHits(lineData.getLineNumber(), lineData.getHits());
            lineHitsList.add(lineHits);
        }
    }
    return lineHitsList;
}
Also used : LineData(com.intellij.rt.coverage.data.LineData) CoverageReport(com.google.jstestdriver.idea.rt.coverage.CoverageReport)

Example 13 with LineData

use of com.intellij.rt.coverage.data.LineData in project intellij-plugins by JetBrains.

the class JstdCoverageRunner method readProjectData.

@NotNull
private static ProjectData readProjectData(@NotNull File dataFile) throws IOException {
    CoverageReport report = CoverageSerializationUtils.readLCOV(dataFile);
    ProjectData projectData = new ProjectData();
    for (Map.Entry<String, List<CoverageReport.LineHits>> entry : report.getInfo().entrySet()) {
        String filePath = SimpleCoverageAnnotator.getFilePath(entry.getKey());
        ClassData classData = projectData.getOrCreateClassData(filePath);
        int max = 0;
        List<CoverageReport.LineHits> lineHitsList = entry.getValue();
        if (lineHitsList.size() > 0) {
            CoverageReport.LineHits lastLineHits = lineHitsList.get(lineHitsList.size() - 1);
            max = lastLineHits.getLineNumber();
        }
        LineData[] lines = new LineData[max + 1];
        for (CoverageReport.LineHits lineHits : lineHitsList) {
            LineData lineData = new LineData(lineHits.getLineNumber(), null);
            lineData.setHits(lineHits.getHits());
            lines[lineHits.getLineNumber()] = lineData;
        }
        classData.setLines(lines);
    }
    return projectData;
}
Also used : CoverageReport(com.google.jstestdriver.idea.rt.coverage.CoverageReport) LineData(com.intellij.rt.coverage.data.LineData) ClassData(com.intellij.rt.coverage.data.ClassData) List(java.util.List) Map(java.util.Map) ProjectData(com.intellij.rt.coverage.data.ProjectData) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with LineData

use of com.intellij.rt.coverage.data.LineData in project intellij-community by JetBrains.

the class PackageAnnotator method collectClassCoverageInformation.

private void collectClassCoverageInformation(final File classFile, @Nullable final PsiClass psiClass, final PackageCoverageInfo packageCoverageInfo, final ProjectData projectInfo, final Map<String, ClassCoverageInfo> toplevelClassCoverage, final String className, final String toplevelClassSrcFQName) {
    final ClassCoverageInfo toplevelClassCoverageInfo = new ClassCoverageInfo();
    final ClassData classData = projectInfo.getClassData(className);
    if (classData != null && classData.getLines() != null) {
        final Object[] lines = classData.getLines();
        for (Object l : lines) {
            if (l instanceof LineData) {
                final LineData lineData = (LineData) l;
                if (lineData.getStatus() == LineCoverage.FULL) {
                    toplevelClassCoverageInfo.fullyCoveredLineCount++;
                } else if (lineData.getStatus() == LineCoverage.PARTIAL) {
                    toplevelClassCoverageInfo.partiallyCoveredLineCount++;
                }
                toplevelClassCoverageInfo.totalLineCount++;
                packageCoverageInfo.totalLineCount++;
            }
        }
        boolean touchedClass = false;
        final Collection methodSigs = classData.getMethodSigs();
        for (final Object nameAndSig : methodSigs) {
            final int covered = classData.getStatus((String) nameAndSig);
            if (covered != LineCoverage.NONE) {
                touchedClass = true;
            }
            if (isGeneratedDefaultConstructor(psiClass, (String) nameAndSig)) {
                continue;
            }
            if (covered != LineCoverage.NONE) {
                toplevelClassCoverageInfo.coveredMethodCount++;
            }
            toplevelClassCoverageInfo.totalMethodCount++;
        }
        if (!methodSigs.isEmpty()) {
            if (touchedClass) {
                packageCoverageInfo.coveredClassCount++;
            }
            packageCoverageInfo.totalClassCount++;
            packageCoverageInfo.coveredLineCount += toplevelClassCoverageInfo.fullyCoveredLineCount;
            packageCoverageInfo.coveredLineCount += toplevelClassCoverageInfo.partiallyCoveredLineCount;
            packageCoverageInfo.coveredMethodCount += toplevelClassCoverageInfo.coveredMethodCount;
            packageCoverageInfo.totalMethodCount += toplevelClassCoverageInfo.totalMethodCount;
        } else {
            LOG.debug("Did not find any method signatures in " + classFile.getName());
            return;
        }
    } else {
        if (!collectNonCoveredClassInfo(classFile, psiClass, toplevelClassCoverageInfo, packageCoverageInfo)) {
            LOG.debug("Did not collect non-covered class info for " + classFile.getName());
            return;
        }
    }
    ClassCoverageInfo classCoverageInfo = getOrCreateClassCoverageInfo(toplevelClassCoverage, toplevelClassSrcFQName);
    LOG.debug("Adding coverage of " + classFile.getName() + " to top-level class " + toplevelClassSrcFQName);
    classCoverageInfo.totalLineCount += toplevelClassCoverageInfo.totalLineCount;
    classCoverageInfo.fullyCoveredLineCount += toplevelClassCoverageInfo.fullyCoveredLineCount;
    classCoverageInfo.partiallyCoveredLineCount += toplevelClassCoverageInfo.partiallyCoveredLineCount;
    classCoverageInfo.totalMethodCount += toplevelClassCoverageInfo.totalMethodCount;
    classCoverageInfo.coveredMethodCount += toplevelClassCoverageInfo.coveredMethodCount;
    if (toplevelClassCoverageInfo.getCoveredLineCount() > 0) {
        classCoverageInfo.coveredClassCount++;
    }
}
Also used : LineData(com.intellij.rt.coverage.data.LineData) ClassData(com.intellij.rt.coverage.data.ClassData) Collection(java.util.Collection)

Example 15 with LineData

use of com.intellij.rt.coverage.data.LineData in project intellij-community by JetBrains.

the class CoverageLineMarkerRenderer method createActionsToolbar.

protected JComponent createActionsToolbar(final Editor editor, final int lineNumber) {
    final JComponent editorComponent = editor.getComponent();
    final DefaultActionGroup group = new DefaultActionGroup();
    final GotoPreviousCoveredLineAction prevAction = new GotoPreviousCoveredLineAction(editor, lineNumber);
    final GotoNextCoveredLineAction nextAction = new GotoNextCoveredLineAction(editor, lineNumber);
    group.add(prevAction);
    group.add(nextAction);
    prevAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_UP, InputEvent.ALT_MASK | InputEvent.SHIFT_MASK)), editorComponent);
    nextAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, InputEvent.ALT_MASK | InputEvent.SHIFT_MASK)), editorComponent);
    final LineData lineData = getLineData(lineNumber);
    if (myCoverageByTestApplicable) {
        group.add(new ShowCoveringTestsAction(myClassName, lineData));
    }
    final AnAction byteCodeViewAction = ActionManager.getInstance().getAction("ByteCodeViewer");
    if (byteCodeViewAction != null) {
        group.add(byteCodeViewAction);
    }
    group.add(new EditCoverageColorsAction(editor, lineNumber));
    group.add(new HideCoverageInfoAction());
    final ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.FILEHISTORY_VIEW_TOOLBAR, group, true);
    final JComponent toolbarComponent = toolbar.getComponent();
    final Color background = ((EditorEx) editor).getBackgroundColor();
    final Color foreground = editor.getColorsScheme().getColor(EditorColors.CARET_COLOR);
    toolbarComponent.setBackground(background);
    toolbarComponent.setBorder(new ColoredSideBorder(foreground, foreground, lineData == null || lineData.getStatus() == LineCoverage.NONE || mySubCoverageActive ? foreground : null, foreground, 1));
    toolbar.updateActionsImmediately();
    return toolbarComponent;
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) ShowCoveringTestsAction(com.intellij.coverage.actions.ShowCoveringTestsAction) HideCoverageInfoAction(com.intellij.coverage.actions.HideCoverageInfoAction) LineData(com.intellij.rt.coverage.data.LineData) ColoredSideBorder(com.intellij.ui.ColoredSideBorder)

Aggregations

LineData (com.intellij.rt.coverage.data.LineData)21 ClassData (com.intellij.rt.coverage.data.ClassData)11 ProjectData (com.intellij.rt.coverage.data.ProjectData)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 Nullable (org.jetbrains.annotations.Nullable)5 Document (com.intellij.openapi.editor.Document)4 PsiFile (com.intellij.psi.PsiFile)4 Map (java.util.Map)4 NotNull (org.jetbrains.annotations.NotNull)4 Module (com.intellij.openapi.module.Module)3 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 CoverageReport (com.google.jstestdriver.idea.rt.coverage.CoverageReport)2 Editor (com.intellij.openapi.editor.Editor)2 DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)2 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)2 DocumentListener (com.intellij.openapi.editor.event.DocumentListener)2 DocumentMarkupModel (com.intellij.openapi.editor.impl.DocumentMarkupModel)2 FileEditor (com.intellij.openapi.fileEditor.FileEditor)2 TextEditor (com.intellij.openapi.fileEditor.TextEditor)2