Package randoop.types

Class InstantiatedType

    • Field Detail

      • genericType

        private final GenericClassType genericType
        The generic class for this type. Its enclosing type is instantiated (or is not generic).
      • argumentList

        private final List<TypeArgument> argumentList
        The type arguments for this class.
    • Constructor Detail

      • InstantiatedType

        InstantiatedType​(GenericClassType genericType,
                         List<TypeArgument> argumentList)
        Create a parameterized type from the generic class type.
        Parameters:
        genericType - the generic class type
        argumentList - the list of type arguments
        Throws:
        IllegalArgumentException - if either argument is null
    • Method Detail

      • equals

        public boolean equals​(Object obj)

        Test if the given object is equal to this parameterized type. Two parameterized types are equal if they have the same raw type and the same type arguments.

        Overrides:
        equals in class ClassOrInterfaceType
      • substitute

        public InstantiatedType substitute​(Substitution substitution)
        Description copied from class: ClassOrInterfaceType
        Applies a substitution to a ReferenceType. 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 class ParameterizedType
        Parameters:
        substitution - the type substitution
        Returns:
        the type created by applying the substitution to this type
      • getMatchingSupertype

        public InstantiatedType getMatchingSupertype​(GenericClassType goalType)
        Finds the parameterized type that is a supertype of this class that also matches the given generic class. For example, if class C<T> implements Comparator<T> and class A extends C<String>, then when applied to A, this method would return C<String> when given C<T>, and Comparator<String> when given Comparator<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.

        An instantiated type may have a wildcard, and so must perform capture conversion before doing supertype search.

        Overrides:
        getMatchingSupertype in class ClassOrInterfaceType
        Parameters:
        goalType - the generic class type
        Returns:
        the instantiated type matching the goal type, or null
      • getReferenceArguments

        List<ReferenceType> getReferenceArguments()
        Returns the list of reference type arguments of this type if there are no wildcards.
        Returns:
        the list of reference types that are arguments to this type
      • getRuntimeClass

        public Class<?> getRuntimeClass()
        Description copied from class: Type
        Returns the runtime Class 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 the Class<?> for the Type object, and not of the represented type. For instance, if a Type object t represented the Java type int, then t.getRuntimeClass() would return int.class while t.getClass() would return Type.class.

        Specified by:
        getRuntimeClass in class Type
        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()
        Constructs the superclass type for this parameterized type.

        Implementation note: we can think of an InstantiatedType A<T1,...,Tk> as being represented as a generic class A<F1,...,Fk> with a substitution [ Fi := Ti] for all of the type parameters Fi. So, when we compute a superclass, we first find the supertype of the generic class B<F1,...,Fk>, and then apply the substitution [ Fi := Ti] using the method GenericClassType.getSuperclass(Substitution).

        Specified by:
        getSuperclass in class ClassOrInterfaceType
        Returns:
        the superclass type for this parameterized type
      • getTypeSubstitution

        public Substitution getTypeSubstitution()
        Creates the type substitution of the type arguments of this type for the type variables of the instantiated class, if the type arguments are reference types. If any type argument is a wildcard, then null is returned.
        Returns:
        the type substitution of the type arguments of this class for the type variables of the instantiated type
      • hasWildcard

        public boolean hasWildcard()
        Description copied from class: Type
        Indicates whether this type has a wildcard anywhere within it.
        Overrides:
        hasWildcard in class ClassOrInterfaceType
        Returns:
        true if this type has a wildcard, false otherwise
      • isAbstract

        public boolean isAbstract()
        Description copied from class: ClassOrInterfaceType
        Indicate whether this class is abstract.
        Specified by:
        isAbstract in class ClassOrInterfaceType
        Returns:
        true if this class is abstract, false otherwise
      • isAssignableFrom

        public boolean isAssignableFrom​(Type otherType)
        Description copied from class: ReferenceType
        Indicates whether there is an assignment conversion from a source Type 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.
        And, if after all those conversions, the type is a raw type, an unchecked conversion may occur.

        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.

        Overrides:
        isAssignableFrom in class ReferenceType
        Parameters:
        otherType - the type to test for assignability
        Returns:
        true if this type can be assigned from the source type, and 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.
        Overrides:
        isGeneric in class ClassOrInterfaceType
        Parameters:
        ignoreWildcards - if true, ignore wildcards; that is, treat wildcards as not making the operation generic
        Returns:
        true if this type is generic, false otherwise
      • isInstantiationOf

        public boolean isInstantiationOf​(ReferenceType otherType)
        Checks whether this type is an instantiation of the given instantiated type. This is only possible if this type is A<T1,...,Tk> where all Ti are instantiated by ground types (e.g., does not have type variables), the other type is A<S1,...,Sk>, and each Ti matches Si for i = 1,...,k as follows:
        1. If Si is the variable X with lower bound L and upper bound U, then Ti is a supertype of L and a subtype of U
        2. Si is identical to Ti
        Overrides:
        isInstantiationOf in class ClassOrInterfaceType
        Parameters:
        otherType - the other InstantiatedType
        Returns:
        true if this type is an instantiation of the other type, false otherwise
        See Also:
        ReferenceType.isInstantiationOf(ReferenceType)
      • getInstantiatingSubstitution

        public Substitution getInstantiatingSubstitution​(ReferenceType goalType)
        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 class ClassOrInterfaceType
        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
      • isInterface

        public boolean isInterface()
        Description copied from class: Type
        Indicates whether this object is an interface type.
        Overrides:
        isInterface in class Type
        Returns:
        true if this object is an interface type, false otherwise
      • isParameterized

        public boolean isParameterized()
        Description copied from class: Type
        Indicate whether this type is a parameterized type. A parameterized type is a type C<T1,...,Tk> that instantiates a generic class C<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 class ClassOrInterfaceType
        Returns:
        true if this type is a parameterized type, false otherwise
      • isRecursiveType

        public boolean isRecursiveType()
        Determines if this type is recursive in the sense that the type is the bound of its type argument. So, should have a single type argument that is a subtype of this type.
        Returns:
        true if the type argument is a subtype of this type, false otherwise
      • isStatic

        public boolean isStatic()
        Description copied from class: ClassOrInterfaceType
        Indicates whether this class is static.
        Specified by:
        isStatic in class ClassOrInterfaceType
        Returns:
        true if this class is static, false otherwise
      • 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.2 of JLS for JavaSE 8.

        Handles specific cases of supertypes of a parameterized type C<T1,...,Tn> instantiating the generic type C<F1,...,Fn> by substitution θ =[F1:=T1,...,Fn:=Tn] for which direct supertypes are:

        1. D<U1θ,...,Ukθ> where D<U1,...,Uk> is a supertype of C<F1,...,Fn>.
        2. C<S1,...,Sn> where Si contains Ti (JLS section 4.5.1).
        3. The rawtype C.
        4. Object if generic form is interface with no interfaces as supertypes.
        Overrides:
        isSubtypeOf in class ClassOrInterfaceType
        Parameters:
        otherType - the possible supertype
        Returns:
        true if this type is a subtype of the given type, false otherwise
        See Also:
        ReferenceType.isAssignableFrom(Type), ClassOrInterfaceType.isSubtypeOf(Type)