|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.google.javascript.jscomp.NodeTraversal
public class NodeTraversal
Nodetraversal allows an iteration through the nodes in the parse tree, and facilitates the optimizations on the parse tree.
Nested Class Summary | |
---|---|
static class |
NodeTraversal.AbstractNodeTypePruningCallback
Abstract callback to visit a pruned set of nodes. |
static class |
NodeTraversal.AbstractPostOrderCallback
Abstract callback to visit all nodes in post order. |
static class |
NodeTraversal.AbstractScopedCallback
Abstract scoped callback to visit all nodes in post order. |
static class |
NodeTraversal.AbstractShallowCallback
Abstract callback to visit all nodes but not traverse into function bodies. |
static class |
NodeTraversal.AbstractShallowStatementCallback
Abstract callback to visit all structure and statement nodes but doesn't traverse into functions or expressions. |
static interface |
NodeTraversal.Callback
Callback |
static interface |
NodeTraversal.ScopedCallback
Callback that also knows about scope changes |
Field Summary | |
---|---|
static DiagnosticType |
NODE_TRAVERSAL_ERROR
|
Constructor Summary | |
---|---|
NodeTraversal(AbstractCompiler compiler,
NodeTraversal.Callback cb)
Creates a node traversal using the specified callback interface. |
|
NodeTraversal(AbstractCompiler compiler,
NodeTraversal.Callback cb,
com.google.javascript.jscomp.ScopeCreator scopeCreator)
Creates a node traversal using the specified callback interface and the scope creator. |
Method Summary | |
---|---|
Compiler |
getCompiler()
Gets the compiler. |
com.google.javascript.jscomp.ControlFlowGraph<Node> |
getControlFlowGraph()
Gets the control flow graph for the current JS scope. |
Node |
getCurrentNode()
Returns the node currently being traversed. |
Node |
getEnclosingFunction()
Examines the functions stack for the last instance of a function node. |
CompilerInput |
getInput()
Gets the current input source. |
int |
getLineNumber()
Gets the current line number, or zero if it cannot be determined. |
JSModule |
getModule()
Gets the current input module. |
Scope |
getScope()
Gets the current scope. |
Node |
getScopeRoot()
Returns the current scope's root. |
String |
getSourceName()
Gets the current input source name. |
boolean |
hasScope()
|
JSError |
makeError(Node n,
CheckLevel level,
DiagnosticType type,
String... arguments)
Creates a JSError during NodeTraversal. |
JSError |
makeError(Node n,
DiagnosticType type,
String... arguments)
Creates a JSError during NodeTraversal. |
void |
report(Node n,
DiagnosticType diagnosticType,
String... arguments)
Reports a diagnostic (error or warning) |
static void |
traverse(AbstractCompiler compiler,
Node root,
NodeTraversal.Callback cb)
Traverses a node recursively. |
void |
traverse(Node root)
Traverses a parse tree recursively. |
protected void |
traverseInnerNode(Node node,
Node parent,
Scope refinedScope)
Traverses an inner node recursively with a refined scope. |
static void |
traverseRoots(AbstractCompiler compiler,
List<Node> roots,
NodeTraversal.Callback cb)
Traverses a list of node trees. |
static void |
traverseRoots(AbstractCompiler compiler,
NodeTraversal.Callback cb,
Node... roots)
|
void |
traverseRoots(List<Node> roots)
|
void |
traverseRoots(Node... roots)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final DiagnosticType NODE_TRAVERSAL_ERROR
Constructor Detail |
---|
public NodeTraversal(AbstractCompiler compiler, NodeTraversal.Callback cb)
public NodeTraversal(AbstractCompiler compiler, NodeTraversal.Callback cb, com.google.javascript.jscomp.ScopeCreator scopeCreator)
Method Detail |
---|
public void traverse(Node root)
public void traverseRoots(Node... roots)
public void traverseRoots(List<Node> roots)
protected void traverseInnerNode(Node node, Node parent, Scope refinedScope)
null
parent (i.e. all nodes except the
root).
node
- the node to traverseparent
- the node's parent, it may be not be null
refinedScope
- the refined scope of the scope currently at the top of
the scope stack or in trivial cases that very scope or null
public Compiler getCompiler()
public int getLineNumber()
public String getSourceName()
public CompilerInput getInput()
public JSModule getModule()
public Node getCurrentNode()
public static void traverse(AbstractCompiler compiler, Node root, NodeTraversal.Callback cb)
public static void traverseRoots(AbstractCompiler compiler, List<Node> roots, NodeTraversal.Callback cb)
public static void traverseRoots(AbstractCompiler compiler, NodeTraversal.Callback cb, Node... roots)
public Node getEnclosingFunction()
public Scope getScope()
public com.google.javascript.jscomp.ControlFlowGraph<Node> getControlFlowGraph()
public Node getScopeRoot()
public boolean hasScope()
public void report(Node n, DiagnosticType diagnosticType, String... arguments)
public JSError makeError(Node n, CheckLevel level, DiagnosticType type, String... arguments)
n
- Determines the line and char position within the source file nametype
- The DiagnosticTypearguments
- Arguments to be incorporated into the messagepublic JSError makeError(Node n, DiagnosticType type, String... arguments)
n
- Determines the line and char position within the source file nametype
- The DiagnosticTypearguments
- Arguments to be incorporated into the message
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |