checkers.flow
Class MainFlow

java.lang.Object
  extended by com.sun.source.util.TreeScanner<R,P>
      extended by com.sun.source.util.TreePathScanner<java.lang.Void,java.lang.Void>
          extended by checkers.flow.MainFlow
All Implemented Interfaces:
com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
Direct Known Subclasses:
TypestateFlow

public class MainFlow
extends com.sun.source.util.TreePathScanner<java.lang.Void,java.lang.Void>

A modified version of Flow. Should report errors during the flow analysis, as no information is recorded for later retrieval. Also, subtyping isn't checked in any way. Detailed changes: - removed the QualifierHierarchy annoRelations field and all its usages - removed the AnnotationMirror test(Tree tree) method - removed the Map<Location, AnnotationMirror> flowResults field and all its usages - removed the void recordBits(TreePath path) method and all its usages

Author:
Adam Warski (adam at warski dot org), The authors of the Flow class.

Field Summary
protected  checkers.flow.GenKillBits<javax.lang.model.element.AnnotationMirror> annos
          Tracks the annotated state of each variable during flow.
protected  checkers.flow.GenKillBits<javax.lang.model.element.AnnotationMirror> annosWhenFalse
          Tracks the annotated state of each variable in a false branch.
protected  checkers.flow.GenKillBits<javax.lang.model.element.AnnotationMirror> annosWhenTrue
          Tracks the annotated state of each variable in a true branch.
protected  java.util.Set<javax.lang.model.element.AnnotationMirror> annotations
          The annotations (qualifiers) to infer.
protected  checkers.types.AnnotatedTypes atypes
          Utility class for operations on annotated types.
protected  java.util.Deque<checkers.flow.GenKillBits<javax.lang.model.element.AnnotationMirror>> catchBits
          Tracks annotations in potential exception-throwing statements in catch blocks.
protected  checkers.source.SourceChecker checker
          The checker to which this instance belongs.
protected  javax.lang.model.util.Elements elements
          Utilities for Elements.
protected  javax.annotation.processing.ProcessingEnvironment env
          The processing environment to use.
protected  checkers.types.AnnotatedTypeFactory factory
          Utility class for determining annotated types.
protected  com.sun.source.tree.CompilationUnitTree root
          The file that's being analyzed.
protected  com.sun.source.util.SourcePositions source
          Utility class for getting source positions.
protected  java.util.Deque<checkers.flow.GenKillBits<javax.lang.model.element.AnnotationMirror>> tryBits
          Tracks annotations in potential exception-throwing statements in try blocks.
protected  java.util.List<javax.lang.model.element.VariableElement> vars
          Maps variables to a bit index.
 
Constructor Summary
MainFlow(checkers.source.SourceChecker checker, com.sun.source.tree.CompilationUnitTree root, java.util.Set<javax.lang.model.element.AnnotationMirror> annotations, checkers.types.AnnotatedTypeFactory factory)
          Creates a new analysis.
 
Method Summary
 java.lang.Void scan(com.sun.source.tree.Tree tree, java.lang.Void p)
           
protected  void scanCond(com.sun.source.tree.Tree tree)
          Called whenever a conditional expression is scanned.
protected  void scanDef(com.sun.source.tree.Tree tree)
          Called whenever a definition is scanned.
protected  void scanExpr(com.sun.source.tree.ExpressionTree tree)
          Called whenever an expression is scanned.
protected  void scanStat(com.sun.source.tree.StatementTree tree)
          Called whenever a statement is scanned.
protected  void scanStats(java.util.List<? extends com.sun.source.tree.StatementTree> trees)
          Called whenever a block of statements is scanned.
protected  void updateExceptionBits()
           
