Class TypeDescription.ForLoadedType

    • Field Detail

      • serialVersionUID

        private static final long serialVersionUID
        The class's serial version UID.
        See Also:
        Constant Field Values
      • TYPE_CACHE

        private static final java.util.Map<java.lang.Class<?>,​TypeDescription> TYPE_CACHE
        A cache of type descriptions for commonly used types to avoid unnecessary allocations.
      • type

        private final java.lang.Class<?> type
        The loaded type this instance represents.
    • Constructor Detail

      • ForLoadedType

        public ForLoadedType​(java.lang.Class<?> type)
        Creates a new immutable type description for a loaded type. This constructor should not normally be used. Use of(Class) instead.
        Parameters:
        type - The type to be represented by this type description.
    • Method Detail

      • doPrivileged

        @Enhance
        private static <T> T doPrivileged​(java.security.PrivilegedAction<T> action)
        A proxy for java.security.AccessController#doPrivileged that 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

        public static java.lang.String getName​(java.lang.Class<?> type)
        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 calling Class.getName().
        Parameters:
        type - The type for which to resolve its name.
        Returns:
        The type's actual name.
      • of

        public static TypeDescription of​(java.lang.Class<?> type)
        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

        public boolean isAssignableFrom​(java.lang.Class<?> type)
        Description copied from class: TypeDescription.AbstractBase
        Checks if this type is assignable from the type described by this instance, for example for class Foo and class Bar extends Foo, this method would return true for Foo.class.isAssignableFrom(Bar.class).
        Specified by:
        isAssignableFrom in interface TypeDescription
        Overrides:
        isAssignableFrom in class TypeDescription.AbstractBase
        Parameters:
        type - The type of interest.
        Returns:
        true if this type is assignable from type.
      • isAssignableTo

        public boolean isAssignableTo​(java.lang.Class<?> type)
        Description copied from class: TypeDescription.AbstractBase
        Checks if this type is assignable from the type described by this instance, for example for class Foo and class Bar extends Foo, this method would return true for Bar.class.isAssignableTo(Foo.class).
        Specified by:
        isAssignableTo in interface TypeDescription
        Overrides:
        isAssignableTo in class TypeDescription.AbstractBase
        Parameters:
        type - The type of interest.
        Returns:
        true if this type is assignable to type.
      • isInHierarchyWith

        public boolean isInHierarchyWith​(java.lang.Class<?> type)
        Description copied from class: TypeDescription.AbstractBase
        Returns true if 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:
        isInHierarchyWith in interface TypeDescription
        Overrides:
        isInHierarchyWith in class TypeDescription.AbstractBase
        Parameters:
        type - The type of interest.
        Returns:
        true if this type and the supplied type are in a type hierarchy with each other.
      • isArray

        public boolean isArray()
        Checks if the type described by this entity is an array.
        Specified by:
        isArray in interface TypeDefinition
        Returns:
        true if this type description represents an array.
      • isPrimitive

        public boolean isPrimitive()
        Checks if the type described by this entity is a primitive type.
        Specified by:
        isPrimitive in interface TypeDefinition
        Returns:
        true if this type description represents a primitive type.
      • getEnclosingMethod

        public MethodDescription.InDefinedShape 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.
        Specified by:
        getEnclosingMethod in interface TypeDescription
        Returns:
        A description of the enclosing method of this type or null if there is no such method.
      • getEnclosingType

        public TypeDescription getEnclosingType()
        Returns a description of this type's enclosing type if any.
        Specified by:
        getEnclosingType in interface TypeDescription
        Returns:
        A description of the enclosing type of this type or null if there is no such type.
      • getDeclaredTypes

        public 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.
        Specified by:
        getDeclaredTypes in interface TypeDescription
        Returns:
        A list of types that are declared within this type.
      • getSimpleName

        public java.lang.String getSimpleName()
        Returns the simple name of this type.
        Specified by:
        getSimpleName in interface TypeDescription
        Returns:
        The simple name of this type.
      • isAnonymousType

        public boolean isAnonymousType()
        Checks if this type description represents an anonymous type.
        Specified by:
        isAnonymousType in interface TypeDescription
        Returns:
        true if this type description represents an anonymous type.
      • isLocalType

        public boolean isLocalType()
        Checks if this type description represents a local type.
        Specified by:
        isLocalType in interface TypeDescription
        Returns:
        true if this type description represents a local type.
      • getPackage

        public PackageDescription getPackage()
        Returns the package of the type described by this instance or null if the described type does not imply a package.
        Specified by:
        getPackage in interface TypeDescription
        Returns:
        The package of the type described by this instance or null if the described type does not imply a package.
      • getStackSize

        public StackSize getStackSize()
        Returns the size of the type described by this instance. Wildcard types (TypeDefinition.Sort.WILDCARD do not have a well-defined a stack size and cause an IllegalStateException to be thrown.
        Specified by:
        getStackSize in interface TypeDefinition
        Returns:
        The size of the type described by this instance.
      • getName

        public java.lang.String 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:
        getName in interface NamedElement.WithRuntimeName
        Returns:
        The binary ame of this byte code element as visible from within a running Java application.
      • getCanonicalName

        public java.lang.String getCanonicalName()
        Returns the canonical name of this type if it exists.
        Specified by:
        getCanonicalName in interface TypeDescription
        Returns:
        The canonical name of this type. Might be null.
      • getDescriptor

        public java.lang.String getDescriptor()
        Returns the descriptor of this byte code element.
        Specified by:
        getDescriptor in interface NamedElement.WithDescriptor
        Returns:
        The descriptor of this byte code element.
      • getModifiers

        public int getModifiers()
        Returns the modifier that is described by this object.
        Specified by:
        getModifiers in interface ModifierReviewable
        Returns:
        The modifier that is described by this object.
      • getTypeVariables

        public TypeList.Generic getTypeVariables()
        Returns the type variables that are declared by this element.
        Specified by:
        getTypeVariables in interface TypeVariableSource
        Returns:
        The type variables that are declared by this element.
      • getNestHost

        public 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.
        Specified by:
        getNestHost in interface TypeDescription
        Returns:
        The nest host of this type.
      • getNestMembers

        public 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.
        Specified by:
        getNestMembers in interface TypeDescription
        Returns:
        A list of members of this nest group.
      • isNestMateOf

        public boolean isNestMateOf​(java.lang.Class<?> type)
        Description copied from class: TypeDescription.AbstractBase
        Checks if this type and the supplied type are members of the same nest group.
        Specified by:
        isNestMateOf in interface TypeDescription
        Overrides:
        isNestMateOf in class TypeDescription.AbstractBase
        Parameters:
        type - The type for which to check if it is a member of the same nest group.
        Returns:
        true if this type and the supplied type are members of the same nest group.
      • isRecord

        public boolean isRecord()
        Checks if this type is a Java record.
        Specified by:
        isRecord in interface TypeDefinition
        Returns:
        true if this type is a Java record.
      • getPermittedSubtypes

        public 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.
        Specified by:
        getPermittedSubtypes in interface TypeDescription
        Returns:
        The list of permitted subtypes or an empty list if this type is not sealed.