Package randoop.types
Class PrimitiveTypes
- java.lang.Object
-
- randoop.types.PrimitiveTypes
-
public final class PrimitiveTypes extends Object
Utilities for working withClass<?> objects
that Java reflection treats as primitive, which includes primitive types andvoid
. Provides conversion from primitive type names (and "void") toClass
objects, boxing and unboxing, as well as primitive subtype and assignment tests.
-
-
Field Summary
Fields Modifier and Type Field Description private static Map<Class<?>,Class<?>>
boxedToPrimitive
Map from boxed primitive to primitiveClass<?>
objects.private static Map<String,Class<?>>
nameToClass
Map from primitive type name (and "void") toClass<?>
objects.private static Map<Class<?>,Class<?>>
primitiveToBoxed
Map from primitive to boxed primitiveClass<?>
objects.private static Map<Class<?>,Set<Class<?>>>
wideningTable
Primitive widening map.
-
Constructor Summary
Constructors Modifier Constructor Description private
PrimitiveTypes()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Class<?>
classForName(String typeName)
Return theClass<?>
object for the given primitive type name or "void".(package private) static boolean
isAssignable(Class<?> target, Class<?> source)
Tests assignability from source to target type via identity conversion and widening primitive conversion.static boolean
isBoxedPrimitive(Class<?> c)
Determine if the givenClass<?>
is a boxed primitive type.(package private) 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.(package private) static Class<?>
toBoxedType(Class<?> cls)
Return boxed type for a primitive type.(package private) static Class<?>
toUnboxedType(Class<?> c)
Returns the primitiveClass<?>
type for a boxed primitive type.
-
-
-
Field Detail
-
boxedToPrimitive
private static final Map<Class<?>,Class<?>> boxedToPrimitive
Map from boxed primitive to primitiveClass<?>
objects.
-
primitiveToBoxed
private static final Map<Class<?>,Class<?>> primitiveToBoxed
Map from primitive to boxed primitiveClass<?>
objects.
-
nameToClass
private static final Map<String,Class<?>> nameToClass
Map from primitive type name (and "void") toClass<?>
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.
-
-
Method Detail
-
classForName
public static Class<?> classForName(String typeName)
Return theClass<?>
object for the given primitive type name or "void". These are names thatClass.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 givenClass<?>
is a boxed primitive type.- Parameters:
c
- theClass<?>
- 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 typesecond
- 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
- theClass
object for the primitive type- Returns:
- the boxed type for the primitive type, or null if the given type is not primitive
-
-