Class NonParameterizedType
- java.lang.Object
-
- randoop.types.Type
-
- randoop.types.ReferenceType
-
- randoop.types.ClassOrInterfaceType
-
- randoop.types.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 aClass
object, which is a runtime representation of a type.
-
-
Field Summary
Fields Modifier and Type Field Description private static Map<Class<?>,NonParameterizedType>
cache
A cache of all NonParameterizedTypes that have been created.private Class<?>
runtimeType
The runtime class of this simple type.-
Fields inherited from class randoop.types.ClassOrInterfaceType
enclosingType
-
-
Constructor Summary
Constructors Constructor Description NonParameterizedType(Class<?> runtimeType)
Create aNonParameterizedType
object for the runtime class.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description NonParameterizedType
applyCaptureConversion()
Applies a capture conversion to this type.boolean
equals(Object obj)
static NonParameterizedType
forClass(Class<?> runtimeType)
Create aNonParameterizedType
object for the runtime class.private List<ClassOrInterfaceType>
getGenericInterfaces()
Returns the list of direct interfaces for this class.List<ClassOrInterfaceType>
getInterfaces()
Returns the interface types directly implemented by this class or interface type.NonParameterizedType
getRawtype()
Returns the non-parameterized form of this class type.private List<ClassOrInterfaceType>
getRawTypeInterfaces()
Returns the list of rawtypes for the direct interfaces for this type.Class<?>
getRuntimeClass()
Returns the runtimeClass
object for this type.ClassOrInterfaceType
getSuperclass()
Return the type for the superclass for this class.int
hashCode()
boolean
isAbstract()
Indicate whether this class is abstract.boolean
isAssignableFrom(Type sourceType)
Indicates whether there is an assignment conversion from a sourceType
to this type.boolean
isBoxedPrimitive()
Indicates whether this is a boxed primitive type.boolean
isEnum()
Indicates whether this is an enum type.boolean
isInstantiationOf(ReferenceType otherType)
Indicates whether this type is an instantiation of a more general type.boolean
isInterface()
Indicates whether this object is an interface type.boolean
isRawtype()
Indicate whether this type is a rawtype of a generic class.boolean
isStatic()
Indicates whether this class is static.NonParameterizedType
substitute(Substitution substitution)
Applies a substitution to aReferenceType
.PrimitiveType
toPrimitive()
If this type is a boxed primitive, unboxes this type and returns the primitive type.-
Methods inherited from class randoop.types.ClassOrInterfaceType
applyCaptureConversion, forType, getAllSupertypesInclusive, getBinaryName, getCanonicalName, getFqName, getImmediateSupertypes, getInstantiatingSubstitution, getMatchingSupertype, getPackage, getPackagePrefix, getSimpleName, getSuperTypes, getTypeArguments, getTypeParameters, getUnqualifiedBinaryName, hasCaptureVariable, hasWildcard, isClassOrInterfaceType, isGeneric, isMemberClass, isNestedClass, isParameterized, isSubtypeOf, substitute
-
Methods inherited from class randoop.types.ReferenceType
getInstantiatingSubstitutionforTypeVariable, isCaptureVariable, isReferenceType
-
Methods inherited from class randoop.types.Type
compareTo, forFullyQualifiedName, forName, forValue, getTypeforFullyQualifiedName, isArray, isAssignableFromTypeOf, isClass, isGeneric, isNonreceiverType, isObject, isPrimitive, isString, isVariable, isVoid, runtimeClassIs, toString
-
-
-
-
Field Detail
-
runtimeType
private final Class<?> runtimeType
The runtime class of this simple type.
-
cache
private static final Map<Class<?>,NonParameterizedType> cache
A cache of all NonParameterizedTypes that have been created.
-
-
Constructor Detail
-
NonParameterizedType
public NonParameterizedType(Class<?> runtimeType)
Create aNonParameterizedType
object for the runtime class.- Parameters:
runtimeType
- the runtime class for the type
-
-
Method Detail
-
forClass
public static NonParameterizedType forClass(Class<?> runtimeType)
Create aNonParameterizedType
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 classClassOrInterfaceType
- Returns:
- true if the runtime types are the same, false otherwise
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classClassOrInterfaceType
-
substitute
public NonParameterizedType substitute(Substitution substitution)
Description copied from class:ClassOrInterfaceType
Applies a substitution to aReferenceType
. 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 classClassOrInterfaceType
- Parameters:
substitution
- the type substitution- Returns:
- the type created by applying the substitution to this type
-
applyCaptureConversion
public NonParameterizedType applyCaptureConversion()
Description copied from class:Type
Applies a capture conversion to this type.- Specified by:
applyCaptureConversion
in classClassOrInterfaceType
- Returns:
- a copy of this type with wildcards replaced by type conversion
-
getInterfaces
public List<ClassOrInterfaceType> getInterfaces()
Description copied from class:ClassOrInterfaceType
Returns the interface types directly implemented by this class or interface type. Preserves the order in the reflection methodClass.getGenericInterfaces()
. If no interfaces are implemented, then returns the empty list.- Specified by:
getInterfaces
in classClassOrInterfaceType
- Returns:
- the list of interfaces directly implemented by 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
-
getRawtype
public NonParameterizedType getRawtype()
Description copied from class:ClassOrInterfaceType
Returns the non-parameterized form of this class type.- Specified by:
getRawtype
in classClassOrInterfaceType
- Returns:
- the non-parameterized form of this class 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 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
that is the runtime representation of the type, or null if this type is a type variable or null reference type
-
getSuperclass
public ClassOrInterfaceType getSuperclass()
Description copied from class:ClassOrInterfaceType
Return the type for the superclass for this class.- Specified by:
getSuperclass
in classClassOrInterfaceType
- Returns:
- superclass of this type, or the
Object
type if this type has no superclass
-
isAbstract
public boolean isAbstract()
Description copied from class:ClassOrInterfaceType
Indicate whether this class is abstract.- Specified by:
isAbstract
in classClassOrInterfaceType
- Returns:
- true if this class is abstract, false otherwise
-
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.
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 classReferenceType
- 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 classType
- 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.
-
isInstantiationOf
public boolean isInstantiationOf(ReferenceType otherType)
Indicates whether this type is an instantiation of a more general type.For a general
ReferenceType
, this is only true if the other type is the same, or the other type is a type variable for which this type satisfies the bounds. Other cases are handled by the overriding implementationsClassOrInterfaceType.isInstantiationOf(ReferenceType)
,InstantiatedType.isInstantiationOf(ReferenceType)
, andTypeVariable.isInstantiationOf(ReferenceType)
.For a
ClassOrInterfaceType
that is a member class, ifotherType
is also a member class, then the enclosing type of this type must instantiate the enclosing type ofotherType
.For a
NonParameterizedType
, if this type instantiates theotherType
, which is aNonParameterizedType
byClassOrInterfaceType.isInstantiationOf(ReferenceType)
also checks that runtime classes are equal. This allows for proper matching of member classes that are ofNonParameterizedType
.- Overrides:
isInstantiationOf
in classClassOrInterfaceType
- Parameters:
otherType
- the general reference type- Returns:
- true if this type instantiates the other reference type, false otherwise
-
isInterface
public boolean isInterface()
Description copied from class:Type
Indicates whether this object is an interface type.- Overrides:
isInterface
in classType
- 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.
-
isStatic
public boolean isStatic()
Description copied from class:ClassOrInterfaceType
Indicates whether this class is static.- Specified by:
isStatic
in classClassOrInterfaceType
- 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
-
-