Top Description Inners Fields Methods
net.bytebuddy.description.type

public Interface TypeDefinition

extends NamedElement, ForTypeDefinition, Iterable<TypeDefinition>
Known Direct Subinterfaces
net.bytebuddy.description.type.TypeDescription, net.bytebuddy.description.type.TypeDescription.Generic
Imports
net.bytebuddy.build.AccessControllerPlugin, net.bytebuddy.description.ModifierReviewable, .NamedElement, net.bytebuddy.description.field.FieldList, net.bytebuddy.description.method.MethodList, net.bytebuddy.implementation.bytecode.StackSize, net.bytebuddy.utility.dispatcher.JavaDispatcher, net.bytebuddy.utility.nullability.MaybeNull, .UnknownNull, java.lang.reflect.*, java.security.PrivilegedAction, java.util.Iterator, .NoSuchElementException

Implementations define a type, either as a TypeDescription or as a TypeDescription.Generic.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
public static class
TypeDefinition.SuperClassIterator

An iterator that iterates over a type's class hierarchy.

Field Summary

Modifier and TypeField and Description
public static final String
RAW_TYPES_PROPERTY

If this property is set to true, non-generic TypeDefinitions do no longer resolve their referenced generic types when traversing type hierarchies.

Inherited from net.bytebuddy.description.NamedElement:
EMPTY_NAMENO_NAME

Method Summary

Modifier and TypeMethod and Description
public TypeDescription

Returns:

The erasure of this type.
asErasure
()

Returns the erasure of this type.

public TypeDescription.Generic

Returns:

This type definition represented as a generic type.
asGenericType
()

Returns this type definition as a generic type.

public TypeDefinition

Returns:

The component type of this type or null if this type does not represent an array type.
getComponentType
()

Returns the component type of this type.

public FieldList<?>

Returns:

