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 Collection<Variable> getInferenceVariables()
      Returns a collection of all inference variables mentioned by this constraint.
      Returns:
      a collection of all inference variables mentioned by this constraint
    • getInputVariables

      public abstract List<Variable> getInputVariables()
      For lambda and method references constraints, input variables are roughly the inference variables mentioned by they function type's parameter types and return types. For conditional expression constraints and switch expression constraints, input variables are the union of the input variables of its subexpressions. For all other constraints, no input variables exist.

      Defined in JLS section 18.5.2.2

      Returns:
      input variables for this constraint
    • getOutputVariables

      public abstract List<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

      Returns:
      output variables for this constraint
    • getInputVariablesForExpression

      protected List<Variable> getInputVariablesForExpression(ExpressionTree tree, AbstractType T)
      Implementation of 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