Interface TypeArgumentInference

All Known Implementing Classes:
DefaultTypeArgumentInference

public interface TypeArgumentInference
Instances of TypeArgumentInference are used to infer the types of method type arguments when no explicit arguments are provided.

e.g. If we have a method declaration:


 <A,B> B method(A a, B b) {...}
 
And an invocation of that method:

 method("some Str", 35);
 
TypeArgumentInference will determine what the type arguments to type parameters A and B are. In Java, if T(A) = the type argument for a, in the above example T(A) == String and T(B) == Integer

For the Checker Framework we also need to infer reasonable annotations for these type arguments. For information on inferring type arguments see JLS chapter 18: https://docs.oracle.com/javase/specs/jls/se25/html/jls-18.html

  • Method Details

    • inferTypeArgs

      InferenceResult inferTypeArgs(AnnotatedTypeFactory typeFactory, ExpressionTree invocation, AnnotatedTypeMirror.AnnotatedExecutableType executableType)
      Infer the type arguments for the method or constructor invocation given by invocation.
      Parameters:
      typeFactory - the type factory used to create executableType
      invocation - a tree representing the method or constructor invocation for which we are inferring type arguments
      executableType - the declaration type of the invoked method
      Returns:
      the result which includes the inferred type arguments or an error message if they were not inferred
    • getLambdaParameterType

      default @Nullable AnnotatedTypeMirror getLambdaParameterType(VariableElement param)
      If param is an implicitly typed lambda parameter whose type an in-progress inference has already determined, returns that type. Otherwise, returns null.

      If an already completed inference, determined the type of the lambda parameter, null is returned.

      Parameters:
      param - an element that might be an implicitly typed lambda parameter
      Returns:
      the type of param as computed by an in-progress inference, or null