Class RenamingPlugin

All Implemented Interfaces:
Closeable, AutoCloseable, AsmVisitorWrapper, Plugin, ElementMatcher<TypeDescription>

@Enhance public class RenamingPlugin extends AsmVisitorWrapper.AbstractBase implements Plugin
A plugin that replaces names that are discovered in class files.
  • Field Details

  • Constructor Details

    • RenamingPlugin

      public RenamingPlugin(String pattern, String replacement)
      Creates a renaming plugin for a given regular expression and replacement that applies to all types.
      Parameters:
      pattern - The pattern to consider.
      replacement - The replacement to apply if the supplied pattern is matched.
    • RenamingPlugin

      public RenamingPlugin(String pattern, String replacement, String prefix)
      Creates a renaming plugin for a given regular expression and replacement that applies to all types that start with a given prefix.
      Parameters:
      pattern - The pattern to consider.
      replacement - The replacement to apply if the supplied pattern is matched.
      prefix - The prefix for types to consider for renaming.
    • RenamingPlugin

      public RenamingPlugin(RenamingPlugin.Renaming renaming)
      Creates a renaming plugin for the given renaming that applies to all types.
      Parameters:
      renaming - The renaming to apply.
    • RenamingPlugin

      public RenamingPlugin(RenamingPlugin.Renaming renaming, ElementMatcher<? super TypeDescription> matcher)
      Creates a renaming plugin for the given renaming and type matcher.
      Parameters:
      renaming - The renaming to apply.
      matcher - A matcher that determines what types to consider for renaming.
  • Method Details

    • apply

      public DynamicType.Builder<?> apply(DynamicType.Builder<?> builder, TypeDescription typeDescription, ClassFileLocator classFileLocator)
      Applies this plugin.
      Specified by:
      apply in interface Plugin
      Parameters:
      builder - The builder to use as a basis for the applied transformation.
      typeDescription - The type being transformed.
      classFileLocator - A class file locator that can locate other types in the scope of the project.
      Returns:
      The supplied builder with additional transformations registered.
    • matches

      public boolean matches(TypeDescription target)
      Matches a target against this element matcher.
      Specified by:
      matches in interface ElementMatcher<TypeDescription>
      Parameters:
      target - The instance to be matched or null.
      Returns:
      true if the given element is matched by this matcher or false otherwise.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • wrap

      public org.objectweb.asm.ClassVisitor wrap(TypeDescription instrumentedType, org.objectweb.asm.ClassVisitor classVisitor, Implementation.Context implementationContext, TypePool typePool, FieldList<FieldDescription.InDefinedShape> fields, MethodList<?> methods, int writerFlags, int readerFlags)
      Applies a ClassVisitorWrapper to the creation of a DynamicType.
      Specified by:
      wrap in interface AsmVisitorWrapper
      Parameters:
      instrumentedType - The instrumented type.
      classVisitor - A ClassVisitor to become the new primary class visitor to which the created DynamicType is written to.
      implementationContext - The implementation context of the current instrumentation.
      typePool - The type pool that was provided for the class creation.
      fields - The instrumented type's fields.
      methods - The instrumented type's methods non-ignored declared and virtually inherited methods.
      writerFlags - The ASM ClassWriter flags to consider.
      readerFlags - The ASM ClassReader flags to consider.
      Returns:
      A new ClassVisitor that usually delegates to the ClassVisitor delivered in the argument.