java.lang.Object
org.checkerframework.framework.util.typeinference8.constraint.TypeConstraint
All Implemented Interfaces:
Constraint, ReductionResult
Direct Known Subclasses:
CheckedExceptionConstraint, Expression, LambdaBodyConstraint, 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 is the root of a constraint history. If null, then source should be nonnull.
    • source

      public @Nullable String source
      A string that describes where this constraint is from, for a constraint that has no parent. Null if this constraint has a parent.
    • derivation

      public @Nullable String derivation
      A string that describes how parent gave rise to this constraint. Null if parent is null, or if this constraint came from an ordinary reduction of 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 the 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)
      Implementation of getInputVariables() that is used both by expressions constraints and checked exception constraints. See JLS 18.5.2.2.
      Parameters:
      tree - an expression tree; its target type is T, the type of the right-hand side of this constraint
      Returns:
      the input variables for this constraint
    • functionTypeParameterVariables

      protected @Nullable List<Variable> functionTypeParameterVariables()
      Returns the inference variables mentioned by the parameter types of the function type of T, or null if T is not a functional interface type.
      Returns:
      the inference variables mentioned by the parameter types of the function type of T, or null if T is not a functional interface type
    • 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