Search in sources :

Example 16 with ExecutionData

use of org.jacoco.core.data.ExecutionData in project jacoco by jacoco.

the class Analyzer method createAnalyzingVisitor.

/**
 * Creates an ASM class visitor for analysis.
 *
 * @param classid
 *            id of the class calculated with {@link CRC64}
 * @param className
 *            VM name of the class
 * @return ASM visitor to write class definition to
 */
private ClassVisitor createAnalyzingVisitor(final long classid, final String className) {
    final ExecutionData data = executionData.get(classid);
    final boolean[] probes;
    final boolean noMatch;
    if (data == null) {
        probes = null;
        noMatch = executionData.contains(className);
    } else {
        probes = data.getProbes();
        noMatch = false;
    }
    final ClassCoverageImpl coverage = new ClassCoverageImpl(className, classid, noMatch);
    final ClassAnalyzer analyzer = new ClassAnalyzer(coverage, probes, stringPool) {

        @Override
        public void visitEnd() {
            super.visitEnd();
            coverageVisitor.visitCoverage(coverage);
        }
    };
    return new ClassProbesAdapter(analyzer, false);
}
Also used : ClassAnalyzer(org.jacoco.core.internal.analysis.ClassAnalyzer) ClassCoverageImpl(org.jacoco.core.internal.analysis.ClassCoverageImpl) ClassProbesAdapter(org.jacoco.core.internal.flow.ClassProbesAdapter) ExecutionData(org.jacoco.core.data.ExecutionData)

Example 17 with ExecutionData

use of org.jacoco.core.data.ExecutionData in project sonar-java by SonarSource.

the class ExecutionDataVisitorTest method test.

@Test
public void test() {
    ExecutionDataVisitor visitor = new ExecutionDataVisitor();
    visitor.visitSessionInfo(new SessionInfo("foo", 1L, 1L));
    visitor.visitClassExecution(new ExecutionData(1, "", new boolean[] { true, false, false }));
    visitor.visitSessionInfo(new SessionInfo("bar", 2L, 2L));
    visitor.visitClassExecution(new ExecutionData(1, "", new boolean[] { false, true, false }));
    visitor.visitSessionInfo(new SessionInfo("foo", 3L, 3L));
    visitor.visitClassExecution(new ExecutionData(1, "", new boolean[] { false, false, true }));
    assertThat(visitor.getSessions()).hasSize(2);
    assertThat(visitor.getSessions().get("foo").getContents()).hasSize(1);
    assertThat(visitor.getSessions().get("foo").get(1).getProbes()).isEqualTo(new boolean[] { true, false, true });
    assertThat(visitor.getSessions().get("bar").getContents()).hasSize(1);
    assertThat(visitor.getSessions().get("bar").get(1).getProbes()).isEqualTo(new boolean[] { false, true, false });
    assertThat(visitor.getMerged().get(1).getProbes()).isEqualTo(new boolean[] { true, true, true });
}
Also used : SessionInfo(org.jacoco.core.data.SessionInfo) ExecutionData(org.jacoco.core.data.ExecutionData) Test(org.junit.Test)

Aggregations

ExecutionData (org.jacoco.core.data.ExecutionData)17 SessionInfo (org.jacoco.core.data.SessionInfo)7 File (java.io.File)6 FileOutputStream (java.io.FileOutputStream)6 ExecutionDataWriter (org.jacoco.core.data.ExecutionDataWriter)6 Test (org.junit.Test)3 FileInputStream (java.io.FileInputStream)2 Date (java.util.Date)2 ExecutionDataReader (org.jacoco.core.data.ExecutionDataReader)2 IExecutionDataVisitor (org.jacoco.core.data.IExecutionDataVisitor)2 ISessionInfoVisitor (org.jacoco.core.data.ISessionInfoVisitor)2 HTMLElement (org.jacoco.report.internal.html.HTMLElement)2 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 Analyzer (org.jacoco.core.analysis.Analyzer)1 CoverageBuilder (org.jacoco.core.analysis.CoverageBuilder)1