Package net.bytebuddy.dynamic
Class DynamicType.Builder.AbstractBase.Adapter.MethodDefinitionAdapter
- java.lang.Object
-
- net.bytebuddy.dynamic.DynamicType.Builder.MethodDefinition.ImplementationDefinition.AbstractBase<V>
-
- net.bytebuddy.dynamic.DynamicType.Builder.MethodDefinition.TypeVariableDefinition.AbstractBase<V>
-
- net.bytebuddy.dynamic.DynamicType.Builder.MethodDefinition.ExceptionDefinition.AbstractBase<V>
-
- net.bytebuddy.dynamic.DynamicType.Builder.MethodDefinition.ParameterDefinition.AbstractBase<W>
-
- net.bytebuddy.dynamic.DynamicType.Builder.MethodDefinition.ParameterDefinition.Initial.AbstractBase<U>
-
- net.bytebuddy.dynamic.DynamicType.Builder.AbstractBase.Adapter.MethodDefinitionAdapter
-
- All Implemented Interfaces:
DynamicType.Builder.MethodDefinition.ExceptionDefinition<U>
,DynamicType.Builder.MethodDefinition.ImplementationDefinition<U>
,DynamicType.Builder.MethodDefinition.ParameterDefinition<U>
,DynamicType.Builder.MethodDefinition.ParameterDefinition.Initial<U>
,DynamicType.Builder.MethodDefinition.ParameterDefinition.Simple<U>
,DynamicType.Builder.MethodDefinition.TypeVariableDefinition<U>
- Enclosing class:
- DynamicType.Builder.AbstractBase.Adapter<U>
@Enhance(includeSyntheticFields=true) protected class DynamicType.Builder.AbstractBase.Adapter.MethodDefinitionAdapter extends DynamicType.Builder.MethodDefinition.ParameterDefinition.Initial.AbstractBase<U>
An adapter for defining a new method.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
DynamicType.Builder.AbstractBase.Adapter.MethodDefinitionAdapter.AnnotationAdapter
An annotation adapter for a method definition.protected class
DynamicType.Builder.AbstractBase.Adapter.MethodDefinitionAdapter.ParameterAnnotationAdapter
An annotation adapter for a parameter definition.protected class
DynamicType.Builder.AbstractBase.Adapter.MethodDefinitionAdapter.SimpleParameterAnnotationAdapter
An annotation adapter for a simple parameter definition.protected class
DynamicType.Builder.AbstractBase.Adapter.MethodDefinitionAdapter.TypeVariableAnnotationAdapter
An adapter for defining a new type variable for the currently defined method.-
Nested classes/interfaces inherited from interface net.bytebuddy.dynamic.DynamicType.Builder.MethodDefinition.ExceptionDefinition
DynamicType.Builder.MethodDefinition.ExceptionDefinition.AbstractBase<V>
-
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>
-
Nested classes/interfaces inherited from interface net.bytebuddy.dynamic.DynamicType.Builder.MethodDefinition.ParameterDefinition
DynamicType.Builder.MethodDefinition.ParameterDefinition.AbstractBase<V>, DynamicType.Builder.MethodDefinition.ParameterDefinition.Annotatable<V>, DynamicType.Builder.MethodDefinition.ParameterDefinition.Initial<V>, DynamicType.Builder.MethodDefinition.ParameterDefinition.Simple<V>
-
Nested classes/interfaces inherited from interface net.bytebuddy.dynamic.DynamicType.Builder.MethodDefinition.ParameterDefinition.Initial
DynamicType.Builder.MethodDefinition.ParameterDefinition.Initial.AbstractBase<W>
-
Nested classes/interfaces inherited from interface net.bytebuddy.dynamic.DynamicType.Builder.MethodDefinition.ParameterDefinition.Simple
DynamicType.Builder.MethodDefinition.ParameterDefinition.Simple.Annotatable<V>
-
Nested classes/interfaces inherited from interface net.bytebuddy.dynamic.DynamicType.Builder.MethodDefinition.TypeVariableDefinition
DynamicType.Builder.MethodDefinition.TypeVariableDefinition.AbstractBase<V>, DynamicType.Builder.MethodDefinition.TypeVariableDefinition.Annotatable<V>
-
-
Field Summary
Fields Modifier and Type Field Description private MethodDescription.Token
token
A token representing the currently defined method.
-
Constructor Summary
Constructors Modifier Constructor Description protected
MethodDefinitionAdapter(MethodDescription.Token token)
Creates a new method definition 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 given handler as the implementation.DynamicType.Builder.MethodDefinition.ExceptionDefinition<U>
throwing(java.util.Collection<? extends TypeDefinition> types)
Defines a method variable to be declared by the currently defined method.DynamicType.Builder.MethodDefinition.TypeVariableDefinition.Annotatable<U>
typeVariable(java.lang.String symbol, java.util.Collection<? extends TypeDefinition> bounds)
Defines a method variable to be declared by the currently defined method.DynamicType.Builder.MethodDefinition.ReceiverTypeDefinition<U>
withoutCode()
Defines the previously defined or matched method not to declare a method body.DynamicType.Builder.MethodDefinition.ParameterDefinition.Simple.Annotatable<U>
withParameter(TypeDefinition type)
Defines the specified parameter for the currently defined method as the last parameter of the currently defined method.DynamicType.Builder.MethodDefinition.ParameterDefinition.Annotatable<U>
withParameter(TypeDefinition type, java.lang.String name, int modifiers)
Defines the specified parameter for the currently defined method as the last parameter of the currently defined method.-
Methods inherited from class net.bytebuddy.dynamic.DynamicType.Builder.MethodDefinition.ParameterDefinition.Initial.AbstractBase
withParameter, withParameters, withParameters, withParameters, withParameters
-
Methods inherited from class net.bytebuddy.dynamic.DynamicType.Builder.MethodDefinition.ParameterDefinition.AbstractBase
withParameter, withParameter, withParameter, withParameter, withParameter
-
Methods inherited from class net.bytebuddy.dynamic.DynamicType.Builder.MethodDefinition.ExceptionDefinition.AbstractBase
throwing, throwing, throwing
-
Methods inherited from class net.bytebuddy.dynamic.DynamicType.Builder.MethodDefinition.TypeVariableDefinition.AbstractBase
typeVariable, typeVariable, typeVariable, typeVariable
-
Methods inherited from class net.bytebuddy.dynamic.DynamicType.Builder.MethodDefinition.ImplementationDefinition.AbstractBase
defaultValue
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.bytebuddy.dynamic.DynamicType.Builder.MethodDefinition.ExceptionDefinition
throwing, throwing, throwing
-
Methods inherited from interface net.bytebuddy.dynamic.DynamicType.Builder.MethodDefinition.ImplementationDefinition
defaultValue
-
Methods inherited from interface net.bytebuddy.dynamic.DynamicType.Builder.MethodDefinition.ParameterDefinition
withParameter, withParameter, withParameter, withParameter, withParameter
-
Methods inherited from interface net.bytebuddy.dynamic.DynamicType.Builder.MethodDefinition.TypeVariableDefinition
typeVariable, typeVariable, typeVariable, typeVariable
-
-
-
-
Field Detail
-
token
private final MethodDescription.Token token
A token representing the currently defined method.
-
-
Constructor Detail
-
MethodDefinitionAdapter
protected MethodDefinitionAdapter(MethodDescription.Token token)
Creates a new method definition adapter.- Parameters:
token
- A token representing the currently defined method.
-
-
Method Detail
-
withParameter
public DynamicType.Builder.MethodDefinition.ParameterDefinition.Annotatable<U> withParameter(TypeDefinition type, java.lang.String name, int modifiers)
Defines the specified parameter for the currently defined method as the last parameter of the currently defined method.- Parameters:
type
- The parameter's type. Can also beTargetType
if the parameter type should be equal to the currently instrumented type.name
- The parameter's name.modifiers
- The parameter's modifiers.- Returns:
- A new builder that is equal to the current builder but where the currently defined method appends the specified parameter.
-
withParameter
public DynamicType.Builder.MethodDefinition.ParameterDefinition.Simple.Annotatable<U> withParameter(TypeDefinition type)
Defines the specified parameter for the currently defined method as the last parameter of the currently defined method.- Parameters:
type
- The parameter's type. Can also beTargetType
if the parameter type should be equal to the currently instrumented type.- Returns:
- A new builder that is equal to the current builder but where the currently defined method appends the specified parameter.
-
throwing
public DynamicType.Builder.MethodDefinition.ExceptionDefinition<U> throwing(java.util.Collection<? extends TypeDefinition> types)
Defines a method variable to be declared by the currently defined method.- Parameters:
types
- The type of the exception being declared by the currently defined method.- Returns:
- A new builder that is equal to the current builder but where the currently defined method declares the specified exception type.
-
typeVariable
public DynamicType.Builder.MethodDefinition.TypeVariableDefinition.Annotatable<U> typeVariable(java.lang.String symbol, java.util.Collection<? extends TypeDefinition> bounds)
Defines a method variable to be declared by the currently defined method.- Parameters:
symbol
- The symbol of the type variable.bounds
- The bounds of the type variables. Can also beTargetType
for any type if a bound type should be equal to the currently instrumented type.- Returns:
- A new builder that is equal to the current builder but where the currently defined method declares the specified type variable.
-
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 given handler as the implementation.- Parameters:
handler
- The handler for implementing the method.- Returns:
- A method definition for the given handler.
-
-