Package randoop.types

Class TypeVariable

    • Constructor Detail

      • TypeVariable

        TypeVariable()
        Creates a type variable with NullReferenceType as the lower bound, and the Object type as upper bound.
      • TypeVariable

        TypeVariable​(ParameterBound lowerBound,
                     ParameterBound upperBound)
        Creates a type variable with the given type bounds. Assumes the bounds are consistent and does not check for the subtype relationship.
        Parameters:
        lowerBound - the lower type bound on this variable
        upperBound - the upper type bound on this variable
    • Method Detail

      • forType

        public static TypeVariable forType​(Type type)
        Creates a TypeVariable object for a given java.lang.reflect.Type reference, which must be a java.lang.reflect.TypeVariable.
        Parameters:
        type - the type reference
        Returns:
        the TypeVariable for the given type
      • substitute

        public ReferenceType substitute​(Substitution substitution)
        Description copied from class: ReferenceType
        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.

        Specified by:
        substitute in class ReferenceType
        Parameters:
        substitution - the type substitution
        Returns:
        the type created by applying the substitution to this type
      • isAssignableFrom

        public boolean isAssignableFrom​(Type sourceType)
        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.

        Returns false, since an uninstantiated type variable may not be assigned to.

        Overrides:
        isAssignableFrom in class ReferenceType
        Parameters:
        sourceType - the type to test for assignability
        Returns:
        true if this type can be assigned from the source type, and false otherwise
      • isSubtypeOf

        public boolean isSubtypeOf​(Type otherType)
        Description copied from class: ReferenceType
        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.

        For ReferenceType, returns true if otherType is Object.

        Overrides:
        isSubtypeOf in class ReferenceType
        Parameters:
        otherType - the possible supertype
        Returns:
        true if this type is a subtype of the given type, false otherwise
      • getSubstitution

        private static Substitution getSubstitution​(TypeVariable variable,
                                                    ReferenceType otherType)
        Creates a substitution of the given ReferenceType for the TypeVariable.
        Parameters:
        variable - the variable
        otherType - the replacement type
        Returns:
        a substitution that replaces variable with otherType
      • isVariable

        public boolean isVariable()
        Description copied from class: Type
        Indicates whether this type is a type variable.
        Overrides:
        isVariable in class Type
        Returns:
        true if this type is a type variable, false otherwise
      • canBeInstantiatedBy

        boolean canBeInstantiatedBy​(ReferenceType otherType)
        Indicates whether this TypeVariable can be instantiated by the ReferenceType. Does not require that all bounds of this variable be instantiated.
        Parameters:
        otherType - the possibly instantiating type, not a variable
        Returns:
        true if the given type can instantiate this variable, false otherwise
      • getRawtype

        public Type getRawtype()
        Description copied from class: Type
        Returns the raw type for this type, which is this type except for generic types.
        Overrides:
        getRawtype in class Type
        Returns:
        the raw type corresponding to this type