Package net.bytebuddy.description.type
Interface TypeDescription
-
- All Superinterfaces:
AnnotationSource
,ByteCodeElement
,DeclaredByType
,java.lang.Iterable<TypeDefinition>
,ModifierReviewable
,ModifierReviewable.ForTypeDefinition
,ModifierReviewable.OfAbstraction
,ModifierReviewable.OfByteCodeElement
,ModifierReviewable.OfEnumeration
,NamedElement
,NamedElement.WithRuntimeName
,TypeDefinition
,TypeVariableSource
- All Known Subinterfaces:
InstrumentedType
,InstrumentedType.WithFlexibleName
- All Known Implementing Classes:
InstrumentedType.Default
,InstrumentedType.Frozen
,TypeDescription.AbstractBase
,TypeDescription.AbstractBase.OfSimpleType
,TypeDescription.AbstractBase.OfSimpleType.WithDelegation
,TypeDescription.ArrayProjection
,TypeDescription.ForLoadedType
,TypeDescription.ForPackageDescription
,TypeDescription.Latent
,TypeDescription.SuperTypeLoading
,TypePool.Default.LazyTypeDescription
,TypePool.Default.WithLazyResolution.LazyTypeDescription
,TypePool.LazyFacade.LazyTypeDescription
public interface TypeDescription extends TypeDefinition, ByteCodeElement, TypeVariableSource
Implementations of this interface represent a Java type, i.e. a class or interface. Instances of this interface always represent non-generic types of sortTypeDefinition.Sort.NON_GENERIC
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
TypeDescription.AbstractBase
An abstract base implementation of a type description.static class
TypeDescription.ArrayProjection
A projection for an array type based on an existingTypeDescription
.static class
TypeDescription.ForLoadedType
A type description implementation that represents a loaded type.static class
TypeDescription.ForPackageDescription
A type representation of a package description.static interface
TypeDescription.Generic
Represents a generic type of the Java programming language.static class
TypeDescription.Latent
A latent type description for a type without methods or fields.static class
TypeDescription.SuperTypeLoading
A delegating type description that always attempts to load the super types of a delegate type.-
Nested classes/interfaces inherited from interface net.bytebuddy.description.annotation.AnnotationSource
AnnotationSource.Empty, AnnotationSource.Explicit
-
Nested classes/interfaces inherited from interface net.bytebuddy.description.ByteCodeElement
ByteCodeElement.Token<T extends ByteCodeElement.Token<T>>, ByteCodeElement.TypeDependant<T extends ByteCodeElement.TypeDependant<?,S>,S extends ByteCodeElement.Token<S>>
-
Nested classes/interfaces inherited from interface net.bytebuddy.description.ModifierReviewable
ModifierReviewable.ForFieldDescription, ModifierReviewable.ForMethodDescription, ModifierReviewable.ForParameterDescription, ModifierReviewable.ForTypeDefinition, ModifierReviewable.OfAbstraction, ModifierReviewable.OfByteCodeElement, ModifierReviewable.OfEnumeration
-
Nested classes/interfaces inherited from interface net.bytebuddy.description.NamedElement
NamedElement.WithGenericName, NamedElement.WithOptionalName, NamedElement.WithRuntimeName
-
Nested classes/interfaces inherited from interface net.bytebuddy.description.type.TypeDefinition
TypeDefinition.Sort, TypeDefinition.SuperClassIterator
-
Nested classes/interfaces inherited from interface net.bytebuddy.description.TypeVariableSource
TypeVariableSource.Visitor<T>
-
-
Field Summary
Fields Modifier and Type Field Description static TypeList.Generic
ARRAY_INTERFACES
A list of interfaces that are implicitly implemented by any array type.static TypeDescription
CLASS
A representation of theClass
type.static TypeDescription
OBJECT
A representation of theObject
type.static TypeDescription
STRING
A representation of theString
type.static TypeDescription
THROWABLE
A representation of theThrowable
type.static TypeDescription
UNDEFINED
Represents any undefined property representing a type description that is instead represented asnull
in order to resemble the Java reflection API which returnsnull
and is intuitive to many Java developers.static TypeDescription
VOID
A representation of thevoid
non-type.-
Fields inherited from interface net.bytebuddy.description.ByteCodeElement
NON_GENERIC_SIGNATURE
-
Fields inherited from interface net.bytebuddy.description.ModifierReviewable
EMPTY_MASK
-
Fields inherited from interface net.bytebuddy.description.NamedElement
EMPTY_NAME, NO_NAME
-
Fields inherited from interface net.bytebuddy.description.type.TypeDefinition
RAW_TYPES_PROPERTY
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description TypeDescription
asBoxed()
Returns a description of this type that represents this type as a boxed type for primitive types, unless itsvoid
.TypeDescription
asUnboxed()
Returns a description of this type that represents this type as an unboxed type for boxing types, unless itsVoid
.int
getActualModifiers(boolean superFlag)
Returns the type's actual modifiers as present in the class file.java.lang.String
getCanonicalName()
Returns the canonical name of this type if it exists.TypeDescription
getComponentType()
Returns the component type of this type.FieldList<FieldDescription.InDefinedShape>
getDeclaredFields()
Returns the fields that this type declares.MethodList<MethodDescription.InDefinedShape>
getDeclaredMethods()
Returns the methods that this type declares.TypeList
getDeclaredTypes()
Returns a list of types that are declared by this type excluding anonymous classes.TypeDescription
getDeclaringType()
Returns the declaring type of this instance.java.lang.Object
getDefaultValue()
Returns the default value for this type, i.e.MethodDescription
getEnclosingMethod()
Returns a description of the method that encloses this type.TypeDescription
getEnclosingType()
Returns a description of this type's enclosing type if any.AnnotationList
getInheritedAnnotations()
Returns the annotations that this type declares or inherits from super types.int
getInnerClassCount()
Returns the amount of outer classes this type defines.PackageDescription
getPackage()
Returns the package internalName of the type described by this instance.java.lang.String
getSimpleName()
Returns the simple internalName of this type.boolean
isAnnotationReturnType()
Checks if instances of this type can be returned from an annotation method.boolean
isAnnotationValue()
Checks if instances of this type can be used for describing an annotation value.boolean
isAnnotationValue(java.lang.Object value)
Checks if instances of this type can be used for describing the given annotation value.boolean
isAnonymousClass()
Checks if this type description represents an anonymous type.boolean
isAssignableFrom(java.lang.Class<?> type)
Checks if this type is assignable from the type described by this instance, for example forclass Foo
andclass Bar extends Foo
, this method would returntrue
forFoo.class.isAssignableFrom(Bar.class)
.boolean
isAssignableFrom(TypeDescription typeDescription)
Checks if this type is assignable from the type described by this instance, for example forclass Foo
andclass Bar extends Foo
, this method would returntrue
forFoo.class.isAssignableFrom(Bar.class)
.boolean
isAssignableTo(java.lang.Class<?> type)
Checks if this type is assignable from the type described by this instance, for example forclass Foo
andclass Bar extends Foo
, this method would returntrue
forBar.class.isAssignableTo(Foo.class)
.boolean
isAssignableTo(TypeDescription typeDescription)
Checks if this type is assignable from the type described by this instance, for example forclass Foo
andclass Bar extends Foo
, this method would returntrue
forBar.class.isAssignableFrom(Foo.class)
.boolean
isConstantPool()
Checks if instances of this type can be stored in the constant pool of a class.boolean
isInnerClass()
Indicates if this class is an inner class.boolean
isInstance(java.lang.Object value)
Checks ifvalue
is an instance of the type represented by this instance.boolean
isLocalClass()
Checks if this type description represents a local type.boolean
isMemberClass()
Checks if this type description represents a member type.boolean
isNestedClass()
Indicates if this class is a nested class.boolean
isPackageType()
Checks if this type represents a class that is a place holder for a package description.boolean
isPrimitiveWrapper()
Checks if this type represents a wrapper type for a primitive type.boolean
isSamePackage(TypeDescription typeDescription)
Checks if two types are defined in the same package.-
Methods inherited from interface net.bytebuddy.description.annotation.AnnotationSource
getDeclaredAnnotations
-
Methods inherited from interface net.bytebuddy.description.ByteCodeElement
getDescriptor, getGenericSignature, isAccessibleTo, isVisibleTo
-
Methods inherited from interface net.bytebuddy.description.ModifierReviewable
getModifiers, getSyntheticState, isFinal, isSynthetic
-
Methods inherited from interface net.bytebuddy.description.ModifierReviewable.ForTypeDefinition
getTypeManifestation, isAnnotation, isInterface
-
Methods inherited from interface net.bytebuddy.description.ModifierReviewable.OfAbstraction
isAbstract
-
Methods inherited from interface net.bytebuddy.description.ModifierReviewable.OfByteCodeElement
getOwnership, getVisibility, isDeprecated, isPackagePrivate, isPrivate, isProtected, isPublic, isStatic
-
Methods inherited from interface net.bytebuddy.description.ModifierReviewable.OfEnumeration
getEnumerationState, isEnum
-
Methods inherited from interface net.bytebuddy.description.NamedElement
getActualName
-
Methods inherited from interface net.bytebuddy.description.NamedElement.WithRuntimeName
getInternalName, getName
-
Methods inherited from interface net.bytebuddy.description.type.TypeDefinition
asErasure, asGenericType, getInterfaces, getSort, getStackSize, getSuperClass, getTypeName, isArray, isPrimitive, represents
-
Methods inherited from interface net.bytebuddy.description.TypeVariableSource
accept, findVariable, getEnclosingSource, getTypeVariables, isGenerified
-
-
-
-
Field Detail
-
OBJECT
static final TypeDescription OBJECT
A representation of theObject
type.
-
STRING
static final TypeDescription STRING
A representation of theString
type.
-
CLASS
static final TypeDescription CLASS
A representation of theClass
type.
-
THROWABLE
static final TypeDescription THROWABLE
A representation of theThrowable
type.
-
VOID
static final TypeDescription VOID
A representation of thevoid
non-type.
-
ARRAY_INTERFACES
static final TypeList.Generic ARRAY_INTERFACES
A list of interfaces that are implicitly implemented by any array type.
-
UNDEFINED
static final TypeDescription UNDEFINED
Represents any undefined property representing a type description that is instead represented asnull
in order to resemble the Java reflection API which returnsnull
and is intuitive to many Java developers.
-
-
Method Detail
-
getDeclaredFields
FieldList<FieldDescription.InDefinedShape> getDeclaredFields()
Description copied from interface:TypeDefinition
Returns the fields that this type declares. A super type is only defined for non-generic types (TypeDefinition.Sort.NON_GENERIC
), parameterized types (TypeDefinition.Sort.PARAMETERIZED
) or generic array types (TypeDefinition.Sort.GENERIC_ARRAY
) types. Generic array types never define fields and the returned list is always empty for such types.- Specified by:
getDeclaredFields
in interfaceTypeDefinition
- Returns:
- The fields that this type declares. A super type is only defined for non-generic types (
TypeDefinition.Sort.NON_GENERIC
), parameterized types (TypeDefinition.Sort.PARAMETERIZED
) or generic array types (TypeDefinition.Sort.GENERIC_ARRAY
) types. Generic array types never define methods and the returned list is always empty for such types.
-
getDeclaredMethods
MethodList<MethodDescription.InDefinedShape> getDeclaredMethods()
Description copied from interface:TypeDefinition
Returns the methods that this type declares.- Specified by:
getDeclaredMethods
in interfaceTypeDefinition
- Returns:
- The methods that this type declares.
-
isInstance
boolean isInstance(java.lang.Object value)
Checks ifvalue
is an instance of the type represented by this instance.- Parameters:
value
- The object of interest.- Returns:
true
if the object is an instance of the type described by this instance.
-
isAssignableFrom
boolean isAssignableFrom(java.lang.Class<?> type)
Checks if this type is assignable from the type described by this instance, for example forclass Foo
andclass Bar extends Foo
, this method would returntrue
forFoo.class.isAssignableFrom(Bar.class)
.- Parameters:
type
- The type of interest.- Returns:
true
if this type is assignable fromtype
.
-
isAssignableFrom
boolean isAssignableFrom(TypeDescription typeDescription)
Checks if this type is assignable from the type described by this instance, for example forclass Foo
andclass Bar extends Foo
, this method would returntrue
forFoo.class.isAssignableFrom(Bar.class)
.isAssignableFrom(Class)
- Parameters:
typeDescription
- The type of interest.- Returns:
true
if this type is assignable fromtype
.
-
isAssignableTo
boolean isAssignableTo(java.lang.Class<?> type)
Checks if this type is assignable from the type described by this instance, for example forclass Foo
andclass Bar extends Foo
, this method would returntrue
forBar.class.isAssignableTo(Foo.class)
.- Parameters:
type
- The type of interest.- Returns:
true
if this type is assignable totype
.
-
isAssignableTo
boolean isAssignableTo(TypeDescription typeDescription)
Checks if this type is assignable from the type described by this instance, for example forclass Foo
andclass Bar extends Foo
, this method would returntrue
forBar.class.isAssignableFrom(Foo.class)
.isAssignableTo(Class)
- Parameters:
typeDescription
- The type of interest.- Returns:
true
if this type is assignable totype
.
-
getComponentType
TypeDescription getComponentType()
Description copied from interface:TypeDefinition
Returns the component type of this type.
Only non-generic types (
TypeDefinition.Sort.NON_GENERIC
) and generic array typesTypeDefinition.Sort.GENERIC_ARRAY
) define a component type. For other types, anIllegalStateException
is thrown.- Specified by:
getComponentType
in interfaceTypeDefinition
- Returns:
- The component type of this type or
null
if this type does not represent an array type.
-
getDeclaringType
TypeDescription getDeclaringType()
Description copied from interface:DeclaredByType
Returns the declaring type of this instance.- Specified by:
getDeclaringType
in interfaceDeclaredByType
- Returns:
- The declaring type or
null
if no such type exists.
-
getDeclaredTypes
TypeList getDeclaredTypes()
Returns a list of types that are declared by this type excluding anonymous classes.- Returns:
- A list of types that are declared within this type.
-
getEnclosingMethod
MethodDescription getEnclosingMethod()
Returns a description of the method that encloses this type. If this method is not enclosed by any type or is enclosed by the type initializer,null
is returned by this method.- Returns:
- A description of the enclosing method of this type or
null
if there is no such method.
-
getEnclosingType
TypeDescription getEnclosingType()
Returns a description of this type's enclosing type if any.- Returns:
- A description of the enclosing type of this type or
null
if there is no such type.
-
getActualModifiers
int getActualModifiers(boolean superFlag)
Returns the type's actual modifiers as present in the class file. For example, a type cannot beprivate
. but it modifiers might reflect this property nevertheless if a class was defined as a private inner class. The returned modifiers take also into account if the type is marked asDeprecated
. Anonymous classes that are enclosed in a static method or the type initializer are additionally marked asfinal
as it is also done by the Java compiler.- Parameters:
superFlag
-true
if the modifier's super flag should be set.- Returns:
- The type's actual modifiers.
-
getSimpleName
java.lang.String getSimpleName()
Returns the simple internalName of this type.- Returns:
- The simple internalName of this type.
-
getCanonicalName
java.lang.String getCanonicalName()
Returns the canonical name of this type if it exists.- Returns:
- The canonical name of this type. Might be
null
.
-
isAnonymousClass
boolean isAnonymousClass()
Checks if this type description represents an anonymous type.- Returns:
true
if this type description represents an anonymous type.
-
isLocalClass
boolean isLocalClass()
Checks if this type description represents a local type.- Returns:
true
if this type description represents a local type.
-
isMemberClass
boolean isMemberClass()
Checks if this type description represents a member type.- Returns:
true
if this type description represents a member type.
-
getPackage
PackageDescription getPackage()
Returns the package internalName of the type described by this instance.- Returns:
- The package internalName of the type described by this instance.
-
getInheritedAnnotations
AnnotationList getInheritedAnnotations()
Returns the annotations that this type declares or inherits from super types.- Returns:
- A list of all inherited annotations.
-
isSamePackage
boolean isSamePackage(TypeDescription typeDescription)
Checks if two types are defined in the same package.- Parameters:
typeDescription
- The type of interest.- Returns:
true
if this type and the given type are in the same package.
-
isConstantPool
boolean isConstantPool()
Checks if instances of this type can be stored in the constant pool of a class. Note that any primitive type that is smaller than anint
cannot be stored in the constant pool as those types are represented asint
values internally.- Returns:
true
if instances of this type can be stored in the constant pool of a class.
-
isPrimitiveWrapper
boolean isPrimitiveWrapper()
Checks if this type represents a wrapper type for a primitive type. TheVoid
type is not considered to be a wrapper type.- Returns:
true
if this type represents a wrapper type.
-
isAnnotationReturnType
boolean isAnnotationReturnType()
Checks if instances of this type can be returned from an annotation method.- Returns:
true
if instances of this type can be returned from an annotation method.
-
isAnnotationValue
boolean isAnnotationValue()
Checks if instances of this type can be used for describing an annotation value.- Returns:
true
if instances of this type can be used for describing an annotation value.
-
isAnnotationValue
boolean isAnnotationValue(java.lang.Object value)
Checks if instances of this type can be used for describing the given annotation value.- Parameters:
value
- The value that is supposed to describe the annotation value for this instance.- Returns:
true
if instances of this type can be used for describing the given annotation value..
-
isPackageType
boolean isPackageType()
Checks if this type represents a class that is a place holder for a package description.- Returns:
true
if this type represents a package description.
-
getInnerClassCount
int getInnerClassCount()
Returns the amount of outer classes this type defines. If this type is not an inner type of another class,0
is returned.- Returns:
- The number of outer classes relatively to this type.
-
isInnerClass
boolean isInnerClass()
Indicates if this class is an inner class.- Returns:
true
if this class is an inner class.
-
isNestedClass
boolean isNestedClass()
Indicates if this class is a nested class.- Returns:
true
if this class is a nested class.
-
asBoxed
TypeDescription asBoxed()
Returns a description of this type that represents this type as a boxed type for primitive types, unless itsvoid
.- Returns:
- A description of this type in its boxed form.
-
asUnboxed
TypeDescription asUnboxed()
Returns a description of this type that represents this type as an unboxed type for boxing types, unless itsVoid
.- Returns:
- A description of this type in its unboxed form.
-
getDefaultValue
java.lang.Object getDefaultValue()
Returns the default value for this type, i.e. the zero value for a primitive type andnull
for a reference type. Forvoid
,null
is returned.- Returns:
- This types default value.
-
-