protected  void updateExceptionBits(checkers.flow.GenKillBits<javax.lang.model.element.AnnotationMirror> exceptionBits)
          Updates the current try and catch bits on an exception-throwing statement.
 java.lang.Void visitAnnotation(com.sun.source.tree.AnnotationTree tree, java.lang.Void p)
           
 java.lang.Void visitAssert(com.sun.source.tree.AssertTree node, java.lang.Void p)
           
 java.lang.Void visitAssignment(com.sun.source.tree.AssignmentTree node, java.lang.Void p)
           
 java.lang.Void visitBlock(com.sun.source.tree.BlockTree node, java.lang.Void p)
           
 java.lang.Void visitBreak(com.sun.source.tree.BreakTree node, java.lang.Void p)
           
 java.lang.Void visitClass(com.sun.source.tree.ClassTree node, java.lang.Void p)
           
 java.lang.Void visitCompoundAssignment(com.sun.source.tree.CompoundAssignmentTree node, java.lang.Void p)
           
 java.lang.Void visitConditionalExpression(com.sun.source.tree.ConditionalExpressionTree node, java.lang.Void p)
           
 java.lang.Void visitContinue(com.sun.source.tree.ContinueTree node, java.lang.Void p)
           
 java.lang.Void visitDoWhileLoop(com.sun.source.tree.DoWhileLoopTree node, java.lang.Void p)
           
 java.lang.Void visitEnhancedForLoop(com.sun.source.tree.EnhancedForLoopTree node, java.lang.Void p)
           
 java.lang.Void visitForLoop(com.sun.source.tree.ForLoopTree node, java.lang.Void p)
           
 java.lang.Void visitIf(com.sun.source.tree.IfTree node, java.lang.Void p)
           
 java.lang.Void visitImport(com.sun.source.tree.ImportTree tree, java.lang.Void p)
           
 java.lang.Void visitMethod(com.sun.source.tree.MethodTree node, java.lang.Void p)
           
 java.lang.Void visitMethodInvocation(com.sun.source.tree.MethodInvocationTree node, java.lang.Void p)
           
 java.lang.Void visitReturn(com.sun.source.tree.ReturnTree node, java.lang.Void p)
           
 java.lang.Void visitThrow(com.sun.source.tree.ThrowTree node, java.lang.Void p)
           
 java.lang.Void visitTry(com.sun.source.tree.TryTree node, java.lang.Void p)
           
 java.lang.Void visitVariable(com.sun.source.tree.VariableTree node, java.lang.Void p)
           
 java.lang.Void visitWhileLoop(com.sun.source.tree.WhileLoopTree node, java.lang.Void p)
           
 
Methods inherited from class com.sun.source.util.TreePathScanner
getCurrentPath, scan
 
Methods inherited from class com.sun.source.util.TreeScanner
reduce, scan, visitAnnotatedType, visitArrayAccess, visitArrayType, visitBinary, visitCase, visitCatch, visitCompilationUnit, visitEmptyStatement, visitErroneous, visitExpressionStatement, visitIdentifier, visitInstanceOf, visitLabeledStatement, visitLiteral, visitMemberSelect, visitModifiers, visitNewArray, visitNewClass, visitOther, visitParameterizedType, visitParenthesized, visitPrimitiveType, visitSwitch, visitSynchronized, visitTypeCast, visitTypeParameter, visitUnary, visitWildcard
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

checker

protected final checkers.source.SourceChecker checker
The checker to which this instance belongs.


env

protected final javax.annotation.processing.ProcessingEnvironment env
The processing environment to use.


root

protected final com.sun.source.tree.CompilationUnitTree root
The file that's being analyzed.


annotations

protected final java.util.Set<javax.lang.model.element.AnnotationMirror> annotations
The annotations (qualifiers) to infer.


source

protected final com.sun.source.util.SourcePositions source
Utility class for getting source positions.


factory

protected final checkers.types.AnnotatedTypeFactory factory
Utility class for determining annotated types.


atypes

protected final checkers.types.AnnotatedTypes atypes
Utility class for operations on annotated types.


vars

protected final java.util.List<javax.lang.model.element.VariableElement> vars
Maps variables to a bit index. This index is also used as the bit index to determine a variable's annotatedness using annos/annosWhenTrue/annosWhenFalse.


annos

