static by providing
a reference to a java.lang.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:
org.easymock.bytebuddy.implementation.bind.annotation.Argument :
This annotation will bind the n-th parameter of Foo#bar to that parameter of Qux#bazthat
is annotated with this annotation where n is the obligatory argument of the @Argument annotation.org.easymock.bytebuddy.implementation.bind.annotation.AllArguments :
This annotation will assign a collection of all parameters of Foo#bar to that parameter of Qux#baz
that is annotated with AllArguments.org.easymock.bytebuddy.implementation.bind.annotation.This : A parameter
of Qux#baz that is annotated with This will be assigned the instance that is instrumented for
a non-static method.org.easymock.bytebuddy.implementation.bind.annotation.Super : A parameter that is annotated with
this annotation is assigned a proxy that allows calling an instrumented type's super methods.org.easymock.bytebuddy.implementation.bind.annotation.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.org.easymock.bytebuddy.implementation.bind.annotation.SuperCall : A parameter
of Qux#baz that is annotated with SuperCall will be assigned an instance of a type implementing both
java.lang.Runnable and java.util.concurrent.Callable 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 the java.util.concurrent.Callable#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.
org.easymock.bytebuddy.implementation.bind.annotation.SuperCall :
This annotation is similar to the org.easymock.bytebuddy.implementation.bind.annotation.DefaultCall
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, the org.easymock.bytebuddy.implementation.bind.annotation.SuperCallHandle
and org.easymock.bytebuddy.implementation.bind.annotation.DefaultCallHandle annotations can be used.org.easymock.bytebuddy.implementation.bind.annotation.SuperMethod or
org.easymock.bytebuddy.implementation.bind.annotation.DefaultMethod annotations can be used on any parameter type
that is assignable from the java.lang.reflect.Method 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 be public
which allows its outside invocation without any access checks by a security manager. For using method handles, the
org.easymock.bytebuddy.implementation.bind.annotation.SuperCallHandle and
org.easymock.bytebuddy.implementation.bind.annotation.DefaultCallHandle annotations can be used.org.easymock.bytebuddy.implementation.bind.annotation.Origin : A parameter of
Qux#baz that is annotated with Origin is assigned a reference to either a java.lang.reflect.Method ,
a java.lang.reflect.Constructor , a java.lang.reflect.Executable or a java.lang.Class instance.
A Method-typed, Constructor or Executable parameter is assigned a reference to the original
method that is instrumented. A Class-typed parameter is assigned the type of the caller. Furthermore, MethodType
and MethodHandle parameters are also supported. When using the annotation on a java.lang.String type,
the intercepted method's toString value is injected. The same holds for a parameter of type int that receives
the modifiers of the instrumented method.org.easymock.bytebuddy.implementation.bind.annotation.StubValue : Assigns the (boxed) default value of the
intercepted method's return type to the parameter. If the return type is void, null is assigned.org.easymock.bytebuddy.implementation.bind.annotation.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.org.easymock.bytebuddy.implementation.bind.annotation.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 the org.easymock.bytebuddy.implementation.bind.annotation.Pipe
annotation's documentation for further information on how this can be done.org.easymock.bytebuddy.implementation.bind.annotation.Morph : The morph annotation is similar to
the org.easymock.bytebuddy.implementation.bind.annotation.SuperCall 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.org.easymock.bytebuddy.implementation.bind.annotation.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.org.easymock.bytebuddy.implementation.bind.annotation.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 of org.easymock.bytebuddy.implementation.FieldAccessor in
combination with org.easymock.bytebuddy.implementation.MethodDelegation#andThen(Implementation) might be a more
performant alternative for implementing field getters and setters.org.easymock.bytebuddy.implementation.bind.annotation.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
org.easymock.bytebuddy.implementation.bind.annotation.RuntimeType
annotation can instruct a parameter to be bound by a
org.easymock.bytebuddy.implementation.bytecode.assign.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:
org.easymock.bytebuddy.implementation.bind.annotation.BindingPriority :
A method that is annotated with this annotation is given a specific priority where the default priority is set
to org.easymock.bytebuddy.implementation.bind.annotation.BindingPriority#DEFAULT
for non-annotated method. A method with a higher priority is considered a better target for delegation.org.easymock.bytebuddy.implementation.bind.DeclaringTypeResolver :
If a target method is declared by a more specific type than another method, the method with the most specific
type is bound.org.easymock.bytebuddy.implementation.bind.MethodNameEqualityResolver :
If a source method Baz#qux is the source method, it will rather be assigned to Foo#qux because
of their equal names. Similar names and case-insensitive equality are not considered.org.easymock.bytebuddy.implementation.bind.ArgumentTypeResolver :
The most specific type resolver will consider all bindings that are using the
org.easymock.bytebuddy.implementation.bind.annotation.Argument
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 method Bar#baz(String)
will rather be bound to a method Foo#bar(String) than Foo#qux(Object) because the String
type is more specific than the Object 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.org.easymock.bytebuddy.implementation.bind.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
org.,
it is never considered as a target for a method delegation.
Important Note
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.
MethodCall, net.bytebuddy.implementation.bind.annotation.TargetMethodAnnotationDrivenBinder.ParameterBinder.ForFixedValue
| Modifier and Type | Class and Description |
|---|---|
| protected static class | MethodDelegation.
The appender for implementing a |
| protected static interface | MethodDelegation.
An implementation delegate is responsible for executing the actual method delegation and for resolving the target methods. |
| public static class | MethodDelegation.
A |
| Modifier and Type | Field and Description |
|---|---|
| private final MethodDelegationBinder. | ambiguityResolver
The |
| private final Assigner | assigner
The |
| 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 | parameterBinders
A list of |
| private final MethodDelegationBinder. | terminationHandler
The termination handler to apply. |
| Access | Constructor and Description |
|---|---|
| protected | MethodDelegation(MethodDelegation.
The implementation delegate to use by this method delegator. implementationDelegate,The parameter binders to use by this method delegator. parameterBinders,The ambiguity resolver to use by this method delegator. ambiguityResolver,The binding resolver being used to select the relevant method binding. bindingResolverCreates a new method delegation. |
| private | MethodDelegation(MethodDelegation.
The implementation delegate to use by this method delegator. implementationDelegate,The parameter binders to use by this method delegator. parameterBinders,The ambiguity resolver to use by this method delegator. ambiguityResolver,The termination handler to apply. terminationHandler,The binding resolver being used to select the relevant method binding. bindingResolver,The assigner to be supplied by this method delegator. assigner)Creates a new method delegation. |
| Modifier and Type | Method and Description |
|---|---|
| public Implementation | andThen(Implementation
The subsequent implementation. implementation)Implements org. |
| public Implementation. | andThen(Implementation.
The subsequent composable implementation. implementationImplements org. |
| public ByteCodeAppender | appender(Implementation.
The target of the current implementation. implementationTargetImplements org. |
| public InstrumentedType | prepare(InstrumentedType
The instrumented type in its current form. instrumentedType)Implements org. |
| public static MethodDelegation | |
| public static MethodDelegation | Returns: A method delegation that redirects method calls to a static method of the supplied type.The target type for the delegation. typeDescription)Delegates any intercepted method to invoke a |
| public static MethodDelegation | |
| public static MethodDelegation | Returns: A method delegation that redirects method calls to a static method of the supplied type.The target instance for the delegation. target, MethodGraph.The method graph compiler to use. methodGraphCompilerDelegates any intercepted method to invoke a non- |
| public static MethodDelegation | Returns: A method delegation that redirects method calls to a static method of the supplied type.The target instance for the delegation. target, String The name of the field that is holding the fieldName)target instance.Delegates any intercepted method to invoke a non- |
| public static MethodDelegation | Returns: A method delegation that redirects method calls to a static method of the supplied type.The target instance for the delegation. target, String The name of the field that is holding the fieldName, MethodGraph.target instance.The method graph compiler to use. methodGraphCompilerDelegates any intercepted method to invoke a non- |
| public static MethodDelegation | Returns: A method delegation that redirects method calls to a static method of the supplied type.The target instance for the delegation. target, Type The most specific type of which type)target should be considered. Must be a super type of the target's actual type.Delegates any intercepted method to invoke a non- |
| public static MethodDelegation | Returns: A method delegation that redirects method calls to a static method of the supplied type.The target instance for the delegation. target, Type The most specific type of which type, MethodGraph.target should be considered. Must be a super type of the target's actual type.The method graph compiler to use. methodGraphCompilerDelegates any intercepted method to invoke a non- |
| public static MethodDelegation | Returns: A method delegation that redirects method calls to a static method of the supplied type.The target instance for the delegation. target, Type The most specific type of which type, String target should be considered. Must be a super type of the target's actual type.The name of the field that is holding the fieldName)target instance.Delegates any intercepted method to invoke a non- |
| public static MethodDelegation | Returns: A method delegation that redirects method calls to a static method of the supplied type.The target instance for the delegation. target, Type The most specific type of which type, String target should be considered. Must be a super type of the target's actual type.The name of the field that is holding the fieldName, MethodGraph.target instance.The method graph compiler to use. methodGraphCompilerDelegates any intercepted method to invoke a non- |
| public static MethodDelegation | Returns: A method delegation that redirects method calls to a static method of the supplied type.The target instance for the delegation. target, TypeDefinition The most specific type of which typeDefinition)target should be considered. Must be a super type of the target's actual type.Delegates any intercepted method to invoke a non- |
| public static MethodDelegation | Returns: A method delegation that redirects method calls to a static method of the supplied type.The target instance for the delegation. target, TypeDefinition The most specific type of which typeDefinition, MethodGraph.target should be considered. Must be a super type of the target's actual type.The method graph compiler to use. methodGraphCompilerDelegates any intercepted method to invoke a non- |
| public static MethodDelegation | Returns: A method delegation that redirects method calls to a static method of the supplied type.The target instance for the delegation. target, TypeDefinition The most specific type of which typeDefinition, String target should be considered. Must be a super type of the target's actual type.The name of the field that is holding the fieldName)target instance.Delegates any intercepted method to invoke a non- |
| public static MethodDelegation | Returns: A method delegation that redirects method calls to a static method of the supplied type.The target instance for the delegation. target, TypeDefinition The most specific type of which typeDefinition, String target should be considered. Must be a super type of the target's actual type.The name of the field that is holding the fieldName, MethodGraph.target instance.The method graph compiler to use. methodGraphCompilerDelegates any intercepted method to invoke a non- |
| public static MethodDelegation | Returns: A delegation that redirects method calls to a constructor of the supplied type.The type to construct. type)Delegates any intercepted method to invoke a constructor of the supplied type. |
| public static MethodDelegation | Returns: A delegation that redirects method calls to a constructor of the supplied type.The type to construct. typeDescription)Delegates any intercepted method to invoke a constructor of the supplied type. |
| public static MethodDelegation | |
| public static MethodDelegation | Returns: A delegation that redirects invocations to a method of the specified field's instance.The field's name. name, FieldLocator.The field locator factory to use. fieldLocatorFactoryDelegates any intercepted method to invoke a non- |
| public static MethodDelegation | Returns: A delegation that redirects invocations to a method of the specified field's instance.The field's name. name, MethodGraph.The method graph compiler to use. methodGraphCompilerDelegates any intercepted method to invoke a non- |
| public static MethodDelegation | Returns: A delegation that redirects invocations to a method of the specified field's instance.The field's name. name, FieldLocator.The field locator factory to use. fieldLocatorFactory,The method graph compiler to use. methodGraphCompilerDelegates any intercepted method to invoke a non- |
| public static MethodDelegation | Returns: A delegation that redirects invocations to the return value of a method that is declared by the instrumented type.The name of the method that returns the delegation target. name)Delegates any intercepted method to invoke a method on an instance that is returned by a parameterless method of the given name. |
| public static MethodDelegation | Returns: A delegation that redirects invocations to the return value of a method that is declared by the instrumented type.The name of the method that returns the delegation target. name, MethodGraph.The method graph compiler to use. methodGraphCompilerDelegates any intercepted method to invoke a method on an instance that is returned by a parameterless method of the given name. |
| public Implementation. | Returns: A method delegation implementation that makes use of the given designer.The assigner to apply. assigner)Applies an assigner to the method delegation that is used for assigning method return and parameter types. |
| public static MethodDelegation. | Returns: A method delegation configuration with pre-configuration.Creates a configuration builder for a method delegation that is pre-configured with the ambiguity resolvers defined by
|
| public static MethodDelegation. | Returns: A method delegation configuration without any pre-configuration.Creates a configuration builder for a method delegation that does not apply any pre-configured
|