Package net.bytebuddy.implementation
Class MethodDelegation
java.lang.Object
net.bytebuddy.implementation.MethodDelegation
- All Implemented Interfaces:
InstrumentedType.Prepareable
,Implementation
,Implementation.Composable
This implementation delegates a method call to another method which can either be
static
by providing
a reference to a Class
or an instance method when another object is provided. The potential
targets of the method delegation can further be filtered by applying a filter. The method delegation can be
customized by invoking the MethodDelegation
's several builder methods.
Without any customization, the method delegation will work as follows:
Binding an instrumented method to a given delegate method
A method will be bound parameter by parameter. Considering a method
Foo#bar
being bound to a method
Qux#baz
, the method delegation will be decided on basis of the following annotations:
Argument
: This annotation will bind then
-th parameter ofFoo#bar
to that parameter ofQux#baz
that is annotated with this annotation wheren
is the obligatory argument of the@Argument
annotation.AllArguments
: This annotation will assign a collection of all parameters ofFoo#bar
to that parameter ofQux#baz
that is annotated withAllArguments
.This
: A parameter ofQux#baz
that is annotated withThis
will be assigned the instance that is instrumented for a non-static method.Super
: A parameter that is annotated with this annotation is assigned a proxy that allows calling an instrumented type's super methods.Default
: A parameter that is annotated with this annotation is assigned a proxy that allows calling an instrumented type's directly implemented interfaces' default methods.SuperCall
: A parameter ofQux#baz
that is annotated withSuperCall
will be assigned an instance of a type implementing bothRunnable
andCallable
which will invoke the instrumented method on the invocation of either interface's method. The call is made using the original arguments of the method invocation. The return value is only emitted for theCallable.call()
method which additionally requires to catch any unchecked exceptions that might be thrown by the original method's implementation. If a source method is abstract, using this annotation excludes the method with this parameter annotation from being bound to this source method.DefaultCall
: This annotation is similar to theSuperCall
annotation but it invokes a default method that is compatible to this method. If a source method does not represent a default method, using this annotation excludes the method with this parameter annotation from being bound to this source method. For using method handles, theSuperCallHandle
andDefaultCallHandle
annotations can be used.- The
SuperMethod
orDefaultMethod
annotations can be used on any parameter type that is assignable from theMethod
type. the parameter is bound a method instance that allows for the reflective invocation of a super or default method. Note that this method is not equal to the intercepted method but represents a synthetic accessor method. Using this annotation also causes this accessor to bepublic
which allows its outside invocation without any access checks by a security manager. For using method handles, theSuperCallHandle
andDefaultCallHandle
annotations can be used. Origin
: A parameter ofQux#baz
that is annotated withOrigin
is assigned a reference to either aMethod
, aConstructor
, ajava.lang.reflect.Executable
or aClass
instance. AMethod
-typed,Constructor
orExecutable
parameter is assigned a reference to the original method that is instrumented. AClass
-typed parameter is assigned the type of the caller. Furthermore,MethodType
andMethodHandle
parameters are also supported. When using the annotation on aString
type, the intercepted method'stoString
value is injected. The same holds for a parameter of typeint
that receives the modifiers of the instrumented method.StubValue
: Assigns the (boxed) default value of the intercepted method's return type to the parameter. If the return type isvoid
,null
is assigned.Empty
: Assigns the parameter type's default value, i.e.null
for a reference type or zero for primitive types. This is an opportunity to ignore a parameter.Pipe
: A parameter that is annotated with this annotation is assigned a proxy for forwarding the source method invocation to another instance of the same type as the declaring type of the intercepted method. This annotation needs to be installed and explicitly registered before it can be used. See thePipe
annotation's documentation for further information on how this can be done.Morph
: The morph annotation is similar to theSuperCall
annotation but allows to explicitly define and therewith alter the arguments that are handed to the super method. This annotation needs to be installed and explicitly registered before it can be used. See the documentation to the annotation for further information.FieldValue
: Allows to access a field's value at the time of the method invocation. The field's value is directly assigned to the annotated parameter.FieldProxy
: Allows to access fields via getter and setter proxies. This annotation needs to be installed and explicitly registered before it can be used. Note that any field access requires boxing such that a use ofFieldAccessor
in combination withandThen(Implementation)
might be a more performant alternative for implementing field getters and setters.
Argument
using the next
unbound parameter index of the source method as its parameter. This means that a method
Qux#baz(@Argument(2) Object p1, Object p2, @Argument(0) Object p3
would be treated as if p2
was annotated
with @Argument(1)
.
In addition, the
RuntimeType
annotation can instruct a parameter to be bound by a
Assigner
with considering the
runtime type of the parameter.
Selecting among different methods that can be used for binding a method of the instrumented type
When deciding between two methods
Foo#bar
and Foo#qux
that could both be used to delegating a
method call, the following consideration is applied in the given order:
BindingPriority
: A method that is annotated with this annotation is given a specific priority where the default priority is set toBindingPriority.DEFAULT
for non-annotated method. A method with a higher priority is considered a better target for delegation.DeclaringTypeResolver
: If a target method is declared by a more specific type than another method, the method with the most specific type is bound.MethodNameEqualityResolver
: If a source methodBaz#qux
is the source method, it will rather be assigned toFoo#qux
because of their equal names. Similar names and case-insensitive equality are not considered.ArgumentTypeResolver
: The most specific type resolver will consider all bindings that are using theArgument
annotation for resolving a binding conflict. In this context, the resolution will equal the most-specific type resolution that is performed by the Java compiler. This means that a source methodBar#baz(String)
will rather be bound to a methodFoo#bar(String)
thanFoo#qux(Object)
because theString
type is more specific than theObject
type. If two methods are equally adequate by their parameter types, then the method with the higher numbers of@Argument
annotated parameters is considered as the better delegation target.ParameterLengthResolver
: If a target methods has a higher number of total parameters that were successfully bound, the method with the higher number will be considered as the better delegation target.
Additionally, if a method is annotated by
IgnoreForBinding
,
it is never considered as a target for a method delegation.
Important: For invoking a method on another instance, use the MethodCall
implementation. A method delegation
intends to bind a interceptor class and its resolution algorithm will not necessarily yield a delegation to the intercepted
method.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
The appender for implementing aMethodDelegation
.protected static interface
An implementation delegate is responsible for executing the actual method delegation and for resolving the target methods.static class
AMethodDelegation
with custom configuration.Nested classes/interfaces inherited from interface net.bytebuddy.implementation.Implementation
Implementation.Composable, Implementation.Compound, Implementation.Context, Implementation.Simple, Implementation.SpecialMethodInvocation, Implementation.Target
Nested classes/interfaces inherited from interface net.bytebuddy.dynamic.scaffold.InstrumentedType.Prepareable
InstrumentedType.Prepareable.NoOp
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final MethodDelegationBinder.AmbiguityResolver
TheMethodDelegationBinder.AmbiguityResolver
to be used by this method delegation.private final Assigner
TheAssigner
to be used by this method delegation.private final MethodDelegationBinder.BindingResolver
The binding resolver being used to select the relevant method binding.private final MethodDelegation.ImplementationDelegate
The implementation delegate for this method delegation.private final List
<TargetMethodAnnotationDrivenBinder.ParameterBinder<?>> A list ofTargetMethodAnnotationDrivenBinder.ParameterBinder
s to be used by this method delegation.private final MethodDelegationBinder.TerminationHandler
The termination handler to apply. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
MethodDelegation
(MethodDelegation.ImplementationDelegate implementationDelegate, List<TargetMethodAnnotationDrivenBinder.ParameterBinder<?>> parameterBinders, MethodDelegationBinder.AmbiguityResolver ambiguityResolver, MethodDelegationBinder.BindingResolver bindingResolver) Creates a new method delegation.private
MethodDelegation
(MethodDelegation.ImplementationDelegate implementationDelegate, List<TargetMethodAnnotationDrivenBinder.ParameterBinder<?>> parameterBinders, MethodDelegationBinder.AmbiguityResolver ambiguityResolver, MethodDelegationBinder.TerminationHandler terminationHandler, MethodDelegationBinder.BindingResolver bindingResolver, Assigner assigner) Creates a new method delegation. -
Method Summary
Modifier and TypeMethodDescriptionandThen
(Implementation implementation) Appends the supplied implementation to this implementation.andThen
(Implementation.Composable implementation) Appends the supplied composable implementation to this implementation.appender
(Implementation.Target implementationTarget) Creates a byte code appender that determines the implementation of the instrumented type's methods.prepare
(InstrumentedType instrumentedType) Prepares a given instrumented type.static MethodDelegation
Delegates any intercepted method to invoke astatic
method that is declared by the supplied type.static MethodDelegation
Delegates any intercepted method to invoke a non-static
method that is declared by the supplied type's instance or any of its super types.static MethodDelegation
Delegates any intercepted method to invoke a non-static
method that is declared by the supplied type's instance or any of its super types.static MethodDelegation
Delegates any intercepted method to invoke a non-static
method that is declared by the supplied type's instance or any of its super types.static MethodDelegation
to
(Object target, Type type, String fieldName, MethodGraph.Compiler methodGraphCompiler) Delegates any intercepted method to invoke a non-static
method that is declared by the supplied type's instance or any of its super types.static MethodDelegation
to
(Object target, Type type, MethodGraph.Compiler methodGraphCompiler) Delegates any intercepted method to invoke a non-static
method that is declared by the supplied type's instance or any of its super types.static MethodDelegation
Delegates any intercepted method to invoke a non-static
method that is declared by the supplied type's instance or any of its super types.static MethodDelegation
to
(Object target, String fieldName, MethodGraph.Compiler methodGraphCompiler) Delegates any intercepted method to invoke a non-static
method that is declared by the supplied type's instance or any of its super types.static MethodDelegation
to
(Object target, TypeDefinition typeDefinition) Delegates any intercepted method to invoke a non-static
method that is declared by the supplied type's instance or any of its super types.static MethodDelegation
to
(Object target, TypeDefinition typeDefinition, String fieldName) Delegates any intercepted method to invoke a non-static
method that is declared by the supplied type's instance or any of its super types.static MethodDelegation
to
(Object target, TypeDefinition typeDefinition, String fieldName, MethodGraph.Compiler methodGraphCompiler) Delegates any intercepted method to invoke a non-static
method that is declared by the supplied type's instance or any of its super types.static MethodDelegation
to
(Object target, TypeDefinition typeDefinition, MethodGraph.Compiler methodGraphCompiler) Delegates any intercepted method to invoke a non-static
method that is declared by the supplied type's instance or any of its super types.static MethodDelegation
to
(Object target, MethodGraph.Compiler methodGraphCompiler) Delegates any intercepted method to invoke a non-static
method that is declared by the supplied type's instance or any of its super types.static MethodDelegation
to
(TypeDescription typeDescription) Delegates any intercepted method to invoke astatic
method that is declared by the supplied type.static MethodDelegation
toConstructor
(Class<?> type) Delegates any intercepted method to invoke a constructor of the supplied type.static MethodDelegation
toConstructor
(TypeDescription typeDescription) Delegates any intercepted method to invoke a constructor of the supplied type.static MethodDelegation
Delegates any intercepted method to invoke a non-static
method on the instance of the supplied field.static MethodDelegation
toField
(String name, FieldLocator.Factory fieldLocatorFactory) Delegates any intercepted method to invoke a non-static
method on the instance of the supplied field.static MethodDelegation
toField
(String name, FieldLocator.Factory fieldLocatorFactory, MethodGraph.Compiler methodGraphCompiler) Delegates any intercepted method to invoke a non-static
method on the instance of the supplied field.static MethodDelegation
toField
(String name, MethodGraph.Compiler methodGraphCompiler) Delegates any intercepted method to invoke a non-static
method on the instance of the supplied field.static MethodDelegation
toMethodReturnOf
(String name) Delegates any intercepted method to invoke a method on an instance that is returned by a parameterless method of the given name.static MethodDelegation
toMethodReturnOf
(String name, MethodGraph.Compiler methodGraphCompiler) Delegates any intercepted method to invoke a method on an instance that is returned by a parameterless method of the given name.withAssigner
(Assigner assigner) Applies an assigner to the method delegation that is used for assigning method return and parameter types.Creates a configuration builder for a method delegation that is pre-configured with the ambiguity resolvers defined byMethodDelegationBinder.AmbiguityResolver.DEFAULT
and the parameter binders defined byTargetMethodAnnotationDrivenBinder.ParameterBinder.DEFAULTS
.Creates a configuration builder for a method delegation that does not apply any pre-configuredMethodDelegationBinder.AmbiguityResolver
s orTargetMethodAnnotationDrivenBinder.ParameterBinder
s.
-
Field Details
-
implementationDelegate
The implementation delegate for this method delegation. -
parameterBinders
A list ofTargetMethodAnnotationDrivenBinder.ParameterBinder
s to be used by this method delegation. -
ambiguityResolver
TheMethodDelegationBinder.AmbiguityResolver
to be used by this method delegation. -
terminationHandler
The termination handler to apply. -
bindingResolver
The binding resolver being used to select the relevant method binding. -
assigner
TheAssigner
to be used by this method delegation.
-
-
Constructor Details
-
MethodDelegation
protected MethodDelegation(MethodDelegation.ImplementationDelegate implementationDelegate, List<TargetMethodAnnotationDrivenBinder.ParameterBinder<?>> parameterBinders, MethodDelegationBinder.AmbiguityResolver ambiguityResolver, MethodDelegationBinder.BindingResolver bindingResolver) Creates a new method delegation.- Parameters:
implementationDelegate
- The implementation delegate to use by this method delegator.parameterBinders
- The parameter binders to use by this method delegator.ambiguityResolver
- The ambiguity resolver to use by this method delegator.bindingResolver
- The binding resolver being used to select the relevant method binding.
-
MethodDelegation
private MethodDelegation(MethodDelegation.ImplementationDelegate implementationDelegate, List<TargetMethodAnnotationDrivenBinder.ParameterBinder<?>> parameterBinders, MethodDelegationBinder.AmbiguityResolver ambiguityResolver, MethodDelegationBinder.TerminationHandler terminationHandler, MethodDelegationBinder.BindingResolver bindingResolver, Assigner assigner) Creates a new method delegation.- Parameters:
implementationDelegate
- The implementation delegate to use by this method delegator.parameterBinders
- The parameter binders to use by this method delegator.ambiguityResolver
- The ambiguity resolver to use by this method delegator.terminationHandler
- The termination handler to apply.bindingResolver
- The binding resolver being used to select the relevant method binding.assigner
- The assigner to be supplied by this method delegator.
-
-
Method Details
-
to
Delegates any intercepted method to invoke astatic
method that is declared by the supplied type. To be considered a valid delegation target, the target method must be visible and accessible to the instrumented type. This is the case if the target type is either public or in the same package as the instrumented type and if the target method is either public or non-private and in the same package as the instrumented type. Private methods can only be used as a delegation target if the interception is targeting the instrumented type.- Parameters:
type
- The target type for the delegation.- Returns:
- A method delegation that redirects method calls to a static method of the supplied type.
-
to
Delegates any intercepted method to invoke astatic
method that is declared by the supplied type. To be considered a valid delegation target, the target method must be visible and accessible to the instrumented type. This is the case if the target type is either public or in the same package as the instrumented type and if the target method is either public or non-private and in the same package as the instrumented type. Private methods can only be used as a delegation target if the interception is targeting the instrumented type.- Parameters:
typeDescription
- The target type for the delegation.- Returns:
- A method delegation that redirects method calls to a static method of the supplied type.
-
to
Delegates any intercepted method to invoke a non-static
method that is declared by the supplied type's instance or any of its super types. To be considered a valid delegation target, a method must be visible and accessible to the instrumented type. This is the case if the method's declaring type is either public or in the same package as the instrumented type and if the method is either public or non-private and in the same package as the instrumented type. Private methods can only be used as a delegation target if the delegation is targeting the instrumented type.- Parameters:
target
- The target instance for the delegation.- Returns:
- A method delegation that redirects method calls to a static method of the supplied type.
-
to
Delegates any intercepted method to invoke a non-static
method that is declared by the supplied type's instance or any of its super types. To be considered a valid delegation target, a method must be visible and accessible to the instrumented type. This is the case if the method's declaring type is either public or in the same package as the instrumented type and if the method is either public or non-private and in the same package as the instrumented type. Private methods can only be used as a delegation target if the delegation is targeting the instrumented type.- Parameters:
target
- The target instance for the delegation.methodGraphCompiler
- The method graph compiler to use.- Returns:
- A method delegation that redirects method calls to a static method of the supplied type.
-
to
Delegates any intercepted method to invoke a non-static
method that is declared by the supplied type's instance or any of its super types. To be considered a valid delegation target, a method must be visible and accessible to the instrumented type. This is the case if the method's declaring type is either public or in the same package as the instrumented type and if the method is either public or non-private and in the same package as the instrumented type. Private methods can only be used as a delegation target if the delegation is targeting the instrumented type.- Parameters:
target
- The target instance for the delegation.fieldName
- The name of the field that is holding thetarget
instance.- Returns:
- A method delegation that redirects method calls to a static method of the supplied type.
-
to
public static MethodDelegation to(Object target, String fieldName, MethodGraph.Compiler methodGraphCompiler) Delegates any intercepted method to invoke a non-static
method that is declared by the supplied type's instance or any of its super types. To be considered a valid delegation target, a method must be visible and accessible to the instrumented type. This is the case if the method's declaring type is either public or in the same package as the instrumented type and if the method is either public or non-private and in the same package as the instrumented type. Private methods can only be used as a delegation target if the delegation is targeting the instrumented type.- Parameters:
target
- The target instance for the delegation.fieldName
- The name of the field that is holding thetarget
instance.methodGraphCompiler
- The method graph compiler to use.- Returns:
- A method delegation that redirects method calls to a static method of the supplied type.
-
to
Delegates any intercepted method to invoke a non-static
method that is declared by the supplied type's instance or any of its super types. To be considered a valid delegation target, a method must be visible and accessible to the instrumented type. This is the case if the method's declaring type is either public or in the same package as the instrumented type and if the method is either public or non-private and in the same package as the instrumented type. Private methods can only be used as a delegation target if the delegation is targeting the instrumented type.- Parameters:
target
- The target instance for the delegation.type
- The most specific type of whichtarget
should be considered. Must be a super type of the target's actual type.- Returns:
- A method delegation that redirects method calls to a static method of the supplied type.
-
to
public static MethodDelegation to(Object target, Type type, MethodGraph.Compiler methodGraphCompiler) Delegates any intercepted method to invoke a non-static
method that is declared by the supplied type's instance or any of its super types. To be considered a valid delegation target, a method must be visible and accessible to the instrumented type. This is the case if the method's declaring type is either public or in the same package as the instrumented type and if the method is either public or non-private and in the same package as the instrumented type. Private methods can only be used as a delegation target if the delegation is targeting the instrumented type.- Parameters:
target
- The target instance for the delegation.type
- The most specific type of whichtarget
should be considered. Must be a super type of the target's actual type.methodGraphCompiler
- The method graph compiler to use.- Returns:
- A method delegation that redirects method calls to a static method of the supplied type.
-
to
Delegates any intercepted method to invoke a non-static
method that is declared by the supplied type's instance or any of its super types. To be considered a valid delegation target, a method must be visible and accessible to the instrumented type. This is the case if the method's declaring type is either public or in the same package as the instrumented type and if the method is either public or non-private and in the same package as the instrumented type. Private methods can only be used as a delegation target if the delegation is targeting the instrumented type.- Parameters:
target
- The target instance for the delegation.type
- The most specific type of whichtarget
should be considered. Must be a super type of the target's actual type.fieldName
- The name of the field that is holding thetarget
instance.- Returns:
- A method delegation that redirects method calls to a static method of the supplied type.
-
to
public static MethodDelegation to(Object target, Type type, String fieldName, MethodGraph.Compiler methodGraphCompiler) Delegates any intercepted method to invoke a non-static
method that is declared by the supplied type's instance or any of its super types. To be considered a valid delegation target, a method must be visible and accessible to the instrumented type. This is the case if the method's declaring type is either public or in the same package as the instrumented type and if the method is either public or non-private and in the same package as the instrumented type. Private methods can only be used as a delegation target if the delegation is targeting the instrumented type.- Parameters:
target
- The target instance for the delegation.type
- The most specific type of whichtarget
should be considered. Must be a super type of the target's actual type.fieldName
- The name of the field that is holding thetarget
instance.methodGraphCompiler
- The method graph compiler to use.- Returns:
- A method delegation that redirects method calls to a static method of the supplied type.
-
to
Delegates any intercepted method to invoke a non-static
method that is declared by the supplied type's instance or any of its super types. To be considered a valid delegation target, a method must be visible and accessible to the instrumented type. This is the case if the method's declaring type is either public or in the same package as the instrumented type and if the method is either public or non-private and in the same package as the instrumented type. Private methods can only be used as a delegation target if the delegation is targeting the instrumented type.- Parameters:
target
- The target instance for the delegation.typeDefinition
- The most specific type of whichtarget
should be considered. Must be a super type of the target's actual type.- Returns:
- A method delegation that redirects method calls to a static method of the supplied type.
-
to
public static MethodDelegation to(Object target, TypeDefinition typeDefinition, MethodGraph.Compiler methodGraphCompiler) Delegates any intercepted method to invoke a non-static
method that is declared by the supplied type's instance or any of its super types. To be considered a valid delegation target, a method must be visible and accessible to the instrumented type. This is the case if the method's declaring type is either public or in the same package as the instrumented type and if the method is either public or non-private and in the same package as the instrumented type. Private methods can only be used as a delegation target if the delegation is targeting the instrumented type.- Parameters:
target
- The target instance for the delegation.typeDefinition
- The most specific type of whichtarget
should be considered. Must be a super type of the target's actual type.methodGraphCompiler
- The method graph compiler to use.- Returns:
- A method delegation that redirects method calls to a static method of the supplied type.
-
to
Delegates any intercepted method to invoke a non-static
method that is declared by the supplied type's instance or any of its super types. To be considered a valid delegation target, a method must be visible and accessible to the instrumented type. This is the case if the method's declaring type is either public or in the same package as the instrumented type and if the method is either public or non-private and in the same package as the instrumented type. Private methods can only be used as a delegation target if the delegation is targeting the instrumented type.- Parameters:
target
- The target instance for the delegation.typeDefinition
- The most specific type of whichtarget
should be considered. Must be a super type of the target's actual type.fieldName
- The name of the field that is holding thetarget
instance.- Returns:
- A method delegation that redirects method calls to a static method of the supplied type.
-
to
public static MethodDelegation to(Object target, TypeDefinition typeDefinition, String fieldName, MethodGraph.Compiler methodGraphCompiler) Delegates any intercepted method to invoke a non-static
method that is declared by the supplied type's instance or any of its super types. To be considered a valid delegation target, a method must be visible and accessible to the instrumented type. This is the case if the method's declaring type is either public or in the same package as the instrumented type and if the method is either public or non-private and in the same package as the instrumented type. Private methods can only be used as a delegation target if the delegation is targeting the instrumented type.- Parameters:
target
- The target instance for the delegation.typeDefinition
- The most specific type of whichtarget
should be considered. Must be a super type of the target's actual type.fieldName
- The name of the field that is holding thetarget
instance.methodGraphCompiler
- The method graph compiler to use.- Returns:
- A method delegation that redirects method calls to a static method of the supplied type.
-
toConstructor
Delegates any intercepted method to invoke a constructor of the supplied type. To be considered a valid delegation target, a constructor must be visible and accessible to the instrumented type. This is the case if the constructor's declaring type is either public or in the same package as the instrumented type and if the constructor is either public or non-private and in the same package as the instrumented type. Private constructors can only be used as a delegation target if the delegation is targeting the instrumented type.- Parameters:
type
- The type to construct.- Returns:
- A delegation that redirects method calls to a constructor of the supplied type.
-
toConstructor
Delegates any intercepted method to invoke a constructor of the supplied type. To be considered a valid delegation target, a constructor must be visible and accessible to the instrumented type. This is the case if the constructor's declaring type is either public or in the same package as the instrumented type and if the constructor is either public or non-private and in the same package as the instrumented type. Private constructors can only be used as a delegation target if the delegation is targeting the instrumented type.- Parameters:
typeDescription
- The type to construct.- Returns:
- A delegation that redirects method calls to a constructor of the supplied type.
-
toField
Delegates any intercepted method to invoke a non-static
method on the instance of the supplied field. To be considered a valid delegation target, a method must be visible and accessible to the instrumented type. This is the case if the method's declaring type is either public or in the same package as the instrumented type and if the method is either public or non-private and in the same package as the instrumented type. Private methods can only be used as a delegation target if the delegation is targeting the instrumented type.- Parameters:
name
- The field's name.- Returns:
- A delegation that redirects invocations to a method of the specified field's instance.
-
toField
Delegates any intercepted method to invoke a non-static
method on the instance of the supplied field. To be considered a valid delegation target, a method must be visible and accessible to the instrumented type. This is the case if the method's declaring type is either public or in the same package as the instrumented type and if the method is either public or non-private and in the same package as the instrumented type. Private methods can only be used as a delegation target if the delegation is targeting the instrumented type.- Parameters:
name
- The field's name.fieldLocatorFactory
- The field locator factory to use.- Returns:
- A delegation that redirects invocations to a method of the specified field's instance.
-
toField
Delegates any intercepted method to invoke a non-static
method on the instance of the supplied field. To be considered a valid delegation target, a method must be visible and accessible to the instrumented type. This is the case if the method's declaring type is either public or in the same package as the instrumented type and if the method is either public or non-private and in the same package as the instrumented type. Private methods can only be used as a delegation target if the delegation is targeting the instrumented type.- Parameters:
name
- The field's name.methodGraphCompiler
- The method graph compiler to use.- Returns:
- A delegation that redirects invocations to a method of the specified field's instance.
-
toField
public static MethodDelegation toField(String name, FieldLocator.Factory fieldLocatorFactory, MethodGraph.Compiler methodGraphCompiler) Delegates any intercepted method to invoke a non-static
method on the instance of the supplied field. To be considered a valid delegation target, a method must be visible and accessible to the instrumented type. This is the case if the method's declaring type is either public or in the same package as the instrumented type and if the method is either public or non-private and in the same package as the instrumented type. Private methods can only be used as a delegation target if the delegation is targeting the instrumented type.- Parameters:
name
- The field's name.fieldLocatorFactory
- The field locator factory to use.methodGraphCompiler
- The method graph compiler to use.- Returns:
- A delegation that redirects invocations to a method of the specified field's instance.
-
toMethodReturnOf
Delegates any intercepted method to invoke a method on an instance that is returned by a parameterless method of the given name. To be considered a valid delegation target, a method must be visible and accessible to the instrumented type. This is the case if the method's declaring type is either public or in the same package as the instrumented type and if the method is either public or non-private and in the same package as the instrumented type. Private methods can only be used as a delegation target if the delegation is targeting the instrumented type.- Parameters:
name
- The name of the method that returns the delegation target.- Returns:
- A delegation that redirects invocations to the return value of a method that is declared by the instrumented type.
-
toMethodReturnOf
public static MethodDelegation toMethodReturnOf(String name, MethodGraph.Compiler methodGraphCompiler) Delegates any intercepted method to invoke a method on an instance that is returned by a parameterless method of the given name. To be considered a valid delegation target, a method must be visible and accessible to the instrumented type. This is the case if the method's declaring type is either public or in the same package as the instrumented type and if the method is either public or non-private and in the same package as the instrumented type. Private methods can only be used as a delegation target if the delegation is targeting the instrumented type.- Parameters:
name
- The name of the method that returns the delegation target.methodGraphCompiler
- The method graph compiler to use.- Returns:
- A delegation that redirects invocations to the return value of a method that is declared by the instrumented type.
-
withDefaultConfiguration
Creates a configuration builder for a method delegation that is pre-configured with the ambiguity resolvers defined byMethodDelegationBinder.AmbiguityResolver.DEFAULT
and the parameter binders defined byTargetMethodAnnotationDrivenBinder.ParameterBinder.DEFAULTS
.- Returns:
- A method delegation configuration with pre-configuration.
-
withEmptyConfiguration
Creates a configuration builder for a method delegation that does not apply any pre-configuredMethodDelegationBinder.AmbiguityResolver
s orTargetMethodAnnotationDrivenBinder.ParameterBinder
s.- Returns:
- A method delegation configuration without any pre-configuration.
-
withAssigner
Applies an assigner to the method delegation that is used for assigning method return and parameter types.- Parameters:
assigner
- The assigner to apply.- Returns:
- A method delegation implementation that makes use of the given designer.
-
andThen
Appends the supplied implementation to this implementation.- Specified by:
andThen
in interfaceImplementation.Composable
- Parameters:
implementation
- The subsequent implementation.- Returns:
- An implementation that combines this implementation with the provided one.
-
andThen
Appends the supplied composable implementation to this implementation.- Specified by:
andThen
in interfaceImplementation.Composable
- Parameters:
implementation
- The subsequent composable implementation.- Returns:
- A composable implementation that combines this implementation with the provided one.
-
prepare
Prepares a given instrumented type.- Specified by:
prepare
in interfaceInstrumentedType.Prepareable
- Parameters:
instrumentedType
- The instrumented type in its current form.- Returns:
- The prepared instrumented type.
-
appender
Creates a byte code appender that determines the implementation of the instrumented type's methods.- Specified by:
appender
in interfaceImplementation
- Parameters:
implementationTarget
- The target of the current implementation.- Returns:
- A byte code appender for implementing methods delegated to this implementation. This byte code appender
is also responsible for handling methods that were added by this implementation on the call to
InstrumentedType.Prepareable.prepare(InstrumentedType)
.
-