Package net.bytebuddy.dynamic
Class DynamicType.Builder.AbstractBase.Adapter.MethodMatchAdapter
- java.lang.Object
-
- net.bytebuddy.dynamic.DynamicType.Builder.MethodDefinition.ImplementationDefinition.AbstractBase<U>
-
- net.bytebuddy.dynamic.DynamicType.Builder.AbstractBase.Adapter.MethodMatchAdapter
-
- All Implemented Interfaces:
DynamicType.Builder.MethodDefinition.ImplementationDefinition<U>
- Enclosing class:
- DynamicType.Builder.AbstractBase.Adapter<U>
@Enhance(includeSyntheticFields=true) protected class DynamicType.Builder.AbstractBase.Adapter.MethodMatchAdapter extends DynamicType.Builder.MethodDefinition.ImplementationDefinition.AbstractBase<U>
An adapter for matching an existing method.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
DynamicType.Builder.AbstractBase.Adapter.MethodMatchAdapter.AnnotationAdapter
An annotation adapter for implementing annotations during a method definition.-
Nested classes/interfaces inherited from interface net.bytebuddy.dynamic.DynamicType.Builder.MethodDefinition.ImplementationDefinition
DynamicType.Builder.MethodDefinition.ImplementationDefinition.AbstractBase<V>, DynamicType.Builder.MethodDefinition.ImplementationDefinition.Optional<V>
-
-
Field Summary
Fields Modifier and Type Field Description private LatentMatcher<? super MethodDescription>
matcher
The method matcher of this adapter.
-
Constructor Summary
Constructors Modifier Constructor Description protected
MethodMatchAdapter(LatentMatcher<? super MethodDescription> matcher)
Creates a new method match adapter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DynamicType.Builder.MethodDefinition.ReceiverTypeDefinition<U>
defaultValue(AnnotationValue<?,?> annotationValue)
Defines the previously defined or matched method to return the supplied value as an annotation default value.DynamicType.Builder.MethodDefinition.ReceiverTypeDefinition<U>
intercept(Implementation implementation)
Implements the previously defined or matched method by the supplied implementation.private DynamicType.Builder.MethodDefinition.ReceiverTypeDefinition<U>
materialize(MethodRegistry.Handler handler)
Materializes the method definition with the supplied handler.DynamicType.Builder.MethodDefinition.ReceiverTypeDefinition<U>
withoutCode()
Defines the previously defined or matched method not to declare a method body.-
Methods inherited from class net.bytebuddy.dynamic.DynamicType.Builder.MethodDefinition.ImplementationDefinition.AbstractBase
defaultValue
-
-
-
-
Field Detail
-
matcher
private final LatentMatcher<? super MethodDescription> matcher
The method matcher of this adapter.
-
-
Constructor Detail
-
MethodMatchAdapter
protected MethodMatchAdapter(LatentMatcher<? super MethodDescription> matcher)
Creates a new method match adapter.- Parameters:
matcher
- The method matcher of this adapter.
-
-
Method Detail
-
intercept
public DynamicType.Builder.MethodDefinition.ReceiverTypeDefinition<U> intercept(Implementation implementation)
Implements the previously defined or matched method by the supplied implementation. A method interception is typically implemented in one of the following ways:- If a method is declared by the instrumented type and the type builder creates a subclass or redefinition, any preexisting method is replaced by the given implementation. Any previously defined implementation is lost.
- If a method is declared by the instrumented type and the type builder creates a rebased version of the instrumented type, the original method is preserved within a private, synthetic method within the instrumented type. The original method therefore remains invokeable and is treated as the direct super method of the new method. When rebasing a type, it therefore becomes possible to invoke a non-virtual method's super method when a preexisting method body is replaced.
- If a virtual method is inherited from a super type, it is overridden. The overridden method is available for super method invocation.
- Parameters:
implementation
- The implementation for implementing the previously defined or matched method.- Returns:
- A new builder where the previously defined or matched method is implemented by the supplied implementation.
-
withoutCode
public DynamicType.Builder.MethodDefinition.ReceiverTypeDefinition<U> withoutCode()
Defines the previously defined or matched method not to declare a method body. This implies the method to beabstract
unless it was already declared to benative
.- Returns:
- A new builder where the previously defined or matched method is implemented to be abstract.
-
defaultValue
public DynamicType.Builder.MethodDefinition.ReceiverTypeDefinition<U> defaultValue(AnnotationValue<?,?> annotationValue)
Defines the previously defined or matched method to return the supplied value as an annotation default value. The value must be supplied in its unloaded state, i.e. enumerations asEnumerationDescription
, types asTypeDescription
and annotations asAnnotationDescription
. For supplying loaded types, useDynamicType.Builder.MethodDefinition.ImplementationDefinition.defaultValue(Object, Class)
must be used.- Parameters:
annotationValue
- The value to be defined as a default value.- Returns:
- A builder where the previously defined or matched method is implemented to return an annotation default value.
-
materialize
private DynamicType.Builder.MethodDefinition.ReceiverTypeDefinition<U> materialize(MethodRegistry.Handler handler)
Materializes the method definition with the supplied handler.- Parameters:
handler
- The handler that implements any method matched by this instances matcher.- Returns:
- A method definition where any matched method is implemented by the supplied handler.
-
-