protected checkers.flow.GenKillBits<javax.lang.model.element.AnnotationMirror> annos
Tracks the annotated state of each variable during flow. Bit indices correspond exactly to indices in vars. This field is set to null immediately after splitting for a branch, and is set to some combination (usually boolean "and") of annosWhenTrue and annosWhenFalse after merging. Since it is used when visiting the true and false branches, however, it may be non-null concurrently with annosWhenTrue and annosWhenFalse.


annosWhenTrue

protected checkers.flow.GenKillBits<javax.lang.model.element.AnnotationMirror> annosWhenTrue
Tracks the annotated state of each variable in a true branch. As in javac's Flow, saving/restoring via local variables handles nested branches. Bit indices correspond exactly to indices in vars. This field is copied from annos when splitting for a branch and is set to null immediately after merging.

See Also:
annos

annosWhenFalse

protected checkers.flow.GenKillBits<javax.lang.model.element.AnnotationMirror> annosWhenFalse
Tracks the annotated state of each variable in a false branch. As in javac's Flow, saving/restoring via local variables handles nested branches. Bit indices correspond exactly to indices in vars. This field is copied from annos when splitting for a branch and is set to null immediately after merging.

See Also:
annos

tryBits

protected final java.util.Deque<checkers.flow.GenKillBits<javax.lang.model.element.AnnotationMirror>> tryBits
Tracks annotations in potential exception-throwing statements in try blocks.


catchBits

protected final java.util.Deque<checkers.flow.GenKillBits<javax.lang.model.element.AnnotationMirror>> catchBits
Tracks annotations in potential exception-throwing statements in catch blocks.


elements

protected final javax.lang.model.util.Elements elements
Utilities for Elements.

Constructor Detail

MainFlow

public MainFlow(checkers.source.SourceChecker checker,
                com.sun.source.tree.CompilationUnitTree root,
                java.util.Set<javax.lang.model.element.AnnotationMirror> annotations,
                checkers.types.AnnotatedTypeFactory factory)
Creates a new analysis. The analysis will use the given AnnotatedTypeFactory to obtain annotated types.

Parameters:
checker - the current checker
root - the compilation unit that will be scanned
annotations - the annotations to track
factory - the factory class that will be used to get annotated types, or null if the default factory should be used
Method Detail

scan

public java.lang.Void scan(com.sun.source.tree.Tree tree,
                           java.lang.Void p)
Overrides:
scan in class com.sun.source.util.TreePathScanner<java.lang.Void,java.lang.Void>

scanDef

protected void scanDef(com.sun.source.tree.Tree tree)
Called whenever a definition is scanned.

Parameters:
tree - the definition being scanned

scanStat

protected void scanStat(com.sun.source.tree.StatementTree tree)
Called whenever a statement is scanned.

Parameters:
tree - the statement being scanned

scanStats

protected void scanStats(java.util.List<? extends com.sun.source.tree.StatementTree> trees)
Called whenever a block of statements is scanned.

Parameters:
trees - the statements being scanned

scanCond

protected void scanCond(com.sun.source.tree.Tree tree)
Called whenever a conditional expression is scanned.

Parameters:
tree - the condition being scanned

scanExpr

protected void scanExpr(com.sun.source.tree.ExpressionTree tree)
Called whenever an expression is scanned.

Parameters:
tree - the expression being scanned

visitClass

public java.lang.Void visitClass(com.sun.source.tree.ClassTree node,
                                 java.lang.Void p)
Specified by:
visitClass in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
Overrides:
visitClass in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>

visitImport

public java.lang.Void visitImport(com.sun.source.tree.ImportTree tree,
                                  java.lang.Void p)
Specified by:
visitImport in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
Overrides:
visitImport in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>

visitAnnotation

public java.lang.Void visitAnnotation(com.sun.source.tree.AnnotationTree tree,
                                      java.lang.Void p)
Specified by:
visitAnnotation in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
Overrides:
visitAnnotation in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>

visitVariable

public java.lang.Void visitVariable(com.sun.source.tree.VariableTree node,
                                    java.lang.Void p)
Specified by:
visitVariable in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
Overrides:
visitVariable in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>

visitAssignment

