Interface TypeDescription
- All Superinterfaces:
AnnotationSource, ByteCodeElement, DeclaredByType, Iterable<TypeDefinition>, ModifierReviewable, ModifierReviewable.ForTypeDefinition, ModifierReviewable.OfAbstraction, ModifierReviewable.OfByteCodeElement, ModifierReviewable.OfEnumeration, NamedElement, NamedElement.WithDescriptor, NamedElement.WithRuntimeName, TypeDefinition, TypeVariableSource
- All Known Subinterfaces:
InstrumentedType, InstrumentedType.WithFlexibleName
- All Known Implementing Classes:
InstrumentedType.Default, InstrumentedType.Frozen, JavaType.LatentTypeWithSimpleName, 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.ExtendedLazyTypeDescription, TypePool.Default.WithLazyResolution.LazyTypeDescription, TypePool.LazyFacade.LazyTypeDescription
Implementations of this interface represent a Java type, i.e. a class or interface. Instances of this interface always
represent non-generic types of sort
TypeDefinition.Sort.NON_GENERIC.-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classAn abstract base implementation of a type description.static classA projection for an array type based on an existingTypeDescription.static classA type description implementation that represents a loaded type.static classA type representation of a package description.static interfaceRepresents a generic type of the Java programming language.static classA latent type description for a type without methods or fields.static classA lazy proxy for representing aTypeDescriptionfor a loaded type.static classA delegating type description that always attempts to load the super types of a delegate type.Nested classes/interfaces inherited from interface AnnotationSource
AnnotationSource.Empty, AnnotationSource.ExplicitNested classes/interfaces inherited from interface ByteCodeElement
ByteCodeElement.Member, ByteCodeElement.Token<T>, ByteCodeElement.TypeDependant<T,S> Nested classes/interfaces inherited from interface DeclaredByType
DeclaredByType.WithMandatoryDeclarationNested classes/interfaces inherited from interface ModifierReviewable
ModifierReviewable.ForFieldDescription, ModifierReviewable.ForMethodDescription, ModifierReviewable.ForModuleDescription, ModifierReviewable.ForModuleRequirement, ModifierReviewable.ForParameterDescription, ModifierReviewable.ForTypeDefinition, ModifierReviewable.OfAbstraction, ModifierReviewable.OfByteCodeElement, ModifierReviewable.OfEnumeration, ModifierReviewable.OfMandatableNested classes/interfaces inherited from interface NamedElement
NamedElement.WithDescriptor, NamedElement.WithGenericName, NamedElement.WithOptionalName, NamedElement.WithRuntimeNameNested classes/interfaces inherited from interface TypeDefinition
TypeDefinition.Sort, TypeDefinition.SuperClassIteratorNested classes/interfaces inherited from interface TypeVariableSource
TypeVariableSource.Visitor<T> -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final TypeList.GenericA list of interfaces that are implicitly implemented by any array type.static final TypeDescriptionDeprecated.static final TypeDescriptionDeprecated.UseTypeDescription.ForLoadedType.of(Class)instead.static final TypeDescriptionDeprecated.UseTypeDescription.ForLoadedType.of(Class)instead.static final TypeDescriptionDeprecated.UseTypeDescription.ForLoadedType.of(Class)instead.static final TypeDescriptionRepresents any undefined property representing a type description that is instead represented asnullin order to resemble the Java reflection API which returnsnulland is intuitive to many Java developers.static final TypeDescriptionDeprecated.UseTypeDescription.ForLoadedType.of(Class)instead.Fields inherited from interface ModifierReviewable
EMPTY_MASKFields inherited from interface NamedElement
EMPTY_NAME, NO_NAMEFields inherited from interface NamedElement.WithDescriptor
NON_GENERIC_SIGNATUREFields inherited from interface TypeDefinition
RAW_TYPES_PROPERTY -
Method Summary
Modifier and TypeMethodDescriptionasBoxed()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 that represents this type as an unboxed type for boxing types, unless itsVoid.intgetActualModifiers(boolean superFlag) Returns the type's actual modifiers as present in the class file.Returns the canonical name of this type if it exists.Attempts to resolve the class file version of this type.Returns the component type of this type.Returns the fields that this type declares.Returns the methods that this type declares.Returns a list of types that are declared by this type.Returns the declaring type of this instance.Returns the default value for this type, i.e.Returns a description of the method that encloses this type.Returns a description of this type's enclosing type if any.Returns the annotations that this type declares or inherits from super types.intReturns the amount of outer classes this type defines.Returns a form of a type's simple name which only shortens the package name but not the names of outer classes.Returns the nest host of this type.Returns a list of members that are part of a nesting group.Returns the package of the type described by this instance ornullif the described type is a primitive type or an array.Returns the list of permitted direct subclasses if this class is a sealed class.Returns the list of record components that are declared by this type.Returns the simple name of this type.booleanChecks if instances of this type can be returned from an annotation method.booleanChecks if instances of this type can be used for describing an annotation value.booleanisAnnotationValue(Object value) Checks if instances of this type can be used for describing the given annotation value.booleanChecks if this type description represents an anonymous type.booleanisAssignableFrom(Class<?> type) Checks if this type is assignable from the type described by this instance, for example forclass Fooandclass Bar extends Foo, this method would returntrueforFoo.class.isAssignableFrom(Bar.class).booleanisAssignableFrom(TypeDescription typeDescription) Checks if this type is assignable from the type described by this instance, for example forclass Fooandclass Bar extends Foo, this method would returntrueforFoo.class.isAssignableFrom(Bar.class).booleanisAssignableTo(Class<?> type) Checks if this type is assignable from the type described by this instance, for example forclass Fooandclass Bar extends Foo, this method would returntrueforBar.class.isAssignableTo(Foo.class).booleanisAssignableTo(TypeDescription typeDescription) Checks if this type is assignable from the type described by this instance, for example forclass Fooandclass Bar extends Foo, this method would returntrueforBar.class.isAssignableFrom(Foo.class).booleanIndicates if this type represents a compile-time constant, i.e.booleanisInHierarchyWith(Class<?> type) Returnstrueif this type and the supplied type are in a type hierarchy with each other, i.e.booleanisInHierarchyWith(TypeDescription typeDescription) Returnstrueif this type and the supplied type are in a type hierarchy with each other, i.e.booleanIndicates if this class is an inner class.booleanisInstance(Object value) Checks ifvalueis an instance of the type represented by this instance.booleanChecks if this type description represents a local type.booleanChecks if this type description represents a member type.booleanReturnstrueif the represented type includes a module description.booleanIndicates if this class is a nested class.booleanChecks if this class is the host of a nest group.booleanisNestMateOf(Class<?> type) Checks if this type and the supplied type are members of the same nest group.booleanisNestMateOf(TypeDescription typeDescription) Checks if this type and the supplied type are members of the same nest group.booleanChecks if this type represents a class that is a place holder for a package description.booleanChecks if this type represents a wrapper type for a primitive type.booleanisSamePackage(TypeDescription typeDescription) Checks if two types are defined in the same package.booleanisSealed()Returnstrueif this class is a sealed class that only permitts a specified range of subclasses.Returns a representation of a Java module that is represented by this type description, normally amodule-info.classfile.Methods inherited from interface AnnotationSource
getDeclaredAnnotationsMethods inherited from interface ByteCodeElement
isAccessibleTo, isVisibleToMethods inherited from interface Iterable
forEach, iterator, spliteratorMethods inherited from interface ModifierReviewable
getModifiers, getSyntheticState, isFinal, isSyntheticMethods inherited from interface ModifierReviewable.ForTypeDefinition
getTypeManifestation, isAnnotation, isInterfaceMethods inherited from interface ModifierReviewable.OfAbstraction
isAbstractMethods inherited from interface ModifierReviewable.OfByteCodeElement
getOwnership, getVisibility, isDeprecated, isPackagePrivate, isPrivate, isProtected, isPublic, isStaticMethods inherited from interface ModifierReviewable.OfEnumeration
getEnumerationState, isEnumMethods inherited from interface NamedElement
getActualNameMethods inherited from interface NamedElement.WithDescriptor
getDescriptor, getGenericSignatureMethods inherited from interface NamedElement.WithRuntimeName
getInternalName, getNameMethods inherited from interface TypeDefinition
asErasure, asGenericType, getInterfaces, getSort, getStackSize, getSuperClass, getTypeName, isArray, isPrimitive, isRecord, representsMethods inherited from interface TypeVariableSource
accept, findExpectedVariable, findVariable, getEnclosingSource, getTypeVariables, isGenerified, isInferrable
-
Field Details
-
OBJECT
Deprecated.UseTypeDescription.ForLoadedType.of(Class)instead.A representation of theObjecttype. -
STRING
Deprecated.UseTypeDescription.ForLoadedType.of(Class)instead.A representation of theStringtype. -
CLASS
Deprecated.UseTypeDescription.ForLoadedType.of(Class)instead.A representation of theClasstype. -
THROWABLE
Deprecated.UseTypeDescription.ForLoadedType.of(Class)instead.A representation of theThrowabletype. -
VOID
Deprecated.UseTypeDescription.ForLoadedType.of(Class)instead.A representation of thevoidnon-type. -
ARRAY_INTERFACES
A list of interfaces that are implicitly implemented by any array type. -
UNDEFINED
Represents any undefined property representing a type description that is instead represented asnullin order to resemble the Java reflection API which returnsnulland is intuitive to many Java developers.
-
-
Method Details
-
getDeclaredFields
FieldList<FieldDescription.InDefinedShape> getDeclaredFields()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:
getDeclaredFieldsin 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()Returns the methods that this type declares.- Specified by:
getDeclaredMethodsin interfaceTypeDefinition- Returns:
- The methods that this type declares.
-
getRecordComponents
RecordComponentList<RecordComponentDescription.InDefinedShape> 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.- Specified by:
getRecordComponentsin interfaceTypeDefinition- Returns:
- A list of record components that this type declares.
-
isInstance
Checks ifvalueis an instance of the type represented by this instance.- Parameters:
value- The object of interest.- Returns:
trueif the object is an instance of the type described by this instance.
-
isAssignableFrom
Checks if this type is assignable from the type described by this instance, for example forclass Fooandclass Bar extends Foo, this method would returntrueforFoo.class.isAssignableFrom(Bar.class).- Parameters:
type- The type of interest.- Returns:
trueif this type is assignable fromtype.
-
isAssignableFrom
Checks if this type is assignable from the type described by this instance, for example forclass Fooandclass Bar extends Foo, this method would returntrueforFoo.class.isAssignableFrom(Bar.class).
Implementations of this methods are allowed to delegate toisAssignableFrom(Class)- Parameters:
typeDescription- The type of interest.- Returns:
trueif this type is assignable fromtype.
-
isAssignableTo
Checks if this type is assignable from the type described by this instance, for example forclass Fooandclass Bar extends Foo, this method would returntrueforBar.class.isAssignableTo(Foo.class).- Parameters:
type- The type of interest.- Returns:
trueif this type is assignable totype.
-
isAssignableTo
Checks if this type is assignable from the type described by this instance, for example forclass Fooandclass Bar extends Foo, this method would returntrueforBar.class.isAssignableFrom(Foo.class).
Implementations of this methods are allowed to delegate toisAssignableTo(Class)- Parameters:
typeDescription- The type of interest.- Returns:
trueif this type is assignable totype.
-
isInHierarchyWith
Returnstrueif this type and the supplied type are in a type hierarchy with each other, i.e. if this type is assignable to the supplied type or the other way around.- Parameters:
type- The type of interest.- Returns:
trueif this type and the supplied type are in a type hierarchy with each other.
-
isInHierarchyWith
Returnstrueif this type and the supplied type are in a type hierarchy with each other, i.e. if this type is assignable to the supplied type or the other way around.- Parameters:
typeDescription- The type of interest.- Returns:
trueif this type and the supplied type are in a type hierarchy with each other.
-
getComponentType
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, anIllegalStateExceptionis thrown.- Specified by:
getComponentTypein interfaceTypeDefinition- Returns:
- The component type of this type or
nullif this type does not represent an array type.
-
getDeclaringType
Returns the declaring type of this instance.- Specified by:
getDeclaringTypein interfaceDeclaredByType- Returns:
- The declaring type or
nullif no such type exists.
-
getDeclaredTypes
TypeList getDeclaredTypes()Returns a list of types that are declared by this type. This list does not normally include anonymous types but might include additional types if they are explicitly added to an instrumented type.- Returns:
- A list of types that are declared within this type.
-
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,nullis returned by this method.- Returns:
- A description of the enclosing method of this type or
nullif there is no such method.
-
getEnclosingType
Returns a description of this type's enclosing type if any.- Returns:
- A description of the enclosing type of this type or
nullif 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 asfinalas it is also done by the Java compiler.- Parameters:
superFlag-trueif the modifier's super flag should be set.- Returns:
- The type's actual modifiers.
-
getSimpleName
-
getLongSimpleName
String getLongSimpleName()Returns a form of a type's simple name which only shortens the package name but not the names of outer classes.- Returns:
- The long form of the simple name of this type.
-
getCanonicalName
Returns the canonical name of this type if it exists.- Returns:
- The canonical name of this type. Might be
null.
-
isAnonymousType
boolean isAnonymousType()Checks if this type description represents an anonymous type.- Returns:
trueif this type description represents an anonymous type.
-
isLocalType
boolean isLocalType()Checks if this type description represents a local type.- Returns:
trueif this type description represents a local type.
-
isMemberType
boolean isMemberType()Checks if this type description represents a member type.- Returns:
trueif this type description represents a member type.
-
getPackage
Returns the package of the type described by this instance ornullif the described type is a primitive type or an array.- Returns:
- The package of the type described by this instance or
nullif the described type is a primitive type or an array.
-
toModuleDescription
Returns a representation of a Java module that is represented by this type description, normally amodule-info.classfile. If there is no module meta-data attached to the current class,nullis returned.- Returns:
- A description of the module information of this type or
nullif no such information is available.
-
isModuleType
boolean isModuleType()Returnstrueif the represented type includes a module description.- Returns:
trueif the represented type includes a module description.
-
getInheritedAnnotations
AnnotationList getInheritedAnnotations()Returns the annotations that this type declares or inherits from super types.- Returns:
- A list of all inherited annotations.
-
isSamePackage
Checks if two types are defined in the same package.- Parameters:
typeDescription- The type of interest.- Returns:
trueif this type and the given type are in the same package.
-
isPrimitiveWrapper
boolean isPrimitiveWrapper()Checks if this type represents a wrapper type for a primitive type. TheVoidtype is not considered to be a wrapper type.- Returns:
trueif this type represents a wrapper type.
-
isAnnotationReturnType
boolean isAnnotationReturnType()Checks if instances of this type can be returned from an annotation method.- Returns:
trueif 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:
trueif instances of this type can be used for describing an annotation value.
-
isAnnotationValue
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:
trueif 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:
trueif 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,0is returned.- Returns:
- The number of outer classes relatively to this type.
-
isInnerClass
boolean isInnerClass()Indicates if this class is an inner class.- Returns:
trueif this class is an inner class.
-
isNestedClass
boolean isNestedClass()Indicates if this class is a nested class.- Returns:
trueif 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
Returns the default value for this type, i.e. the zero value for a primitive type andnullfor a reference type. Forvoid,nullis returned.- Returns:
- This types default value.
-
getNestHost
TypeDescription getNestHost()Returns the nest host of this type. For types prior to Java 11, this type is returned which is the default nest host.- Returns:
- The nest host of this type.
-
getNestMembers
TypeList getNestMembers()Returns a list of members that are part of a nesting group. Prior to Java 11, a list that only contains this type is returned which is the default nest group.- Returns:
- A list of members of this nest group.
-
isNestHost
boolean isNestHost()Checks if this class is the host of a nest group.- Returns:
trueif this class is a nest group's host.
-
isNestMateOf
Checks if this type and the supplied type are members of the same nest group.- Parameters:
type- The type for which to check if it is a member of the same nest group.- Returns:
trueif this type and the supplied type are members of the same nest group.
-
isNestMateOf
Checks if this type and the supplied type are members of the same nest group.- Parameters:
typeDescription- The type for which to check if it is a member of the same nest group.- Returns:
trueif this type and the supplied type are members of the same nest group.
-
isCompileTimeConstant
boolean isCompileTimeConstant()Indicates if this type represents a compile-time constant, i.e.int,long,float,double,String,Classorjava.lang.invoke.MethodHandleorjava.lang.invoke.MethodType. Since Java 11's *constantdynamic* any type can be considered a constant value; this method does however only consider classical compile time constants.- Returns:
trueif this type represents a compile-time constant.
-
getPermittedSubtypes
TypeList getPermittedSubtypes()Returns the list of permitted direct subclasses if this class is a sealed class. Permitted subclasses might or might not be resolvable, where unresolvable subclasses might also be missing from the list. For returned types, methods that return the class's name will always be invokable without errors. If this type is not sealed, an empty list is returned. Note that an empty list might also be returned for a sealed type, if no type permitted subtype is resolvable.- Returns:
- The list of permitted subtypes or an empty list if this type is not sealed.
-
isSealed
boolean isSealed()Returnstrueif this class is a sealed class that only permitts a specified range of subclasses.- Returns:
trueif this class is a sealed class that only permitts a specified range of subclasses.
-
getClassFileVersion
Attempts to resolve the class file version of this type. If this description is not based on a class file or if the class file version cannot be resolved,nullis returned.- Returns:
- This type's class file version or
nullif it cannot be resolved.
-
TypeDescription.ForLoadedType.of(Class)instead.