java.lang.Object
com.sun.source.util.SimpleTreeVisitor<Void,AnnotatedTypeMirror>
org.checkerframework.framework.type.treeannotator.TreeAnnotator
All Implemented Interfaces:
TreeVisitor<Void,AnnotatedTypeMirror>
Direct Known Subclasses:
AccumulationAnnotatedTypeFactory.AccumulationTreeAnnotator, AliasingAnnotatedTypeFactory.AliasingTreeAnnotator, ClassValAnnotatedTypeFactory.ClassValTreeAnnotator, DependentTypesTreeAnnotator, InitializationAnnotatedTypeFactory.CommitmentTreeAnnotator, KeyForPropagationTreeAnnotator, ListTreeAnnotator, LiteralTreeAnnotator, LockTreeAnnotator, MethodValAnnotatedTypeFactory.MethodValTreeAnnotator, NullnessAnnotatedTypeFactory.NullnessTreeAnnotator, PropagationTreeAnnotator, PropertyKeyAnnotatedTypeFactory.KeyLookupTreeAnnotator, SameLenAnnotatedTypeFactory.SameLenTreeAnnotator, UpperBoundAnnotatedTypeFactory.UpperBoundTreeAnnotator

public abstract class TreeAnnotator extends SimpleTreeVisitor<Void,AnnotatedTypeMirror>
TreeAnnotator is an abstract SimpleTreeVisitor to be used with ListTreeAnnotator.

A TreeAnnotator is mainly intended to change the type of an expression. If a TreeAnnotator changes the type of a variable declaration, that change will not generally be seen at uses of the variable, because uses of a variable tend to obtain the variable's type from an Element (which always exists) rather than from a Tree (which might or might not be available at the time of the variable's use).

This class does not visit component parts of the tree. By default, the visit methods all call SimpleTreeVisitor.defaultAction(Tree, Object), which does nothing unless overridden. Therefore, subclass implementations of methods do not need to call super() unless they override SimpleTreeVisitor.defaultAction(Tree, Object).

See Also:
  • Field Details

  • Constructor Details

    • TreeAnnotator

      protected TreeAnnotator(AnnotatedTypeFactory atypeFactory)
      Create a new TreeAnnotator.
      Parameters:
      atypeFactory - the type factory
  • Method Details

    • log

      @FormatMethod protected void log(String format, Object... args)
      Output a message, if logging is on.
      Parameters:
      format - a format string
      args - arguments to the format string
    • visitMethod

      public Void visitMethod(MethodTree tree, AnnotatedTypeMirror p)
      This method is not called when checking a method invocation against its declaration. So, instead of overriding this method, override TypeAnnotator.visitExecutable. TypeAnnotator.visitExecutable is called both when checking method declarations and method invocations.
      Specified by:
      visitMethod in interface TreeVisitor<Void,AnnotatedTypeMirror>
      Overrides:
      visitMethod in class SimpleTreeVisitor<Void,AnnotatedTypeMirror>
      See Also:
    • visitBinary

      public Void visitBinary(BinaryTree tree, AnnotatedTypeMirror mirror)
      When overriding this method, getAnnotatedType on the left and right operands should only be called when absolutely necessary. Otherwise, the checker will be very slow on heavily nested binary trees. (For example, a + b + c + d + e + f + g + h.)

      If a checker's performance is still too slow, the types of binary trees could be computed in a subclass of CFTransfer. When computing the types in a transfer, look up the value in the store rather than the AnnotatedTypeFactory. Then this method should annotate binary trees with top so that the type applied in the transfer is always a subtype of the type the AnnotatedTypeFactory computes.

      Specified by:
      visitBinary in interface TreeVisitor<Void,AnnotatedTypeMirror>
      Overrides:
      visitBinary in class SimpleTreeVisitor<Void,AnnotatedTypeMirror>