U
- A loaded type that the built type is guaranteed to be a subclass of.public abstract static class DynamicType.Builder.AbstractBase.Delegator<U> extends DynamicType.Builder.AbstractBase<U>
DynamicType.Builder.AbstractBase.Adapter<U>, DynamicType.Builder.AbstractBase.Delegator<U>
DynamicType.Builder.AbstractBase<S>, DynamicType.Builder.FieldDefinition<S>, DynamicType.Builder.MethodDefinition<S>, DynamicType.Builder.TypeVariableDefinition<S>
Constructor and Description |
---|
Delegator() |
Modifier and Type | Method and Description |
---|---|
DynamicType.Builder<U> |
annotateType(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.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(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(String name,
TypeDefinition returnType,
int modifiers)
Defines the specified method to be declared by the instrumented type.
|
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(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.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 specificied dynamic type.
|
protected abstract DynamicType.Builder<U> |
materialize()
Creates a new builder that realizes the current state of the builder.
|
DynamicType.Builder<U> |
merge(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(String name)
Names the dynamic type by the supplied name.
|
DynamicType.Builder.TypeVariableDefinition<U> |
typeVariable(String symbol,
Collection<? extends TypeDefinition> bounds)
Defines the supplied type variable with the given bound as a type variable of the instrumented type.
|
DynamicType.Builder<U> |
visit(AsmVisitorWrapper asmVisitorWrapper)
Applies the supplied
AsmVisitorWrapper onto the ClassVisitor during building a dynamic type. |
annotateType, annotateType, annotateType, constructor, define, define, define, define, define, defineConstructor, defineConstructor, defineField, defineField, defineField, defineField, defineField, defineMethod, defineMethod, defineMethod, defineMethod, defineMethod, field, implement, implement, implement, invokable, merge, method, modifiers, modifiers, serialVersionUid, typeVariable, typeVariable, typeVariable, typeVariable
public DynamicType.Builder<U> visit(AsmVisitorWrapper asmVisitorWrapper)
DynamicType.Builder
AsmVisitorWrapper
onto the ClassVisitor
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.asmVisitorWrapper
- The ASM visitor wrapper to apply duringpublic DynamicType.Builder<U> initializer(LoadedTypeInitializer loadedTypeInitializer)
DynamicType.Builder
loadedTypeInitializer
- The loaded type initializer to execute upon loading the instrumented type.public DynamicType.Builder<U> annotateType(Collection<? extends AnnotationDescription> annotations)
DynamicType.Builder
annotations
- The annotations to add to the instrumented type.public DynamicType.Builder<U> attribute(TypeAttributeAppender typeAttributeAppender)
DynamicType.Builder
Annotation
s.typeAttributeAppender
- The type attribute appender to apply.public DynamicType.Builder<U> modifiers(int modifiers)
DynamicType.Builder
modifiers
- The modifiers of the instrumented type.public DynamicType.Builder<U> merge(Collection<? extends ModifierContributor.ForType> modifierContributors)
DynamicType.Builder
modifierContributors
- The modifiers of the instrumented type.public DynamicType.Builder<U> name(String name)
DynamicType.Builder
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.name
- The fully qualified name of the generated class in a binary format.public DynamicType.Builder.MethodDefinition.ImplementationDefinition.Optional<U> implement(Collection<? extends TypeDefinition> interfaceTypes)
DynamicType.Builder
interfaceTypes
- The interface types to implement.public DynamicType.Builder<U> initializer(ByteCodeAppender byteCodeAppender)
DynamicType.Builder
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 the ElementMatchers.isTypeInitializer()
matcher.
byteCodeAppender
- The byte code appender to execute within the instrumented type's type initializer.public DynamicType.Builder<U> ignoreAlso(ElementMatcher<? super MethodDescription> ignoredMethods)
DynamicType.Builder
ignoreAlso
in interface DynamicType.Builder<U>
ignoreAlso
in class DynamicType.Builder.AbstractBase<U>
ignoredMethods
- The matcher for determining what methods to exclude from instrumentation.public DynamicType.Builder<U> ignoreAlso(LatentMatcher<? super MethodDescription> ignoredMethods)
DynamicType.Builder
ElementMatcher
based on the instrumented type before applying the
matcher.ignoredMethods
- The matcher for determining what methods to exclude from instrumentation.public DynamicType.Builder.TypeVariableDefinition<U> typeVariable(String symbol, Collection<? extends TypeDefinition> bounds)
DynamicType.Builder
symbol
- The type variable's symbol.bounds
- The type variable's upper bounds. Can also be TargetType
if the bound type
should be equal to the currently instrumented type.public DynamicType.Builder.FieldDefinition.Optional.Valuable<U> defineField(String name, TypeDefinition type, int modifiers)
DynamicType.Builder
name
- The name of the field.type
- The type of the field. Can also be TargetType
if the field type
should be equal to the currently instrumented type.modifiers
- The modifiers of the field.public DynamicType.Builder.FieldDefinition.Valuable<U> field(LatentMatcher<? super FieldDescription> matcher)
DynamicType.Builder
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.
matcher
- The matcher that determines what declared fields are affected by the subsequent specification.public DynamicType.Builder.MethodDefinition.ParameterDefinition.Initial<U> defineMethod(String name, TypeDefinition returnType, int modifiers)
DynamicType.Builder
name
- The name of the method.returnType
- The method's return type. Can also be TargetType
if the return type
should be equal to the currently instrumented type.modifiers
- The method's modifiers.public DynamicType.Builder.MethodDefinition.ParameterDefinition.Initial<U> defineConstructor(int modifiers)
DynamicType.Builder
modifiers
- The constructor's modifiers.public DynamicType.Builder.MethodDefinition.ImplementationDefinition<U> invokable(LatentMatcher<? super MethodDescription> matcher)
DynamicType.Builder
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.
matcher
- The matcher that determines what declared methods or constructors are affected by the subsequent specification.public DynamicType.Unloaded<U> make()
DynamicType.Builder
IllegalStateException
is thrown.protected abstract DynamicType.Builder<U> materialize()
Copyright © 2014–2016. All rights reserved.