Package net.bytebuddy.asm
Class MemberRemoval
- java.lang.Object
-
- net.bytebuddy.asm.AsmVisitorWrapper.AbstractBase
-
- net.bytebuddy.asm.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
MemberRemoval.MemberRemovingClassVisitor
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
Fields Modifier and Type Field Description private ElementMatcher.Junction<FieldDescription.InDefinedShape>
fieldMatcher
The matcher that decides upon field removal.private ElementMatcher.Junction<MethodDescription>
methodMatcher
The matcher that decides upon method removal.-
Fields inherited from interface net.bytebuddy.asm.AsmVisitorWrapper
NO_FLAGS
-
-
Constructor Summary
Constructors Modifier Constructor Description MemberRemoval()
Creates 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MemberRemoval
stripConstructors(ElementMatcher<? super MethodDescription> matcher)
Specifies that any constructor that matches the specified matcher should be removed.MemberRemoval
stripFields(ElementMatcher<? super FieldDescription.InDefinedShape> matcher)
Specifies that any field that matches the specified matcher should be removed.MemberRemoval
stripInvokables(ElementMatcher<? super MethodDescription> matcher)
Specifies that any method or constructor that matches the specified matcher should be removed.MemberRemoval
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 Detail
-
fieldMatcher
private final ElementMatcher.Junction<FieldDescription.InDefinedShape> fieldMatcher
The matcher that decides upon field removal.
-
methodMatcher
private final ElementMatcher.Junction<MethodDescription> methodMatcher
The matcher that decides upon method removal.
-
-
Constructor Detail
-
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 Detail
-
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.- 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.- 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.
-
-