Package randoop.types

Class PrimitiveTypes


  • public final class PrimitiveTypes
    extends Object
    Utilities for working with Class<?> objects that Java reflection treats as primitive, which includes primitive types and void. Provides conversion from primitive type names (and "void") to Class objects, boxing and unboxing, as well as primitive subtype and assignment tests.
    • Field Detail

      • boxedToPrimitive

        private static final Map<Class<?>,​Class<?>> boxedToPrimitive
        Map from boxed primitive to primitive Class<?> objects.
      • primitiveToBoxed

        private static final Map<Class<?>,​Class<?>> primitiveToBoxed
        Map from primitive to boxed primitive Class<?> objects.
      • nameToClass

        private static final Map<String,​Class<?>> nameToClass
        Map from primitive type name (and "void") to Class<?> objects.
      • wideningTable

        private static final Map<Class<?>,​Set<Class<?>>> wideningTable
        Primitive widening map. Maps a primitive type to the set of primitive types to which it may be converted by widening as defined in JLS section 5.1.2.
    • Constructor Detail

      • PrimitiveTypes

        private PrimitiveTypes()
    • Method Detail

      • classForName

        public static Class<?> classForName​(String typeName)
        Return the Class<?> object for the given primitive type name or "void". These are names that Class.forName() will not convert.
        Parameters:
        typeName - the name of the type
        Returns:
        the Class<?> object for the type, or null
      • isAssignable

        static boolean isAssignable​(Class<?> target,
                                    Class<?> source)
        Tests assignability from source to target type via identity conversion and widening primitive conversion.
        Parameters:
        target - the target type for assignment; that is, the lvalue or left-hand side. Must be primitive.
        source - the source type for assignment; that is, the rvalue or right-hand side. Must be primitive.
        Returns:
        true if the source type can be assigned to the target type, false otherwise
      • isBoxedPrimitive

        public static boolean isBoxedPrimitive​(Class<?> c)
        Determine if the given Class<?> is a boxed primitive type.
        Parameters:
        c - the Class<?>
        Returns:
        true if the Class<?> is a boxed primitive, false otherwise
      • isSubtype

        static boolean isSubtype​(Class<?> first,
                                 Class<?> second)
        Indicates whether the first primitive type is a (transitive) subtype of the second primitive as determined by primitive widening. Note: returns false when both types are the same.
        Parameters:
        first - the first primitive type
        second - the second primitive type
        Returns:
        true if the first type is a subtype of the second type
      • toBoxedType

        static Class<?> toBoxedType​(Class<?> cls)
        Return boxed type for a primitive type.
        Parameters:
        cls - the Class object for the primitive type
        Returns:
        the boxed type for the primitive type, or null if the given type is not primitive
      • toUnboxedType

        static Class<?> toUnboxedType​(Class<?> c)
        Returns the primitive Class<?> type for a boxed primitive type.
        Parameters:
        c - the Class<?> type
        Returns:
        the primitive type for the boxed type, or null if given type is not a boxed primitive