Search in sources :

Example 46 with ICounter

use of org.jacoco.core.analysis.ICounter in project jacoco by jacoco.

the class ClassRowWriter method writeRow.

/**
 * Writes the class summary information as a row.
 *
 * @param groupName
 *            name of the group
 * @param packageName
 *            vm name of the package
 * @param node
 *            class coverage data
 * @throws IOException
 *             in case of problems with the writer
 */
public void writeRow(final String groupName, final String packageName, final IClassCoverage node) throws IOException {
    writer.write(groupName);
    writer.write(languageNames.getPackageName(packageName));
    final String className = languageNames.getClassName(node.getName(), node.getSignature(), node.getSuperName(), node.getInterfaceNames());
    writer.write(className);
    for (final CounterEntity entity : COUNTERS) {
        final ICounter counter = node.getCounter(entity);
        writer.write(counter.getMissedCount());
        writer.write(counter.getCoveredCount());
    }
    writer.nextLine();
}
Also used : ICounter(org.jacoco.core.analysis.ICounter) CounterEntity(org.jacoco.core.analysis.ICoverageNode.CounterEntity)

Example 47 with ICounter

use of org.jacoco.core.analysis.ICounter in project jacoco by jacoco.

the class SourceHighlighter method highlight.

HTMLElement highlight(final HTMLElement pre, final ILine line, final int lineNr) throws IOException {
    final String style;
    switch(line.getStatus()) {
        case ICounter.NOT_COVERED:
            style = Styles.NOT_COVERED;
            break;
        case ICounter.FULLY_COVERED:
            style = Styles.FULLY_COVERED;
            break;
        case ICounter.PARTLY_COVERED:
            style = Styles.PARTLY_COVERED;
            break;
        default:
            return pre;
    }
    final String lineId = "L" + Integer.toString(lineNr);
    final ICounter branches = line.getBranchCounter();
    switch(branches.getStatus()) {
        case ICounter.NOT_COVERED:
            return span(pre, lineId, style, Styles.BRANCH_NOT_COVERED, "All %2$d branches missed.", branches);
        case ICounter.FULLY_COVERED:
            return span(pre, lineId, style, Styles.BRANCH_FULLY_COVERED, "All %2$d branches covered.", branches);
        case ICounter.PARTLY_COVERED:
            return span(pre, lineId, style, Styles.BRANCH_PARTLY_COVERED, "%1$d of %2$d branches missed.", branches);
        default:
            return pre.span(style, lineId);
    }
}
Also used : ICounter(org.jacoco.core.analysis.ICounter)

Example 48 with ICounter

use of org.jacoco.core.analysis.ICounter in project jacoco by jacoco.

the class BarColumn method footer.

public void footer(final HTMLElement td, final ICoverageNode total, final Resources resources, final ReportOutputFolder base) throws IOException {
    final ICounter counter = total.getCounter(entity);
    td.text(integerFormat.format(counter.getMissedCount())).text(" of ").text(integerFormat.format(counter.getTotalCount()));
}
Also used : ICounter(org.jacoco.core.analysis.ICounter)

Example 49 with ICounter

use of org.jacoco.core.analysis.ICounter in project jacoco by jacoco.

the class XMLCoverageWriter method writeCounters.

/**
 * Writes all non-zero counters of the given node.
 *
 * @param node
 *            node to retrieve counters from
 * @param parent
 *            container for the counter elements
 * @throws IOException
 *             if XML can't be written to the underlying output
 */
public static void writeCounters(final ICoverageNode node, final XMLElement parent) throws IOException {
    for (final CounterEntity counterEntity : CounterEntity.values()) {
        final ICounter counter = node.getCounter(counterEntity);
        if (counter.getTotalCount() > 0) {
            final XMLElement counterNode = parent.element("counter");
            counterNode.attr("type", counterEntity.name());
            writeCounter(counterNode, "missed", "covered", counter);
            counterNode.close();
        }
    }
}
Also used : ICounter(org.jacoco.core.analysis.ICounter) CounterEntity(org.jacoco.core.analysis.ICoverageNode.CounterEntity)

Example 50 with ICounter

use of org.jacoco.core.analysis.ICounter in project sonar-java by SonarSource.

the class UnitTestAnalyzer method analyzeFile.

private static void analyzeFile(NewCoverage newCoverage, InputFile resource, ISourceFileCoverage coverage) {
    for (int lineId = coverage.getFirstLine(); lineId <= coverage.getLastLine(); lineId++) {
        final int hits;
        ILine line = coverage.getLine(lineId);
        switch(line.getInstructionCounter().getStatus()) {
            case ICounter.FULLY_COVERED:
            case ICounter.PARTLY_COVERED:
                hits = 1;
                break;
            case ICounter.NOT_COVERED:
                hits = 0;
                break;
            case ICounter.EMPTY:
                continue;
            default:
                JaCoCoExtensions.LOG.warn("Unknown status for line {} in {}", lineId, resource);
                continue;
        }
        newCoverage.lineHits(lineId, hits);
        ICounter branchCounter = line.getBranchCounter();
        int conditions = branchCounter.getTotalCount();
        if (conditions > 0) {
            int coveredConditions = branchCounter.getCoveredCount();
            newCoverage.conditions(lineId, conditions, coveredConditions);
        }
    }
}
Also used : ILine(org.jacoco.core.analysis.ILine) ICounter(org.jacoco.core.analysis.ICounter)

Aggregations

ICounter (org.jacoco.core.analysis.ICounter)50 Test (org.junit.Test)40 CounterEntity (org.jacoco.core.analysis.ICoverageNode.CounterEntity)2 FileWriter (java.io.FileWriter)1 PrintWriter (java.io.PrintWriter)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 IBundleCoverage (org.jacoco.core.analysis.IBundleCoverage)1 IClassCoverage (org.jacoco.core.analysis.IClassCoverage)1 ILine (org.jacoco.core.analysis.ILine)1 IMethodCoverage (org.jacoco.core.analysis.IMethodCoverage)1 IPackageCoverage (org.jacoco.core.analysis.IPackageCoverage)1 ISourceFileCoverage (org.jacoco.core.analysis.ISourceFileCoverage)1 Instruction (org.jacoco.core.internal.flow.Instruction)1 IReportVisitor (org.jacoco.report.IReportVisitor)1 ISourceFileLocator (org.jacoco.report.ISourceFileLocator)1 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)1