Class ClassOrInterfaceType
- All Implemented Interfaces:
Comparable<Type>
- Direct Known Subclasses:
NonParameterizedType
,ParameterizedType
This abstract class corresponds to this grammar production in the JLS:
ClassOrInterfaceType: ClassType InterfaceTypeInterfaceType is syntactically the same as ClassType. Therefore,
ClassType
and
InterfaceType
do not exist as subclasses of this class, Rather, the subclasses of this type
distinguish between types with parameters (ParameterizedType
), and types without (NonParameterizedType
).-
Field Summary
Modifier and TypeFieldDescriptionprivate static boolean
Set to true to enable debug output to standard out.protected ClassOrInterfaceType
The enclosing type. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract ClassOrInterfaceType
Applies a capture conversion to this type.(package private) final ClassOrInterfaceType
Applies capture conversion to the enclosing type of this type and adds the result as the enclosing class of the given type.boolean
static ClassOrInterfaceType
Translates aClass
object that represents a class or interface into aClassOrInterfaceType
object.static ClassOrInterfaceType
Creates aClassOrInterfaceType
object for a givenjava.lang.reflect.Type
reference.Return all supertypes of this type, including itself.Returns the binary name of this type, including type arguments if this is a parameterized type (so, it isn't really a binary name).Returns the name of this type as the "canonical name" of the underlying runtime class.Returns the fully-qualified name of this type, including type arguments if this is a parameterized type.Return the immediate supertypes of this type.getInstantiatingSubstitution
(ReferenceType goalType) Computes a substitution that can be applied to the type variables of the generic goal type to instantiate operations of this type, possibly inherited from from the goal type.abstract List<ClassOrInterfaceType>
Returns the interface types directly implemented by this class or interface type.getMatchingSupertype
(GenericClassType goalType) Finds the parameterized type that is a supertype of this class that also matches the given generic class.Returns the package of the runtime class of this type.(package private) String
Return the package part of a type name, including the final period.abstract NonParameterizedType
Returns the non-parameterized form of this class type.Returns the name of this class type.abstract ClassOrInterfaceType
Return the type for the superclass for this class.Return the set of all of the supertypes of this type.Returns the type arguments for this type.Returns the list of type parameters for this type.Returns the name of this type without package name, but with type arguments if parameterized, and enclosing class if a member class.boolean
Indicates whether thisReferenceType
has a capture variable.int
hashCode()
boolean
Indicates whether this type has a wildcard anywhere within it.abstract boolean
Indicate whether this class is abstract.boolean
Indicate whether this type is a class or interface type.boolean
isGeneric
(boolean ignoreWildcards) Indicate whether this type is generic.boolean
isInstantiationOf
(ReferenceType otherType) Indicates whether this type is an instantiation of a more general type.final boolean
Indicate whether this class is a member of another class.final boolean
Indicate whether this class is a nested class.boolean
Indicate whether this type is a parameterized type.abstract boolean
isStatic()
Indicates whether this class is static.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.2 of JLS for JavaSE 8.protected void
setEnclosingType
(ClassOrInterfaceType enclosingType) Sets the enclosing type for this class type.abstract ClassOrInterfaceType
substitute
(Substitution substitution) Applies a substitution to aReferenceType
.(package private) final ClassOrInterfaceType
substitute
(Substitution substitution, ClassOrInterfaceType type) Applies the substitution to the enclosing type of this type and adds the result as the enclosing class of the given type.Methods inherited from class randoop.types.ReferenceType
getInstantiatingSubstitutionforTypeVariable, isAssignableFrom, isCaptureVariable, isReferenceType
Methods inherited from class randoop.types.Type
compareTo, forFullyQualifiedName, forName, forValue, getRuntimeClass, getTypeforFullyQualifiedName, isArray, isAssignableFromTypeOf, isBoxedPrimitive, isClass, isEnum, isGeneric, isInterface, isNonreceiverType, isObject, isPrimitive, isRawtype, isString, isVariable, isVoid, runtimeClassIs, toString
-
Field Details
-
debug
private static boolean debugSet to true to enable debug output to standard out. -
enclosingType
The enclosing type. Non-null only if this is a nested type (either a member type or a nested static type).
-
-
Constructor Details
-
ClassOrInterfaceType
public ClassOrInterfaceType()
-
-
Method Details
-
forClass
Translates aClass
object that represents a class or interface into aClassOrInterfaceType
object. If the object has parameters, then delegates toParameterizedType.forClass(Class)
. Otherwise, creates aNonParameterizedType
object from the given object.- Parameters:
classType
- the class type to translate- Returns:
- the
ClassOrInterfaceType
object created from the given class type
-
forType
Creates aClassOrInterfaceType
object for a givenjava.lang.reflect.Type
reference. If type is ajava.lang.reflect.ParameterizedType
, then callsParameterizedType.forType(java.lang.reflect.Type)
. Otherwise, if type is aClass
object, callsforClass(Class)
.- Parameters:
type
- the type reference- Returns:
- the
ClassOrInterfaceType
object for the given type
-
equals
-
hashCode
public int hashCode() -
substitute
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 classReferenceType
- Parameters:
substitution
- the type substitution- Returns:
- the type created by applying the substitution to this type
-
substitute
Applies the substitution to the enclosing type of this type and adds the result as the enclosing class of the given type.- Parameters:
substitution
- the substitution to apply to the enclosing typetype
- the type to which resulting enclosing type is to be added; will be side-effected- Returns:
- the type with enclosing type added if needed
-
applyCaptureConversion
Description copied from class:Type
Applies a capture conversion to this type.- Overrides:
applyCaptureConversion
in classReferenceType
- Returns:
- a copy of this type with wildcards replaced by type conversion
-
applyCaptureConversion
Applies capture conversion to the enclosing type of this type and adds the result as the enclosing class of the given type.- Parameters:
type
- this type with capture conversion applied; will be side-effected- Returns:
- the type with converted enclosing type
-
getSimpleName
Returns the name of this class type. Does not include package, enclosing classes, or type arguments.- Specified by:
getSimpleName
in classType
- Returns:
- the name of this class
-
getCanonicalName
Description copied from class:Type
Returns the name of this type as the "canonical name" of the underlying runtime class. Identical toType.getFqName()
except for types with type arguments. Forjava.util.List<T>
returns"java.util.List"
. Returnsnull
whenClass<?>.getCanonicalName()
does for the underlyingClass<?>
object (e.g., the type is a local or anonymous class, or array type where the component type that has no canonical name).- Overrides:
getCanonicalName
in classType
- Returns:
- the fully-qualified canonical name of this type
-
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
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
-
getUnqualifiedBinaryName
Description copied from class:Type
Returns the name of this type without package name, but with type arguments if parameterized, and enclosing class if a member class. For instance, forjava.util.List<T>
would return"List<T>"
.- Overrides:
getUnqualifiedBinaryName
in classType
- Returns:
- the unqualified name of this type
-
getInterfaces
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.- Returns:
- the list of interfaces directly implemented by this type
-
getPackage
Returns the package of the runtime class of this type.- Returns:
- the package of the runtime class of this type, or null if there is none
-
getPackagePrefix
String getPackagePrefix()Return the package part of a type name, including the final period. Returns the empty string for a type in the unnamed package.- Returns:
- the package part of a type name, or ""
-
getRawtype
Returns the non-parameterized form of this class type.- Overrides:
getRawtype
in classType
- Returns:
- the non-parameterized form of this class type
-
getMatchingSupertype
Finds the parameterized type that is a supertype of this class that also matches the given generic class. For example, ifclass C<T> implements Comparator<T>
andclass A extends C<String>
, then when applied toA
, this method would returnC<String>
when givenC<T>
, andComparator<String>
when givenComparator<E>
. Returns null if there is no such type.Performs a depth-first search of the supertype relation for this type. If the goal type is an interface, then searches the interfaces of this type first.
- Parameters:
goalType
- the generic class type- Returns:
- the instantiated type matching the goal type, or null
-
getInstantiatingSubstitution
Description copied from class:ReferenceType
Computes a substitution that can be applied to the type variables of the generic goal type to instantiate operations of this type, possibly inherited from from the goal type. The substitution will unify this type or a supertype of this type with the given goal type.If there is no unifying substitution, returns
null
.- Overrides:
getInstantiatingSubstitution
in classReferenceType
- Parameters:
goalType
- the generic type for which a substitution is needed- Returns:
- a substitution unifying this type or a supertype of this type with the goal type
-
getSuperclass
Return the type for the superclass for this class.- Returns:
- superclass of this type, or the
Object
type if this type has no superclass
-
getSuperTypes
Return the set of all of the supertypes of this type.- Returns:
- the set of all supertypes of this type
-
getImmediateSupertypes
Return the immediate supertypes of this type.- Returns:
- the immediate supertypes of this type
-
getAllSupertypesInclusive
Return all supertypes of this type, including itself.- Returns:
- all supertypes of this type, including itself
-
isAbstract
public abstract boolean isAbstract()Indicate whether this class is abstract.- Returns:
- true if this class is abstract, false otherwise
-
isGeneric
public boolean isGeneric(boolean ignoreWildcards) Description copied from class:Type
Indicate whether this type is generic. A type is generic if it has one or more type variables. -
isInstantiationOf
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 implementationsisInstantiationOf(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
.- Overrides:
isInstantiationOf
in classReferenceType
- Parameters:
otherType
- the general reference type- Returns:
- true if this type instantiates the other reference type, false otherwise
-
isNestedClass
public final boolean isNestedClass()Indicate whether this class is a nested class.- Returns:
- true iff this class is a nested class
-
isMemberClass
public final boolean isMemberClass()Indicate whether this class is a member of another class. (see JLS section 8.5).- Returns:
- true if this class is a member class, false otherwise
-
isParameterized
public boolean isParameterized()Description copied from class:Type
Indicate whether this type is a parameterized type. A parameterized type is a typeC<T1,...,Tk>
that instantiates a generic classC<F1,...,Fk>
.If inputType.isParameterized returns true, there are two possibilities:
inputType instanceof InstantiatedType
, or inputType is a member class and the enclosing type is a parameterized type- Overrides:
isParameterized
in classType
- Returns:
- true if this type is a parameterized type, false otherwise
-
isStatic
public abstract boolean isStatic()Indicates whether this class is static.- Returns:
- true if this class is static, false otherwise
-
isSubtypeOf
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.2 of JLS for JavaSE 8.- Overrides:
isSubtypeOf
in classReferenceType
- Parameters:
otherType
- the possible supertype- Returns:
- true if this type is a subtype of the given type, false otherwise
- See Also:
-
hasWildcard
public boolean hasWildcard()Description copied from class:Type
Indicates whether this type has a wildcard anywhere within it.- Overrides:
hasWildcard
in classType
- Returns:
- true if this type has a wildcard, false otherwise
-
hasCaptureVariable
public boolean hasCaptureVariable()Description copied from class:Type
Indicates whether thisReferenceType
has a capture variable.- Overrides:
hasCaptureVariable
in classType
- Returns:
- true iff this type has a capture variable
-
setEnclosingType
Sets the enclosing type for this class type.- Parameters:
enclosingType
- the type for the class enclosing the declaration of this type
-
getTypeArguments
Returns the type arguments for this type.- Returns:
- the list of type arguments
-
getTypeParameters
Description copied from class:ReferenceType
Returns the list of type parameters for this type. Reference types that may have type parameters includeArrayType
(such asE[]
), and subclasses ofParameterizedType
.- Overrides:
getTypeParameters
in classReferenceType
- Returns:
- the type parameters for this type
-
isClassOrInterfaceType
public boolean isClassOrInterfaceType()Description copied from class:Type
Indicate whether this type is a class or interface type.- Overrides:
isClassOrInterfaceType
in classType
- Returns:
- true if this type is a class or interface type; false, otherwise
-