Class DynamicType.Builder.AbstractBase.Delegator<U>
- java.lang.Object
-
- net.bytebuddy.dynamic.DynamicType.Builder.AbstractBase<U>
-
- net.bytebuddy.dynamic.DynamicType.Builder.AbstractBase.Delegator<U>
-
- Type Parameters:
U
- A loaded type that the built type is guaranteed to be a subclass of.
- All Implemented Interfaces:
DynamicType.Builder<U>
- Direct Known Subclasses:
DynamicType.Builder.AbstractBase.Adapter.InnerTypeDefinitionForMethodAdapter
,DynamicType.Builder.AbstractBase.Adapter.InnerTypeDefinitionForTypeAdapter
,DynamicType.Builder.AbstractBase.Adapter.OptionalMethodMatchAdapter
,DynamicType.Builder.FieldDefinition.Optional.AbstractBase
,DynamicType.Builder.MethodDefinition.AbstractBase
,DynamicType.Builder.RecordComponentDefinition.Optional.AbstractBase
,DynamicType.Builder.TypeVariableDefinition.AbstractBase
- Enclosing class:
- DynamicType.Builder.AbstractBase<S>
public abstract static class DynamicType.Builder.AbstractBase.Delegator<U> extends DynamicType.Builder.AbstractBase<U>
A delegator for a dynamic type builder delegating all invocations to another dynamic type builder.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class net.bytebuddy.dynamic.DynamicType.Builder.AbstractBase
DynamicType.Builder.AbstractBase.Adapter<U>, DynamicType.Builder.AbstractBase.Delegator<U>
-
Nested classes/interfaces inherited from interface net.bytebuddy.dynamic.DynamicType.Builder
DynamicType.Builder.AbstractBase<S>, DynamicType.Builder.FieldDefinition<S>, DynamicType.Builder.InnerTypeDefinition<S>, DynamicType.Builder.MethodDefinition<S>, DynamicType.Builder.RecordComponentDefinition<S>, DynamicType.Builder.TypeVariableDefinition<S>
-
-
Constructor Summary
Constructors Constructor Description Delegator()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description DynamicType.Builder<U>
annotateType(java.util.Collection<? extends AnnotationDescription> annotations)
Annotates the instrumented type with the supplied annotations.DynamicType.Builder<U>
attribute(TypeAttributeAppender typeAttributeAppender)
Applies the given type attribute appender onto the instrumented type.DynamicType.Builder<U>
declaredTypes(java.util.Collection<? extends TypeDescription> types)
Defines this type as an the outer type of the supplied types.DynamicType.Builder.RecordComponentDefinition.Optional<U>
define(RecordComponentDescription recordComponentDescription)
Defines a new record component.DynamicType.Builder.MethodDefinition.ParameterDefinition.Initial<U>
defineConstructor(int modifiers)
Defines the specified constructor to be declared by the instrumented type.DynamicType.Builder.FieldDefinition.Optional.Valuable<U>
defineField(java.lang.String name, TypeDefinition type, int modifiers)
Defines the specified field as a field of the built dynamic type.DynamicType.Builder.MethodDefinition.ParameterDefinition.Initial<U>
defineMethod(java.lang.String name, TypeDefinition returnType, int modifiers)
Defines the specified method to be declared by the instrumented type.DynamicType.Builder.RecordComponentDefinition.Optional<U>
defineRecordComponent(java.lang.String name, TypeDefinition type)
Defines a new record component.DynamicType.Builder.FieldDefinition.Valuable<U>
field(LatentMatcher<? super FieldDescription> matcher)
Matches a field that is already declared by the instrumented type.DynamicType.Builder<U>
ignoreAlso(ElementMatcher<? super MethodDescription> ignoredMethods)
Specifies to exclude any method that is matched by the supplied matcher from instrumentation.DynamicType.Builder<U>
ignoreAlso(LatentMatcher<? super MethodDescription> ignoredMethods)
Specifies to exclude any method that is matched by the supplied matcher from instrumentation.DynamicType.Builder.MethodDefinition.ImplementationDefinition.Optional<U>
implement(java.util.Collection<? extends TypeDefinition> interfaceTypes)
Implements the supplied interfaces for the instrumented type.DynamicType.Builder<U>
initializer(ByteCodeAppender byteCodeAppender)
Executes the supplied byte code appender within the beginning of the instrumented type's type initializer.DynamicType.Builder<U>
initializer(LoadedTypeInitializer loadedTypeInitializer)
Executes the supplied loaded type initializer when loading the created instrumented type.DynamicType.Builder.InnerTypeDefinition<U>
innerTypeOf(MethodDescription.InDefinedShape methodDescription)
Defines this type as an inner type that was declared within the supplied method or constructor.DynamicType.Builder.InnerTypeDefinition.ForType<U>
innerTypeOf(TypeDescription type)
Defines this type as an inner type of the supplied type.DynamicType.Builder.MethodDefinition.ImplementationDefinition<U>
invokable(LatentMatcher<? super MethodDescription> matcher)
Matches a method or constructor that is already declared or inherited by the instrumented type.DynamicType.Unloaded<U>
make()
Creates the dynamic type this builder represents.DynamicType.Unloaded<U>
make(TypeResolutionStrategy typeResolutionStrategy)
Creates the dynamic type this builder represents.DynamicType.Unloaded<U>
make(TypeResolutionStrategy typeResolutionStrategy, TypePool typePool)
Creates the dynamic type this builder represents.DynamicType.Unloaded<U>
make(TypePool typePool)
Creates the dynamic type this builder represents.protected abstract DynamicType.Builder<U>
materialize()
Creates a new builder that realizes the current state of the builder.DynamicType.Builder<U>
merge(java.util.Collection<? extends ModifierContributor.ForType> modifierContributors)
Merges the supplied modifier contributors with the modifiers of the instrumented type and defines them as the instrumented type's new modifiers.DynamicType.Builder<U>
modifiers(int modifiers)
Defines the supplied modifiers as the modifiers of the instrumented type.DynamicType.Builder<U>
name(java.lang.String name)
Names the dynamic type by the supplied name.DynamicType.Builder<U>
nestHost(TypeDescription type)
Defines this type as a nest member of the supplied type as a nest host.DynamicType.Builder<U>
nestMembers(java.util.Collection<? extends TypeDescription> types)
Defines this type as a nest host for the supplied types.DynamicType.Builder<U>
permittedSubclass(java.util.Collection<? extends TypeDescription> types)
Defines this type to allow the supplied permitted subclasses additionally to any prior permitted subclasses.DynamicType.Builder.RecordComponentDefinition<U>
recordComponent(ElementMatcher<? super RecordComponentDescription> matcher)
Matches a record component that is already declared by the instrumented type.DynamicType.Builder.RecordComponentDefinition<U>
recordComponent(LatentMatcher<? super RecordComponentDescription> matcher)
Matches a record component that is already declared by the instrumented type.DynamicType.Builder<U>
require(java.util.Collection<DynamicType> auxiliaryTypes)
Explicitly requires other dynamic types for the creation of this type.DynamicType.Builder<U>
suffix(java.lang.String suffix)
Adds a suffix to the current type name without changing the type's package.DynamicType.Builder<U>
topLevelType()
Defines this type as a top-level type that is not declared by another type or enclosed by another member.TypeDescription
toTypeDescription()
Returns aTypeDescription
for the currently built type.DynamicType.Builder<U>
transform(ElementMatcher<? super TypeDescription.Generic> matcher, Transformer<TypeVariableToken> transformer)
Transforms any type variable that is defined by this type if it is matched by the supplied matcher.DynamicType.Builder.TypeVariableDefinition<U>
typeVariable(java.lang.String symbol, java.util.Collection<? extends TypeDefinition> bounds)
Defines the supplied type variable with the given bound as a type variable of the instrumented type.DynamicType.Builder<U>
unsealed()
Unseales this type.DynamicType.Builder<U>
visit(AsmVisitorWrapper asmVisitorWrapper)
Applies the suppliedAsmVisitorWrapper
onto theClassVisitor
during building a dynamic type.-
Methods inherited from class net.bytebuddy.dynamic.DynamicType.Builder.AbstractBase
annotateType, annotateType, annotateType, constructor, declaredTypes, declaredTypes, declaredTypes, define, define, define, define, define, defineConstructor, defineConstructor, defineField, defineField, defineField, defineField, defineField, defineMethod, defineMethod, defineMethod, defineMethod, defineMethod, defineProperty, defineProperty, defineProperty, defineProperty, defineRecordComponent, field, implement, implement, implement, innerTypeOf, innerTypeOf, innerTypeOf, invokable, merge, method, modifiers, modifiers, nestHost, nestMembers, nestMembers, nestMembers, noNestMate, permittedSubclass, permittedSubclass, permittedSubclass, require, require, require, serialVersionUid, typeVariable, typeVariable, typeVariable, typeVariable, withHashCodeEquals, withToString
-
-
-
-
Method Detail
-
visit
public DynamicType.Builder<U> visit(AsmVisitorWrapper asmVisitorWrapper)
Applies the suppliedAsmVisitorWrapper
onto theClassVisitor
during building a dynamic type. Using an ASM visitor, it is possible to manipulate byte code directly. Byte Buddy does not validate directly created byte code and it remains the responsibility of the visitor's implementor to generate legal byte code. If several ASM visitor wrappers are registered, they are applied on top of another in their registration order.- Parameters:
asmVisitorWrapper
- The ASM visitor wrapper to apply during- Returns:
- A new builder that is equal to this builder and applies the ASM visitor wrapper.
-
initializer
public DynamicType.Builder<U> initializer(LoadedTypeInitializer loadedTypeInitializer)
Executes the supplied loaded type initializer when loading the created instrumented type. If several loaded type initializers are supplied, each loaded type initializer is executed in its registration order.- Parameters:
loadedTypeInitializer
- The loaded type initializer to execute upon loading the instrumented type.- Returns:
- A new builder that is equal to this builder but with the supplied loaded type initializer executed upon loading the instrumented type.
-
annotateType
public DynamicType.Builder<U> annotateType(java.util.Collection<? extends AnnotationDescription> annotations)
Annotates the instrumented type with the supplied annotations.- Parameters:
annotations
- The annotations to add to the instrumented type.- Returns:
- A new builder that is equal to this builder but with the annotations added to the instrumented type.
-
attribute
public DynamicType.Builder<U> attribute(TypeAttributeAppender typeAttributeAppender)
Applies the given type attribute appender onto the instrumented type. Using a type attribute appender, it is possible to append any type of meta data to a type, not only JavaAnnotation
s.- Parameters:
typeAttributeAppender
- The type attribute appender to apply.- Returns:
- A new builder that is equal to this builder but with the supplied type attribute appender applied to the instrumented type.
-
modifiers
public DynamicType.Builder<U> modifiers(int modifiers)
Defines the supplied modifiers as the modifiers of the instrumented type.- Parameters:
modifiers
- The modifiers of the instrumented type.- Returns:
- A new builder that is equal to this builder but with the supplied modifiers applied onto the instrumented type.
-
merge
public DynamicType.Builder<U> merge(java.util.Collection<? extends ModifierContributor.ForType> modifierContributors)
Merges the supplied modifier contributors with the modifiers of the instrumented type and defines them as the instrumented type's new modifiers.- Parameters:
modifierContributors
- The modifiers of the instrumented type.- Returns:
- A new builder that is equal to this builder but with the supplied modifiers merged into the instrumented type's modifiers.
-
suffix
public DynamicType.Builder<U> suffix(java.lang.String suffix)
Adds a suffix to the current type name without changing the type's package.- Parameters:
suffix
- The suffix to append to the current type name.- Returns:
- A new builder that is equal to this builder but with the instrumented type named suffixed by the supplied suffix.
-
name
public DynamicType.Builder<U> name(java.lang.String name)
Names the dynamic type by the supplied name. The name needs to be fully qualified and in the binary format (packages separated by dots:foo.Bar
). A type's package determines what other types are visible to the instrumented type and what methods can be overridden or be represented in method signatures or as field types.- Parameters:
name
- The fully qualified name of the generated class in a binary format.- Returns:
- A new builder that is equal to this builder but with the instrumented type named by the supplied name.
-
topLevelType
public DynamicType.Builder<U> topLevelType()
Defines this type as a top-level type that is not declared by another type or enclosed by another member.
Important: Changing the declaration hierarchy of a type has no influence on the nest mate hierarchy.
Warning: By changing this type's declaration, any other type will not change its declaration of enclosing members or declared types about any nesting of a declaration. It is the responsibility of the user of this API to keep such declarations consistent among the definitions of connected types.
- Returns:
- A new builder that is equal to this builder but without any declaration of a a declared or enclosed type.
-
innerTypeOf
public DynamicType.Builder.InnerTypeDefinition.ForType<U> innerTypeOf(TypeDescription type)
Defines this type as an inner type of the supplied type. Without any additional configuration, the type declaration is defined as a local type.
Important: Changing the declaration hierarchy of a type has no influence on the nest mate hierarchy.
Warning: By changing this type's declaration, any other type will not change its declaration of enclosing members or declared types about any nesting of a declaration. It is the responsibility of the user of this API to keep such declarations consistent among the definitions of connected types.
- Parameters:
type
- The type to declare as the built type's outer type.- Returns:
- A new builder that is equal to this builder with the supplied type as the built type's outer type.
-
innerTypeOf
public DynamicType.Builder.InnerTypeDefinition<U> innerTypeOf(MethodDescription.InDefinedShape methodDescription)
Defines this type as an inner type that was declared within the supplied method or constructor. Without any additional configuration, the type declaration is defined as a local type.
Important: Changing the declaration hierarchy of a type has no influence on the nest mate hierarchy.
Warning: By changing this type's declaration, any other type will not change its declaration of enclosing members or declared types about any nesting of a declaration. It is the responsibility of the user of this API to keep such declarations consistent among the definitions of connected types.
- Parameters:
methodDescription
- The method or constructor to declare as the built type's declaring method.- Returns:
- A new builder that is equal to this builder with the supplied method as the built type's declaring method or constructor.
-
declaredTypes
public DynamicType.Builder<U> declaredTypes(java.util.Collection<? extends TypeDescription> types)
Defines this type as an the outer type of the supplied types. Using this method, it is possible to add inner type declarations for anonymous or local types which are not normally exposed by type descriptions. Doing so, it is however possible to indicate to Byte Buddy that the required attributes for such an inner type declaration should be added to a class file.
Important: Changing the declaration hierarchy of a type has no influence on the nest mate hierarchy.
Warning: By changing this type's declaration, any other type will not change its declaration of enclosing members or declared types about any nesting of a declaration. It is the responsibility of the user of this API to keep such declarations consistent among the definitions of connected types.
- Parameters:
types
- The types being declared.- Returns:
- A new builder that is equal to this builder with the supplied types being declared by the built type.
-
nestHost
public DynamicType.Builder<U> nestHost(TypeDescription type)
Defines this type as a nest member of the supplied type as a nest host.
Important: Changing the nest mate hierarchy of a type has no influence on the declaration hierarchy.
Warning: Changing nest mate hierarchies always requires changing a member and its host or a host and all its members. Otherwise, the runtime will not accept further nest mates. It is the responsibility of the user of this API to keep such declarations consistent among the definitions of connected types.
- Parameters:
type
- The nest host.- Returns:
- A new builder that is equal to this builder but where the built type is a nest member of the supplied host.
-
nestMembers
public DynamicType.Builder<U> nestMembers(java.util.Collection<? extends TypeDescription> types)
Defines this type as a nest host for the supplied types.
Important: Changing the nest mate hierarchy of a type has no influence on the declaration hierarchy.
Warning: Changing nest mate hierarchies always requires changing a member and its host or a host and all its members. Otherwise, the runtime will not accept further nest mates. It is the responsibility of the user of this API to keep such declarations consistent among the definitions of connected types.
- Parameters:
types
- The nest members.- Returns:
- A new builder that is equal to this builder but where the built type is a nest host of the supplied types.
-
permittedSubclass
public DynamicType.Builder<U> permittedSubclass(java.util.Collection<? extends TypeDescription> types)
Defines this type to allow the supplied permitted subclasses additionally to any prior permitted subclasses. If this type was not previously sealed, only the supplied subclasses are permitted.- Parameters:
types
- The permitted subclasses.- Returns:
- A new builder that is equal to this builder but where the built type permits the supplied subclasses.
-
unsealed
public DynamicType.Builder<U> unsealed()
Unseales this type.- Returns:
- A new builder that is equal to this builder but where the built type does not restrain its permitted subclasses.
-
implement
public DynamicType.Builder.MethodDefinition.ImplementationDefinition.Optional<U> implement(java.util.Collection<? extends TypeDefinition> interfaceTypes)
Implements the supplied interfaces for the instrumented type. Optionally, it is possible to define the methods that are defined by the interfaces or the interfaces' super interfaces. This excludes methods that are explicitly ignored.
Note: This methods implements the supplied types as is, i.e. any
TypeDescription
values are implemented as raw types if they declare type variables or an owner type.- Parameters:
interfaceTypes
- The interface types to implement.- Returns:
- A new builder that is equal to this builder but with the interfaces implemented by the instrumented type.
-
initializer
public DynamicType.Builder<U> initializer(ByteCodeAppender byteCodeAppender)
Executes the supplied byte code appender within the beginning of the instrumented type's type initializer. The supplied byte code appender must not return from the method. If several byte code appenders are supplied, they are executed within their application order.
This method should only be used for preparing an instrumented type with a specific configuration. Normally, a byte code appender is applied via Byte Buddy's standard API by invoking
DynamicType.Builder.invokable(ElementMatcher)
using theElementMatchers.isTypeInitializer()
matcher.- Parameters:
byteCodeAppender
- The byte code appender to execute within the instrumented type's type initializer.- Returns:
- A new builder that is equal to this builder but with the supplied byte code appender being executed within the instrumented type's type initializer.
-
ignoreAlso
public DynamicType.Builder<U> ignoreAlso(ElementMatcher<? super MethodDescription> ignoredMethods)
Specifies to exclude any method that is matched by the supplied matcher from instrumentation. Previously supplied matchers remain valid after supplying a new matcher, i.e. any method that is matched by a previously supplied matcher is always ignored.
When ignoring a type, previously registered matchers are applied before this matcher. If a previous matcher indicates that a type is to be ignored, this matcher is no longer executed.
- Specified by:
ignoreAlso
in interfaceDynamicType.Builder<U>
- Overrides:
ignoreAlso
in classDynamicType.Builder.AbstractBase<U>
- Parameters:
ignoredMethods
- The matcher for determining what methods to exclude from instrumentation.- Returns:
- A new builder that is equal to this builder but that is excluding any method that is matched by the supplied matcher from instrumentation.
-
ignoreAlso
public DynamicType.Builder<U> ignoreAlso(LatentMatcher<? super MethodDescription> ignoredMethods)
Specifies to exclude any method that is matched by the supplied matcher from instrumentation. Previously supplied matchers remain valid after supplying a new matcher, i.e. any method that is matched by a previously supplied matcher is always ignored. Using a latent matcher gives opportunity to resolve an
ElementMatcher
based on the instrumented type before applying the matcher.When ignoring a type, previously registered matchers are applied before this matcher. If a previous matcher indicates that a type is to be ignored, this matcher is no longer executed.
- Parameters:
ignoredMethods
- The matcher for determining what methods to exclude from instrumentation.- Returns:
- A new builder that is equal to this builder but that is excluding any method that is matched by the supplied matcher from instrumentation.
-
typeVariable
public DynamicType.Builder.TypeVariableDefinition<U> typeVariable(java.lang.String symbol, java.util.Collection<? extends TypeDefinition> bounds)
Defines the supplied type variable with the given bound as a type variable of the instrumented type.- Parameters:
symbol
- The type variable's symbol.bounds
- The type variable's upper bounds. Can also beTargetType
if the bound type should be equal to the currently instrumented type.- Returns:
- A new builder that is equal to this builder but with the given type variable defined for the instrumented type.
-
transform
public DynamicType.Builder<U> transform(ElementMatcher<? super TypeDescription.Generic> matcher, Transformer<TypeVariableToken> transformer)
Transforms any type variable that is defined by this type if it is matched by the supplied matcher.- Parameters:
matcher
- The matcher to decide what type variables to transform.transformer
- The transformer to apply to the matched type variables.- Returns:
- A new builder that is equal to this builder but with the supplied transformer applied to all type variables.
-
defineField
public DynamicType.Builder.FieldDefinition.Optional.Valuable<U> defineField(java.lang.String name, TypeDefinition type, int modifiers)
Defines the specified field as a field of the built dynamic type.- Parameters:
name
- The name of the field.type
- The type of the field. Can also beTargetType
if the field type should be equal to the currently instrumented type.modifiers
- The modifiers of the field.- Returns:
- A new builder that is equal to this builder but with the given field defined for the instrumented type. Furthermore, it is possible to optionally define a value, annotations or custom attributes for the field.
-
field
public DynamicType.Builder.FieldDefinition.Valuable<U> field(LatentMatcher<? super FieldDescription> matcher)
Matches a field that is already declared by the instrumented type. This gives opportunity to change that field's default value, annotations or custom attributes. Using a latent matcher gives opportunity to resolve an
ElementMatcher
based on the instrumented type before applying the matcher.When a type is redefined or rebased, any annotations that the field declared previously is preserved as it is if Byte Buddy is configured to retain such annotations by
AnnotationRetention.ENABLED
. If any existing annotations should be altered, annotation retention must be disabled.If a field is already matched by a previously specified field matcher, the new field definition gets precedence over the previous definition, i.e. the previous field definition is no longer applied.
- Parameters:
matcher
- The matcher that determines what declared fields are affected by the subsequent specification.- Returns:
- A builder that allows for changing a field's definition.
-
defineMethod
public DynamicType.Builder.MethodDefinition.ParameterDefinition.Initial<U> defineMethod(java.lang.String name, TypeDefinition returnType, int modifiers)
Defines the specified method to be declared by the instrumented type. Method parameters or parameter types, declared exceptions and type variables can be defined in subsequent steps.- Parameters:
name
- The name of the method.returnType
- The method's return type. Can also beTargetType
if the return type should be equal to the currently instrumented type.modifiers
- The method's modifiers.- Returns:
- A builder that allows for further defining the method, either by adding more properties or by defining an implementation.
-
defineConstructor
public DynamicType.Builder.MethodDefinition.ParameterDefinition.Initial<U> defineConstructor(int modifiers)
Defines the specified constructor to be declared by the instrumented type. Method parameters or parameter types, declared exceptions and type variables can be defined in subsequent steps.- Parameters:
modifiers
- The constructor's modifiers.- Returns:
- A builder that allows for further defining the constructor, either by adding more properties or by defining an implementation.
-
invokable
public DynamicType.Builder.MethodDefinition.ImplementationDefinition<U> invokable(LatentMatcher<? super MethodDescription> matcher)
Matches a method or constructor that is already declared or inherited by the instrumented type. This gives opportunity to change or to override that method's or constructor's implementation, default value, annotations or custom attributes. It is also possible to make a method abstract. Using a latent matcher gives opportunity to resolve an
ElementMatcher
based on the instrumented type before applying the matcher.When a type is redefined or rebased, any annotations that the method or constructor declared previously is preserved as it is if Byte Buddy is configured to retain such annotations by
AnnotationRetention.ENABLED
. If any existing annotations should be altered, annotation retention must be disabled.If a method or constructor is already matched by a previously specified matcher, the new definition gets precedence over the previous definition, i.e. the previous definition is no longer applied.
Note that the specified definition does never apply for methods that are explicitly ignored.
Important: It is possible to instrument the dynamic type's initializer. Depending on the used
TypeResolutionStrategy
, the type initializer might be run before Byte Buddy could apply anyLoadedTypeInitializer
s which are responsible for preparing the instrumented type prior to the initializer's execution. For preparing the type prior to executing the initializer, anTypeResolutionStrategy.Active
resolver must be chosen.- Parameters:
matcher
- The matcher that determines what declared methods or constructors are affected by the subsequent specification.- Returns:
- A builder that allows for changing a method's or constructor's definition.
-
require
public DynamicType.Builder<U> require(java.util.Collection<DynamicType> auxiliaryTypes)
Explicitly requires other dynamic types for the creation of this type.- Parameters:
auxiliaryTypes
- The required dynamic types.- Returns:
- A new builder that is equal to this builder but which explicitly requires the supplied types.
-
defineRecordComponent
public DynamicType.Builder.RecordComponentDefinition.Optional<U> defineRecordComponent(java.lang.String name, TypeDefinition type)
Defines a new record component. Note that this does not add or change implementations for a field, an accessor to this field or a constructor unlessByteBuddy.makeRecord()
is used.- Parameters:
name
- The record component's name.type
- The record component's type.- Returns:
- A new builder that is equal to this builder but also defines the supplied record component.
-
define
public DynamicType.Builder.RecordComponentDefinition.Optional<U> define(RecordComponentDescription recordComponentDescription)
Defines a new record component. Note that this does not add or change implementations for a field, an accessor to this field or a constructor unlessByteBuddy.makeRecord()
is used.- Specified by:
define
in interfaceDynamicType.Builder<U>
- Overrides:
define
in classDynamicType.Builder.AbstractBase<U>
- Parameters:
recordComponentDescription
- A description of the record component to immitate.- Returns:
- A new builder that is equal to this builder but also defines the supplied record component.
-
recordComponent
public DynamicType.Builder.RecordComponentDefinition<U> recordComponent(ElementMatcher<? super RecordComponentDescription> matcher)
Matches a record component that is already declared by the instrumented type. This gives opportunity to change that record component's annotations or custom attributes.
When a type is redefined or rebased, any annotations that the field declared previously is preserved as it is if Byte Buddy is configured to retain such annotations by
AnnotationRetention.ENABLED
. If any existing annotations should be altered, annotation retention must be disabled.If a record component is already matched by a previously specified record component matcher, the new record component definition gets precedence over the previous definition, i.e. the previous record component definition is no longer applied.
- Specified by:
recordComponent
in interfaceDynamicType.Builder<U>
- Overrides:
recordComponent
in classDynamicType.Builder.AbstractBase<U>
- Parameters:
matcher
- The matcher that determines what declared record components are affected by the subsequent specification.- Returns:
- A builder that allows for changing a record component's definition.
-
recordComponent
public DynamicType.Builder.RecordComponentDefinition<U> recordComponent(LatentMatcher<? super RecordComponentDescription> matcher)
Matches a record component that is already declared by the instrumented type. This gives opportunity to change that record component's annotations or custom attributes.
When a type is redefined or rebased, any annotations that the field declared previously is preserved as it is if Byte Buddy is configured to retain such annotations by
AnnotationRetention.ENABLED
. If any existing annotations should be altered, annotation retention must be disabled.If a record component is already matched by a previously specified record component matcher, the new record component definition gets precedence over the previous definition, i.e. the previous record component definition is no longer applied.
- Parameters:
matcher
- The matcher that determines what declared record components are affected by the subsequent specification.- Returns:
- A builder that allows for changing a record component's definition.
-
make
public DynamicType.Unloaded<U> make()
Creates the dynamic type this builder represents. If the specified dynamic type is not legal, an
IllegalStateException
is thrown.Other than
DynamicType.Builder.make(TypePool)
, this method supplies a context-dependant type pool to the underlying class writer. Supplying a type pool only makes sense if custom byte code is created by adding a customAsmVisitorWrapper
where ASM might be required to compute stack map frames by processing information over any mentioned type's class hierarchy.The dynamic type is initialized using a
TypeResolutionStrategy.Passive
strategy. Using this strategy, noLoadedTypeInitializer
is run during the execution of the type's initializer such that noImplementation
used for executing the initializer must rely on such an initializer.- Specified by:
make
in interfaceDynamicType.Builder<U>
- Overrides:
make
in classDynamicType.Builder.AbstractBase<U>
- Returns:
- An unloaded dynamic type representing the type specified by this builder.
-
make
public DynamicType.Unloaded<U> make(TypeResolutionStrategy typeResolutionStrategy)
Creates the dynamic type this builder represents. If the specified dynamic type is not legal, an
IllegalStateException
is thrown.The dynamic type is initialized using a
TypeResolutionStrategy.Passive
strategy. Using this strategy, noLoadedTypeInitializer
is run during the execution of the type's initializer such that noImplementation
used for executing the initializer must rely on such an initializer.- Parameters:
typeResolutionStrategy
- The type resolution strategy to use for the created type's initialization.- Returns:
- An unloaded dynamic type representing the type specified by this builder.
-
make
public DynamicType.Unloaded<U> make(TypePool typePool)
Creates the dynamic type this builder represents. If the specified dynamic type is not legal, an
IllegalStateException
is thrown.The dynamic type is initialized using a
TypeResolutionStrategy.Passive
strategy. Using this strategy, noLoadedTypeInitializer
is run during the execution of the type's initializer such that noImplementation
used for executing the initializer must rely on such an initializer.- Specified by:
make
in interfaceDynamicType.Builder<U>
- Overrides:
make
in classDynamicType.Builder.AbstractBase<U>
- Parameters:
typePool
- A type pool that is used for computing stack map frames by the underlying class writer, if required.- Returns:
- An unloaded dynamic type representing the type specified by this builder.
-
make
public DynamicType.Unloaded<U> make(TypeResolutionStrategy typeResolutionStrategy, TypePool typePool)
Creates the dynamic type this builder represents. If the specified dynamic type is not legal, anIllegalStateException
is thrown.- Parameters:
typeResolutionStrategy
- The type resolution strategy to use for the created type's initialization.typePool
- A type pool that is used for computing stack map frames by the underlying class writer, if required.- Returns:
- An unloaded dynamic type representing the type specified by this builder.
-
toTypeDescription
public TypeDescription toTypeDescription()
Returns aTypeDescription
for the currently built type.- Returns:
- A
TypeDescription
for the currently built type.
-
materialize
protected abstract DynamicType.Builder<U> materialize()
Creates a new builder that realizes the current state of the builder.- Returns:
- A new builder that realizes the current state of the builder.
-
-