Class Java8InferenceContext

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

public class Java8InferenceContext extends Object
An object to pass around for use during invocation type inference. One context is created per top-level invocation expression.
  • Field Details

    • env

      public final ProcessingEnvironment env
      javax.annotation.processing.ProcessingEnvironment
    • object

      public final ProperType object
      ProperType for java.lang.Object.
    • inference

      public final InvocationTypeInference inference
      Invocation type inference object.
    • types

      public final com.sun.tools.javac.code.Types types
      com.sun.tools.javac.code.Types
    • modelTypes

      public final Types modelTypes
      javax.lang.model.util.Types
    • enclosingType

      public final DeclaredType enclosingType
      The type of class that encloses the top level expression whose type arguments are inferred.
    • maps

      public final Map<ExpressionTree,Theta> maps
      Store previously created type variable to inference variable maps as a map from invocation expression to Theta.
    • error

      public final TypeMirror error
      TypeMirror for java.lang.Error.
    • runtimeException

      public final TypeMirror runtimeException
      TypeMirror for java.lang.RuntimeException.
    • inferenceTypeFactory

      public final InferenceFactory inferenceTypeFactory
      The inference factory.
    • typeFactory

      public final AnnotatedTypeFactory typeFactory
      The annotated type factory.
    • lambdaParamTargets

      Maps each implicitly typed lambda parameter encountered by this inference problem to the information needed to compute its type.
      See Also:
  • Constructor Details

    • Java8InferenceContext

      public Java8InferenceContext(AnnotatedTypeFactory factory, TreePath pathToExpression, InvocationTypeInference inference)
      Creates a context.
      Parameters:
      factory - type factory
      pathToExpression - path to the expression whose type arguments are inferred
      inference - inference object
  • Method Details

    • inferenceProblemHashCode

      public int inferenceProblemHashCode(boolean ignoreAnnotations)
      Returns a hash code for the fields that AbstractType.sameInferenceProblem(org.checkerframework.framework.util.typeinference8.types.AbstractType) compares. Those fields are final, so an AbstractType of this inference problem has one of only two values: this is computed once per context rather than once per AbstractType.
      Parameters:
      ignoreAnnotations - the value of AbstractType.ignoreAnnotations
      Returns:
      a hash code for the fields that AbstractType.sameInferenceProblem(org.checkerframework.framework.util.typeinference8.types.AbstractType) compares
    • addLambdaParamTargets

      public void addLambdaParamTargets(List<? extends VariableTree> parameters, AbstractType lambdaTargetType)
      Records where each parameter of an implicitly typed lambda gets its type from.
      Parameters:
      parameters - the formal parameters of an implicitly typed lambda
      lambdaTargetType - the target type of that lambda
    • hasPolymorphicQualifier

      public boolean hasPolymorphicQualifier(AnnotatedTypeMirror type)
      Returns true if type, or any type that it contains, has a polymorphic primary annotation.
      Parameters:
      type - an annotated type
      Returns:
      true if type, or any type that it contains, has a polymorphic primary annotation
    • replacePolymorphicQualifiers

      public Java8InferenceContext.ReplacedTypes replacePolymorphicQualifiers(AnnotatedTypeMirror type1, AnnotatedTypeMirror type2)
      Returns copies of type1 and type2 in which each polymorphic primary annotation has been replaced by the annotation at the same position and in the same qualifier hierarchy in the other type. A comparison of the copies therefore succeeds wherever a polymorphic qualifier is compared -- a polymorphic qualifier could be instantiated to whatever it is compared against -- and is unchanged everywhere else.

      The two types must have the same structure, which holds when their underlying Java types are the same.

      Parameters:
      type1 - a type
      type2 - a type with the same structure as type1
      Returns:
      copies of the two types, in the order the arguments were given
    • getPathToExpression

      public TreePath getPathToExpression()
      Returns the path to the expression whose type arguments are inferred.
      Returns:
      the path to the expression whose type arguments are inferred
    • setPathToExpression

      public void setPathToExpression(TreePath pathToExpression)
      Sets the path to the expression whose type arguments are inferred.

      This method exists because inference for an outer invocation does not always instantiate the type variables of a method reference that appears within one of its arguments. (The method reference need not be the argument itself; it might be nested, as A::m is in foo(flag ? A::m : B::m).) In that case, inference is run a second time, on the method reference itself, in this same context: the variables and maps that the first run created are still needed, but the target type (see InferenceFactory.getTargetType()) must now be computed with respect to the method reference rather than the outer invocation. Calling this method is what makes that happen, so its effect depends on when it is called relative to the two inference runs.

      Parameters:
      pathToExpression - the path to the expression whose type arguments are inferred
    • getNextVariableId

      public int getNextVariableId()
      Returns the next number to use as the id for a non-capture variable. This id is only unique for this inference problem.
      Returns:
      the next number to use as the id for a non-capture variable
    • getNextCaptureVariableId

      public int getNextCaptureVariableId()
      Returns the next number to use as the id for a capture variable. This id is only unique for this inference problem.
      Returns:
      the next number to use as the id for a capture variable
    • getNextQualifierVariableId

      public int getNextQualifierVariableId()
      Returns the next number to use as the id for a qualifier variable. This id is only unique for this inference problem.
      Returns:
      the next number to use as the id for a qualifier variable