Top Description Inners Fields Constructors Methods
net.bytebuddy.asm

public Class MemberSubstitution

extends Object
implements MethodVisitorWrapper
Class Inheritance
All Implemented Interfaces
net.bytebuddy.asm.AsmVisitorWrapper.ForDeclaredMethods.MethodVisitorWrapper
Annotations
@Enhance
Imports
edu.umd.cs.findbugs.annotations.SuppressFBWarnings, net.bytebuddy.ClassFileVersion, net.bytebuddy.build.HashCodeAndEqualsPlugin, net.bytebuddy.description.ByteCodeElement, net.bytebuddy.description.annotation.AnnotationDescription, .AnnotationValue, net.bytebuddy.description.enumeration.EnumerationDescription, net.bytebuddy.description.field.FieldDescription, .FieldList, net.bytebuddy.description.method.MethodDescription, .MethodList, .ParameterDescription, net.bytebuddy.description.type.TypeDefinition, .TypeDescription, .TypeList, .TypeVariableToken, net.bytebuddy.dynamic.ClassFileLocator, .TargetType, net.bytebuddy.dynamic.scaffold.FieldLocator, .MethodGraph, net.bytebuddy.implementation.Implementation, net.bytebuddy.implementation.bytecode.*, net.bytebuddy.implementation.bytecode.assign.Assigner, net.bytebuddy.implementation.bytecode.collection.ArrayFactory, net.bytebuddy.implementation.bytecode.constant.*, net.bytebuddy.implementation.bytecode.member.FieldAccess, .MethodInvocation, .MethodVariableAccess, net.bytebuddy.matcher.ElementMatcher, .ElementMatchers, net.bytebuddy.pool.TypePool, net.bytebuddy.utility.*, net.bytebuddy.utility.nullability.MaybeNull, net.bytebuddy.utility.visitor.LocalVariableAwareMethodVisitor, net.bytebuddy.jar.asm.MethodVisitor, .Opcodes, java.io.Serializable, java.lang.annotation.*, java.lang.reflect.Constructor, .Field, .Method, .Type, java.util.*

Substitutes field access, method invocations or constructor calls within a method's body.

Note

This substitution must not be used to match constructor calls to an instrumented class's super constructor invocation from within a constructor. Matching such constructors will result in an invalid stack and a verification error.

Note

This visitor will compute the required stack size on a best effort basis. For allocating an optimal stack size, ASM needs to be configured to compute the stack size.

Important Note

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 net.bytebuddy.dynamic.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.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static @interface
MemberSubstitution.AllArguments

Assigns an array containing all arguments of the targeted element to the annotated parameter.

public static @interface
MemberSubstitution.Argument

Indicates that the annotated parameter should be mapped to the parameter with index Argument#value().

public static @interface
MemberSubstitution.Current

Indicates that the annotated parameter should be assigned the value of the result that was yielded by the previous chain expression.

public static @interface
MemberSubstitution.FieldGetterHandle

Indicates that the annotated parameter should be mapped to a java.lang.invoke.MethodHandle representing a field getter.

public static @interface
MemberSubstitution.FieldSetterHandle

Indicates that the annotated parameter should be mapped to a java.lang.invoke.MethodHandle representing a field setter.

public static @interface
MemberSubstitution.FieldValue

Indicates that the annotated parameter should be mapped to a field in the scope of the instrumented type.

public static @interface
MemberSubstitution.Origin

Indicates that the annotated parameter should be mapped to a representation of the substituted element or instrumented method.

protected static interface
MemberSubstitution.Replacement

A replacement combines a Substitution and a way of choosing if this substitution should be applied for a discovered member.

public static @interface
MemberSubstitution.SelfCallHandle

Indicates that the annotated parameter should load a java.lang.invoke.MethodHandle that represents an invocation of the substituted expression or instrumented method.

public static enum
MemberSubstitution.Source

Identifies the source of an instruction that might describe a value of the substituted element or the instrumented method.

public static @interface
MemberSubstitution.StubValue

Indicates that the annotated parameter should always return a boxed version of the instrumented method's return value (i.e. 0 for numeric values, false for boolean types and null for reference types).

protected static class
MemberSubstitution.SubstitutingMethodVisitor

A method visitor that applies a substitution for matched methods.

public static interface
MemberSubstitution.Substitution

A substitution replaces or enhances an interaction with a field or method within an instrumented method.

public static @interface
MemberSubstitution.This

Indicates that the annotated parameter should be mapped to the this reference of the substituted field, method, constructor or of the instrumented method.

public static interface
MemberSubstitution.TypePoolResolver

A type pool resolver is responsible for resolving a TypePool for locating substituted members.

public static @interface
MemberSubstitution.Unused

Indicates that the annotated parameter should always return a default value (i.e. 0 for numeric values, false for boolean types and null for reference types).

public abstract static class
MemberSubstitution.WithoutSpecification

A member substitution that lacks a specification for how to substitute the matched members references within a method body.

Field Summary

Modifier and TypeField and Description
private final boolean
failIfNoMatch

