Interface DynamicType
- All Superinterfaces:
AutoCloseable
,ClassFileLocator
,Closeable
- All Known Subinterfaces:
DynamicType.Loaded<T>
,DynamicType.Unloaded<T>
- All Known Implementing Classes:
AgentBuilder.Transformer.ForAdvice.LazyDynamicType
,DynamicType.AbstractBase
,DynamicType.Default
,DynamicType.Default.Loaded
,DynamicType.Default.Unloaded
DynamicType.Builder
or as the result of an
AuxiliaryType
.
Note that the
TypeDescription
s will represent their
unloaded forms and therefore differ from the loaded types, especially with regards to annotations.-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic class
static interface
A builder for creating a dynamic type.static class
A default implementation of a dynamic type.static interface
A dynamic type that has been loaded into the running instance of the Java virtual machine.static interface
A dynamic type that has not yet been loaded by a givenClassLoader
.Nested classes/interfaces inherited from interface net.bytebuddy.dynamic.ClassFileLocator
ClassFileLocator.Compound, ClassFileLocator.Filtering, ClassFileLocator.ForClassLoader, ClassFileLocator.ForFolder, ClassFileLocator.ForInstrumentation, ClassFileLocator.ForJarFile, ClassFileLocator.ForModule, ClassFileLocator.ForModuleFile, ClassFileLocator.ForUrl, ClassFileLocator.MultiReleaseAware, ClassFileLocator.NoOp, ClassFileLocator.PackageDiscriminating, ClassFileLocator.Resolution, ClassFileLocator.Simple
-
Field Summary
Fields inherited from interface net.bytebuddy.dynamic.ClassFileLocator
CLASS_FILE_EXTENSION, META_INF_VERSIONS
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Returns a set of all types that are represented by this dynamic type.Map
<TypeDescription, byte[]> Returns all types that are implied by this dynamic type.List
<? extends DynamicType> Returns all auxiliary types of this dynamic type.Returns a set of all auxiliary types that are represented by this dynamic type.Map
<TypeDescription, byte[]> Returns a map of all auxiliary types that are required for making use of the main type.byte[]
getBytes()
Returns a byte array representing this dynamic type.Returns the loaded type initializer of this dynamic type.Returns a map of all loaded type initializers for the main type and all auxiliary types, if any.Returns a description of this dynamic type.boolean
Checks if a dynamic type requires some form of explicit type initialization, either for itself or for one of its auxiliary types, if any.Injects the types of this dynamic type into a given jar file.Injects the types of this dynamic type into a given jar file.Saves a dynamic type in a given folder using the Java class file format while respecting the naming conventions for saving compiled Java classes.Saves the contents of this dynamic type inside a jar file.Saves the contents of this dynamic type inside a jar file.Methods inherited from interface net.bytebuddy.dynamic.ClassFileLocator
locate
-
Method Details
-
getTypeDescription
TypeDescription getTypeDescription()Returns a description of this dynamic type.
Note: This description will most likely differ from the binary representation of this type. Normally, annotations and intercepted methods are not added to this type description.
- Returns:
- A description of this dynamic type.
-
getBytes
byte[] getBytes()Returns a byte array representing this dynamic type. This byte array might be reused by this dynamic type and must therefore not be altered.- Returns:
- A byte array of the type's binary representation.
-
getLoadedTypeInitializer
LoadedTypeInitializer getLoadedTypeInitializer()Returns the loaded type initializer of this dynamic type.- Returns:
- The loaded type initializer of this dynamic type.
-
getAuxiliaries
List<? extends DynamicType> getAuxiliaries()Returns all auxiliary types of this dynamic type.- Returns:
- A list of all auxiliary types of this dynamic type.
-
getAuxiliaryTypeDescriptions
Set<TypeDescription> getAuxiliaryTypeDescriptions()Returns a set of all auxiliary types that are represented by this dynamic type.- Returns:
- A set of all auxiliary types.
-
getAllTypeDescriptions
Set<TypeDescription> getAllTypeDescriptions()Returns a set of all types that are represented by this dynamic type.- Returns:
- A set of all represented types.
-
getAuxiliaryTypes
Map<TypeDescription,byte[]> getAuxiliaryTypes()Returns a map of all auxiliary types that are required for making use of the main type.
Note: The type descriptions will most likely differ from the binary representation of this type. Normally, annotations and intercepted methods are not added to the type descriptions of auxiliary types.
- Returns:
- A map of all auxiliary types by their descriptions to their binary representation.
-
getAllTypes
Map<TypeDescription,byte[]> getAllTypes()Returns all types that are implied by this dynamic type.- Returns:
- A mapping from all type descriptions, the actual type and its auxiliary types to their binary representation
-
getLoadedTypeInitializers
Map<TypeDescription,LoadedTypeInitializer> getLoadedTypeInitializers()Returns a map of all loaded type initializers for the main type and all auxiliary types, if any.
Note: The type descriptions will most likely differ from the binary representation of this type. Normally, annotations and intercepted methods are not added to the type descriptions of auxiliary types.
- Returns:
- A mapping of all types' descriptions to their loaded type initializers.
-
hasAliveLoadedTypeInitializers
boolean hasAliveLoadedTypeInitializers()Checks if a dynamic type requires some form of explicit type initialization, either for itself or for one of its auxiliary types, if any. This is the case when this dynamic type was defined to delegate method calls to a specific instance which is stored in a field of the created type. If this class serialized, it could not be used without its loaded type initializers since the field value represents a specific runtime context.- Returns:
true
if this type requires explicit type initialization.
-
saveIn
Saves a dynamic type in a given folder using the Java class file format while respecting the naming conventions for saving compiled Java classes. All auxiliary types, if any, are saved in the same directory. The resulting folder structure will resemble the structure that is required for Java run times, i.e. each folder representing a segment of the package name. If the specified
folder
does not yet exist, it is created during the call of this method.Note: The type descriptions will most likely differ from the binary representation of this type. Normally, annotations and intercepted methods are not added to the type descriptions of auxiliary types.
- Parameters:
folder
- The base target folder for storing this dynamic type and its auxiliary types, if any.- Returns:
- A map of type descriptions pointing to files with their stored binary representations within
folder
. - Throws:
IOException
- Thrown if the underlying file operations cause anIOException
.
-
inject
Injects the types of this dynamic type into a given jar file. Any pre-existent type with the same name is overridden during injection. The resulting jar is going to be a recreation of the original jar and not a patched version with a new central directory. No directory entries are added to the generated jar.- Parameters:
sourceJar
- The original jar file.targetJar
- Thesource
jar file with the injected contents.- Returns:
- The
target
jar file. - Throws:
IOException
- If an I/O exception occurs while injecting from the source into the target.
-
inject
Injects the types of this dynamic type into a given jar file. Any pre-existent type with the same name is overridden during injection. The resulting jar is going to be a recreation of the original jar and not a patched version with a new central directory. No directory entries are added to the generated jar.- Parameters:
jar
- The jar file to replace with an injected version.- Returns:
- The
jar
file. - Throws:
IOException
- If an I/O exception occurs while injecting into the jar.
-
toJar
Saves the contents of this dynamic type inside a jar file. The folder of the givenfile
must exist prior to calling this method. The jar file is created with a simple manifest that only contains a version number. No directory entries are added to the generated jar.- Parameters:
file
- The target file to which the jar is written to.- Returns:
- The given
file
. - Throws:
IOException
- If an I/O exception occurs while writing the file.
-
toJar
Saves the contents of this dynamic type inside a jar file. The folder of the givenfile
must exist prior to calling this method. No directory entries are added to the generated jar.- Parameters:
file
- The target file to which the jar is written to.manifest
- The manifest of the created jar.- Returns:
- The given
file
. - Throws:
IOException
- If an I/O exception occurs while writing the file.
-
close
void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-