java.lang.Object
org.checkerframework.framework.util.typeinference8.types.VariableBounds

public class VariableBounds extends Object
Data structure to stores the bounds of a variable.
  • Field Details

  • Constructor Details

    • VariableBounds

      public VariableBounds(Variable variable, Java8InferenceContext context)
      Creates bounds for variable.
      Parameters:
      variable - a variable
      context - the context
  • Method Details

    • save

      public void save()
      Save the current bounds in case the first attempt at resolution fails.
    • restore

      public void restore()
      Restore the bounds to the state previously saved. This method is called if the first attempt at resolution fails.
    • hasThrowsBound

      public boolean hasThrowsBound()
      Return true if this has a throws bound.
      Returns:
      true if this has a throws bound
    • setHasThrowsBound

      public void setHasThrowsBound(boolean b)
      Set has throws bound
      Parameters:
      b - has thrown bound
    • addBound

      public boolean addBound(VariableBounds.BoundKind kind, AbstractType otherType)
      Adds otherType as bound against this variable.
      Parameters:
      kind - the kind of bound
      otherType - the bound type
      Returns:
      if a new bound was added
    • addQualifierBound

      public void addQualifierBound(VariableBounds.BoundKind kind, Set<? extends AbstractQualifier> qualifiers)
      Adds qualifiers as a qualifier bound against this variable.
      Parameters:
      kind - the kind of bound
      qualifiers - the qualifiers
    • addConstraintsFromComplementaryQualifierBounds

      public void addConstraintsFromComplementaryQualifierBounds(VariableBounds.BoundKind kind, Set<? extends AbstractQualifier> qualifiers)
      Add constraints created via incorporation of the bound. See JLS 18.3.1.
      Parameters:
      kind - the kind of bound
      qualifiers - the qualifiers
    • addConstraintsFromComplementaryBounds

      public void addConstraintsFromComplementaryBounds(VariableBounds.BoundKind kind, AbstractType s)
      Add constraints created via incorporation of the bound. See JLS 18.3.1.
      Parameters:
      kind - the kind of bound
      s - the type of the bound
    • addConstraintsFromComplementaryBounds

      public void addConstraintsFromComplementaryBounds(VariableBounds.BoundKind kind, Set<? extends AbstractQualifier> s)
      Adds constraints from complementary bounds.
      Parameters:
      kind - kind of bound
      s - qualifiers
    • onlyProperBounds

      public boolean onlyProperBounds()
      Returns whether this variable only has bounds against proper types.
      Returns:
      whether this variable only has bounds against proper types.
    • findProperLowerBounds

      public Set<ProperType> findProperLowerBounds()
      Return all lower bounds that are proper types.
      Returns:
      all lower bounds that are proper types
    • findProperUpperBounds

      public Set<ProperType> findProperUpperBounds()
      Returns all upper bounds that proper types.
      Returns:
      all upper bounds that are proper types
    • upperBounds

      public Set<AbstractType> upperBounds()
      Returns all upper bounds.
      Returns:
      all upper bounds
    • applyInstantiationsToBounds

      public boolean applyInstantiationsToBounds()
      Apply instantiations to all bounds and constraints of this variable.
      Returns:
      whether any of the bounds changed
    • getVariablesMentionedInBounds

      public Collection<? extends Variable> getVariablesMentionedInBounds()
      Return all variables mentioned in a bound against this variable.
      Returns:
      all variables mentioned in a bound against this variable
    • getInstantiation

      public ProperType getInstantiation()
      Returns the instantiation of this variable.
      Returns:
      the instantiation of this variable
    • hasInstantiation

      public boolean hasInstantiation()
      Return true if this has an instantiation.
      Returns:
      true if this has an instantiation
    • hasPrimitiveWrapperBound

      public boolean hasPrimitiveWrapperBound()
      Returns true if any bound mentions a primitive wrapper type.
      Returns:
      true if any bound mentions a primitive wrapper type
    • hasWildcardParameterizedLowerOrEqualBound

      public boolean hasWildcardParameterizedLowerOrEqualBound()
      Returns true if any lower or equal bound is a parameterized type with at least one wildcard as a type argument.
      Returns:
      true if any lower or equal bound is a parameterized type with at least one wildcard for a type argument
    • hasLowerBoundDifferentParam

      public boolean hasLowerBoundDifferentParam()
      Does this bound set contain two bounds of the forms S1 <: var and S2 <: var, where S1 and S2 have supertypes that are two different parameterizations of the same generic class or interface?
      Returns:
      whether this bound set contain two bounds of the forms S1 <: var and S2 <: var, where S1 and S2 have supertypes that are two different parameterizations of the same generic class or interface
    • hasRawTypeLowerOrEqualBound

      public boolean hasRawTypeLowerOrEqualBound(AbstractType t)
      Returns true if there exists an equal or lower bound against a type, S, such that S is not a subtype of G<...>, but S is a subtype of the raw type |G<...>|, where G a generic class or interface for which the parameter of this method, t, is a parameterization.
      Parameters:
      t - a parameterization of a generic class or interface, G
      Returns:
      true if there exists an equal or lower bound against a type, S, such that S is not a subtype of G<...>, but S is a subtype of the raw type |G<...>|, where G a generic class or interface for which the parameter of this method, t, is a parameterization.
    • getWildcardConstraints

      public ConstraintSet getWildcardConstraints(AbstractType Ai, AbstractType Bi)
      Returns the constraints generated when incorporating a capture bound. See JLS 18.3.2.
      Parameters:
      Ai - the captured type argument
      Bi - the bound of the type variable
      Returns:
      constraints generated when incorporating a capture bound