All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.undefinedlabs.scope.coverage.instrumentation.CoverageTransformer Maven / Gradle / Ivy

package com.undefinedlabs.scope.coverage.instrumentation;

import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.asm.AsmVisitorWrapper;
import net.bytebuddy.description.field.FieldDescription;
import net.bytebuddy.description.field.FieldList;
import net.bytebuddy.description.method.MethodList;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.dynamic.DynamicType;
import net.bytebuddy.implementation.Implementation;
import net.bytebuddy.jar.asm.ClassReader;
import net.bytebuddy.jar.asm.ClassVisitor;
import net.bytebuddy.jar.asm.ClassWriter;
import net.bytebuddy.pool.TypePool;
import net.bytebuddy.utility.JavaModule;

public class CoverageTransformer implements AgentBuilder.Transformer {

  public static final AgentBuilder.Transformer INSTANCE = new CoverageTransformer();

  @Override
  public DynamicType.Builder transform(
      final DynamicType.Builder builder,
      final TypeDescription typeDescription,
      final ClassLoader classLoader,
      final JavaModule module) {
    return builder.visit(
        new AsmVisitorWrapper() {
          @Override
          public int mergeWriter(final int flags) {
            return ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES;
          }

          @Override
          public int mergeReader(final int flags) {
            return ClassReader.EXPAND_FRAMES;
          }

          @Override
          public ClassVisitor wrap(
              final TypeDescription instrumentedType,
              final ClassVisitor classVisitor,
              final Implementation.Context implementationContext,
              final TypePool typePool,
              final FieldList fields,
              final MethodList methods,
              final int writerFlags,
              final int readerFlags) {
            return new CoverageClassVisitor(classVisitor);
          }
        });
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy