public class ByteBuddy extends Object
DynamicType.Builder
interface. Byte Buddy's API is expressed by fully immutable
components and is therefore thread-safe. As a consequence, method calls must be chained for all of Byte Buddy's
component, e.g. a method call like the following has no effect:
ByteBuddy byteBuddy = new ByteBuddy(); byteBuddy.foo()Instead, the following method chain is corrent use of the API:
ByteBuddy byteBuddy = new ByteBuddy().foo();
For the creation of Java agents, Byte Buddy offers a convenience API implemented by the
AgentBuilder
. The API wraps a ByteBuddy
instance and offers agent-specific
configuration opportunities by integrating against the Instrumentation
API.
AgentBuilder
Modifier and Type | Class and Description |
---|---|
protected static class |
ByteBuddy.EnumerationImplementation
An implementation fo the
values method of an enumeration type. |
Modifier and Type | Field and Description |
---|---|
protected AnnotationRetention |
annotationRetention
The annotation retention strategy to use.
|
protected AnnotationValueFilter.Factory |
annotationValueFilterFactory
The annotation value filter factory to use.
|
protected AuxiliaryType.NamingStrategy |
auxiliaryTypeNamingStrategy
The naming strategy to use for naming auxiliary types.
|
protected ClassFileVersion |
classFileVersion
The class file version to use for types that are not based on an existing class file.
|
protected LatentMatcher<? super MethodDescription> |
ignoredMethods
A matcher for identifying methods that should be excluded from instrumentation.
|
protected Implementation.Context.Factory |
implementationContextFactory
The implementation context factory to use.
|
protected MethodGraph.Compiler |
methodGraphCompiler
The method graph compiler to use.
|
protected NamingStrategy |
namingStrategy
The naming strategy to use.
|
protected TypeValidation |
typeValidation
Determines if a type should be explicitly validated.
|
Modifier | Constructor and Description |
---|---|
|
ByteBuddy()
Creates a new Byte Buddy instance with a default configuration that is suitable for most use cases.
|
|
ByteBuddy(ClassFileVersion classFileVersion)
Creates a new Byte Buddy instance with a default configuration that is suitable for most use cases.
|
protected |
ByteBuddy(ClassFileVersion classFileVersion,
NamingStrategy namingStrategy,
AuxiliaryType.NamingStrategy auxiliaryTypeNamingStrategy,
AnnotationValueFilter.Factory annotationValueFilterFactory,
AnnotationRetention annotationRetention,
Implementation.Context.Factory implementationContextFactory,
MethodGraph.Compiler methodGraphCompiler,
TypeValidation typeValidation,
LatentMatcher<? super MethodDescription> ignoredMethods)
Creates a new Byte Buddy instance.
|
Modifier and Type | Method and Description |
---|---|
ByteBuddy |
ignore(ElementMatcher<? super MethodDescription> ignoredMethods)
Creates a new configuration where any
MethodDescription that matches the provided method matcher is excluded
from instrumentation. |
ByteBuddy |
ignore(LatentMatcher<? super MethodDescription> ignoredMethods)
Creates a new configuration where any
MethodDescription that matches the provided method matcher is excluded
from instrumentation. |
DynamicType.Builder<? extends Annotation> |
makeAnnotation()
Creates a new
Annotation type. |
DynamicType.Builder<? extends Enum<?>> |
makeEnumeration(Collection<? extends String> values)
Creates a new
Enum type. |
DynamicType.Builder<? extends Enum<?>> |
makeEnumeration(String... value)
Creates a new
Enum type. |
DynamicType.Builder<?> |
makeInterface()
Creates a new, plain interface type.
|
<T> DynamicType.Builder<T> |
makeInterface(Class<T> interfaceType)
Creates a new interface type that extends the provided interface.
|
DynamicType.Builder<?> |
makeInterface(Collection<? extends TypeDefinition> interfaceTypes)
Creates a new interface type that extends the provided interface.
|
DynamicType.Builder<?> |
makeInterface(List<? extends Type> interfaceTypes)
Creates a new interface type that extends the provided interface.
|
DynamicType.Builder<?> |
makeInterface(Type... interfaceType)
Creates a new interface type that extends the provided interface.
|
DynamicType.Builder<?> |
makeInterface(TypeDefinition... interfaceType)
Creates a new interface type that extends the provided interface.
|
DynamicType.Builder<?> |
makePackage(String name)
Creates a new package definition.
|
<T> DynamicType.Builder<T> |
rebase(Class<T> type)
Rebases the given type where any intercepted method that is declared by the redefined type is preserved within the
rebased type's class such that the class's original can be invoked from the new method implementations.
|
<T> DynamicType.Builder<T> |
rebase(Class<T> type,
ClassFileLocator classFileLocator)
Rebases the given type where any intercepted method that is declared by the redefined type is preserved within the
rebased type's class such that the class's original can be invoked from the new method implementations.
|
<T> DynamicType.Builder<T> |
rebase(Class<T> type,
ClassFileLocator classFileLocator,
MethodNameTransformer methodNameTransformer)
Rebases the given type where any intercepted method that is declared by the redefined type is preserved within the
rebased type's class such that the class's original can be invoked from the new method implementations.
|
DynamicType.Builder<?> |
rebase(Package aPackage,
ClassFileLocator classFileLocator)
Rebases a package.
|
DynamicType.Builder<?> |
rebase(PackageDescription aPackage,
ClassFileLocator classFileLocator)
Rebases a package.
|
<T> DynamicType.Builder<T> |
rebase(TypeDescription type,
ClassFileLocator classFileLocator)
Rebases the given type where any intercepted method that is declared by the redefined type is preserved within the
rebased type's class such that the class's original can be invoked from the new method implementations.
|
<T> DynamicType.Builder<T> |
rebase(TypeDescription type,
ClassFileLocator classFileLocator,
MethodNameTransformer methodNameTransformer)
Rebases the given type where any intercepted method that is declared by the redefined type is preserved within the
rebased type's class such that the class's original can be invoked from the new method implementations.
|
<T> DynamicType.Builder<T> |
redefine(Class<T> type)
Redefines the given type where any intercepted method that is declared by the redefined type is fully replaced
by the new implementation.
|
<T> DynamicType.Builder<T> |
redefine(Class<T> type,
ClassFileLocator classFileLocator)
Redefines the given type where any intercepted method that is declared by the redefined type is fully replaced
by the new implementation.
|
<T> DynamicType.Builder<T> |
redefine(TypeDescription type,
ClassFileLocator classFileLocator)
Redefines the given type where any intercepted method that is declared by the redefined type is fully replaced
by the new implementation.
|
<T> DynamicType.Builder<T> |
subclass(Class<T> superType)
Creates a new builder for subclassing the provided type.
|
<T> DynamicType.Builder<T> |
subclass(Class<T> superType,
ConstructorStrategy constructorStrategy)
Creates a new builder for subclassing the provided type.
|
DynamicType.Builder<?> |
subclass(Type superType)
Creates a new builder for subclassing the provided type.
|
DynamicType.Builder<?> |
subclass(Type superType,
ConstructorStrategy constructorStrategy)
Creates a new builder for subclassing the provided type.
|
DynamicType.Builder<?> |
subclass(TypeDefinition superType)
Creates a new builder for subclassing the provided type.
|
DynamicType.Builder<?> |
subclass(TypeDefinition superType,
ConstructorStrategy constructorStrategy)
Creates a new builder for subclassing the provided type.
|
ByteBuddy |
with(AnnotationRetention annotationRetention)
Creates a new configuration where annotations that are found in an existing class file are or are not preserved
in the format they are discovered, i.e. rewritten in the format they were already present in the class file.
|
ByteBuddy |
with(AnnotationValueFilter.Factory annotationValueFilterFactory)
Creates a new configuration where annotation values are written according to the given filter factory.
|
ByteBuddy |
with(AuxiliaryType.NamingStrategy auxiliaryTypeNamingStrategy)
Creates a new configuration where auxiliary types are named by applying the given naming strategy.
|
ByteBuddy |
with(ClassFileVersion classFileVersion)
Creates a new configuration where all class files that are not based on an existing class file are created
using the supplied class file version.
|
ByteBuddy |
with(Implementation.Context.Factory implementationContextFactory)
Creates a new configuration where the
Implementation.Context of any created
type is a product of the given implementation context factory. |
ByteBuddy |
with(MethodGraph.Compiler methodGraphCompiler)
Creates a new configuration where the
MethodGraph.Compiler is used for creating a MethodGraph
of the instrumented type. |
ByteBuddy |
with(NamingStrategy namingStrategy)
Creates a new configuration where new types are named by applying the given naming strategy.
|
ByteBuddy |
with(TypeValidation typeValidation)
Creates a new configuration that applies the supplied type validation.
|
protected final ClassFileVersion classFileVersion
protected final NamingStrategy namingStrategy
protected final AuxiliaryType.NamingStrategy auxiliaryTypeNamingStrategy
protected final AnnotationValueFilter.Factory annotationValueFilterFactory
protected final AnnotationRetention annotationRetention
protected final Implementation.Context.Factory implementationContextFactory
protected final MethodGraph.Compiler methodGraphCompiler
protected final LatentMatcher<? super MethodDescription> ignoredMethods
protected final TypeValidation typeValidation
public ByteBuddy()
Creates a new Byte Buddy instance with a default configuration that is suitable for most use cases.
When creating this configuration, Byte Buddy attempts to discover the current JVM's version. If this is not possible, class files are created Java 6-compatible.
public ByteBuddy(ClassFileVersion classFileVersion)
classFileVersion
- The class file version to use for types that are not based on an existing class file.protected ByteBuddy(ClassFileVersion classFileVersion, NamingStrategy namingStrategy, AuxiliaryType.NamingStrategy auxiliaryTypeNamingStrategy, AnnotationValueFilter.Factory annotationValueFilterFactory, AnnotationRetention annotationRetention, Implementation.Context.Factory implementationContextFactory, MethodGraph.Compiler methodGraphCompiler, TypeValidation typeValidation, LatentMatcher<? super MethodDescription> ignoredMethods)
classFileVersion
- The class file version to use for types that are not based on an existing class file.namingStrategy
- The naming strategy to use.auxiliaryTypeNamingStrategy
- The naming strategy to use for naming auxiliary types.annotationValueFilterFactory
- The annotation value filter factory to use.annotationRetention
- The annotation retention strategy to use.implementationContextFactory
- The implementation context factory to use.methodGraphCompiler
- The method graph compiler to use.typeValidation
- Determines if a type should be explicitly validated.ignoredMethods
- A matcher for identifying methods that should be excluded from instrumentation.public <T> DynamicType.Builder<T> subclass(Class<T> superType)
Creates a new builder for subclassing the provided type. If the provided type is an interface, a new class implementing this interface type is created.
When extending a class, Byte Buddy imitates all visible constructors of the subclassed type. Any constructor is implemented
to only invoke its super type constructor of equal signature. Another behavior can be specified by supplying an explicit
ConstructorStrategy
by subclass(Class, ConstructorStrategy)
.
Note: This methods implements the supplied types in a generified state if they declare type variables or an owner type.
Note: Byte Buddy does not cache previous subclasses but will attempt the generation of a new subclass. For caching
types, a external cache or TypeCache
should be used.
T
- A loaded type that the generated class is guaranteed to inherit.superType
- The super class or interface type to extend.public <T> DynamicType.Builder<T> subclass(Class<T> superType, ConstructorStrategy constructorStrategy)
Creates a new builder for subclassing the provided type. If the provided type is an interface, a new class implementing this interface type is created.
Note: This methods implements the supplied types in a generified state if they declare type variables or an owner type.
Note: Byte Buddy does not cache previous subclasses but will attempt the generation of a new subclass. For caching
types, a external cache or TypeCache
should be used.
T
- A loaded type that the generated class is guaranteed to inherit.superType
- The super class or interface type to extend.constructorStrategy
- A constructor strategy that determines thepublic DynamicType.Builder<?> subclass(Type superType)
Creates a new builder for subclassing the provided type. If the provided type is an interface, a new class implementing this interface type is created.
When extending a class, Byte Buddy imitates all visible constructors of the subclassed type. Any constructor is implemented
to only invoke its super type constructor of equal signature. Another behavior can be specified by supplying an explicit
ConstructorStrategy
by subclass(Type, ConstructorStrategy)
.
Note: This methods implements the supplied types as is, i.e. any Class
values are implemented
as raw types if they declare type variables.
Note: Byte Buddy does not cache previous subclasses but will attempt the generation of a new subclass. For caching
types, a external cache or TypeCache
should be used.
superType
- The super class or interface type to extend. The type must be a raw type or parameterized type. All type
variables that are referenced by the generic type must be declared by the generated subclass before creating
the type.public DynamicType.Builder<?> subclass(Type superType, ConstructorStrategy constructorStrategy)
Creates a new builder for subclassing the provided type. If the provided type is an interface, a new class implementing this interface type is created.
Note: This methods implements the supplied types as is, i.e. any Class
values are implemented
as raw types if they declare type variables.
Note: Byte Buddy does not cache previous subclasses but will attempt the generation of a new subclass. For caching
types, a external cache or TypeCache
should be used.
superType
- The super class or interface type to extend. The type must be a raw type or parameterized
type. All type variables that are referenced by the generic type must be declared by the
generated subclass before creating the type.constructorStrategy
- A constructor strategy that determines thepublic DynamicType.Builder<?> subclass(TypeDefinition superType)
Creates a new builder for subclassing the provided type. If the provided type is an interface, a new class implementing this interface type is created.
When extending a class, Byte Buddy imitates all visible constructors of the subclassed type and sets them to be public
.
Any constructor is implemented to only invoke its super type constructor of equal signature. Another behavior can be specified by
supplying an explicit ConstructorStrategy
by subclass(TypeDefinition, ConstructorStrategy)
.
Note: This methods implements the supplied types as is, i.e. any TypeDescription
values are implemented
as raw types if they declare type variables.
Note: Byte Buddy does not cache previous subclasses but will attempt the generation of a new subclass. For caching
types, a external cache or TypeCache
should be used.
superType
- The super class or interface type to extend. The type must be a raw type or parameterized type. All type
variables that are referenced by the generic type must be declared by the generated subclass before creating
the type.public DynamicType.Builder<?> subclass(TypeDefinition superType, ConstructorStrategy constructorStrategy)
Creates a new builder for subclassing the provided type. If the provided type is an interface, a new class implementing this interface type is created.
Note: This methods implements the supplied types as is, i.e. any TypeDescription
values are implemented
as raw types if they declare type variables.
Note: Byte Buddy does not cache previous subclasses but will attempt the generation of a new subclass. For caching
types, a external cache or TypeCache
should be used.
superType
- The super class or interface type to extend. The type must be a raw type or parameterized
type. All type variables that are referenced by the generic type must be declared by the
generated subclass before creating the type.constructorStrategy
- A constructor strategy that determines thepublic DynamicType.Builder<?> makeInterface()
Creates a new, plain interface type.
Note: Byte Buddy does not cache previous subclasses but will attempt the generation of a new subclass. For caching
types, a external cache or TypeCache
should be used.
public <T> DynamicType.Builder<T> makeInterface(Class<T> interfaceType)
Creates a new interface type that extends the provided interface.
Note: This methods implements the supplied types in a generified state if they declare type variables or an owner type.
Note: Byte Buddy does not cache previous subclasses but will attempt the generation of a new subclass. For caching
types, a external cache or TypeCache
should be used.
T
- A loaded type that the generated interface is guaranteed to inherit.interfaceType
- An interface type that the generated interface implements.public DynamicType.Builder<?> makeInterface(Type... interfaceType)
Creates a new interface type that extends the provided interface.
Note: This methods implements the supplied types as is, i.e. any Class
values are implemented
as raw types if they declare type variables or an owner type.
Note: Byte Buddy does not cache previous subclasses but will attempt the generation of a new subclass. For caching
types, a external cache or TypeCache
should be used.
interfaceType
- The interface types to implement. The types must be raw or parameterized types. All type
variables that are referenced by a parameterized type must be declared by the generated
subclass before creating the type.public DynamicType.Builder<?> makeInterface(List<? extends Type> interfaceTypes)
Creates a new interface type that extends the provided interface.
Note: This methods implements the supplied types as is, i.e. any Class
values are implemented
as raw types if they declare type variables or an owner type.
Note: Byte Buddy does not cache previous subclasses but will attempt the generation of a new subclass. For caching
types, a external cache or TypeCache
should be used.
interfaceTypes
- The interface types to implement. The types must be raw or parameterized types. All
type variables that are referenced by a parameterized type must be declared by the
generated subclass before creating the type.public DynamicType.Builder<?> makeInterface(TypeDefinition... interfaceType)
Creates a new interface type that extends the provided interface.
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.
Note: Byte Buddy does not cache previous subclasses but will attempt the generation of a new subclass. For caching
types, a external cache or TypeCache
should be used.
interfaceType
- The interface types to implement. The types must be raw or parameterized types. All
type variables that are referenced by a parameterized type must be declared by the
generated subclass before creating the type.public DynamicType.Builder<?> makeInterface(Collection<? extends TypeDefinition> interfaceTypes)
Creates a new interface type that extends the provided interface.
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.
Note: Byte Buddy does not cache previous subclasses but will attempt the generation of a new subclass. For caching
types, a external cache or TypeCache
should be used.
interfaceTypes
- The interface types to implement. The types must be raw or parameterized types. All
type variables that are referenced by a parameterized type must be declared by the
generated subclass before creating the type.public DynamicType.Builder<?> makePackage(String name)
Creates a new package definition. Package definitions are defined by classes named package-info
without any methods or fields but permit annotations. Any field or method definition will cause an
IllegalStateException
to be thrown when the type is created.
Note: Byte Buddy does not cache previous subclasses but will attempt the generation of a new subclass. For caching
types, a external cache or TypeCache
should be used.
name
- The fully qualified name of the package.package-info
class file.public DynamicType.Builder<? extends Annotation> makeAnnotation()
Creates a new Annotation
type. Annotation properties are implemented as non-static, public methods with the
property type being defined as the return type.
Note: Byte Buddy does not cache previous subclasses but will attempt the generation of a new subclass. For caching
types, a external cache or TypeCache
should be used.
Annotation
type.public DynamicType.Builder<? extends Enum<?>> makeEnumeration(String... value)
Creates a new Enum
type.
Note: Byte Buddy does not cache previous subclasses but will attempt the generation of a new subclass. For caching
types, a external cache or TypeCache
should be used.
value
- The names of the type's enumeration constantspublic DynamicType.Builder<? extends Enum<?>> makeEnumeration(Collection<? extends String> values)
Creates a new Enum
type.
Note: Byte Buddy does not cache previous subclasses but will attempt the generation of a new subclass. For caching
types, a external cache or TypeCache
should be used.
values
- The names of the type's enumeration constantspublic <T> DynamicType.Builder<T> redefine(Class<T> type)
Redefines the given type where any intercepted method that is declared by the redefined type is fully replaced by the new implementation.
The class file of the redefined type is located by querying the redefined type's class loader by name. For specifying an
alternative ClassFileLocator
, use redefine(Class, ClassFileLocator)
.
Note: When a user redefines a class with the purpose of reloading this class using a ClassReloadingStrategy
,
it is important that no fields or methods are added to the redefined class. Note that some Implementation
s implicitly add fields or methods.
Finally, Byte Buddy might be forced to add a method if a redefined class already defines a class initializer. This can be disabled by setting
with(Implementation.Context.Factory)
to use a Implementation.Context.Disabled.Factory
where the class initializer is retained as is.
T
- The loaded type of the redefined type.type
- The type that is being redefined.public <T> DynamicType.Builder<T> redefine(Class<T> type, ClassFileLocator classFileLocator)
Redefines the given type where any intercepted method that is declared by the redefined type is fully replaced by the new implementation.
Note: When a user redefines a class with the purpose of reloading this class using a ClassReloadingStrategy
,
it is important that no fields or methods are added to the redefined class. Note that some Implementation
s implicitly add fields or methods.
Finally, Byte Buddy might be forced to add a method if a redefined class already defines a class initializer. This can be disabled by setting
with(Implementation.Context.Factory)
to use a Implementation.Context.Disabled.Factory
where the class initializer is retained as is.
T
- The loaded type of the redefined type.type
- The type that is being redefined.classFileLocator
- The class file locator that is queried for the redefined type's class file.public <T> DynamicType.Builder<T> redefine(TypeDescription type, ClassFileLocator classFileLocator)
Redefines the given type where any intercepted method that is declared by the redefined type is fully replaced by the new implementation.
Note: When a user redefines a class with the purpose of reloading this class using a ClassReloadingStrategy
,
it is important that no fields or methods are added to the redefined class. Note that some Implementation
s implicitly add fields or methods.
Finally, Byte Buddy might be forced to add a method if a redefined class already defines a class initializer. This can be disabled by setting
with(Implementation.Context.Factory)
to use a Implementation.Context.Disabled.Factory
where the class initializer is retained as is.
T
- The loaded type of the redefined type.type
- The type that is being redefined.classFileLocator
- The class file locator that is queried for the redefined type's class file.public <T> DynamicType.Builder<T> rebase(Class<T> type)
Rebases the given type where any intercepted method that is declared by the redefined type is preserved within the rebased type's class such that the class's original can be invoked from the new method implementations. Rebasing a type can be seen similarly to creating a subclass where the subclass is later merged with the original class file.
The class file of the rebased type is located by querying the rebased type's class loader by name. For specifying an
alternative ClassFileLocator
, use redefine(Class, ClassFileLocator)
.
T
- The loaded type of the rebased type.type
- The type that is being rebased.public <T> DynamicType.Builder<T> rebase(Class<T> type, ClassFileLocator classFileLocator)
Rebases the given type where any intercepted method that is declared by the redefined type is preserved within the rebased type's class such that the class's original can be invoked from the new method implementations. Rebasing a type can be seen similarly to creating a subclass where the subclass is later merged with the original class file.
When a method is rebased, the original method is copied into a new method with a different name. These names are
generated automatically by Byte Buddy unless a MethodNameTransformer
is specified explicitly.
Use rebase(Class, ClassFileLocator, MethodNameTransformer)
for doing so.
T
- The loaded type of the rebased type.type
- The type that is being rebased.classFileLocator
- The class file locator that is queried for the rebased type's class file.public <T> DynamicType.Builder<T> rebase(Class<T> type, ClassFileLocator classFileLocator, MethodNameTransformer methodNameTransformer)
T
- The loaded type of the rebased type.type
- The type that is being rebased.classFileLocator
- The class file locator that is queried for the rebased type's class file.methodNameTransformer
- The method name transformer for renaming a method that is rebased.public <T> DynamicType.Builder<T> rebase(TypeDescription type, ClassFileLocator classFileLocator)
Rebases the given type where any intercepted method that is declared by the redefined type is preserved within the rebased type's class such that the class's original can be invoked from the new method implementations. Rebasing a type can be seen similarly to creating a subclass where the subclass is later merged with the original class file.
When a method is rebased, the original method is copied into a new method with a different name. These names are
generated automatically by Byte Buddy unless a MethodNameTransformer
is specified explicitly.
Use rebase(TypeDescription, ClassFileLocator, MethodNameTransformer)
for doing so.
T
- The loaded type of the rebased type.type
- The type that is being rebased.classFileLocator
- The class file locator that is queried for the rebased type's class file.public <T> DynamicType.Builder<T> rebase(TypeDescription type, ClassFileLocator classFileLocator, MethodNameTransformer methodNameTransformer)
T
- The loaded type of the rebased type.type
- The type that is being rebased.classFileLocator
- The class file locator that is queried for the rebased type's class file.methodNameTransformer
- The method name transformer for renaming a method that is rebased.public DynamicType.Builder<?> rebase(Package aPackage, ClassFileLocator classFileLocator)
package-info
without any methods or fields but permit annotations. Any field or method
definition will cause an IllegalStateException
to be thrown when the type is created.aPackage
- The package that is being rebased.classFileLocator
- The class file locator to use for locating the package's class file.public DynamicType.Builder<?> rebase(PackageDescription aPackage, ClassFileLocator classFileLocator)
package-info
without any methods or fields but permit annotations. Any field or method
definition will cause an IllegalStateException
to be thrown when the type is created.aPackage
- The package that is being rebased.classFileLocator
- The class file locator to use for locating the package's class file.public ByteBuddy with(ClassFileVersion classFileVersion)
ByteBuddy()
, the class
file version is detected automatically. If the class file version is known before creating a Byte Buddy instance, the
ByteBuddy(ClassFileVersion)
constructor should be used.classFileVersion
- The class file version to use for types that are not based on an existing class file.public ByteBuddy with(NamingStrategy namingStrategy)
java.*
namespace, Byte Buddy also adds a suffix to the generated
class because this namespace is only available for the bootstrap class loader.namingStrategy
- The naming strategy to apply when creating a new dynamic type.public ByteBuddy with(AuxiliaryType.NamingStrategy auxiliaryTypeNamingStrategy)
Implementation
s. By default, Byte Buddy
adds a random suffix to the instrumented type's name when naming its auxiliary types.auxiliaryTypeNamingStrategy
- The naming strategy to apply when creating a new auxiliary type.public ByteBuddy with(AnnotationValueFilter.Factory annotationValueFilterFactory)
annotationValueFilterFactory
- The annotation value filter factory to use.public ByteBuddy with(AnnotationRetention annotationRetention)
Creates a new configuration where annotations that are found in an existing class file are or are not preserved in the format they are discovered, i.e. rewritten in the format they were already present in the class file. By default, Byte Buddy retains annotations when a class is rebased or redefined.
Warning: Retaining annotations can cause problems when annotations of a field or method are added based on the annotations of a matched method. Doing so, Byte Buddy might write the annotations of the field or method explicitly to a class file while simultaneously retaining the existing annotation what results in duplicates. When matching fields or methods while adding annotations, disabling annotation retention might be required.
annotationRetention
- The annotation retention strategy to use.public ByteBuddy with(Implementation.Context.Factory implementationContextFactory)
Implementation.Context
of any created
type is a product of the given implementation context factory. An implementation context might imply unwanted
side-effects, for example, the creation of an additional synthetic methods in order to support specific features
for realizing an Implementation
. By default, Byte Buddy supplies a factory that enables all features. When
redefining a loaded class, it is however required by the JVM that no additional members are added such that a
Implementation.Context.Disabled
factory might be more appropriate.implementationContextFactory
- The implementation context factory to use for defining an instrumented type.public ByteBuddy with(MethodGraph.Compiler methodGraphCompiler)
MethodGraph.Compiler
is used for creating a MethodGraph
of the instrumented type. A method graph is a representation of a type's virtual methods, including all information
on bridge methods that are inserted by the Java compiler. Creating a method graph is a rather expensive operation
and more efficient strategies might exist for certain types or ava types that are created by alternative JVM
languages. By default, a general purpose method graph compiler is used that uses the information that is exposed
by the generic type information that is embedded in any class file.methodGraphCompiler
- The method graph compiler to use for analyzing the instrumented type.public ByteBuddy with(TypeValidation typeValidation)
Error
is thrown if a type is invalid, while Byte Buddy throws
some RuntimeException
.typeValidation
- The type validation to apply during type creation.public ByteBuddy ignore(ElementMatcher<? super MethodDescription> ignoredMethods)
MethodDescription
that matches the provided method matcher is excluded
from instrumentation. Any previous matcher for ignored methods is replaced. By default, Byte Buddy ignores any
synthetic method (bridge methods are handled automatically) and the Object.finalize()
method.ignoredMethods
- A matcher for identifying methods to be excluded from instrumentation.public ByteBuddy ignore(LatentMatcher<? super MethodDescription> ignoredMethods)
Creates a new configuration where any MethodDescription
that matches the provided method matcher is excluded
from instrumentation. Any previous matcher for ignored methods is replaced. By default, Byte Buddy ignores any
synthetic method (bridge methods are handled automatically) and the Object.finalize()
method. Using a latent
matcher gives opportunity to resolve an ElementMatcher
based on the instrumented type before applying the matcher.
ignoredMethods
- A matcher for identifying methods to be excluded from instrumentation.Copyright © 2014–2017. All rights reserved.