Class CoverageTransformer

java.lang.Object
org.jacoco.agent.rt.internal.CoverageTransformer
All Implemented Interfaces:
ClassFileTransformer

public class CoverageTransformer extends Object implements ClassFileTransformer
Class file transformer to instrument classes for code coverage analysis.
  • Field Details

    • AGENT_PREFIX

      private static final String AGENT_PREFIX
    • instrumenter

      private final Instrumenter instrumenter
    • logger

      private final IExceptionLogger logger
    • includes

      private final WildcardMatcher includes
    • excludes

      private final WildcardMatcher excludes
    • exclClassloader

      private final WildcardMatcher exclClassloader
    • classFileDumper

      private final ClassFileDumper classFileDumper
    • inclBootstrapClasses

      private final boolean inclBootstrapClasses
    • inclNoLocationClasses

      private final boolean inclNoLocationClasses
  • Constructor Details

    • CoverageTransformer

      public CoverageTransformer(IRuntime runtime, AgentOptions options, IExceptionLogger logger)
      New transformer with the given delegates.
      Parameters:
      runtime - coverage runtime
      options - configuration options for the generator
      logger - logger for exceptions during instrumentation
  • Method Details

    • transform

      public byte[] transform(ClassLoader loader, String classname, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException
      Specified by:
      transform in interface ClassFileTransformer
      Throws:
      IllegalClassFormatException
    • filter

      boolean filter(ClassLoader loader, String classname, ProtectionDomain protectionDomain)
      Checks whether this class should be instrumented.
      Parameters:
      loader - loader for the class
      classname - VM name of the class to check
      protectionDomain - protection domain for the class
      Returns:
      true if the class should be instrumented
    • hasSourceLocation

      private boolean hasSourceLocation(ProtectionDomain protectionDomain)
      Checks whether this protection domain is associated with a source location.
      Parameters:
      protectionDomain - protection domain to check (or null)
      Returns:
      true if a source location is defined
    • toVMName

      private static String toVMName(String srcName)