use of org.jacoco.core.internal.instr.ClassInstrumenter 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;
}
Aggregations