Class TypeDescription.ForLoadedType
java.lang.Object
net.bytebuddy.description.ModifierReviewable.AbstractBase
net.bytebuddy.description.TypeVariableSource.AbstractBase
net.bytebuddy.description.type.TypeDescription.AbstractBase
net.bytebuddy.description.type.TypeDescription.ForLoadedType
- All Implemented Interfaces:
Serializable, Iterable<TypeDefinition>, AnnotationSource, ByteCodeElement, DeclaredByType, ModifierReviewable, ModifierReviewable.ForFieldDescription, ModifierReviewable.ForMethodDescription, ModifierReviewable.ForModuleDescription, ModifierReviewable.ForModuleRequirement, ModifierReviewable.ForParameterDescription, ModifierReviewable.ForTypeDefinition, ModifierReviewable.OfAbstraction, ModifierReviewable.OfByteCodeElement, ModifierReviewable.OfEnumeration, ModifierReviewable.OfMandatable, NamedElement, NamedElement.WithDescriptor, NamedElement.WithRuntimeName, TypeDefinition, TypeDescription, TypeVariableSource
- Enclosing interface:
TypeDescription
public static class TypeDescription.ForLoadedType
extends TypeDescription.AbstractBase
implements Serializable
A type description implementation that represents a loaded type.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static interfaceA dispatcher for using methods ofClassthat are not declared for Java 6.Nested classes/interfaces inherited from class TypeDescription.AbstractBase
TypeDescription.AbstractBase.OfSimpleTypeNested 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.AbstractBase, 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 TypeDescription
TypeDescription.AbstractBase, TypeDescription.ArrayProjection, TypeDescription.ForLoadedType, TypeDescription.ForPackageDescription, TypeDescription.Generic, TypeDescription.Latent, TypeDescription.LazyProxy, TypeDescription.SuperTypeLoadingNested classes/interfaces inherited from interface TypeVariableSource
TypeVariableSource.AbstractBase, TypeVariableSource.Visitor<T> -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final TypeDescription.ForLoadedType.DispatcherA dispatcher for invking methods onClassreflectively.private static final longThe class's serial version UID.private final Class<?> The loaded type this instance represents.private static final Map<Class<?>, TypeDescription> A cache of type descriptions for commonly used types to avoid unnecessary allocations.Fields inherited from class TypeDescription.AbstractBase
RAW_TYPESFields 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_PROPERTYFields inherited from interface TypeDescription
ARRAY_INTERFACES, CLASS, OBJECT, STRING, THROWABLE, UNDEFINED, VOIDFields inherited from interface TypeVariableSource
UNDEFINED -
Constructor Summary
ConstructorsConstructorDescriptionForLoadedType(Class<?> type) Creates a new immutable type description for a loaded type. -
Method Summary
Modifier and TypeMethodDescriptionReturns this type definition as a generic type.private static <T> TdoPrivileged(PrivilegedAction<T> action) A proxy forjava.security.AccessController#doPrivilegedthat is activated if available.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 a list of annotations that are declared by this instance.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 descriptor of this byte code element.Returns a description of the method that encloses this type.Returns a description of this type's enclosing type if any.Returns the interfaces that this type implements.intReturns the modifier that is described by this object.getName()Returns the binary name of this byte code element.static StringReturns the type's actual name where it is taken into consideration that this type might be loaded anonymously.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.Returns the size of the type described by this instance.Returns the super class of this type.Returns the type variables that are declared by this element.booleanSpecifies if the modifier described by this object represents the annotation flag.booleanChecks if this type description represents an anonymous type.booleanisArray()Checks if the type described by this entity is an array.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).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.booleanChecks if this type description represents a local type.booleanChecks if this type description represents a member type.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 the type described by this entity is a primitive type.booleanisRecord()Checks if this type is a Java record.booleanisSealed()Returnstrueif this class is a sealed class that only permitts a specified range of subclasses.static TypeDescriptionReturns a new immutable type description for a loaded type.booleanrepresents(Type type) Checks if the type described by this instance representstype.Returns a representation of a Java module that is represented by this type description, normally amodule-info.classfile.Methods inherited from class TypeDescription.AbstractBase
accept, asBoxed, asErasure, asUnboxed, equals, getActualModifiers, getActualName, getDefaultValue, getEnclosingSource, getGenericSignature, getInheritedAnnotations, getInnerClassCount, getInternalName, getLongSimpleName, getSort, getTypeName, hashCode, isAccessibleTo, isAnnotationReturnType, isAnnotationValue, isAnnotationValue, isCompileTimeConstant, isGenerified, isInferrable, isInnerClass, isInstance, isModuleType, isNestedClass, isPackageType, isPrimitiveWrapper, isSamePackage, isVisibleTo, iterator, toSafeString, toStringMethods inherited from class TypeVariableSource.AbstractBase
findExpectedVariable, findVariableMethods inherited from class ModifierReviewable.AbstractBase
getEnumerationState, getFieldManifestation, getFieldPersistence, getMandate, getMethodManifestation, getMethodStrictness, getOpenness, getOwnership, getParameterManifestation, getProvisioningState, getRequiredPhase, getSynchronizationState, getSyntheticState, getTransitivity, getTypeManifestation, getVisibility, isAbstract, isBridge, isDeprecated, isEnum, isFinal, isInterface, isMandated, isNative, isOpen, isPackagePrivate, isPrivate, isProtected, isPublic, isStatic, isStaticPhase, isStrict, isSynchronized, isSynthetic, isTransient, isTransitive, isVarArgs, isVolatileMethods inherited from interface Iterable
forEach, spliteratorMethods inherited from interface ModifierReviewable
getSyntheticState, isFinal, isSyntheticMethods inherited from interface ModifierReviewable.ForTypeDefinition
getTypeManifestation, 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 TypeVariableSource
findExpectedVariable, findVariable
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDThe class's serial version UID.- See Also:
-
DISPATCHER
A dispatcher for invking methods onClassreflectively. -
TYPE_CACHE
A cache of type descriptions for commonly used types to avoid unnecessary allocations. -
type
The loaded type this instance represents.
-
-
Constructor Details
-
ForLoadedType
-
-
Method Details
-
doPrivileged
A proxy forjava.security.AccessController#doPrivilegedthat is activated if available.- Type Parameters:
T- The type of the action's resolved value.- Parameters:
action- The action to execute from a privileged context.- Returns:
- The action's resolved value.
-
getName
Returns the type's actual name where it is taken into consideration that this type might be loaded anonymously. In this case, the remainder of the types name is suffixed by/<id>which is removed when using this method but is retained when callingClass.getName().- Parameters:
type- The type for which to resolve its name.- Returns:
- The type's actual name.
-
of
Returns a new immutable type description for a loaded type.- Parameters:
type- The type to be represented by this type description.- Returns:
- The type description representing the given type.
-
isAssignableFrom
Description copied from class:TypeDescription.AbstractBaseChecks 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).- Specified by:
isAssignableFromin interfaceTypeDescription- Overrides:
isAssignableFromin classTypeDescription.AbstractBase- Parameters:
type- The type of interest.- Returns:
trueif this type is assignable fromtype.
-
isAssignableFrom
Description copied from class:TypeDescription.AbstractBaseChecks 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 toTypeDescription.isAssignableFrom(Class)- Specified by:
isAssignableFromin interfaceTypeDescription- Overrides:
isAssignableFromin classTypeDescription.AbstractBase- Parameters:
typeDescription- The type of interest.- Returns:
trueif this type is assignable fromtype.
-
isAssignableTo
Description copied from class:TypeDescription.AbstractBaseChecks 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).- Specified by:
isAssignableToin interfaceTypeDescription- Overrides:
isAssignableToin classTypeDescription.AbstractBase- Parameters:
type- The type of interest.- Returns:
trueif this type is assignable totype.
-
isAssignableTo
Description copied from class:TypeDescription.AbstractBaseChecks 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 toTypeDescription.isAssignableTo(Class)- Specified by:
isAssignableToin interfaceTypeDescription- Overrides:
isAssignableToin classTypeDescription.AbstractBase- Parameters:
typeDescription- The type of interest.- Returns:
trueif this type is assignable totype.
-
isInHierarchyWith
Description copied from class:TypeDescription.AbstractBaseReturnstrueif 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.- Specified by:
isInHierarchyWithin interfaceTypeDescription- Overrides:
isInHierarchyWithin classTypeDescription.AbstractBase- Parameters:
type- The type of interest.- Returns:
trueif this type and the supplied type are in a type hierarchy with each other.
-
isInHierarchyWith
Description copied from class:TypeDescription.AbstractBaseReturnstrueif 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.- Specified by:
isInHierarchyWithin interfaceTypeDescription- Overrides:
isInHierarchyWithin classTypeDescription.AbstractBase- Parameters:
typeDescription- The type of interest.- Returns:
trueif this type and the supplied type are in a type hierarchy with each other.
-
represents
Description copied from class:TypeDescription.AbstractBaseChecks if the type described by this instance representstype.- Specified by:
representsin interfaceTypeDefinition- Overrides:
representsin classTypeDescription.AbstractBase- Parameters:
type- The type of interest.- Returns:
trueif the type described by this instance representstype.
-
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- Specified by:
getComponentTypein interfaceTypeDescription- Returns:
- The component type of this type or
nullif this type does not represent an array type.
-
isArray
public boolean isArray()Checks if the type described by this entity is an array.- Specified by:
isArrayin interfaceTypeDefinition- Returns:
trueif this type description represents an array.
-
isPrimitive
public boolean isPrimitive()Checks if the type described by this entity is a primitive type.- Specified by:
isPrimitivein interfaceTypeDefinition- Returns:
trueif this type description represents a primitive type.
-
isAnnotation
public boolean isAnnotation()Description copied from class:ModifierReviewable.AbstractBaseSpecifies if the modifier described by this object represents the annotation flag.- Specified by:
isAnnotationin interfaceModifierReviewable.ForTypeDefinition- Overrides:
isAnnotationin classModifierReviewable.AbstractBase- Returns:
trueif the modifier described by this object represents the annotation flag.
-
getSuperClass
Returns the super class of this type. 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. Interface types and theObjectclass do not define a super class wherenullis returned. Array types defineObjectas their direct super class.- Specified by:
getSuperClassin interfaceTypeDefinition- Returns:
- The super class of this type or
nullif no super class exists for this type.
-
getInterfaces
Returns the interfaces that this type implements. 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.- Specified by:
getInterfacesin interfaceTypeDefinition- Returns:
- The interfaces that this type implements.
-
getDeclaringType
Returns the declaring type of this instance.- Specified by:
getDeclaringTypein interfaceDeclaredByType- Specified by:
getDeclaringTypein interfaceTypeDescription- Returns:
- The declaring type or
nullif no such type exists.
-
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.- Specified by:
getEnclosingMethodin interfaceTypeDescription- 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.- Specified by:
getEnclosingTypein interfaceTypeDescription- Returns:
- A description of the enclosing type of this type or
nullif there is no such type.
-
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.- Specified by:
getDeclaredTypesin interfaceTypeDescription- Returns:
- A list of types that are declared within this type.
-
getSimpleName
Returns the simple name of this type.- Specified by:
getSimpleNamein interfaceTypeDescription- Returns:
- The simple name of this type.
-
isAnonymousType
public boolean isAnonymousType()Checks if this type description represents an anonymous type.- Specified by:
isAnonymousTypein interfaceTypeDescription- Returns:
trueif this type description represents an anonymous type.
-
isLocalType
public boolean isLocalType()Checks if this type description represents a local type.- Specified by:
isLocalTypein interfaceTypeDescription- Returns:
trueif this type description represents a local type.
-
isMemberType
public boolean isMemberType()Description copied from class:TypeDescription.AbstractBaseChecks if this type description represents a member type.- Specified by:
isMemberTypein interfaceTypeDescription- Overrides:
isMemberTypein classTypeDescription.AbstractBase- Returns:
trueif this type description represents a member type.
-
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- Specified by:
getDeclaredFieldsin interfaceTypeDescription- 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
@Enhance("declaredMethods") public MethodList<MethodDescription.InDefinedShape> getDeclaredMethods()Returns the methods that this type declares.- Specified by:
getDeclaredMethodsin interfaceTypeDefinition- Specified by:
getDeclaredMethodsin interfaceTypeDescription- Returns:
- The methods that this type declares.
-
getPackage
Returns the package of the type described by this instance ornullif the described type is a primitive type or an array.- Specified by:
getPackagein interfaceTypeDescription- 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.- Specified by:
toModuleDescriptionin interfaceTypeDescription- Returns:
- A description of the module information of this type or
nullif no such information is available.
-
getStackSize
Returns the size of the type described by this instance. Wildcard types (TypeDefinition.Sort.WILDCARDdo not have a well-defined a stack size and cause anIllegalStateExceptionto be thrown.- Specified by:
getStackSizein interfaceTypeDefinition- Returns:
- The size of the type described by this instance.
-
getName
Returns the binary name of this byte code element. If no well-defined internal name is known for this element, the actual name is returned.- Specified by:
getNamein interfaceNamedElement.WithRuntimeName- Returns:
- The binary ame of this byte code element as visible from within a running Java application.
-
getCanonicalName
Returns the canonical name of this type if it exists.- Specified by:
getCanonicalNamein interfaceTypeDescription- Returns:
- The canonical name of this type. Might be
null.
-
getDescriptor
Returns the descriptor of this byte code element.- Specified by:
getDescriptorin interfaceNamedElement.WithDescriptor- Returns:
- The descriptor of this byte code element.
-
getModifiers
public int getModifiers()Returns the modifier that is described by this object.- Specified by:
getModifiersin interfaceModifierReviewable- Returns:
- The modifier that is described by this object.
-
getTypeVariables
Returns the type variables that are declared by this element.- Specified by:
getTypeVariablesin interfaceTypeVariableSource- Returns:
- The type variables that are declared by this element.
-
getDeclaredAnnotations
Returns a list of annotations that are declared by this instance.- Specified by:
getDeclaredAnnotationsin interfaceAnnotationSource- Returns:
- A list of declared annotations.
-
asGenericType
Returns this type definition as a generic type.- Specified by:
asGenericTypein interfaceTypeDefinition- Overrides:
asGenericTypein classTypeDescription.AbstractBase- Returns:
- This type definition represented as a generic type.
-
getNestHost
Returns the nest host of this type. For types prior to Java 11, this type is returned which is the default nest host.- Specified by:
getNestHostin interfaceTypeDescription- Returns:
- The nest host of this type.
-
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.- Specified by:
getNestMembersin interfaceTypeDescription- Returns:
- A list of members of this nest group.
-
isNestHost
public boolean isNestHost()Description copied from class:TypeDescription.AbstractBaseChecks if this class is the host of a nest group.- Specified by:
isNestHostin interfaceTypeDescription- Overrides:
isNestHostin classTypeDescription.AbstractBase- Returns:
trueif this class is a nest group's host.
-
isNestMateOf
Description copied from class:TypeDescription.AbstractBaseChecks if this type and the supplied type are members of the same nest group.- Specified by:
isNestMateOfin interfaceTypeDescription- Overrides:
isNestMateOfin classTypeDescription.AbstractBase- 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
Description copied from class:TypeDescription.AbstractBaseChecks if this type and the supplied type are members of the same nest group.- Specified by:
isNestMateOfin interfaceTypeDescription- Overrides:
isNestMateOfin classTypeDescription.AbstractBase- 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.
-
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- Specified by:
getRecordComponentsin interfaceTypeDescription- Returns:
- A list of record components that this type declares.
-
isRecord
public boolean isRecord()Checks if this type is a Java record.- Specified by:
isRecordin interfaceTypeDefinition- Returns:
trueif this type is a Java record.
-
isSealed
public boolean isSealed()Description copied from class:TypeDescription.AbstractBaseReturnstrueif this class is a sealed class that only permitts a specified range of subclasses.- Specified by:
isSealedin interfaceTypeDescription- Overrides:
isSealedin classTypeDescription.AbstractBase- Returns:
trueif this class is a sealed class that only permitts a specified range of subclasses.
-
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.- Specified by:
getPermittedSubtypesin interfaceTypeDescription- Returns:
- The list of permitted subtypes or an empty list if this type is not sealed.
-
getClassFileVersion
Description copied from class:TypeDescription.AbstractBaseAttempts 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.- Specified by:
getClassFileVersionin interfaceTypeDescription- Overrides:
getClassFileVersionin classTypeDescription.AbstractBase- Returns:
- This type's class file version or
nullif it cannot be resolved.
-