Package randoop.types

Class PrimitiveType

  • All Implemented Interfaces:
    Comparable<Type>

    public class PrimitiveType
    extends Type
    Represents a Java primitive type. Corresponds to primitive types as defined in JLS section 4.2.
    • Field Detail

      • runtimeClass

        private final Class<?> runtimeClass
        The runtime class of the primitive type.
      • cache

        private static Map<Class<?>,​PrimitiveType> cache
        All the PrimitiveTypes that have been created.
    • Constructor Detail

      • PrimitiveType

        private PrimitiveType​(Class<?> runtimeClass)
        Creates a primitive type from the given runtime class.
        Parameters:
        runtimeClass - the runtime class
    • Method Detail

      • forClass

        public static PrimitiveType forClass​(Class<?> runtimeClass)
        Creates a primitive type from the given runtime class.
        Parameters:
        runtimeClass - the runtime class
        Returns:
        the PrimitiveType for the given runtime class
      • equals

        public boolean equals​(Object obj)
        Overrides:
        equals in class Object
        Returns:
        true if the runtime class of this primitive type and the object are the same, false otherwise
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • getFqName

        public String getFqName()
        Description copied from class: Type
        Returns the fully-qualified name of this type, including type arguments if this is a parameterized type. For java.util.List<T> return "java.util.List<T>".
        Specified by:
        getFqName in class Type
        Returns:
        the fully-qualified type name for this type
      • getBinaryName

        public String getBinaryName()
        Description copied from class: Type
        Returns the binary name of this type, including type arguments if this is a parameterized type (so, it isn't really a binary name). For java.util.List<T> return "java.util.List<T>".
        Specified by:
        getBinaryName in class Type
        Returns:
        the binary name for this type
      • getSimpleName

        public String getSimpleName()
        Description copied from class: Type
        Returns the name of this type without type arguments or package qualifiers. For java.util.List<T>, returns "List".
        Specified by:
        getSimpleName in class Type
        Returns:
        the name of this type without type arguments
      • getRuntimeClass

        public Class<?> getRuntimeClass()
        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 object for this primitive type
      • 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.

        Checks for primitive widening (section 5.1.2), and unboxing (section 5.1.8) conversions. For a primitive type, returns true if this type can be assigned from the source type by primitive widening or unboxing.

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

        public boolean isPrimitive()
        Indicates whether this is a primitive type.
        Overrides:
        isPrimitive in class Type
        Returns:
        true since this object represents a primitive type
      • isNonreceiverType

        public boolean isNonreceiverType()
        Indicates whether this is the type of a non-receiver term: primitive, boxed primitive, String, or Class.
        Overrides:
        isNonreceiverType in class Type
        Returns:
        true since this object represents a non-receiver type
      • isSubtypeOf

        public boolean isSubtypeOf​(Type otherType)
        Test whether this type is a subtype of the given type according to transitive closure of definition of the direct supertype relation in section 4.10 of JLS for Java SE 8.

        Specifically implements tests for primitive types as defined in section 4.10.1 of JLS for JavaSE 8.

        Overrides:
        isSubtypeOf in class Type
        Parameters:
        otherType - the possible supertype
        Returns:
        true if this type is a subtype of the given type, false otherwise
      • toBoxedPrimitive

        public NonParameterizedType toBoxedPrimitive()
        Returns the boxed type for this primitive type.
        Returns:
        the boxed type for this primitive type