Class FormatterVisitor

All Implemented Interfaces:
TreeVisitor<Void,Void>

public class FormatterVisitor extends BaseTypeVisitor<FormatterAnnotatedTypeFactory>
Whenever a format method invocation is found in the syntax tree, checks are performed as specified in the Format String Checker manual.
See the Checker Framework Manual:
Format String Checker
  • Constructor Details

  • Method Details

    • processMethodTree

      public void processMethodTree(String className, MethodTree tree)
      Description copied from class: BaseTypeVisitor
      Type-check methodTree. Subclasses should override this method instead of BaseTypeVisitor.visitMethod(MethodTree, Void).
      Overrides:
      processMethodTree in class BaseTypeVisitor<FormatterAnnotatedTypeFactory>
      Parameters:
      className - the class that contains the method, for diagnostics only
      tree - the method to type-check
    • visitMethodInvocation

      public Void visitMethodInvocation(MethodInvocationTree tree, Void p)
      Description copied from class: BaseTypeVisitor
      Performs a method invocation check.

      An invocation of a method, m, on the receiver, r is valid only if:

      • passed arguments are subtypes of corresponding m parameters
      • r is a subtype of m receiver type
      • if m is generic, passed type arguments are subtypes of m type variables
      Specified by:
      visitMethodInvocation in interface TreeVisitor<Void,Void>
      Overrides:
      visitMethodInvocation in class BaseTypeVisitor<FormatterAnnotatedTypeFactory>
    • formatStringIndex

      public static int formatStringIndex(ExecutableElement m)
      Returns the index of the format string of a method: the first formal parameter with declared type String.
      Parameters:
      m - a method
      Returns:
      the index of the last String formal parameter, or -1 if none
    • commonAssignmentCheck

      protected boolean commonAssignmentCheck(AnnotatedTypeMirror varType, AnnotatedTypeMirror valueType, Tree errorLocation, @CompilerMessageKey String errorKey, Object... extraArgs)
      Description copied from class: BaseTypeVisitor
      Checks the validity of an assignment (or pseudo-assignment) from valueType to variableType and emits an error message (through the compiler's messaging interface) if it is not valid.

      Subclasses should override this method unless the tree for the varType or valueType are needed.

      Overrides:
      commonAssignmentCheck in class BaseTypeVisitor<FormatterAnnotatedTypeFactory>
      Parameters:
      varType - the annotated type of the variable
      valueType - the annotated type of the value
      errorLocation - the location to use when reporting the error message; this is NOT the tree for valueType in all cases
      errorKey - the error message key to use if the check fails
      extraArgs - arguments to the error message key, before "found" and "expected" types
      Returns:
      true if the check succeeds, false if an error message was issued