Top Description Inners Fields Constructors Methods
net.bytebuddy.asm

public Class MemberRemoval

extends AbstractBase
Class Inheritance
Annotations
@Enhance
Imports
net.bytebuddy.build.HashCodeAndEqualsPlugin, net.bytebuddy.description.field.FieldDescription, .FieldList, net.bytebuddy.description.method.MethodDescription, .MethodList, net.bytebuddy.description.type.TypeDescription, net.bytebuddy.implementation.Implementation, net.bytebuddy.matcher.ElementMatcher, .ElementMatchers, net.bytebuddy.pool.TypePool, net.bytebuddy.utility.CompoundList, .OpenedClassReader, net.bytebuddy.utility.nullability.AlwaysNull, .MaybeNull, net.bytebuddy.jar.asm.ClassVisitor, .FieldVisitor, .MethodVisitor, java.util.HashMap, .Map

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

Important Note

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 Note

The removal of the method is not reflected in the created net.bytebuddy.dynamic.DynamicType's type description of the instrumented type.

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class
MemberRemoval.MemberRemovingClassVisitor

A class visitor that removes members based on element matchers.

Field Summary

Modifier and TypeField and Description
private final ElementMatcher.Junction<FieldDescription.InDefinedShape>
fieldMatcher

The matcher that decides upon field removal.

private final ElementMatcher.Junction<MethodDescription>
methodMatcher

The matcher that decides upon method removal.

Constructor Summary

AccessConstructor and Description
public
MemberRemoval()

Creates a new member removal instance that does not specify the removal of any methods.

protected
MemberRemoval(ElementMatcher.Junction<FieldDescription.InDefinedShape>
The matcher that decides upon field removal.
fieldMatcher
,
ElementMatcher.Junction<MethodDescription>
The matcher that decides upon field removal.
methodMatcher
)

Creates a new member removal instance.

Method Summary

Modifier and TypeMethod and Description
public MemberRemoval

Returns:

A new member removal instance that removes all previously specified members and any constructor that matches the specified matcher.
stripConstructors
(ElementMatcher<? super MethodDescription>
The matcher that decides upon constructor removal.
matcher
)

Specifies that any constructor that matches the specified matcher should be removed.

public MemberRemoval

Returns:

A new member removal instance that removes all previously specified members and any fields that match the specified matcher.
stripFields
(ElementMatcher<? super FieldDescription.InDefinedShape>
The matcher that decides upon field removal.
matcher
)

Specifies that any field that matches the specified matcher should be removed.

public MemberRemoval

Returns:

A new member removal instance that removes all previously specified members and any method or constructor that matches the specified matcher.
stripInvokables
(ElementMatcher<? super MethodDescription>
The matcher that decides upon method and constructor removal.
matcher
)

Specifies that any method or constructor that matches the specified matcher should be removed.

public MemberRemoval

Returns:

A new member removal instance that removes all previously specified members and any method that matches the specified matcher.
stripMethods
(ElementMatcher<? super MethodDescription>
The matcher that decides upon method removal.
matcher
)

Specifies that any method that matches the specified matcher should be removed.

public ClassVisitor
wrap(TypeDescription
The instrumented type.
instrumentedType
,
ClassVisitor
A ClassVisitor to become the new primary class visitor to which the created net.bytebuddy.dynamic.DynamicType is written to.
classVisitor
,
Implementation.Context
The implementation context of the current instrumentation.
implementationContext
,
TypePool
The type pool that was provided for the class creation.
typePool
,
FieldList<FieldDescription.InDefinedShape>
The instrumented type's fields.
fields
,
MethodList<?>
The instrumented type's methods non-ignored declared and virtually inherited methods.
methods
,
int
The ASM net.bytebuddy.jar.asm.ClassWriter flags to consider.
writerFlags
,
int
The ASM net.bytebuddy.jar.asm.ClassReader flags to consider.
readerFlags
)

Implements net.bytebuddy.asm.AsmVisitorWrapper.wrap.

Applies a ClassVisitorWrapper to the creation of a net.bytebuddy.dynamic.DynamicType.
Inherited from net.bytebuddy.asm.AsmVisitorWrapper.AbstractBase:
mergeReadermergeWriter

Field Detail

fieldMatcherback to summary
private final ElementMatcher.Junction<FieldDescription.InDefinedShape> fieldMatcher

The matcher that decides upon field removal.

methodMatcherback to summary
private final ElementMatcher.Junction<MethodDescription> methodMatcher

The matcher that decides upon method removal.

Constructor Detail

MemberRemovalback to summary
public MemberRemoval()

Creates a new member removal instance that does not specify the removal of any methods.

MemberRemovalback to summary
protected MemberRemoval(ElementMatcher.Junction<FieldDescription.InDefinedShape> fieldMatcher, ElementMatcher.Junction<MethodDescription> methodMatcher)

Creates a new member removal instance.

Parameters
fieldMatcher:ElementMatcher.Junction<FieldDescription.InDefinedShape>