public java.lang.Void visitAssignment(com.sun.source.tree.AssignmentTree node,
                                      java.lang.Void p)
Specified by:
visitAssignment in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
Overrides:
visitAssignment in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>

visitCompoundAssignment

public java.lang.Void visitCompoundAssignment(com.sun.source.tree.CompoundAssignmentTree node,
                                              java.lang.Void p)
Specified by:
visitCompoundAssignment in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
Overrides:
visitCompoundAssignment in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>

visitEnhancedForLoop

public java.lang.Void visitEnhancedForLoop(com.sun.source.tree.EnhancedForLoopTree node,
                                           java.lang.Void p)
Specified by:
visitEnhancedForLoop in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
Overrides:
visitEnhancedForLoop in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>

visitAssert

public java.lang.Void visitAssert(com.sun.source.tree.AssertTree node,
                                  java.lang.Void p)
Specified by:
visitAssert in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
Overrides:
visitAssert in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>

visitIf

public java.lang.Void visitIf(com.sun.source.tree.IfTree node,
                              java.lang.Void p)
Specified by:
visitIf in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
Overrides:
visitIf in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>

visitConditionalExpression

public java.lang.Void visitConditionalExpression(com.sun.source.tree.ConditionalExpressionTree node,
                                                 java.lang.Void p)
Specified by:
visitConditionalExpression in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
Overrides:
visitConditionalExpression in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>

visitWhileLoop

public java.lang.Void visitWhileLoop(com.sun.source.tree.WhileLoopTree node,
                                     java.lang.Void p)
Specified by:
visitWhileLoop in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
Overrides:
visitWhileLoop in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>

visitDoWhileLoop

public java.lang.Void visitDoWhileLoop(com.sun.source.tree.DoWhileLoopTree node,
                                       java.lang.Void p)
Specified by:
visitDoWhileLoop in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
Overrides:
visitDoWhileLoop in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>

visitForLoop

public java.lang.Void visitForLoop(com.sun.source.tree.ForLoopTree node,
                                   java.lang.Void p)
Specified by:
visitForLoop in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
Overrides:
visitForLoop in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>

visitBreak

public java.lang.Void visitBreak(com.sun.source.tree.BreakTree node,
                                 java.lang.Void p)
Specified by:
visitBreak in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
Overrides:
visitBreak in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>

visitContinue

public java.lang.Void visitContinue(com.sun.source.tree.ContinueTree node,
                                    java.lang.Void p)
Specified by:
visitContinue in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
Overrides:
visitContinue in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>

visitReturn

public java.lang.Void visitReturn(com.sun.source.tree.ReturnTree node,
                                  java.lang.Void p)
Specified by:
visitReturn in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
Overrides:
visitReturn in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>

visitThrow

public java.lang.Void visitThrow(com.sun.source.tree.ThrowTree node,
                                 java.lang.Void p)
Specified by:
visitThrow in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
Overrides:
visitThrow in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>

visitTry

public java.lang.Void visitTry(com.sun.source.tree.TryTree node,
                               java.lang.Void p)
Specified by:
visitTry in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
Overrides:
visitTry in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>

updateExceptionBits

protected void updateExceptionBits(checkers.flow.GenKillBits<javax.lang.model.element.AnnotationMirror> exceptionBits)
Updates the current try and catch bits on an exception-throwing statement.

Parameters:
exceptionBits - The annotations on the statement, in case an exception is thrown.

updateExceptionBits

protected void updateExceptionBits()

visitMethodInvocation

public java.lang.Void visitMethodInvocation(com.sun.source.tree.MethodInvocationTree node,
                                            java.lang.Void p)
Specified by:
visitMethodInvocation in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
Overrides:
visitMethodInvocation in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>

visitBlock

public java.lang.Void visitBlock(com.sun.source.tree.BlockTree node,
                                 java.lang.Void p)
Specified by:
visitBlock in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
Overrides:
visitBlock in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>

visitMethod

public java.lang.Void visitMethod(com.sun.source.tree.MethodTree node,
                                  java.lang.Void p)
Specified by:
visitMethod in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
Overrides:
visitMethod in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>