Search in sources :

Example 1 with ClassProbesAdapter

use of org.jacoco.core.internal.flow.ClassProbesAdapter in project jacoco by jacoco.

the class Instrumenter method instrument.

private byte[] instrument(final byte[] source) {
    final long classId = CRC64.classId(source);
    final int originalVersion = BytecodeVersion.get(source);
    final byte[] b = BytecodeVersion.downgradeIfNeeded(originalVersion, source);
    final ClassReader reader = new ClassReader(b);
    final ClassWriter writer = new ClassWriter(reader, 0) {

        @Override
        protected String getCommonSuperClass(final String type1, final String type2) {
            throw new IllegalStateException();
        }
    };
    final IProbeArrayStrategy strategy = ProbeArrayStrategyFactory.createFor(classId, reader, accessorGenerator);
    final ClassVisitor visitor = new ClassProbesAdapter(new ClassInstrumenter(strategy, writer), true);
    reader.accept(visitor, ClassReader.EXPAND_FRAMES);
    final byte[] instrumented = writer.toByteArray();
    BytecodeVersion.set(instrumented, originalVersion);
    return instrumented;
}
Also used : ClassInstrumenter(org.jacoco.core.internal.instr.ClassInstrumenter) ClassReader(org.objectweb.asm.ClassReader) IProbeArrayStrategy(org.jacoco.core.internal.instr.IProbeArrayStrategy) ClassVisitor(org.objectweb.asm.ClassVisitor) ClassProbesAdapter(org.jacoco.core.internal.flow.ClassProbesAdapter) ClassWriter(org.objectweb.asm.ClassWriter)

Example 2 with ClassProbesAdapter

use of org.jacoco.core.internal.flow.ClassProbesAdapter in project bazel by bazelbuild.

the class BranchDetailAnalyzer method mapProbes.

// Generate the line to probeExp map so that we can evaluate the coverage.
private Map<Integer, BranchExp> mapProbes(final ClassReader reader) {
    final ClassProbesMapper mapper = new ClassProbesMapper();
    final ClassProbesAdapter adapter = new ClassProbesAdapter(mapper, false);
    reader.accept(adapter, 0);
    return mapper.result();
}
Also used : ClassProbesAdapter(org.jacoco.core.internal.flow.ClassProbesAdapter)

Example 3 with ClassProbesAdapter

use of org.jacoco.core.internal.flow.ClassProbesAdapter in project jacoco by jacoco.

the class ProbeArrayStrategyFactory method getProbeCounter.

private static ProbeCounter getProbeCounter(final ClassReader reader) {
    final ProbeCounter counter = new ProbeCounter();
    reader.accept(new ClassProbesAdapter(counter, false), 0);
    return counter;
}
Also used : ClassProbesAdapter(org.jacoco.core.internal.flow.ClassProbesAdapter)

Example 4 with ClassProbesAdapter

use of org.jacoco.core.internal.flow.ClassProbesAdapter 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)

Aggregations

ClassProbesAdapter (org.jacoco.core.internal.flow.ClassProbesAdapter)4 ExecutionData (org.jacoco.core.data.ExecutionData)1 ClassAnalyzer (org.jacoco.core.internal.analysis.ClassAnalyzer)1 ClassCoverageImpl (org.jacoco.core.internal.analysis.ClassCoverageImpl)1 ClassInstrumenter (org.jacoco.core.internal.instr.ClassInstrumenter)1 IProbeArrayStrategy (org.jacoco.core.internal.instr.IProbeArrayStrategy)1 ClassReader (org.objectweb.asm.ClassReader)1 ClassVisitor (org.objectweb.asm.ClassVisitor)1 ClassWriter (org.objectweb.asm.ClassWriter)1