The matcher that decides upon field removal.

methodMatcher:ElementMatcher.Junction<MethodDescription>

The matcher that decides upon field removal.

Method Detail

stripConstructorsback to summary
public MemberRemoval stripConstructors(ElementMatcher<? super MethodDescription> matcher)

Specifies that any constructor that matches the specified matcher should be removed.

Parameters
matcher:ElementMatcher<? super MethodDescription>

The matcher that decides upon constructor removal.

Returns:MemberRemoval

A new member removal instance that removes all previously specified members and any constructor that matches the specified matcher.

stripFieldsback to summary
public MemberRemoval stripFields(ElementMatcher<? super FieldDescription.InDefinedShape> matcher)

Specifies that any field that matches the specified matcher should be removed.

Parameters
matcher:ElementMatcher<? super FieldDescription.InDefinedShape>

The matcher that decides upon field removal.

Returns:MemberRemoval

A new member removal instance that removes all previously specified members and any fields that match the specified matcher.

stripInvokablesback to summary
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:ElementMatcher<? super MethodDescription>

The matcher that decides upon method and constructor removal.

Returns:MemberRemoval

A new member removal instance that removes all previously specified members and any method or constructor that matches the specified matcher.

stripMethodsback to summary
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:ElementMatcher<? super MethodDescription>

The matcher that decides upon method removal.

Returns:MemberRemoval

A new member removal instance that removes all previously specified members and any method that matches the specified matcher.

wrapback to summary
public ClassVisitor wrap(TypeDescription instrumentedType, ClassVisitor classVisitor, Implementation.Context implementationContext, TypePool typePool, FieldList<FieldDescription.InDefinedShape> fields, MethodList<?> methods, int writerFlags, int readerFlags)

Implements net.bytebuddy.asm.AsmVisitorWrapper.wrap.

Doc from net.bytebuddy.asm.AsmVisitorWrapper.wrap.

Applies a ClassVisitorWrapper to the creation of a net.bytebuddy.dynamic.DynamicType.

Parameters
instrumentedType:TypeDescription

The instrumented type.

classVisitor:ClassVisitor

A ClassVisitor to become the new primary class visitor to which the created net.bytebuddy.dynamic.DynamicType is written to.

implementationContext:Implementation.Context

The implementation context of the current instrumentation.

typePool:TypePool

The type pool that was provided for the class creation.

fields:FieldList<FieldDescription.InDefinedShape>

The instrumented type's fields.

methods:MethodList<?>

The instrumented type's methods non-ignored declared and virtually inherited methods.

writerFlags:int

The ASM net.bytebuddy.jar.asm.ClassWriter flags to consider.

readerFlags:int

The ASM net.bytebuddy.jar.asm.ClassReader flags to consider.

Returns:ClassVisitor

A new ClassVisitor that usually delegates to the ClassVisitor delivered in the argument.

net.bytebuddy.asm back to summary

protected Class MemberRemoval.MemberRemovingClassVisitor

extends ClassVisitor
Class Inheritance

A class visitor that removes members based on element matchers.

Field Summary

Modifier and TypeField and Description
private final ElementMatcher.Junction<FieldDescription.InDefinedShape>
fieldMatcher

The matcher that determines field removal.

private final Map<String, FieldDescription.InDefinedShape>
fields

A mapping of field names and descriptors to their description.

private final ElementMatcher.Junction<MethodDescription>
methodMatcher

The matcher that determines method removal.

private final Map<String, MethodDescription>
methods

A mapping of method names and descriptors to their description.

private static final FieldVisitor
REMOVE_FIELD

Indicates the removal of a field.

private static final MethodVisitor
REMOVE_METHOD

Indicates the removal of a method.

Inherited from net.bytebuddy.jar.asm.ClassVisitor:
apicv

Constructor Summary

AccessConstructor and Description
protected
MemberRemovingClassVisitor(ClassVisitor
The class visitor to delegate to.
classVisitor
,
ElementMatcher.Junction<FieldDescription.InDefinedShape>
The matcher that determines field removal.
fieldMatcher
,
ElementMatcher.Junction<MethodDescription>
The matcher that determines method removal.
methodMatcher
,
Map<String, FieldDescription.InDefinedShape>
A mapping of field names and descriptors to their description.
fields
,
Map<String, MethodDescription>
A mapping of method names and descriptors to their description.
methods
)

Creates a new member removing class visitor.

Method Summary

Modifier and TypeMethod and Description
public FieldVisitor
visitField(int
the field's access flags (see Opcodes). This parameter also indicates if the field is synthetic and/or deprecated.
modifiers
,
String
the field's name.
internalName
,
String
the field's descriptor (see Type).
descriptor
,
String
the field's signature. May be null if the field's type does not use generic types.
signature
,
Object
the field's initial value. This parameter, which may be null if the field does not have an initial value, must be an Integer, a Float, a Long, a Double or a String (for int, float, long or String fields respectively). This parameter is only used for static fields. Its value is ignored for non static fields, which must be initialized through bytecode instructions in constructors or methods.
value
)

