public class MemberSubstitution extends Object implements AsmVisitorWrapper.ForDeclaredMethods.MethodVisitorWrapper
Substitutes field access or method invocations within a method's body.
Important: This component relies on using a TypePool
for locating types within method bodies. Within a redefinition
or a rebasement, this type pool normally resolved correctly by Byte Buddy. When subclassing a type, the type pool must be set
explicitly, using DynamicType.Builder.make(TypePool)
or any similar method. It is however not normally
necessary to use this component when subclassing a type where methods are only defined explicitly.
Modifier and Type | Class and Description |
---|---|
protected static class |
MemberSubstitution.SubstitutingMethodVisitor
A method visitor that applies a substitution for matched methods.
|
protected static interface |
MemberSubstitution.Substitution
Resolves an actual substitution.
|
static interface |
MemberSubstitution.TypePoolResolver
A type pool resolver is responsible for resolving a
TypePool for locating substituted members. |
static class |
MemberSubstitution.WithoutSpecification
A member substitution that lacks a specification for how to substitute the matched members references within a method body.
|
Modifier | Constructor and Description |
---|---|
protected |
MemberSubstitution(boolean strict)
Creates a default member substitution.
|
Modifier and Type | Method and Description |
---|---|
MemberSubstitution.WithoutSpecification |
constructor(ElementMatcher<? super MethodDescription> matcher)
Substitutes any constructor invocation that matches the given matcher.
|
MemberSubstitution.WithoutSpecification |
element(ElementMatcher<? super ByteCodeElement> matcher)
Substitutes any interaction with a field or method that matches the given matcher.
|
MemberSubstitution.WithoutSpecification.ForMatchedField |
field(ElementMatcher<? super FieldDescription.InDefinedShape> matcher)
Substitutes any field access that matches the given matcher.
|
MemberSubstitution.WithoutSpecification |
invokable(ElementMatcher<? super MethodDescription> matcher)
Substitutes any method or constructor invocation that matches the given matcher.
|
MemberSubstitution.WithoutSpecification.ForMatchedMethod |
method(ElementMatcher<? super MethodDescription> matcher)
Substitutes any method invocation that matches the given matcher.
|
AsmVisitorWrapper.ForDeclaredMethods |
on(ElementMatcher<? super MethodDescription> matcher)
Applies this member substitutor to any method that matches the supplied matcher.
|
static MemberSubstitution |
relaxed()
Creates a member substitutor that skips any unresolvable fields or methods that are referenced within a method body.
|
static MemberSubstitution |
strict()
Creates a member substitutor that requires the resolution of all fields and methods that are referenced within a method body.
|
MemberSubstitution |
with(MemberSubstitution.TypePoolResolver typePoolResolver)
Specifies a type pool resolver to be used for locating members.
|
MemberSubstitution |
with(MethodGraph.Compiler methodGraphCompiler)
Specifies the use of a specific method graph compiler for the resolution of virtual methods.
|
MethodVisitor |
wrap(TypeDescription instrumentedType,
MethodDescription instrumentedMethod,
MethodVisitor methodVisitor,
Implementation.Context implementationContext,
TypePool typePool,
int writerFlags,
int readerFlags)
Wraps a method visitor.
|
protected MemberSubstitution(boolean strict)
strict
- true
if the method processing should be strict where an exception is raised if a member cannot be found.public static MemberSubstitution strict()
public static MemberSubstitution relaxed()
public MemberSubstitution.WithoutSpecification element(ElementMatcher<? super ByteCodeElement> matcher)
matcher
- The matcher to determine what access to byte code elements to substitute.public MemberSubstitution.WithoutSpecification.ForMatchedField field(ElementMatcher<? super FieldDescription.InDefinedShape> matcher)
matcher
- The matcher to determine what fields to substitute.public MemberSubstitution.WithoutSpecification.ForMatchedMethod method(ElementMatcher<? super MethodDescription> matcher)
matcher
- The matcher to determine what methods to substitute.public MemberSubstitution.WithoutSpecification constructor(ElementMatcher<? super MethodDescription> matcher)
matcher
- The matcher to determine what constructors to substitute.public MemberSubstitution.WithoutSpecification invokable(ElementMatcher<? super MethodDescription> matcher)
matcher
- The matcher to determine what method or constructors to substitute.public MemberSubstitution with(MethodGraph.Compiler methodGraphCompiler)
methodGraphCompiler
- The method graph compiler to use.public MemberSubstitution with(MemberSubstitution.TypePoolResolver typePoolResolver)
typePoolResolver
- The type pool resolver to use.public AsmVisitorWrapper.ForDeclaredMethods on(ElementMatcher<? super MethodDescription> matcher)
matcher
- The matcher to determine this substitutors application.public MethodVisitor wrap(TypeDescription instrumentedType, MethodDescription instrumentedMethod, MethodVisitor methodVisitor, Implementation.Context implementationContext, TypePool typePool, int writerFlags, int readerFlags)
AsmVisitorWrapper.ForDeclaredMethods.MethodVisitorWrapper
wrap
in interface AsmVisitorWrapper.ForDeclaredMethods.MethodVisitorWrapper
instrumentedType
- The instrumented type.instrumentedMethod
- The method that is currently being defined.methodVisitor
- The original field visitor that defines the given method.implementationContext
- The implementation context to use.typePool
- The type pool to use.writerFlags
- The ASM ClassWriter
reader flags to consider.readerFlags
- The ASM ClassReader
reader flags to consider.Copyright © 2014–2017. All rights reserved.