Class UpperBoundVisitor

All Implemented Interfaces:
TreeVisitor<Void,Void>

public class UpperBoundVisitor extends BaseTypeVisitor<UpperBoundAnnotatedTypeFactory>
Warns about array accesses that could be too high.
  • Constructor Details

  • Method Details

    • visitArrayAccess

      public Void visitArrayAccess(ArrayAccessTree tree, Void type)
      When the visitor reaches an array access, it needs to check a couple of things. First, it checks if the index has been assigned a reasonable UpperBound type: only an index with type LTLengthOf(arr) is safe to access arr. If that fails, it checks if the access is still safe. To do so, it checks if the Value Checker knows the minimum length of arr by querying the Value Annotated Type Factory. If the minimum length of the array is known, the visitor can check if the index is less than that minimum length. If so, then the access is still safe. Otherwise, report a potential unsafe access.
      Specified by:
      visitArrayAccess in interface TreeVisitor<Void,Void>
      Overrides:
      visitArrayAccess in class TreeScanner<Void,Void>
    • visitAnnotation

      public Void visitAnnotation(AnnotationTree tree, Void p)
      Warns about LTLengthOf annotations with arguments whose lengths do not match.
      Specified by:
      visitAnnotation in interface TreeVisitor<Void,Void>
      Overrides:
      visitAnnotation in class BaseTypeVisitor<UpperBoundAnnotatedTypeFactory>
    • commonAssignmentCheck

      protected boolean commonAssignmentCheck(Tree varTree, ExpressionTree 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<UpperBoundAnnotatedTypeFactory>
      Parameters:
      varTree - the AST node for the lvalue (usually a variable)
      valueTree - the AST node for the rvalue (the new value)
      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
    • commonAssignmentCheck

      protected boolean commonAssignmentCheck(AnnotatedTypeMirror varType, ExpressionTree 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<UpperBoundAnnotatedTypeFactory>
      Parameters:
      varType - the annotated type for the lvalue (usually a variable)
      valueTree - the AST node for the rvalue (the new value)
      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