true if the instrumentation should fail if applied to a method without match.

private final MethodGraph.Compiler
methodGraphCompiler

The method graph compiler to use.

private final MemberSubstitution.Replacement.Factory
replacementFactory

The replacement factory to use.

private final boolean
strict

true if the method processing should be strict where an exception is raised if a member cannot be found.

protected static final int
THIS_REFERENCE

The index of the this reference within a non-static method.

private final MemberSubstitution.TypePoolResolver
typePoolResolver

The type pool resolver to use.

Constructor Summary

AccessConstructor and Description
protected
MemberSubstitution(boolean
true if the method processing should be strict where an exception is raised if a member cannot be found.
strict
)

Creates a default member substitution.

protected
MemberSubstitution(MethodGraph.Compiler
The method graph compiler to use.
methodGraphCompiler
,
MemberSubstitution.TypePoolResolver
The type pool resolver to use.
typePoolResolver
,
boolean
true if the method processing should be strict where an exception is raised if a member cannot be found.
strict
,
boolean
true if the instrumentation should fail if applied to a method without match.
failIfNoMatch
,
MemberSubstitution.Replacement.Factory
The replacement factory to use.
replacementFactory
)

Creates a new member substitution.

Method Summary

Modifier and TypeMethod and Description
public MemberSubstitution.WithoutSpecification

Returns:

A specification that allows to determine how to substitute any constructor invocations that match the supplied matcher.
constructor
(ElementMatcher<? super MethodDescription>
The matcher to determine what constructors to substitute.
matcher
)

Substitutes any constructor invocation that matches the given matcher.

public MemberSubstitution.WithoutSpecification

Returns:

A specification that allows to determine how to substitute any interaction with byte code elements that match the supplied matcher.
element
(ElementMatcher<? super ByteCodeElement.Member>
The matcher to determine what access to byte code elements to substitute.
matcher
)

Substitutes any interaction with a field or method that matches the given matcher.

public MemberSubstitution

Returns:

A new instance of this member substitution that fails if applied on a method without a match.
failIfNoMatch
(boolean
true if the instrumentation should fail if applied to a method without match.
failIfNoMatch
)

Specifies if this substitution should fail if applied on a method without a match.

public MemberSubstitution.WithoutSpecification.ForMatchedField

Returns:

A specification that allows to determine how to substitute any field access that match the supplied matcher.
field
(ElementMatcher<? super FieldDescription>
The matcher to determine what fields to substitute.
matcher
)

Substitutes any field access that matches the given matcher.

public MemberSubstitution.WithoutSpecification

Returns:

A specification that allows to determine how to substitute any constructor invocations that match the supplied matcher.
invokable
(ElementMatcher<? super MethodDescription>
The matcher to determine what method or constructors to substitute.
matcher
)

Substitutes any method or constructor invocation that matches the given matcher.

public MemberSubstitution.WithoutSpecification.ForMatchedMethod

Returns:

A specification that allows to determine how to substitute any method invocations that match the supplied matcher.
method
(ElementMatcher<? super MethodDescription>
The matcher to determine what methods to substitute.
matcher
)

Substitutes any method invocation that matches the given matcher.

public AsmVisitorWrapper.ForDeclaredMethods

Returns:

An ASM visitor wrapper that applies all specified substitutions for any matched method.
on
(ElementMatcher<? super MethodDescription>
The matcher to determine this substitutions application.
matcher
)

Applies this member substitution to any method that matches the supplied matcher.

public static MemberSubstitution

Returns:

A relaxed member substitution.
relaxed
()

Creates a member substitution that skips any unresolvable fields or methods that are referenced within a method body.

public static MemberSubstitution

Returns:

A strict member substitution.
strict
()

Creates a member substitution that requires the resolution of all fields and methods that are referenced within a method body.

public MemberSubstitution

Returns:

A new member substitution that is equal to this but uses the specified method graph compiler.
with
(MethodGraph.Compiler
The method graph compiler to use.
methodGraphCompiler
)

Specifies the use of a specific method graph compiler for the resolution of virtual methods.

public MemberSubstitution

Returns:

A new instance of this member substitution that uses the supplied type pool resolver.
with
(MemberSubstitution.TypePoolResolver
The type pool resolver to use.
typePoolResolver
)

Specifies a type pool resolver to be used for locating members.

public MethodVisitor
wrap(TypeDescription
The instrumented type.
instrumentedType
,
MethodDescription
The method that is currently being defined.
instrumentedMethod
,
MethodVisitor
The original field visitor that defines the given method.
methodVisitor
,
Implementation.Context
The implementation context to use.
implementationContext
,
TypePool
The type pool to use.
typePool
,
int
The ASM net.bytebuddy.jar.asm.ClassWriter reader flags to consider.
writerFlags
,
int
The ASM net.bytebuddy.jar.asm.ClassReader reader flags to consider.
readerFlags
)

Implements net.bytebuddy.asm.AsmVisitorWrapper.ForDeclaredMethods.MethodVisitorWrapper.wrap.

Wraps a method visitor.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait