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

    • visitMethod

      public Void visitMethod(MethodTree tree, Void p)
      Description copied from class: BaseTypeVisitor
      Checks that the method obeys override and subtype rules to all overridden methods. (Uses the pseudo-assignment logic to do so.)

      The override rule specifies that a method, m1, may override a method m2 only if:

      • m1 return type is a subtype of m2
      • m1 receiver type is a supertype of m2
      • m1 parameters are supertypes of corresponding m2 parameters
      Also, it issues a "missing.this" error for static method annotated receivers.
      Specified by:
      visitMethod in interface TreeVisitor<Void,Void>
      Overrides:
      visitMethod in class BaseTypeVisitor<FormatterAnnotatedTypeFactory>
    • 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 void commonAssignmentCheck(AnnotatedTypeMirror varType, AnnotatedTypeMirror valueType, Tree valueTree, @CompilerMessageKey String errorKey, Object... extraArgs)
      Description copied from class: BaseTypeVisitor
      Checks the validity of an assignment (or pseudo-assignment) from a value to a variable and emits an error message (through the compiler's messaging interface) if it is not valid.
      Overrides:
      commonAssignmentCheck in class BaseTypeVisitor<FormatterAnnotatedTypeFactory>
      Parameters:
      varType - the annotated type of the variable
      valueType - the annotated type of the value
      valueTree - the location to use when reporting the error message
      errorKey - the error message key to use if the check fails
      extraArgs - arguments to the error message key, before "found" and "expected" types