The fields that this type declares. A super type is only defined for non-generic types (Sort#NON_GENERIC), parameterized types (Sort#PARAMETERIZED) or generic array types (Sort#GENERIC_ARRAY) types. Generic array types never define methods and the returned list is always empty for such types.
getDeclaredFields
()

Returns the fields that this type declares.

public MethodList<?>

Returns:

The methods that this type declares.
getDeclaredMethods
()

Returns the methods that this type declares.

public TypeList.Generic

Returns:

The interfaces that this type implements.
getInterfaces
()

Returns the interfaces that this type implements.

public RecordComponentList<?>

Returns:

A list of record components that this type declares.
getRecordComponents
()

Returns the list of record components that are declared by this type.

public TypeDefinition.Sort

Returns:

The sort of the generic type.
getSort
()

Returns the sort of the generic type this instance represents.

public StackSize

Returns:

The size of the type described by this instance.
getStackSize
()

Returns the size of the type described by this instance.

public TypeDescription.Generic

Returns:

The super class of this type or null if no super class exists for this type.
getSuperClass
()

Returns the super class of this type.

public String

Returns:

The name of this type.
getTypeName
()

Returns the name of the type.

public boolean

Returns:

true if this type description represents an array.
isArray
()

Checks if the type described by this entity is an array.

public boolean

Returns:

true if this type description represents a primitive type.
isPrimitive
()

Checks if the type described by this entity is a primitive type.

public boolean

Returns:

true if this type is a Java record.
isRecord
()

Checks if this type is a Java record.

public boolean

Returns:

true if the type described by this instance represents type.
represents
(Type
The type of interest.
type
)

Checks if the type described by this instance represents type.

Inherited from java.lang.Iterable:
forEachiteratorspliterator
Inherited from net.bytebuddy.description.ModifierReviewable.ForTypeDefinition:
getTypeManifestationisAnnotationisInterface
Inherited from net.bytebuddy.description.NamedElement:
getActualName

Field Detail

RAW_TYPES_PROPERTYback to summary
public static final String RAW_TYPES_PROPERTY

If this property is set to true, non-generic TypeDefinitions do no longer resolve their referenced generic types when traversing type hierarchies. Setting this property can cause unexpected side effects such as ClassCastExceptions from overridden methods as type variables are resolved to their erasures where a method might return that is unexpected by the callee. Setting this property also makes type annotations unavailable using such type navigation.

Setting this property can be useful if generic type information is not required in order to avoid bugs in implementations of the JVM where processing generic types can cause segmentation faults. Byte Buddy will undertake a best effort to retain the generic type information and information about type annotations within the redefined types' class files. Typically, this property can be meaningful in combination with a Java agent that only changes byte code without changing a class type's structure.

Method Detail

asErasureback to summary
public TypeDescription asErasure()

Returns the erasure of this type. Wildcard types (TypeDescription.Generic.Sort#WILDCARD) do not have a well-defined erasure and cause an IllegalStateException to be thrown.

Returns:TypeDescription

The erasure of this type.

asGenericTypeback to summary
public TypeDescription.Generic asGenericType()

Returns this type definition as a generic type.

Returns:TypeDescription.Generic

This type definition represented as a generic type.

getComponentTypeback to summary
public TypeDefinition getComponentType()

Returns the component type of this type.

Only non-generic types (TypeDescription.Generic.Sort#NON_GENERIC) and generic array types TypeDescription.Generic.Sort#GENERIC_ARRAY) define a component type. For other types, an IllegalStateException is thrown.

Returns:TypeDefinition

The component type of this type or null if this type does not represent an array type.

Annotations
@MaybeNull
getDeclaredFieldsback to summary
public FieldList<?> getDeclaredFields()

Returns the fields that this type declares. A super type is only defined for non-generic types (Sort#NON_GENERIC), parameterized types (Sort#PARAMETERIZED) or generic array types (Sort#GENERIC_ARRAY) types. Generic array types never define fields and the returned list is always empty for such types.

Returns:FieldList<?>

The fields that this type declares. A super type is only defined for non-generic types (Sort#NON_GENERIC), parameterized types (Sort#PARAMETERIZED) or generic array types (Sort#GENERIC_ARRAY) types. Generic array types never define methods and the returned list is always empty for such types.

getDeclaredMethodsback to summary
public MethodList<?> getDeclaredMethods()

Returns the methods that this type declares.

Returns:MethodList<?>

The methods that this type declares.

getInterfacesback to summary
public TypeList.Generic getInterfaces()

Returns the interfaces that this type implements. A super type is only defined for non-generic types (Sort#NON_GENERIC), parameterized types (Sort#PARAMETERIZED) or generic array types (Sort#GENERIC_ARRAY) types.

Returns:TypeList.Generic

The interfaces that this type implements.

getRecordComponentsback to summary
public RecordComponentList<?> getRecordComponents()

Returns the list of record components that are declared by this type. If this type is not a record, the returned list is empty.

Returns:RecordComponentList<?>

A list of record components that this type declares.

getSortback to summary
public TypeDefinition.Sort getSort()

Returns the sort of the generic type this instance represents.

Returns:TypeDefinition.Sort

The sort of the generic type.

getStackSizeback to summary
public StackSize getStackSize()

Returns the size of the type described by this instance. Wildcard types (TypeDescription.Generic.Sort#WILDCARD do not have a well-defined a stack size and cause an IllegalStateException to be thrown.

Returns:StackSize

The size of the type described by this instance.

getSuperClassback to summary
public TypeDescription.Generic getSuperClass()

Returns the super class of this type. A super type is only defined for non-generic types (Sort#NON_GENERIC), parameterized types (Sort#PARAMETERIZED) or generic array types (Sort#GENERIC_ARRAY) types. Interface types and the Object class do not define a super class where null is returned. Array types define Object as their direct super class.

Returns:TypeDescription.Generic

The super class of this type or null if no super class exists for this type.

Annotations
@MaybeNull
getTypeNameback to summary
public String getTypeName()

Returns the name of the type. For generic types, this name is their Object#toString() representations. For a non-generic type, it is the fully qualified binary name of the type.

Returns:String

The name of this type.

isArrayback to summary
public boolean isArray()

Checks if the type described by this entity is an array.

Returns:boolean

true if this type description represents an array.

isPrimitiveback to summary
public boolean isPrimitive()

Checks if the type described by this entity is a primitive type.

Returns:boolean

true if this type description represents a primitive type.

isRecordback to summary
public boolean isRecord()

Checks if this type is a Java record.

Returns:boolean

true if this type is a Java record.

representsback to summary
public boolean represents(Type type)

Checks if the type described by this instance represents type.

Parameters
type:Type

The type of interest.

Returns:boolean

true if the type described by this instance represents type.

net.bytebuddy.description.type back to summary

public final Enum TypeDefinition.Sort

extends Enum<TypeDefinition.Sort>
Class Inheritance

Represents a TypeDescription.Generic's form.

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static interface
TypeDefinition.Sort.AnnotatedType

A proxy for interacting with java.lang.reflect.AnnotatedType.

Field Summary

Modifier and TypeField and Description
private static final TypeDefinition.Sort.AnnotatedType
ANNOTATED_TYPE

A dispatcher for interacting with java.lang.reflect.AnnotatedType.

public static final TypeDefinition.Sort
GENERIC_ARRAY

Represents a generic array type.

public static final TypeDefinition.Sort
NON_GENERIC

Represents a non-generic type.

public static final TypeDefinition.Sort
PARAMETERIZED

Represents a parameterized type.

public static final TypeDefinition.Sort
VARIABLE

Represents a type variable that is attached to a net.bytebuddy.description.TypeVariableSource.

public static final TypeDefinition.Sort
VARIABLE_SYMBOLIC

Represents a type variable that is merely symbolic and is not attached to a net.bytebuddy.description.TypeVariableSource and does not defined bounds.

public static final TypeDefinition.Sort
WILDCARD

Represents a wildcard type.

Constructor Summary

AccessConstructor and Description
private
Sort()

Method Summary

Modifier and TypeMethod and Description
public static TypeDescription.Generic

Returns:

A description of the provided generic type.
describe
(Type
The type to describe.
type
)

Describes a loaded generic type as a TypeDescription.Generic.

protected static TypeDescription.Generic

Returns:

A description of the provided generic annotated type.
describe
(Type
The type to describe.
type
,
TypeDescription.Generic.AnnotationReader
The annotation reader for extracting type annotations.
annotationReader
)

Describes the generic type while using the supplied annotation reader for resolving type annotations if this language feature is available on the current JVM.

public static TypeDescription.Generic

Returns:

A description of the provided generic type.
describeAnnotated
(AnnotatedElement
The java.lang.reflect.AnnotatedType to describe.
annotatedType
)

Describes a loaded java.lang.reflect.AnnotatedType as a TypeDescription.Generic.

private static <
The type of the action's resolved value.
T
>
T

Returns:

The action's resolved value.
doPrivileged
(PrivilegedAction<T>
The action to execute from a privileged context.
action
)

A proxy for java.security.AccessController#doPrivileged that is activated if available.

public boolean

Returns:

true if this type sort represents a generic array.
isGenericArray
()

Checks if this type sort represents a generic array.

public boolean

Returns:

true if this sort form represents a non-generic.
isNonGeneric
()

Checks if this type sort represents a non-generic type.

public boolean

Returns:

true if this sort form represents a parameterized type.
isParameterized
()

Checks if this type sort represents a parameterized type.

public boolean

Returns:

true if this type sort represents an attached type variable.
isTypeVariable
()

Checks if this type sort represents a type variable of any form.

public boolean

Returns:

true if this type sort represents a wildcard.
isWildcard
()

Checks if this type sort represents a wildcard.

public static TypeDefinition.Sort
public static TypeDefinition.Sort[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

ANNOTATED_TYPEback to summary
private static final TypeDefinition.Sort.AnnotatedType ANNOTATED_TYPE

A dispatcher for interacting with java.lang.reflect.AnnotatedType.

GENERIC_ARRAYback to summary
public static final TypeDefinition.Sort GENERIC_ARRAY

Represents a generic array type.

NON_GENERICback to summary
public static final TypeDefinition.Sort NON_GENERIC

Represents a non-generic type.

PARAMETERIZEDback to summary
public static final TypeDefinition.Sort PARAMETERIZED

Represents a parameterized type.

VARIABLEback to summary
public static final TypeDefinition.Sort VARIABLE

Represents a type variable that is attached to a net.bytebuddy.description.TypeVariableSource.

VARIABLE_SYMBOLICback to summary
public static final TypeDefinition.Sort VARIABLE_SYMBOLIC

Represents a type variable that is merely symbolic and is not attached to a net.bytebuddy.description.TypeVariableSource and does not defined bounds.

WILDCARDback to summary
public static final TypeDefinition.Sort WILDCARD

Represents a wildcard type.

Constructor Detail

Sortback to summary
private Sort()

Method Detail

describeback to summary
public static TypeDescription.Generic describe(Type type)

Describes a loaded generic type as a TypeDescription.Generic.

Parameters
type:Type

The type to describe.

Returns:TypeDescription.Generic

A description of the provided generic type.

describeback to summary
protected static TypeDescription.Generic describe(Type type, TypeDescription.Generic.AnnotationReader annotationReader)

Describes the generic type while using the supplied annotation reader for resolving type annotations if this language feature is available on the current JVM.

Parameters
type:Type

The type to describe.

annotationReader:TypeDescription.Generic.AnnotationReader

The annotation reader for extracting type annotations.

Returns:TypeDescription.Generic

A description of the provided generic annotated type.

describeAnnotatedback to summary
public static TypeDescription.Generic describeAnnotated(AnnotatedElement annotatedType)

Describes a loaded java.lang.reflect.AnnotatedType as a TypeDescription.Generic.

Parameters
annotatedType:AnnotatedElement

The java.lang.reflect.AnnotatedType to describe.

Returns:TypeDescription.Generic

A description of the provided generic type.

doPrivilegedback to summary
private static <T> T doPrivileged(PrivilegedAction<T> action)

A proxy for java.security.AccessController#doPrivileged that is activated if available.

Parameters
<T>
The type of the action's resolved value.
action:PrivilegedAction<T>

The action to execute from a privileged context.

Returns:T

The action's resolved value.

Annotations
@Enhance
isGenericArrayback to summary
public boolean isGenericArray()

Checks if this type sort represents a generic array.

Returns:boolean

true if this type sort represents a generic array.

isNonGenericback to summary
public boolean isNonGeneric()

Checks if this type sort represents a non-generic type.

Returns:boolean

true if this sort form represents a non-generic.

isParameterizedback to summary
public boolean isParameterized()

Checks if this type sort represents a parameterized type.

Returns:boolean

true if this sort form represents a parameterized type.

isTypeVariableback to summary
public boolean isTypeVariable()

Checks if this type sort represents a type variable of any form.

Returns:boolean

true if this type sort represents an attached type variable.

isWildcardback to summary
public boolean isWildcard()

Checks if this type sort represents a wildcard.

Returns:boolean

true if this type sort represents a wildcard.

valueOfback to summary
public static TypeDefinition.Sort valueOf(String name)
valuesback to summary
public static TypeDefinition.Sort[] values()
net.bytebuddy.description.type back to summary

protected Interface TypeDefinition.Sort.AnnotatedType

Annotations
@Proxied:AnnotatedType

A proxy for interacting with java.lang.reflect.AnnotatedType.

Method Summary

Modifier and TypeMethod and Description
public Type

Returns:

The annotated type's type.
getType
(AnnotatedElement
The java.lang.reflect.AnnotatedType to resolve.
value
)

Resolves the supplied java.lang.reflect.AnnotatedType's type.

public boolean

Returns:

true if the supplied instance is of type java.lang.reflect.AnnotatedType.
isInstance
(AnnotatedElement
The instance to consider.
value
)

Returns true if the supplied value is an instance of java.lang.reflect.AnnotatedType.

Method Detail

getTypeback to summary
public Type getType(AnnotatedElement value)

Resolves the supplied java.lang.reflect.AnnotatedType's type.

Parameters
value:AnnotatedElement

The java.lang.reflect.AnnotatedType to resolve.

Returns:Type

The annotated type's type.

isInstanceback to summary
public boolean isInstance(AnnotatedElement value)

Returns true if the supplied value is an instance of java.lang.reflect.AnnotatedType.

Parameters
value:AnnotatedElement

The instance to consider.

Returns:boolean

true if the supplied instance is of type java.lang.reflect.AnnotatedType.

Annotations
@Instance
net.bytebuddy.description.type back to summary

public Class TypeDefinition.SuperClassIterator

extends Object
implements Iterator<TypeDefinition>
Class Inheritance
  • java.lang.Object
  • net.bytebuddy.description.type.TypeDefinition.SuperClassIterator
All Implemented Interfaces
java.util.Iterator

An iterator that iterates over a type's class hierarchy.

Field Summary

Modifier and TypeField and Description
private TypeDefinition
nextClass

The next class to represent.

Constructor Summary

AccessConstructor and Description
public
SuperClassIterator(TypeDefinition
The initial type of this iterator.
initialType
)

Creates a new iterator.

Method Summary

Modifier and TypeMethod and Description
public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.
public TypeDefinition
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.
public void
remove()

Overrides default java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation).
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

nextClassback to summary
private TypeDefinition nextClass

The next class to represent.

Annotations
@UnknownNull

Constructor Detail

SuperClassIteratorback to summary
public SuperClassIterator(TypeDefinition initialType)

Creates a new iterator.

Parameters
initialType:TypeDefinition

The initial type of this iterator.

Method Detail

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the iteration has more elements

nextback to summary
public TypeDefinition next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:TypeDefinition

the next element in the iteration

removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Doc from java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call to next.

The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.

The behavior of an iterator is unspecified if this method is called after a call to the forEachRemaining method.