Class AnnotationRemoval

All Implemented Interfaces:
AsmVisitorWrapper

@Enhance public class AnnotationRemoval extends AsmVisitorWrapper.AbstractBase
A visitor wrapper that removes annotations from the instrumented type.
  • Field Details

    • METHOD_NONE

      private static final int METHOD_NONE
      Indicates that neither method annotations and method parameter annotations should be considered.
      See Also:
    • METHOD_ALL

      private static final int METHOD_ALL
      Indicates that bother method annotations and method parameter annotations should be considered.
      See Also:
    • METHOD_ONLY

      private static final int METHOD_ONLY
      Indicates that only method annotations should be considered.
      See Also:
    • METHOD_PARAMETERS

      private static final int METHOD_PARAMETERS
      Indicates that only method parameter annotations should be considered.
      See Also:
    • type

      private final boolean type
      true if annotations on the type should be removed.
    • fieldMatcher

      private final ElementMatcher<? super FieldDescription.InDefinedShape> fieldMatcher
      Matches fields from which annotations should be removed.
    • methodMatcher

      private final ElementMatcher<? super MethodDescription> methodMatcher
      Matches methods from which annotations should be removed.
    • annotationMatcher

      private final ElementMatcher<? super AnnotationDescription> annotationMatcher
      Matches annotations that should be removed.
    • parameters

      private final int parameters
      Indices the method parameter index from which annotations should be removed, or a negative value to indicate different treatment.
  • Constructor Details

    • AnnotationRemoval

      protected AnnotationRemoval(boolean type, ElementMatcher<? super FieldDescription.InDefinedShape> fieldMatcher, ElementMatcher<? super MethodDescription> methodMatcher, ElementMatcher<? super AnnotationDescription> annotationMatcher, int parameters)
      Creates a visitor for annotation removal.
      Parameters:
      type - true if annotations on the type should be removed.
      fieldMatcher - Matches fields from which annotations should be removed.
      methodMatcher - Matches methods from which annotations should be removed.
      annotationMatcher - Matches annotations that should be removed.
      parameters - Indices the method parameter index from which annotations should be removed, or a negative value to indicate different treatment.
  • Method Details

    • strip

      public static AnnotationRemoval strip(ElementMatcher<? super AnnotationDescription> matcher)
      Creates a visitor that removes all annotations that match the specified matcher from the instrumented type.
      Parameters:
      matcher - The matcher to indicate what annotations to remove.
      Returns:
      A visitor that removes the specified annotations.
    • onType

      public AsmVisitorWrapper onType()
      Creates a visitor that only removes annotations from the type.
      Returns:
      An appropriate visitor for annotation removal.
    • onFields

      public AsmVisitorWrapper onFields(ElementMatcher<? super FieldDescription> matcher)
      Creates a visitor that only removes annotations from fields that match the specified matcher.
      Parameters:
      matcher - A matcher that indicates from what fields annotations should be removed.
      Returns:
      An appropriate visitor for annotation removal.
    • onMethods

      public AsmVisitorWrapper onMethods(ElementMatcher<? super MethodDescription> matcher)
      Creates a visitor that removes annotations from methods that match the specified matcher.
      Parameters:
      matcher - A matcher that indicates from what methods annotations should be removed.
      Returns:
      An appropriate visitor for annotation removal.
    • onMethodsAndParameters

      public AsmVisitorWrapper onMethodsAndParameters(ElementMatcher<? super MethodDescription> matcher)
      Creates a visitor that removes annotations from methods and their parameters that match the specified matcher.
      Parameters:
      matcher - A matcher that indicates from what methods annotations should be removed.
      Returns:
      An appropriate visitor for annotation removal.
    • onMethodParameters

      public AsmVisitorWrapper onMethodParameters(ElementMatcher<? super MethodDescription> matcher)
      Creates a visitor that removes annotations from method parameters where the method matches the specified matcher.
      Parameters:
      matcher - A matcher that indicates from what methods annotations should be removed.
      Returns:
      An appropriate visitor for annotation removal.
    • onMethodParameter

      public AsmVisitorWrapper onMethodParameter(ElementMatcher<? super MethodDescription> matcher, int parameter)
      Creates a visitor that removes annotations from the method parameters with the given index where the method matches the specified matcher.
      Parameters:
      matcher - A matcher that indicates from what methods annotations should be removed.
      parameter - The index of the parameter of which to remove annotations.
      Returns:
      An appropriate visitor for annotation removal.
    • onConstructors

      public AsmVisitorWrapper onConstructors(ElementMatcher<? super MethodDescription> matcher)
      Creates a visitor that removes annotations from constructors that match the specified matcher.
      Parameters:
      matcher - A matcher that indicates from what constructors annotations should be removed.
      Returns:
      An appropriate visitor for annotation removal.
    • onConstructorsAndParameters

      public AsmVisitorWrapper onConstructorsAndParameters(ElementMatcher<? super MethodDescription> matcher)
      Creates a visitor that removes annotations from constructors and their parameters that match the specified matcher.
      Parameters:
      matcher - A matcher that indicates from what constructors annotations should be removed.
      Returns:
      An appropriate visitor for annotation removal.
    • onConstructorParameters

      public AsmVisitorWrapper onConstructorParameters(ElementMatcher<? super MethodDescription> matcher)
      Creates a visitor that removes annotations from constructor parameters where the constructor matches the specified matcher.
      Parameters:
      matcher - A matcher that indicates from what constructors annotations should be removed.
      Returns:
      An appropriate visitor for annotation removal.
    • onConstructorParameter

      public AsmVisitorWrapper onConstructorParameter(ElementMatcher<? super MethodDescription> matcher, int parameter)
      Creates a visitor that removes annotations from the constructor parameters with the given index where the constructor matches the specified matcher.
      Parameters:
      matcher - A matcher that indicates from what constructors annotations should be removed.
      parameter - The index of the parameter of which to remove annotations.
      Returns:
      An appropriate visitor for annotation removal.
    • onInvokables

      public AsmVisitorWrapper onInvokables(ElementMatcher<? super MethodDescription> matcher)
      Creates a visitor that removes annotations from constructors or methods that match the specified matcher.
      Parameters:
      matcher - A matcher that indicates from what constructors or methods annotations should be removed.
      Returns:
      An appropriate visitor for annotation removal.
    • onInvokablesAndParameters

      public AsmVisitorWrapper onInvokablesAndParameters(ElementMatcher<? super MethodDescription> matcher)
      Creates a visitor that removes annotations from constructors or methods and their parameters that match the specified matcher.
      Parameters:
      matcher - A matcher that indicates from what constructors or methods annotations should be removed.
      Returns:
      An appropriate visitor for annotation removal.
    • onInvokableParameters

      public AsmVisitorWrapper onInvokableParameters(ElementMatcher<? super MethodDescription> matcher)
      Creates a visitor that removes annotations from constructor or method parameters where the constructor or method matches the specified matcher.
      Parameters:
      matcher - A matcher that indicates from what constructors or methods annotations should be removed.
      Returns:
      An appropriate visitor for annotation removal.
    • onInvokableParameter

      public AsmVisitorWrapper onInvokableParameter(ElementMatcher<? super MethodDescription> matcher, int parameter)
      Creates a visitor that removes annotations from the constructor or method parameters with the given index where the constructor or method matches the specified matcher.
      Parameters:
      matcher - A matcher that indicates from what constructors or methods annotations should be removed.
      parameter - The index of the parameter of which to remove annotations.
      Returns:
      An appropriate visitor for annotation removal.
    • 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.