Class LocalVariableScanner
java.lang.Object
com.sun.source.util.TreeScanner<Void,Void>
com.sun.source.util.TreePathScanner<Void,Void>
org.checkerframework.afu.annotator.scanner.CommonScanner
org.checkerframework.afu.annotator.scanner.LocalVariableScanner
- All Implemented Interfaces:
TreeVisitor<Void,
Void>
LocalVariableScanner stores information about the names and offsets of local variables inside a
method, and can also be used to scan the source tree and determine the index of a local variable
with a given name, so that the i^th index corresponds to the i^th declaration of a local variable
with that name, using 0-based indexing.
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
addToMethodNameCounter
(String methodName, String varName, Integer offset) Adds to the given method the fact that the local variable with the given name is declared at the given start offset.static void
addToMethodNameIndexMap
(com.sun.tools.javac.util.Pair<String, com.sun.tools.javac.util.Pair<Integer, Integer>> varInfo, String name) Adds the given variable specified as a pair of method name and (index, start-offset) under the given name to the list of all local variables.getFromMethodNameCounter
(String methodName, String varName) Returns a list of all start bytecode offsets of variable declarations with the given variable name in the given method.static String
getFromMethodNameIndexMap
(com.sun.tools.javac.util.Pair<String, com.sun.tools.javac.util.Pair<Integer, Integer>> varInfo) Gets the name of the local variable in the given method, and at the given index and offset.static int
indexOfVarTree
(TreePath origpath, Tree varTree, String varName) Computes the index i of the given tree along the given tree path such that it is the i^th declaration of the local variable with the given var name, using 0-based indexing.visitVariable
(VariableTree node, Void p) Methods inherited from class org.checkerframework.afu.annotator.scanner.CommonScanner
visitClass
Methods inherited from class com.sun.source.util.TreePathScanner
getCurrentPath, scan, scan
Methods inherited from class com.sun.source.util.TreeScanner
reduce, scan, visitAnnotatedType, visitAnnotation, visitAnyPattern, visitArrayAccess, visitArrayType, visitAssert, visitAssignment, visitBinary, visitBindingPattern, visitBlock, visitBreak, visitCase, visitCatch, visitCompilationUnit, visitCompoundAssignment, visitConditionalExpression, visitConstantCaseLabel, visitContinue, visitDeconstructionPattern, visitDefaultCaseLabel, visitDoWhileLoop, visitEmptyStatement, visitEnhancedForLoop, visitErroneous, visitExports, visitExpressionStatement, visitForLoop, visitIdentifier, visitIf, visitImport, visitInstanceOf, visitIntersectionType, visitLabeledStatement, visitLambdaExpression, visitLiteral, visitMemberReference, visitMemberSelect, visitMethod, visitMethodInvocation, visitModifiers, visitModule, visitNewArray, visitNewClass, visitOpens, visitOther, visitPackage, visitParameterizedType, visitParenthesized, visitPatternCaseLabel, visitPrimitiveType, visitProvides, visitRequires, visitReturn, visitStringTemplate, visitSwitch, visitSwitchExpression, visitSynchronized, visitThrow, visitTry, visitTypeCast, visitTypeParameter, visitUnary, visitUnionType, visitUses, visitWhileLoop, visitWildcard, visitYield
-
Method Details
-
indexOfVarTree
Computes the index i of the given tree along the given tree path such that it is the i^th declaration of the local variable with the given var name, using 0-based indexing.- Parameters:
origpath
- the source path that ends in varTreevarTree
- the variable tree that declares the local variablevarName
- the name of the local variable- Returns:
- the index of the variable tree with respect to the given local variable name
-
visitVariable
- Specified by:
visitVariable
in interfaceTreeVisitor<Void,
Void> - Overrides:
visitVariable
in classTreeScanner<Void,
Void>
-
addToMethodNameIndexMap
public static void addToMethodNameIndexMap(com.sun.tools.javac.util.Pair<String, com.sun.tools.javac.util.Pair<Integer, Integer>> varInfo, String name) Adds the given variable specified as a pair of method name and (index, start-offset) under the given name to the list of all local variables.- Parameters:
varInfo
- a pair of the method and a pair describing the local variable index and start offset of the local variablename
- the name of the local variable
-
getFromMethodNameIndexMap
public static String getFromMethodNameIndexMap(com.sun.tools.javac.util.Pair<String, com.sun.tools.javac.util.Pair<Integer, Integer>> varInfo) Gets the name of the local variable in the given method, and at the given index and offset.- Parameters:
varInfo
- a pair of the method name and a pair of the local variable's index and start offset- Returns:
- the name of the local variable at the specified location
-
addToMethodNameCounter
Adds to the given method the fact that the local variable with the given name is declared at the given start offset.- Parameters:
methodName
- the method containing the local variablevarName
- the name of the local variableoffset
- the start offset of the local variable
-
getFromMethodNameCounter
Returns a list of all start bytecode offsets of variable declarations with the given variable name in the given method.- Parameters:
methodName
- the name of the methodvarName
- the name of the local variable- Returns:
- a list of start offsets for live ranges of all local variables with the given name in the given method
-