Package net.bytebuddy.implementation
Class MethodDelegation.WithCustomProperties
java.lang.Object
net.bytebuddy.implementation.MethodDelegation.WithCustomProperties
- Enclosing class:
MethodDelegation
A
MethodDelegation
with custom configuration.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final MethodDelegationBinder.AmbiguityResolver
The ambiguity resolver to use.private final MethodDelegationBinder.BindingResolver
The binding resolver being used to select the relevant method binding.private final ElementMatcher
<? super MethodDescription> The matcher to use for filtering relevant methods.private final List
<TargetMethodAnnotationDrivenBinder.ParameterBinder<?>> The parameter binders to use. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
WithCustomProperties
(MethodDelegationBinder.AmbiguityResolver ambiguityResolver, List<TargetMethodAnnotationDrivenBinder.ParameterBinder<?>> parameterBinders) Creates a new method delegation with custom properties that does not filter any methods.private
WithCustomProperties
(MethodDelegationBinder.AmbiguityResolver ambiguityResolver, List<TargetMethodAnnotationDrivenBinder.ParameterBinder<?>> parameterBinders, MethodDelegationBinder.BindingResolver bindingResolver, ElementMatcher<? super MethodDescription> matcher) Creates a new method delegation with custom properties. -
Method Summary
Modifier and TypeMethodDescriptionfilter
(ElementMatcher<? super MethodDescription> matcher) Configures this method delegation to only consider methods or constructors as a delegation target if they match the supplied matcher.Delegates any intercepted method to invoke astatic
method that is declared by the supplied type.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.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.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
(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
(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.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
(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
(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.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.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
(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
(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.to
(TypeDescription typeDescription) Delegates any intercepted method to invoke astatic
method that is declared by the supplied type.toConstructor
(Class<?> type) Delegates any intercepted method to invoke a constructor of the supplied type.toConstructor
(TypeDescription typeDescription) Delegates any intercepted method to invoke a constructor of the supplied type.Delegates any intercepted method to invoke a non-static
method on the instance of the supplied field.toField
(String name, FieldLocator.Factory fieldLocatorFactory) Delegates any intercepted method to invoke a non-static
method on the instance of the supplied field.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.toField
(String name, MethodGraph.Compiler methodGraphCompiler) Delegates any intercepted method to invoke a non-static
method on the instance of the supplied field.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.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.withBinders
(List<? extends TargetMethodAnnotationDrivenBinder.ParameterBinder<?>> parameterBinders) Configures this method delegation to use the supplied parameter binders when deciding what value to assign to a parameter of a delegation target.withBinders
(TargetMethodAnnotationDrivenBinder.ParameterBinder<?>... parameterBinder) Configures this method delegation to use the supplied parameter binders when deciding what value to assign to a parameter of a delegation target.withBindingResolver
(MethodDelegationBinder.BindingResolver bindingResolver) Configures a custom binding resolver which is responsible for choosing a method binding among multiple candidates.withResolvers
(List<? extends MethodDelegationBinder.AmbiguityResolver> ambiguityResolvers) Configures this method delegation to use the supplied ambiguity resolvers when deciding which out of two ore more legal delegation targets should be considered.withResolvers
(MethodDelegationBinder.AmbiguityResolver... ambiguityResolver) Configures this method delegation to use the supplied ambiguity resolvers when deciding which out of two ore more legal delegation targets should be considered.
-
Field Details
-
ambiguityResolver
The ambiguity resolver to use. -
parameterBinders
The parameter binders to use. -
bindingResolver
The binding resolver being used to select the relevant method binding. -
matcher
The matcher to use for filtering relevant methods.
-
-
Constructor Details
-
WithCustomProperties
protected WithCustomProperties(MethodDelegationBinder.AmbiguityResolver ambiguityResolver, List<TargetMethodAnnotationDrivenBinder.ParameterBinder<?>> parameterBinders) Creates a new method delegation with custom properties that does not filter any methods.- Parameters:
ambiguityResolver
- The ambiguity resolver to use.parameterBinders
- The parameter binders to use.
-
WithCustomProperties
private WithCustomProperties(MethodDelegationBinder.AmbiguityResolver ambiguityResolver, List<TargetMethodAnnotationDrivenBinder.ParameterBinder<?>> parameterBinders, MethodDelegationBinder.BindingResolver bindingResolver, ElementMatcher<? super MethodDescription> matcher) Creates a new method delegation with custom properties.- Parameters:
ambiguityResolver
- The ambiguity resolver to use.parameterBinders
- The parameter binders to use.bindingResolver
- The binding resolver being used to select the relevant method binding.matcher
- The matcher to use for filtering relevant methods.
-
-
Method Details
-
withResolvers
public MethodDelegation.WithCustomProperties withResolvers(MethodDelegationBinder.AmbiguityResolver... ambiguityResolver) Configures this method delegation to use the supplied ambiguity resolvers when deciding which out of two ore more legal delegation targets should be considered.- Parameters:
ambiguityResolver
- The ambiguity resolvers to use in their application order.- Returns:
- A new delegation configuration which also applies the supplied ambiguity resolvers.
-
withResolvers
public MethodDelegation.WithCustomProperties withResolvers(List<? extends MethodDelegationBinder.AmbiguityResolver> ambiguityResolvers) Configures this method delegation to use the supplied ambiguity resolvers when deciding which out of two ore more legal delegation targets should be considered.- Parameters:
ambiguityResolvers
- The ambiguity resolvers to use in their application order.- Returns:
- A new delegation configuration which also applies the supplied ambiguity resolvers.
-
withBinders
public MethodDelegation.WithCustomProperties withBinders(TargetMethodAnnotationDrivenBinder.ParameterBinder<?>... parameterBinder) Configures this method delegation to use the supplied parameter binders when deciding what value to assign to a parameter of a delegation target.- Parameters:
parameterBinder
- The parameter binders to use.- Returns:
- A new delegation configuration which also applies the supplied parameter binders.
-
withBinders
public MethodDelegation.WithCustomProperties withBinders(List<? extends TargetMethodAnnotationDrivenBinder.ParameterBinder<?>> parameterBinders) Configures this method delegation to use the supplied parameter binders when deciding what value to assign to a parameter of a delegation target.- Parameters:
parameterBinders
- The parameter binders to use.- Returns:
- A new delegation configuration which also applies the supplied parameter binders.
-
withBindingResolver
public MethodDelegation.WithCustomProperties withBindingResolver(MethodDelegationBinder.BindingResolver bindingResolver) Configures a custom binding resolver which is responsible for choosing a method binding among multiple candidates. Configuring a resolver overrides any previous configuration.- Parameters:
bindingResolver
- The binding resolver being used to select the relevant method binding.- Returns:
- A new delegation configuration which applies the supplied binding resolver.
-
filter
public MethodDelegation.WithCustomProperties filter(ElementMatcher<? super MethodDescription> matcher) Configures this method delegation to only consider methods or constructors as a delegation target if they match the supplied matcher.- Parameters:
matcher
- The matcher any delegation target needs to match in order to be considered a for delegation.- Returns:
- A new delegation configuration which only considers methods for delegation if they match the supplied matcher.
-
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 delegation 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 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
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 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 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 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 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
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.
-