java.lang.Object
org.checkerframework.framework.util.typeinference8.util.Theta

public class Theta extends Object
A mapping from type variables to inference variables.

Two type variables are the same key if TypesUtils.areSame(TypeVariable, TypeVariable) returns true for them; they need not be the same object. (Two objects for the same type variable arise when a type has undergone type variable substitution, or when the type variable is the type of a tree created by TreeBuilder.) That is why this class is not a Map: a Map would compare keys using TypeVariable.equals, which javac's Type.TypeVar does not override and which is therefore reference equality.

Iteration order is insertion order, as for LinkedHashMap.

  • Constructor Details

    • Theta

      public Theta()
      Creates Theta.
  • Method Details

    • put

      public @Nullable Variable put(TypeVariable typeVariable, Variable variable)
      Maps typeVariable to variable. If some type variable that is TypesUtils.areSame(TypeVariable, TypeVariable) as typeVariable is already mapped, then its inference variable is replaced, but getTypeVariables() continues to return the type variable that was passed to the earlier call. That distinction does not matter to clients, which compare type variables using areSame.

      Callers that iterate over values() in lockstep with the type variables they passed to this method, such as CaptureBound, depend on each call adding an entry rather than replacing one. That holds because the type variables of a single declaration have distinct simple names and the same enclosing element, so no two of them are areSame.

      Parameters:
      typeVariable - a type variable
      variable - the inference variable for typeVariable
      Returns:
      the inference variable that typeVariable was previously mapped to, or null if it was not mapped
    • get

      public @Nullable Variable get(TypeMirror type)
      Returns the inference variable for type, or null if there is none. type need not be the same object as the type variable that was passed to put(javax.lang.model.type.TypeVariable, org.checkerframework.framework.util.typeinference8.types.Variable); it is enough that the two are TypesUtils.areSame(TypeVariable, TypeVariable).
      Parameters:
      type - a type; if it is not a type variable, then this method returns null
      Returns:
      the inference variable for type, or null if there is none
    • containsValue

      public boolean containsValue(Variable variable)
      Returns true if variable is the inference variable for some type variable.
      Parameters:
      variable - an inference variable
      Returns:
      true if variable is the inference variable for some type variable
    • values

      public Collection<Variable> values()
      Returns the inference variables, in the order in which they were added. The result is unmodifiable.
      Returns:
      the inference variables, in the order in which they were added
    • getTypeVariables

      public Collection<? extends TypeVariable> getTypeVariables()
      Returns the type variables that have an inference variable, in the order in which they were added. The result is unmodifiable.

      The result's contains method uses equals, which for a type variable is reference equality. A client that wants this class's notion of key equality must compare the elements using TypesUtils.areSame(TypeVariable, TypeVariable) itself, or call get(javax.lang.model.type.TypeMirror).

      Returns:
      the type variables that have an inference variable
    • getNotInstantiated

      public Collection<? extends TypeVariable> getNotInstantiated()
      Returns the type variables that do not yet have a value, in the order in which they were added. Unlike getTypeVariables(), the result is not cached, because a type variable acquires a value without any call to put(javax.lang.model.type.TypeVariable, org.checkerframework.framework.util.typeinference8.types.Variable).
      Returns:
      the type variables that do not yet have a value
    • toString

      public String toString()
      Overrides:
      toString in class Object