|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.sun.source.util.TreeScanner<R,P> com.sun.source.util.TreePathScanner<Void,Void> checkers.flow.Flow
public class Flow extends TreePathScanner<Void,Void>
Provides a generalized flow-sensitive qualifier inference for the checkers framework.
This implementation is based largely on javac
's dataflow analysis
module, which may be found in com.sun.tools.javac.comp.Flow
from 13
Sep 2007. It differs from that class in two ways:
javac
's Flow
.
It does not perform exception analysis, and performs liveness analysis only
to the extent required for the GEN-KILL analysis.
BitSet
, the Compiler Tree API) over those in
com.sun.tools.javac
(for these reasons, examining a diff against that
class would not be particularly enlightening).
javac
's Flow
class, methods named "visit*" perform
analysis for a particular type of tree node, while methods named "scan*"
perform the analysis for a general, higher-level class of structural element.
Typically "visit*" methods delegate to "scan*" methods. As an example,
visitIf(com.sun.source.tree.IfTree, java.lang.Void)
, visitWhileLoop(com.sun.source.tree.WhileLoopTree, java.lang.Void)
, visitAssert(com.sun.source.tree.AssertTree, java.lang.Void)
, and
visitConditionalExpression(com.sun.source.tree.ConditionalExpressionTree, java.lang.Void)
all use scanCond(com.sun.source.tree.Tree)
for analyzing
conditions and handling branching.
A separate instance of the analysis must be created for each compilation unit.
Modifier and Type | Class and Description |
---|---|
static class |
Flow.SplitTuple
Tracks the annotated state of each variable in a false branch. |
Modifier and Type | Field and Description |
---|---|
protected boolean |
alive
Stores the result of liveness analysis, required by the GEN-KILL analysis for proper handling of jumps (break, return, throw, etc.). |
protected QualifierHierarchy |
annoRelations
The hierarchy for the type qualifiers that this class infers. |
protected GenKillBits<AnnotationMirror> |
annos
Tracks the annotated state of each variable during flow. |
protected Set<AnnotationMirror> |
annotations
The annotations (qualifiers) to infer. |
protected AnnotatedTypes |
atypes
Utility class for operations on annotated types. |
protected SourceChecker |
checker
The checker to which this instance belongs. |
protected PrintStream |
debug
Where to print debugging messages; set via setDebug(java.io.PrintStream) . |
protected Elements |
elements
Utilities for Element s. |
protected ProcessingEnvironment |
env
The processing environment to use. |
protected AnnotatedTypeFactory |
factory
Utility class for determining annotated types. |
protected Map<Tree,AnnotationMirror> |
flowResults
Stores the results of the analysis (source location to qualifier). |
protected CompilationUnitTree |
root
The file that's being analyzed. |
protected List<VariableElement> |
vars
Maps variables to a bit index. |
Constructor and Description |
---|
Flow(BaseTypeChecker checker,
CompilationUnitTree root,
Set<AnnotationMirror> annotations,
AnnotatedTypeFactory factory)
Creates a new analysis. |
Modifier and Type | Method and Description |
---|---|
protected static boolean |
containsKey(Tree tree,
Collection<String> keys)
|
protected void |
popLastLevel()
|
protected void |
pushNewLevel()
|
protected void |
recordBits(TreePath path)
Record the value of the annotation bit for the given usage of a variable, so that a type-checker may use its value after the analysis has finished. |
Void |
scan(Tree tree,
Void p)
|
protected Flow.SplitTuple |
scanCond(Tree tree)
Called whenever a conditional expression is scanned. |
protected void |
scanDef(Tree tree)
Called whenever a definition is scanned. |
protected void |
scanExpr(ExpressionTree tree)
Called whenever an expression is scanned. |
protected void |
scanStat(StatementTree tree)
Called whenever a statement is scanned. |
protected void |
scanStats(List<? extends StatementTree> trees)
Called whenever a block of statements is scanned. |
void |
setDebug(PrintStream debug)
Sets the PrintStream for printing debug messages, such as
System.out or System.err , or null if no debugging output
should be emitted. |
protected Flow.SplitTuple |
split()
Split the bitset before a conditional branch. |
AnnotationMirror |
test(Tree tree)
Determines the inference result for tree. |
Void |
visitAnnotation(AnnotationTree tree,
Void p)
|
Void |
visitAssert(AssertTree node,
Void p)
|
Void |
visitAssignment(AssignmentTree node,
Void p)
|
Void |
visitBlock(BlockTree node,
Void p)
|
Void |
visitBreak(BreakTree node,
Void p)
|
Void |
visitClass(ClassTree node,
Void p)
|
Void |
visitCompoundAssignment(CompoundAssignmentTree node,
Void p)
|
Void |
visitConditionalExpression(ConditionalExpressionTree node,
Void p)
|
Void |
visitContinue(ContinueTree node,
Void p)
|
Void |
visitDoWhileLoop(DoWhileLoopTree node,
Void p)
|
Void |
visitEnhancedForLoop(EnhancedForLoopTree node,
Void p)
|
Void |
visitForLoop(ForLoopTree node,
Void p)
|
Void |
visitIdentifier(IdentifierTree node,
Void p)
|
Void |
visitIf(IfTree node,
Void p)
|
Void |
visitImport(ImportTree tree,
Void p)
|
Void |
visitMemberSelect(MemberSelectTree node,
Void p)
|
Void |
visitMethod(MethodTree node,
Void p)
|
void |
visitMethodEndCallback(MethodTree node)
|
Void |
visitMethodInvocation(MethodInvocationTree node,
Void p)
|
Void |
visitReturn(ReturnTree node,
Void p)
|
Void |
visitThrow(ThrowTree node,
Void p)
|
Void |
visitTry(TryTree node,
Void p)
|
Void |
visitTypeCast(TypeCastTree node,
Void p)
|
Void |
visitVariable(VariableTree node,
Void p)
|
Void |
visitWhileLoop(WhileLoopTree node,
Void p)
|
protected void |
whenConditionFalse(ExpressionTree condition,
Void p)
|
Methods inherited from class com.sun.source.util.TreePathScanner |
---|
getCurrentPath, scan |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected PrintStream debug
setDebug(java.io.PrintStream)
.
protected final SourceChecker checker
protected final ProcessingEnvironment env
protected final CompilationUnitTree root
protected final Set<AnnotationMirror> annotations
BaseTypeChecker.getQualifierHierarchy()
. By
consulting the hierarchy, the analysis will only infer a qualifier on a
type if it is more restrictive (i.e. a subtype) than the existing
qualifier for that type.
protected final AnnotatedTypeFactory factory
protected final AnnotatedTypes atypes
protected final Map<Tree,AnnotationMirror> flowResults
protected List<VariableElement> vars
annos
,
Flow.SplitTuple
protected GenKillBits<AnnotationMirror> annos
vars
. This field is set to
null immediately after splitting for a branch, and is set to some
combination (usually boolean "and") of Flow.SplitTuple
's annosWhenTrue and
annosWhenFalse after merging. Since it is used when visiting the
true and false branches, however, it may be non-null concurrently with
Flow.SplitTuple
's annosWhenTrue and annosWhenFalse.
protected boolean alive
protected final QualifierHierarchy annoRelations
protected final Elements elements
Element
s.
Constructor Detail |
---|
public Flow(BaseTypeChecker checker, CompilationUnitTree root, Set<AnnotationMirror> annotations, AnnotatedTypeFactory factory)
AnnotatedTypeFactory
to obtain annotated types.
checker
- the current checkerroot
- the compilation unit that will be scannedannotations
- the annotations to trackfactory
- the factory class that will be used to get annotated
types, or null
if the default factory should be usedMethod Detail |
---|
public void setDebug(PrintStream debug)
PrintStream
for printing debug messages, such as
System.out
or System.err
, or null if no debugging output
should be emitted.
public Void scan(Tree tree, Void p)
scan
in class TreePathScanner<Void,Void>
public AnnotationMirror test(Tree tree)
tree
- the tree to testprotected void recordBits(TreePath path)
path
- protected void scanDef(Tree tree)
tree
- the definition being scannedprotected void scanStat(StatementTree tree)
tree
- the statement being scannedprotected void scanStats(List<? extends StatementTree> trees)
trees
- the statements being scannedprotected Flow.SplitTuple scanCond(Tree tree)
tree
- the condition being scannedprotected Flow.SplitTuple split()
protected void scanExpr(ExpressionTree tree)
tree
- the expression being scannedpublic Void visitClass(ClassTree node, Void p)
visitClass
in interface TreeVisitor<Void,Void>
visitClass
in class TreeScanner<Void,Void>
public Void visitImport(ImportTree tree, Void p)
visitImport
in interface TreeVisitor<Void,Void>
visitImport
in class TreeScanner<Void,Void>
public Void visitTypeCast(TypeCastTree node, Void p)
visitTypeCast
in interface TreeVisitor<Void,Void>
visitTypeCast
in class TreeScanner<Void,Void>
public Void visitAnnotation(AnnotationTree tree, Void p)
visitAnnotation
in interface TreeVisitor<Void,Void>
visitAnnotation
in class TreeScanner<Void,Void>
public Void visitIdentifier(IdentifierTree node, Void p)
visitIdentifier
in interface TreeVisitor<Void,Void>
visitIdentifier
in class TreeScanner<Void,Void>
public Void visitMemberSelect(MemberSelectTree node, Void p)
visitMemberSelect
in interface TreeVisitor<Void,Void>
visitMemberSelect
in class TreeScanner<Void,Void>
public Void visitVariable(VariableTree node, Void p)
visitVariable
in interface TreeVisitor<Void,Void>
visitVariable
in class TreeScanner<Void,Void>
public Void visitAssignment(AssignmentTree node, Void p)
visitAssignment
in interface TreeVisitor<Void,Void>
visitAssignment
in class TreeScanner<Void,Void>
public Void visitCompoundAssignment(CompoundAssignmentTree node, Void p)
visitCompoundAssignment
in interface TreeVisitor<Void,Void>
visitCompoundAssignment
in class TreeScanner<Void,Void>
public Void visitEnhancedForLoop(EnhancedForLoopTree node, Void p)
visitEnhancedForLoop
in interface TreeVisitor<Void,Void>
visitEnhancedForLoop
in class TreeScanner<Void,Void>
protected static boolean containsKey(Tree tree, Collection<String> keys)
protected void pushNewLevel()
protected void popLastLevel()
public Void visitAssert(AssertTree node, Void p)
visitAssert
in interface TreeVisitor<Void,Void>
visitAssert
in class TreeScanner<Void,Void>
protected void whenConditionFalse(ExpressionTree condition, Void p)
public Void visitIf(IfTree node, Void p)
visitIf
in interface TreeVisitor<Void,Void>
visitIf
in class TreeScanner<Void,Void>
public Void visitConditionalExpression(ConditionalExpressionTree node, Void p)
visitConditionalExpression
in interface TreeVisitor<Void,Void>
visitConditionalExpression
in class TreeScanner<Void,Void>
public Void visitWhileLoop(WhileLoopTree node, Void p)
visitWhileLoop
in interface TreeVisitor<Void,Void>
visitWhileLoop
in class TreeScanner<Void,Void>
public Void visitDoWhileLoop(DoWhileLoopTree node, Void p)
visitDoWhileLoop
in interface TreeVisitor<Void,Void>
visitDoWhileLoop
in class TreeScanner<Void,Void>
public Void visitForLoop(ForLoopTree node, Void p)
visitForLoop
in interface TreeVisitor<Void,Void>
visitForLoop
in class TreeScanner<Void,Void>
public Void visitBreak(BreakTree node, Void p)
visitBreak
in interface TreeVisitor<Void,Void>
visitBreak
in class TreeScanner<Void,Void>
public Void visitContinue(ContinueTree node, Void p)
visitContinue
in interface TreeVisitor<Void,Void>
visitContinue
in class TreeScanner<Void,Void>
public Void visitReturn(ReturnTree node, Void p)
visitReturn
in interface TreeVisitor<Void,Void>
visitReturn
in class TreeScanner<Void,Void>
public Void visitThrow(ThrowTree node, Void p)
visitThrow
in interface TreeVisitor<Void,Void>
visitThrow
in class TreeScanner<Void,Void>
public Void visitTry(TryTree node, Void p)
visitTry
in interface TreeVisitor<Void,Void>
visitTry
in class TreeScanner<Void,Void>
public Void visitMethodInvocation(MethodInvocationTree node, Void p)
visitMethodInvocation
in interface TreeVisitor<Void,Void>
visitMethodInvocation
in class TreeScanner<Void,Void>
public Void visitBlock(BlockTree node, Void p)
visitBlock
in interface TreeVisitor<Void,Void>
visitBlock
in class TreeScanner<Void,Void>
public Void visitMethod(MethodTree node, Void p)
visitMethod
in interface TreeVisitor<Void,Void>
visitMethod
in class TreeScanner<Void,Void>
public void visitMethodEndCallback(MethodTree node)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |