Package randoop.types

Class NonParameterizedType

  • All Implemented Interfaces:
    Comparable<Type>

    public class NonParameterizedType
    extends ClassOrInterfaceType
    NonParameterizedType represents a non-parameterized class, interface, enum, or the rawtype of a generic class. It is a wrapper for a Class object, which is a runtime representation of a type.
    • Field Detail

      • runtimeType

        private final Class<?> runtimeType
        The runtime class of this simple type.
    • Constructor Detail

      • NonParameterizedType

        public NonParameterizedType​(Class<?> runtimeType)
        Create a NonParameterizedType object for the runtime class.
        Parameters:
        runtimeType - the runtime class for the type
    • Method Detail

      • forClass

        public static NonParameterizedType forClass​(Class<?> runtimeType)
        Create a NonParameterizedType object for the runtime class.
        Parameters:
        runtimeType - the runtime class for the type
        Returns:
        a NonParameterizedType for the argument
      • equals

        public boolean equals​(Object obj)
        Overrides:
        equals in class ClassOrInterfaceType
        Returns:
        true if the runtime types are the same, false otherwise
      • substitute

        public NonParameterizedType substitute​(Substitution substitution)
        Description copied from class: ClassOrInterfaceType
        Applies a substitution to a ReferenceType. If the type is parameterized then replaces type variables that occur, otherwise returns this type.

        This abstract method forces typing of substitutions applied to ReferenceType objects without an explicit cast.

        This abstract method allows substitutions to be applied to ClassOrInterfaceType objects without casting.

        Specified by:
        substitute in class ClassOrInterfaceType
        Parameters:
        substitution - the type substitution
        Returns:
        the type created by applying the substitution to this type
      • getGenericInterfaces

        private List<ClassOrInterfaceType> getGenericInterfaces()
        Returns the list of direct interfaces for this class.
        Returns:
        the list of direct interfaces for this class or interface type
      • getRawTypeInterfaces

        private List<ClassOrInterfaceType> getRawTypeInterfaces()
        Returns the list of rawtypes for the direct interfaces for this type.
        Returns:
        the list of rawtypes for the direct interfaces of this type
      • getRuntimeClass

        public Class<?> getRuntimeClass()
        Description copied from class: Type
        Returns the runtime Class object for this type. For use when reflection is needed.

        Note that type variables and the null reference type do not have a runtime class, and this method will return null in those cases.

        This method should not be confused with the inherited Object.getClass() method, which returns the Class<?> for the Type object, and not of the represented type. For instance, if a Type object t represented the Java type int, then t.getRuntimeClass() would return int.class while t.getClass() would return Type.class.

        Specified by:
        getRuntimeClass in class Type
        Returns:
        the Class that is the runtime representation of the type, or null if this type is a type variable or null reference type
      • isAbstract

        public boolean isAbstract()
        Description copied from class: ClassOrInterfaceType
        Indicate whether this class is abstract.
        Specified by:
        isAbstract in class ClassOrInterfaceType
        Returns:
        true if this class is abstract, false otherwise
      • isAssignableFrom

        public boolean isAssignableFrom​(Type sourceType)
        Indicates whether there is an assignment conversion from a source Type to this type. (In other words, a value of the source type can be assigned to an l-value of this type.) Returns true if this is a legal assignment conversion: Variablethis = Expressionsourcetype.

        Based on the definition of assignment context in section 5.2 of the Java Language Specification, a value of one type is assignable to a variable of another type if the first type can be converted to the second by

        • an identity conversion (section 5.1.1),
        • a widening primitive conversion (section 5.1.2),
        • a widening reference conversion (section 5.1.5),
        • a boxing conversion (5.1.7), or
        • an unboxing conversion (section 5.1.8) possibly followed by a widening conversion.
        And, if after all those conversions, the type is a raw type, an unchecked conversion may occur.

        For assignment to ReferenceType, checks for widening reference conversion when the source type is also a reference type. See section JLS 5.1.5 for details.

        Specifically checks for boxing conversion (section 5.1.7)

        Overrides:
        isAssignableFrom in class ReferenceType
        Parameters:
        sourceType - the type to test for assignability
        Returns:
        true if this type can be assigned from the source type, and false otherwise
      • isBoxedPrimitive

        public boolean isBoxedPrimitive()
        Description copied from class: Type
        Indicates whether this is a boxed primitive type.
        Overrides:
        isBoxedPrimitive in class Type
        Returns:
        true if this type is a boxed primitive, false otherwise
      • isEnum

        public boolean isEnum()
        Description copied from class: Type
        Indicates whether this is an enum type.
        Overrides:
        isEnum in class Type
        Returns:
        true if this is an enum type, false otherwise
      • isInterface

        public boolean isInterface()
        Description copied from class: Type
        Indicates whether this object is an interface type.
        Overrides:
        isInterface in class Type
        Returns:
        true if this object is an interface type, false otherwise
      • isRawtype

        public boolean isRawtype()
        Description copied from class: Type
        Indicate whether this type is a rawtype of a generic class. The rawtype is the runtime type of the class that has type parameters erased.
        Overrides:
        isRawtype in class Type
        Returns:
        true if this type is a rawtype of a generic class, false otherwise
      • isStatic

        public boolean isStatic()
        Description copied from class: ClassOrInterfaceType
        Indicates whether this class is static.
        Specified by:
        isStatic in class ClassOrInterfaceType
        Returns:
        true if this class is static, false otherwise
      • toPrimitive

        public PrimitiveType toPrimitive()
        If this type is a boxed primitive, unboxes this type and returns the primitive type.
        Returns:
        the primitive type if this is a boxed primitive
        Throws:
        IllegalArgumentException - if this is not a boxed primitive type