Class PrimitiveType
- java.lang.Object
-
- randoop.types.Type
-
- randoop.types.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 Summary
Fields Modifier and Type Field Description private static Map<Class<?>,PrimitiveType>
cache
All the PrimitiveTypes that have been created.private Class<?>
runtimeClass
The runtime class of the primitive type.
-
Constructor Summary
Constructors Modifier Constructor Description private
PrimitiveType(Class<?> runtimeClass)
Creates a primitive type from the given runtime class.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
static PrimitiveType
forClass(Class<?> runtimeClass)
Creates a primitive type from the given runtime class.String
getBinaryName()
Returns the binary name of this type, including type arguments if this is a parameterized type (so, it isn't really a binary name).String
getFqName()
Returns the fully-qualified name of this type, including type arguments if this is a parameterized type.Class<?>
getRuntimeClass()
Returns the runtimeClass
object for this type.String
getSimpleName()
Returns the name of this type without type arguments or package qualifiers.int
hashCode()
boolean
isAssignableFrom(Type sourceType)
Indicates whether there is an assignment conversion from a sourceType
to this type.boolean
isNonreceiverType()
Indicates whether this is the type of a non-receiver term: primitive, boxed primitive,String
, orClass
.boolean
isPrimitive()
Indicates whether this is a primitive type.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.NonParameterizedType
toBoxedPrimitive()
Returns the boxed type for this primitive type.-
Methods inherited from class randoop.types.Type
applyCaptureConversion, compareTo, forFullyQualifiedName, forName, forType, forValue, getCanonicalName, getRawtype, getTypeforFullyQualifiedName, getUnqualifiedBinaryName, hasCaptureVariable, hasWildcard, isArray, isAssignableFromTypeOf, isBoxedPrimitive, isClass, isClassOrInterfaceType, isEnum, isGeneric, isGeneric, isInterface, isObject, isParameterized, isRawtype, isReferenceType, isString, isVariable, isVoid, runtimeClassIs, substitute, toString
-
-
-
-
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)
-
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. Forjava.util.List<T>
return"java.util.List<T>"
.
-
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). Forjava.util.List<T>
return"java.util.List<T>"
.- Specified by:
getBinaryName
in classType
- 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. Forjava.util.List<T>
, returns"List"
.- Specified by:
getSimpleName
in classType
- Returns:
- the name of this type without type arguments
-
getRuntimeClass
public Class<?> getRuntimeClass()
Returns the runtimeClass
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 theClass<?>
for theType
object, and not of the represented type. For instance, if aType
objectt
represented the Java typeint
, thent.getRuntimeClass()
would returnint.class
whilet.getClass()
would returnType.class
.- Specified by:
getRuntimeClass
in classType
- Returns:
- the
Class
object for this primitive type
-
isAssignableFrom
public boolean isAssignableFrom(Type sourceType)
Indicates whether there is an assignment conversion from a sourceType
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.
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 classType
- 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 classType
- 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
, orClass
.- Overrides:
isNonreceiverType
in classType
- 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 classType
- 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
-
-