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 private static classMemberRemoval.MemberRemovingClassVisitorA 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>fieldMatcherThe matcher that decides upon field removal.private ElementMatcher.Junction<MethodDescription>methodMatcherThe 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.protectedMemberRemoval(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 MemberRemovalstripConstructors(ElementMatcher<? super MethodDescription> matcher)Specifies that any constructor that matches the specified matcher should be removed.MemberRemovalstripFields(ElementMatcher<? super FieldDescription.InDefinedShape> matcher)Specifies that any field that matches the specified matcher should be removed.MemberRemovalstripInvokables(ElementMatcher<? super MethodDescription> matcher)Specifies that any method or constructor that matches the specified matcher should be removed.MemberRemovalstripMethods(ElementMatcher<? super MethodDescription> matcher)Specifies that any method that matches the specified matcher should be removed.org.objectweb.asm.ClassVisitorwrap(TypeDescription instrumentedType, org.objectweb.asm.ClassVisitor classVisitor, Implementation.Context implementationContext, TypePool typePool, FieldList<FieldDescription.InDefinedShape> fields, MethodList<?> methods, int writerFlags, int readerFlags)Applies aClassVisitorWrapperto 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. 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 aClassVisitorWrapperto the creation of aDynamicType.- Parameters:
instrumentedType- The instrumented type.classVisitor- AClassVisitorto become the new primary class visitor to which the createdDynamicTypeis 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 ASMClassWriterflags to consider.readerFlags- The ASMClassReaderflags to consider.- Returns:
- A new
ClassVisitorthat usually delegates to theClassVisitordelivered in the argument.
-
-