Package net.bytebuddy.asm
Class MemberRemoval
java.lang.Object
net.bytebuddy.asm.AsmVisitorWrapper.AbstractBase
net.bytebuddy.asm.MemberRemoval
- All Implemented Interfaces:
AsmVisitorWrapper
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
A class visitor that removes members based on element matchers.Nested classes/interfaces inherited from interface net.bytebuddy.asm.AsmVisitorWrapper
AsmVisitorWrapper.AbstractBase, AsmVisitorWrapper.Compound, AsmVisitorWrapper.ForDeclaredFields, AsmVisitorWrapper.ForDeclaredMethods, AsmVisitorWrapper.NoOp
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ElementMatcher.Junction
<FieldDescription.InDefinedShape> The matcher that decides upon field removal.private final ElementMatcher.Junction
<MethodDescription> The matcher that decides upon method removal.Fields inherited from interface net.bytebuddy.asm.AsmVisitorWrapper
NO_FLAGS
-
Constructor Summary
ConstructorsModifierConstructorDescriptionCreates a new member removal instance that does not specify the removal of any methods.protected
MemberRemoval
(ElementMatcher.Junction<FieldDescription.InDefinedShape> fieldMatcher, ElementMatcher.Junction<MethodDescription> methodMatcher) Creates a new member removal instance. -
Method Summary
Modifier and TypeMethodDescriptionstripConstructors
(ElementMatcher<? super MethodDescription> matcher) Specifies that any constructor that matches the specified matcher should be removed.stripFields
(ElementMatcher<? super FieldDescription.InDefinedShape> matcher) Specifies that any field that matches the specified matcher should be removed.stripInvokables
(ElementMatcher<? super MethodDescription> matcher) Specifies that any method or constructor that matches the specified matcher should be removed.stripMethods
(ElementMatcher<? super MethodDescription> matcher) Specifies that any method that matches the specified matcher should be removed.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 aClassVisitorWrapper
to the creation of aDynamicType
.Methods inherited from class net.bytebuddy.asm.AsmVisitorWrapper.AbstractBase
mergeReader, mergeWriter
-
Field Details
-
fieldMatcher
The matcher that decides upon field removal. -
methodMatcher
The matcher that decides upon method removal.
-
-
Constructor Details
-
MemberRemoval
public MemberRemoval()Creates a new member removal instance that does not specify the removal of any methods. -
MemberRemoval
protected MemberRemoval(ElementMatcher.Junction<FieldDescription.InDefinedShape> fieldMatcher, ElementMatcher.Junction<MethodDescription> methodMatcher) Creates a new member removal instance.- Parameters:
fieldMatcher
- The matcher that decides upon field removal.methodMatcher
- The matcher that decides upon field removal.
-
-
Method Details
-
stripFields
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
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
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
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 aClassVisitorWrapper
to the creation of aDynamicType
.- Parameters:
instrumentedType
- The instrumented type.classVisitor
- AClassVisitor
to become the new primary class visitor to which the createdDynamicType
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 ASMClassWriter
flags to consider.readerFlags
- The ASMClassReader
flags to consider.- Returns:
- A new
ClassVisitor
that usually delegates to theClassVisitor
delivered in the argument.
-