Overrides net.bytebuddy.jar.asm.ClassVisitor.visitField.

Visits a field of the class.
public MethodVisitor
visitMethod(int
the method's access flags (see Opcodes). This parameter also indicates if the method is synthetic and/or deprecated.
modifiers
,
String
the method's name.
internalName
,
String
the method's descriptor (see Type).
descriptor
,
String
the method's signature. May be null if the method parameters, return type and exceptions do not use generic types.
signature
,
String[]
the internal names of the method's exception classes (see Type#getInternalName()). May be null.
exception
)

Overrides net.bytebuddy.jar.asm.ClassVisitor.visitMethod.

Visits a method of the class.
Inherited from net.bytebuddy.jar.asm.ClassVisitor:
getDelegatevisitvisitAnnotationvisitAttributevisitEndvisitInnerClassvisitModulevisitNestHostvisitNestMembervisitOuterClassvisitPermittedSubclassvisitRecordComponentvisitSourcevisitTypeAnnotation

Field Detail

fieldMatcherback to summary
private final ElementMatcher.Junction<FieldDescription.InDefinedShape> fieldMatcher

The matcher that determines field removal.

fieldsback to summary
private final Map<String, FieldDescription.InDefinedShape> fields

A mapping of field names and descriptors to their description.

methodMatcherback to summary
private final ElementMatcher.Junction<MethodDescription> methodMatcher

The matcher that determines method removal.

methodsback to summary
private final Map<String, MethodDescription> methods

A mapping of method names and descriptors to their description.

REMOVE_FIELDback to summary
private static final FieldVisitor REMOVE_FIELD

Indicates the removal of a field.

Annotations
@Nonnull
when:NEVER
REMOVE_METHODback to summary
private static final MethodVisitor REMOVE_METHOD

Indicates the removal of a method.

Annotations
@AlwaysNull

Constructor Detail

MemberRemovingClassVisitorback to summary
protected MemberRemovingClassVisitor(ClassVisitor classVisitor, ElementMatcher.Junction<FieldDescription.InDefinedShape> fieldMatcher, ElementMatcher.Junction<MethodDescription> methodMatcher, Map<String, FieldDescription.InDefinedShape> fields, Map<String, MethodDescription> methods)

Creates a new member removing class visitor.

Parameters
classVisitor:ClassVisitor

The class visitor to delegate to.

fieldMatcher:ElementMatcher.Junction<FieldDescription.InDefinedShape>

The matcher that determines field removal.

methodMatcher:ElementMatcher.Junction<MethodDescription>

The matcher that determines method removal.

fields:Map<String, FieldDescription.InDefinedShape>

A mapping of field names and descriptors to their description.

methods:Map<String, MethodDescription>

A mapping of method names and descriptors to their description.

Method Detail

visitFieldback to summary
public FieldVisitor visitField(int modifiers, String internalName, String descriptor, String signature, Object value)

Overrides net.bytebuddy.jar.asm.ClassVisitor.visitField.

Doc from net.bytebuddy.jar.asm.ClassVisitor.visitField.

Visits a field of the class.

Parameters
modifiers:int

the field's access flags (see Opcodes). This parameter also indicates if the field is synthetic and/or deprecated.

internalName:String

the field's name.

descriptor:String

the field's descriptor (see Type).

signature:String

the field's signature. May be null if the field's type does not use generic types.

value:Object

the field's initial value. This parameter, which may be null if the field does not have an initial value, must be an Integer, a Float, a Long, a Double or a String (for int, float, long or String fields respectively). This parameter is only used for static fields. Its value is ignored for non static fields, which must be initialized through bytecode instructions in constructors or methods.

Returns:FieldVisitor

a visitor to visit field annotations and attributes, or null if this class visitor is not interested in visiting these annotations and attributes.

Annotations
@Override
@MaybeNull
visitMethodback to summary
public MethodVisitor visitMethod(int modifiers, String internalName, String descriptor, String signature, String[] exception)

Overrides net.bytebuddy.jar.asm.ClassVisitor.visitMethod.

Doc from net.bytebuddy.jar.asm.ClassVisitor.visitMethod.

Visits a method of the class. This method must return a new MethodVisitor instance (or null) each time it is called, i.e., it should not return a previously returned visitor.

Parameters
modifiers:int

the method's access flags (see Opcodes). This parameter also indicates if the method is synthetic and/or deprecated.

internalName:String

the method's name.

descriptor:String

the method's descriptor (see Type).

signature:String

the method's signature. May be null if the method parameters, return type and exceptions do not use generic types.

exception:String[]

the internal names of the method's exception classes (see Type#getInternalName()). May be null.

Returns:MethodVisitor

an object to visit the byte code of the method, or null if this class visitor is not interested in visiting the code of this method.

Annotations
@Override
@MaybeNull