Package net.bytebuddy.asm
Class AsmVisitorWrapper.ForDeclaredMethods
java.lang.Object
net.bytebuddy.asm.AsmVisitorWrapper.ForDeclaredMethods
- All Implemented Interfaces:
AsmVisitorWrapper
- Enclosing interface:
AsmVisitorWrapper
@Enhance
public static class AsmVisitorWrapper.ForDeclaredMethods
extends Object
implements AsmVisitorWrapper
An ASM visitor wrapper that allows to wrap declared methods of the instrumented type with a AsmVisitorWrapper.ForDeclaredMethods.MethodVisitorWrapper
.
Note: Inherited methods are not matched by this visitor, even if they are intercepted by a normal interception.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected class
A class visitor that applies the outer ASM visitor for identifying declared methods.protected static class
An entry describing a method visitor wrapper paired with a matcher for fields to be wrapped.static interface
A method visitor wrapper that allows for wrapping aMethodVisitor
defining a declared method.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 List
<AsmVisitorWrapper.ForDeclaredMethods.Entry> The list of entries that describe matched methods in their application order.private final int
The reader flags to set.private final int
The writer flags to set.Fields inherited from interface net.bytebuddy.asm.AsmVisitorWrapper
NO_FLAGS
-
Constructor Summary
ConstructorsModifierConstructorDescriptionCreates a new visitor wrapper for declared methods.protected
ForDeclaredMethods
(List<AsmVisitorWrapper.ForDeclaredMethods.Entry> entries, int writerFlags, int readerFlags) Creates a new visitor wrapper for declared methods. -
Method Summary
Modifier and TypeMethodDescriptionconstructor
(ElementMatcher<? super MethodDescription> matcher, List<? extends AsmVisitorWrapper.ForDeclaredMethods.MethodVisitorWrapper> methodVisitorWrappers) Defines a new method visitor wrapper to be applied on any constructor if the given method matcher is matched.constructor
(ElementMatcher<? super MethodDescription> matcher, AsmVisitorWrapper.ForDeclaredMethods.MethodVisitorWrapper... methodVisitorWrapper) Defines a new method visitor wrapper to be applied on any constructor if the given method matcher is matched.invokable
(ElementMatcher<? super MethodDescription> matcher, List<? extends AsmVisitorWrapper.ForDeclaredMethods.MethodVisitorWrapper> methodVisitorWrappers) Defines a new method visitor wrapper to be applied on any method or constructor if the given method matcher is matched.invokable
(ElementMatcher<? super MethodDescription> matcher, AsmVisitorWrapper.ForDeclaredMethods.MethodVisitorWrapper... methodVisitorWrapper) Defines a new method visitor wrapper to be applied on any method or constructor if the given method matcher is matched.int
mergeReader
(int flags) Defines the flags that are provided to anyClassReader
when reading a class if applicable.int
mergeWriter
(int flags) Defines the flags that are provided to anyClassWriter
when writing a class.method
(ElementMatcher<? super MethodDescription> matcher, List<? extends AsmVisitorWrapper.ForDeclaredMethods.MethodVisitorWrapper> methodVisitorWrappers) Defines a new method visitor wrapper to be applied on any method if the given method matcher is matched.method
(ElementMatcher<? super MethodDescription> matcher, AsmVisitorWrapper.ForDeclaredMethods.MethodVisitorWrapper... methodVisitorWrapper) Defines a new method visitor wrapper to be applied on any method if the given method matcher is matched.readerFlags
(int flags) Sets flags for theClassReader
this wrapper is applied to.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
.writerFlags
(int flags) Sets flags for theClassWriter
this wrapper is applied to.
-
Field Details
-
entries
The list of entries that describe matched methods in their application order. -
writerFlags
private final int writerFlagsThe writer flags to set. -
readerFlags
private final int readerFlagsThe reader flags to set.
-
-
Constructor Details
-
ForDeclaredMethods
public ForDeclaredMethods()Creates a new visitor wrapper for declared methods. -
ForDeclaredMethods
protected ForDeclaredMethods(List<AsmVisitorWrapper.ForDeclaredMethods.Entry> entries, int writerFlags, int readerFlags) Creates a new visitor wrapper for declared methods.- Parameters:
entries
- The list of entries that describe matched methods in their application order.writerFlags
- The writer flags to set.readerFlags
- The reader flags to set.
-
-
Method Details
-
method
public AsmVisitorWrapper.ForDeclaredMethods method(ElementMatcher<? super MethodDescription> matcher, AsmVisitorWrapper.ForDeclaredMethods.MethodVisitorWrapper... methodVisitorWrapper) Defines a new method visitor wrapper to be applied on any method if the given method matcher is matched. Previously defined entries are applied before the given matcher is applied.- Parameters:
matcher
- The matcher to identify methods to be wrapped.methodVisitorWrapper
- The method visitor wrapper to be applied if the given matcher is matched.- Returns:
- A new ASM visitor wrapper that applied the given method visitor wrapper if the supplied matcher is matched.
-
method
public AsmVisitorWrapper.ForDeclaredMethods method(ElementMatcher<? super MethodDescription> matcher, List<? extends AsmVisitorWrapper.ForDeclaredMethods.MethodVisitorWrapper> methodVisitorWrappers) Defines a new method visitor wrapper to be applied on any method if the given method matcher is matched. Previously defined entries are applied before the given matcher is applied.- Parameters:
matcher
- The matcher to identify methods to be wrapped.methodVisitorWrappers
- The method visitor wrapper to be applied if the given matcher is matched.- Returns:
- A new ASM visitor wrapper that applied the given method visitor wrapper if the supplied matcher is matched.
-
constructor
public AsmVisitorWrapper.ForDeclaredMethods constructor(ElementMatcher<? super MethodDescription> matcher, AsmVisitorWrapper.ForDeclaredMethods.MethodVisitorWrapper... methodVisitorWrapper) Defines a new method visitor wrapper to be applied on any constructor if the given method matcher is matched. Previously defined entries are applied before the given matcher is applied.- Parameters:
matcher
- The matcher to identify constructors to be wrapped.methodVisitorWrapper
- The method visitor wrapper to be applied if the given matcher is matched.- Returns:
- A new ASM visitor wrapper that applied the given method visitor wrapper if the supplied matcher is matched.
-
constructor
public AsmVisitorWrapper.ForDeclaredMethods constructor(ElementMatcher<? super MethodDescription> matcher, List<? extends AsmVisitorWrapper.ForDeclaredMethods.MethodVisitorWrapper> methodVisitorWrappers) Defines a new method visitor wrapper to be applied on any constructor if the given method matcher is matched. Previously defined entries are applied before the given matcher is applied.- Parameters:
matcher
- The matcher to identify constructors to be wrapped.methodVisitorWrappers
- The method visitor wrapper to be applied if the given matcher is matched.- Returns:
- A new ASM visitor wrapper that applied the given method visitor wrapper if the supplied matcher is matched.
-
invokable
public AsmVisitorWrapper.ForDeclaredMethods invokable(ElementMatcher<? super MethodDescription> matcher, AsmVisitorWrapper.ForDeclaredMethods.MethodVisitorWrapper... methodVisitorWrapper) Defines a new method visitor wrapper to be applied on any method or constructor if the given method matcher is matched. Previously defined entries are applied before the given matcher is applied.- Parameters:
matcher
- The matcher to identify methods or constructors to be wrapped.methodVisitorWrapper
- The method visitor wrapper to be applied if the given matcher is matched.- Returns:
- A new ASM visitor wrapper that applied the given method visitor wrapper if the supplied matcher is matched.
-
invokable
public AsmVisitorWrapper.ForDeclaredMethods invokable(ElementMatcher<? super MethodDescription> matcher, List<? extends AsmVisitorWrapper.ForDeclaredMethods.MethodVisitorWrapper> methodVisitorWrappers) Defines a new method visitor wrapper to be applied on any method or constructor if the given method matcher is matched. Previously defined entries are applied before the given matcher is applied.- Parameters:
matcher
- The matcher to identify methods or constructors to be wrapped.methodVisitorWrappers
- The method visitor wrapper to be applied if the given matcher is matched.- Returns:
- A new ASM visitor wrapper that applied the given method visitor wrapper if the supplied matcher is matched.
-
writerFlags
Sets flags for theClassWriter
this wrapper is applied to.- Parameters:
flags
- The flags to set for theClassWriter
.- Returns:
- A new ASM visitor wrapper that sets the supplied writer flags.
-
readerFlags
Sets flags for theClassReader
this wrapper is applied to.- Parameters:
flags
- The flags to set for theClassReader
.- Returns:
- A new ASM visitor wrapper that sets the supplied reader flags.
-
mergeWriter
public int mergeWriter(int flags) Defines the flags that are provided to anyClassWriter
when writing a class. Typically, this gives opportunity to instruct ASM to compute stack map frames or the size of the local variables array and the operand stack. If no specific flags are required for applying this wrapper, the given value is to be returned.- Specified by:
mergeWriter
in interfaceAsmVisitorWrapper
- Parameters:
flags
- The currently set flags. This value should be combined (e.g.flags | foo
) into the value that is returned by this wrapper.- Returns:
- The flags to be provided to the ASM
ClassWriter
.
-
mergeReader
public int mergeReader(int flags) Defines the flags that are provided to anyClassReader
when reading a class if applicable. Typically, this gives opportunity to instruct ASM to expand or skip frames and to skip code and debug information. If no specific flags are required for applying this wrapper, the given value is to be returned.- Specified by:
mergeReader
in interfaceAsmVisitorWrapper
- Parameters:
flags
- The currently set flags. This value should be combined (e.g.flags | foo
) into the value that is returned by this wrapper.- Returns:
- The flags to be provided to the ASM
ClassReader
.
-
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
.- Specified by:
wrap
in interfaceAsmVisitorWrapper
- 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.
-