Class FormatterVisitor

  • All Implemented Interfaces:
    com.sun.source.tree.TreeVisitor<java.lang.Void,​java.lang.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 Detail

    • Method Detail

      • visitMethod

        public java.lang.Void visitMethod​(com.sun.source.tree.MethodTree tree,
                                          java.lang.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 com.sun.source.tree.TreeVisitor<java.lang.Void,​java.lang.Void>
        Overrides:
        visitMethod in class BaseTypeVisitor<FormatterAnnotatedTypeFactory>
      • visitMethodInvocation

        public java.lang.Void visitMethodInvocation​(com.sun.source.tree.MethodInvocationTree tree,
                                                    java.lang.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 com.sun.source.tree.TreeVisitor<java.lang.Void,​java.lang.Void>
        Overrides:
        visitMethodInvocation in class BaseTypeVisitor<FormatterAnnotatedTypeFactory>
      • formatStringIndex

        public static int formatStringIndex​(javax.lang.model.element.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,
                                                com.sun.source.tree.Tree valueTree,
                                                @CompilerMessageKey java.lang.String errorKey,
                                                java.lang.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
        Returns:
        true if the check succeeds, false if an error message was issued