java.lang.Object
org.checkerframework.framework.util.typeinference8.constraint.TypeConstraint
All Implemented Interfaces:
Constraint, ReductionResult
Direct Known Subclasses:
CheckedExceptionConstraint, Expression, Typing

public abstract class TypeConstraint extends Object implements Constraint
Constraints are between either an expression and a type, two types, or an expression and a thrown type. Defined in JLS section 18.1.2
  • Field Details

    • T

      protected AbstractType T
      T, the type on the right-hand side of the constraint; may contain inference variables.
    • parent

      public @Nullable Constraint parent
      The constraint whose reduction created this constraint or null if this constraint isn't from a reduction from another. If null, then source should be nonnull.
    • source

      public @Nullable String source
      A string that describes where this constraint is from. If null, then the constraint came from reducing parent.
  • Constructor Details

    • TypeConstraint

      protected TypeConstraint(String source, AbstractType T)
      Creates a type constraint.
      Parameters:
      source - a string describing where this constraint came from
      T - the type of the right-hand side of the constraint
    • TypeConstraint

      protected TypeConstraint(Constraint parent, AbstractType T)
      Creates a type constraint.
      Parameters:
      parent - the constraint whose reduction created this constraint
      T - the type of the right-hand side of the constraint
  • Method Details

    • constraintHistory

      public String constraintHistory()
      Returns a string that explains where this constraint came from.
      Returns:
      a string that explains where this constraint came from
    • getT

      public AbstractType getT()
      Returns T which is the type on the right-hand side of the constraint.
      Returns:
      t, that is the type on the right-hand side of the constraint
    • getInferenceVariables

      public Set<Variable> getInferenceVariables()
      Returns a set of all inference variables mentioned by this constraint.

      The mutability/freshness guarantees are the same as AbstractType.getInferenceVariables().

      Returns:
      a set of all inference variables mentioned by this constraint
    • getOutputVariables

      public abstract Set<Variable> getOutputVariables()
      "The output variables of [expression] constraints are all inference variables mentioned by the type on the right-hand side of the constraint, T, that are not input variables."

      As defined in JLS section 18.5.2.2

      Callers that need to mutate the result should make a defensive copy first.

      Returns:
      output variables for this constraint
    • addAllLazily

      protected static Set<Variable> addAllLazily(Set<Variable> inputs, Set<Variable> toAdd)
      Returns the union of inputs and toAdd without modifying inputs.

      This method avoids allocation when toAdd is empty.

      Parameters:
      inputs - the input set
      toAdd - the set to add
      Returns:
      inputs itself when toAdd is empty; otherwise a new mutable set containing all variables from inputs and toAdd
    • getInputVariablesForExpression

      protected Set<Variable> getInputVariablesForExpression(ExpressionTree tree, AbstractType T)
      Implementation of Constraint.getInputVariables() that is used both by expressions constraints and checked exception constraints https://docs.oracle.com/javase/specs/jls/se8/html/jls-18.html#jls-18.5.2-200
      Parameters:
      tree - an expression tree
      T - the type of the right-hand side of the constraint
      Returns:
      the input variables for this constraint
    • applyInstantiations

      public void applyInstantiations()
      Apply the given instantiations to any type mentioned in this constraint -- meaning replace any mention of a variable in instantiations with its proper type.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object