Class MemberRemoval

All Implemented Interfaces:
AsmVisitorWrapper

@Enhance public class MemberRemoval extends AsmVisitorWrapper.AbstractBase

A visitor wrapper that removes fields or methods that match a given ElementMatcher.

Important: This matcher is not capable of removing synthetic bridge methods which will be retained if they are declared by the same class. As bridge methods only invoke an overridden method, the dispatch should however not be influenced by their retention.

Important: The removal of the method is not reflected in the created DynamicType's type description of the instrumented type.

  • Field Details

  • Constructor Details

  • Method Details

    • stripFields

      public MemberRemoval stripFields(ElementMatcher<? super FieldDescription.InDefinedShape> matcher)
      Specifies that any field that matches the specified matcher should be removed.
      Parameters:
      matcher - The matcher that decides upon field removal.
      Returns:
      A new member removal instance that removes all previously specified members and any fields that match the specified matcher.
    • stripMethods

      public MemberRemoval stripMethods(ElementMatcher<? super MethodDescription> matcher)
      Specifies that any method that matches the specified matcher should be removed. Note that this implementation will not strip bridge methods for virtual overrides of generic methods.
      Parameters:
      matcher - The matcher that decides upon method removal.
      Returns:
      A new member removal instance that removes all previously specified members and any method that matches the specified matcher.
    • stripConstructors

      public MemberRemoval stripConstructors(ElementMatcher<? super MethodDescription> matcher)
      Specifies that any constructor that matches the specified matcher should be removed.
      Parameters:
      matcher - The matcher that decides upon constructor removal.
      Returns:
      A new member removal instance that removes all previously specified members and any constructor that matches the specified matcher.
    • stripInvokables

      public MemberRemoval stripInvokables(ElementMatcher<? super MethodDescription> matcher)
      Specifies that any method or constructor that matches the specified matcher should be removed. Note that this implementation will not strip bridge methods for virtual overrides of generic methods.
      Parameters:
      matcher - The matcher that decides upon method and constructor removal.
      Returns:
      A new member removal instance that removes all previously specified members and any method or constructor that matches the specified matcher.
    • 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.
      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.