Package com.google.javascript.jscomp
Class ReferenceCollector
- java.lang.Object
-
- com.google.javascript.jscomp.ReferenceCollector
-
- All Implemented Interfaces:
CompilerPass
,StaticSymbolTable<Var,Reference>
public final class ReferenceCollector extends java.lang.Object implements CompilerPass, StaticSymbolTable<Var,Reference>
A helper class for passes that want to access all information about where a variable is referenced and declared at once and then make a decision as to how it should be handled, possibly inlining, reordering, or generating warnings. Callers do this by providingReferenceCollector.Behavior
and then callingprocess(Node, Node)
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ReferenceCollector.Behavior
Way for callers to add specific behavior during traversal that utilizes the built-up reference information.
-
Constructor Summary
Constructors Constructor Description ReferenceCollector(AbstractCompiler compiler, ReferenceCollector.Behavior behavior, com.google.javascript.jscomp.ScopeCreator creator)
Constructor initializes block stack.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Iterable<Var>
getAllSymbols()
Gets the variables that were referenced in this callback.ReferenceCollection
getReferences(Var v)
Gets the reference collection for the given variable.Scope
getScope(Var var)
Returns the scope for a given symbol.void
process(Node root)
void
process(Node externs, Node root)
Convenience method for running this pass over a tree with this class as a callback.
-
-
-
Constructor Detail
-
ReferenceCollector
public ReferenceCollector(AbstractCompiler compiler, ReferenceCollector.Behavior behavior, com.google.javascript.jscomp.ScopeCreator creator)
Constructor initializes block stack.
-
-
Method Detail
-
process
public void process(Node externs, Node root)
Convenience method for running this pass over a tree with this class as a callback.- Specified by:
process
in interfaceCompilerPass
- Parameters:
externs
- Top of external JS treeroot
- Top of JS tree
-
process
public void process(Node root)
-
getAllSymbols
public java.lang.Iterable<Var> getAllSymbols()
Gets the variables that were referenced in this callback.- Specified by:
getAllSymbols
in interfaceStaticSymbolTable<Var,Reference>
-
getScope
public Scope getScope(Var var)
Description copied from interface:StaticSymbolTable
Returns the scope for a given symbol.- Specified by:
getScope
in interfaceStaticSymbolTable<Var,Reference>
-
getReferences
public ReferenceCollection getReferences(Var v)
Gets the reference collection for the given variable.- Specified by:
getReferences
in interfaceStaticSymbolTable<Var,Reference>
-
-