Package randoop.types

Class ParameterBound

  • Direct Known Subclasses:
    IntersectionTypeBound, LazyParameterBound, ReferenceBound

    public abstract class ParameterBound
    extends Object
    Represents a type bound on a type variable or wildcard occurring as a type parameter of a generic class, interface, method or constructor.

    Type bounds for explicitly defined type variables of generic declarations are defined in JLS section 8.1.2 as

       TypeBound:
         extends TypeVariable
         extends ClassOrInterfaceType [ & InterfaceType ]
     
    Type bounds for wildcards may be any reference type, which includes type variables, so the ParameterBound class hierarchy is simplified to use this ReferenceType objects as bounds. Intersection types (which includes the greatest lower bound construction used in capture conversion) are explicitly represented. And, recursive type bounds are avoided by holding any java.lang.reflect.Type with variables as a LazyParameterBound.

    Type parameters only have upper bounds, but variables introduced by capture conversion can have lower bounds. This class and its subclasses can represent both, with the default lower bound being JavaTypes.NULL_TYPE, and the default upperbound being JavaTypes.OBJECT_TYPE.

    See Also:
    EagerReferenceBound, IntersectionTypeBound, LazyParameterBound
    • Constructor Detail

      • ParameterBound

        public ParameterBound()
    • Method Detail

      • forTypes

        static ParameterBound forTypes​(Set<TypeVariable<?>> variableSet,
                                       Type[] bounds)
        Creates a bound from the array of bounds of a java.lang.reflect.TypeVariable.

        The bounds of a type parameter are restricted, but those of a wildcard may be any reference type. See JLS section 8.1.2.

        Parameters:
        variableSet - the set of variables affected by this bound
        bounds - the type bounds
        Returns:
        the ParameterBound for the given types
      • forType

        static ParameterBound forType​(Set<TypeVariable<?>> variableSet,
                                      Type type)
        Creates a ParameterBound object from a single java.lang.reflect.Type. Tests for types that are represented by Class objects, or java.lang.reflect.ParameterizedType objects.
        Parameters:
        variableSet - the set of type variables bound by this type
        type - the type for type bound
        Returns:
        a type bound that ensures the given type is satisfied as an upper bound
      • substitute

        public abstract ParameterBound substitute​(Substitution substitution)
        Applies the given substitution to this type bound by replacing type variables.
        Parameters:
        substitution - the type substitution
        Returns:
        this bound with the type after the substitution has been applied
      • applyCaptureConversion

        public abstract ParameterBound applyCaptureConversion()
        Applies a capture conversion to any wildcard arguments in the type of this bound.
        Returns:
        this type with any wildcards replaced by capture conversion
        See Also:
        ReferenceType.applyCaptureConversion()
      • getTypeParameters

        public abstract List<TypeVariable> getTypeParameters()
        Returns any type parameters in the type of this bound.
        Returns:
        the list of TypeVariable objects in this bound
      • hasTypeVariable

        private static boolean hasTypeVariable​(Type type,
                                               Set<TypeVariable<?>> variableSet)
        Indicates whether the given (reflection) type reference represents a type in which a type variable occurs.
        Parameters:
        type - the reflection type
        variableSet - the set of variables
        Returns:
        true if the type has a type variable, and false otherwise
      • isTypeVariable

        static boolean isTypeVariable​(Type type)
        Indicates whether the type is a type variable.
        Parameters:
        type - the type to test
        Returns:
        true if the type is a type variable, false otherwise
      • hasWildcard

        abstract boolean hasWildcard()
        Indicates whether the type of this bound has a wildcard type argument.
        Returns:
        true, if this bound has a wildcard argument, and false otherwise
      • hasCaptureVariable

        abstract boolean hasCaptureVariable()
        Indicates whether the type of this bound has a capture variable.
        Returns:
        true iff this bound has a capture variable
      • isGeneric

        final boolean isGeneric()
        Indicates whether the type of this bound is generic.
        Returns:
        true, if this bound type is generic, and false otherwise
      • isGeneric

        public abstract boolean isGeneric​(boolean ignoreWildcards)
        Indicates whether the type of this bound is generic.
        Parameters:
        ignoreWildcards - if true, ignore wildcards; that is, treat wildcards as not making the operation generic
        Returns:
        true, if this bound type is generic, and false otherwise
      • isLowerBound

        public abstract boolean isLowerBound​(Type argType,
                                             Substitution subst)
        Indicates whether this bound is a lower bound of the given argument type.
        Parameters:
        argType - the concrete argument type
        subst - the substitution
        Returns:
        true if this bound is a subtype of the given type
      • isLowerBound

        boolean isLowerBound​(ParameterBound bound,
                             Substitution substitution)
        Tests whether this is a lower bound on the type of a given bound with respect to a type substitution. The body is approximately:
        return this.substitute(substitution).isLowerBound(bound.substitute(substitution);
         
        Parameters:
        bound - the other bound
        substitution - the type substitution
        Returns:
        true iff this bound is a lower bound on the type of the given bound
      • isObject

        public abstract boolean isObject()
        Indicate whether this bound is Object.
        Returns:
        true if this bound is Object, false otherwise
      • isSubtypeOf

        public abstract boolean isSubtypeOf​(ParameterBound boundType)
        Indicates whether the type of this bound is a subtype of the type of the given bound.
        Parameters:
        boundType - the other bound
        Returns:
        true if this type is a subtype of the other bound, false otherwise
      • isUpperBound

        public abstract boolean isUpperBound​(Type argType,
                                             Substitution subst)
        Determines if this bound is an upper bound for the argument type.
        Parameters:
        argType - the concrete argument type
        subst - the substitution
        Returns:
        true if this bound is satisfied by the concrete type when the substitution is used on the bound, false otherwise
      • isUpperBound

        abstract boolean isUpperBound​(ParameterBound bound,
                                      Substitution substitution)
        Indicates whether this bound is an upper bound on the type of the given bound with respect to the type substitution.
        Parameters:
        bound - the other bound
        substitution - the type substitution
        Returns:
        true if this bound is an upper bound on the type of the given bound, false otherwise
      • isVariable

        public boolean isVariable()
        Indicates whether this bound is a type variable.
        Returns:
        true if this bound is a type variable, false otherwise