public class Scope extends java.lang.Object implements StaticScope
NodeTraversal| Modifier and Type | Field and Description |
|---|---|
private Var |
arguments |
protected int |
depth |
private Scope |
parent |
protected Node |
rootNode |
private java.util.Map<java.lang.String,Var> |
vars |
| Modifier | Constructor and Description |
|---|---|
protected |
Scope(Node rootNode) |
(package private) |
Scope(Scope parent,
Node rootNode)
Creates a Scope given the parent Scope and the root node of the scope.
|
| Modifier and Type | Method and Description |
|---|---|
(package private) static Scope |
createGlobalScope(Node rootNode) |
(package private) Var |
declare(java.lang.String name,
Node nameNode,
CompilerInput input)
Declares a variable.
|
java.lang.Iterable<? extends Var> |
getAllSymbols() |
Var |
getArgumentsVar()
Get a unique VAR object to represents "arguments" within this scope
|
Scope |
getClosestHoistScope()
If a var were declared in this scope, return the scope it would be hoisted to.
|
int |
getDepth()
The depth of the scope.
|
(package private) Scope |
getGlobalScope() |
Var |
getOwnSlot(java.lang.String name)
Like
getSlot but does not recurse into parent scopes. |
Scope |
getParent() |
StaticScope |
getParentScope()
Returns the scope enclosing this one or null if none.
|
Node |
getRootNode()
Gets the container node of the scope.
|
Var |
getSlot(java.lang.String name)
Returns any defined slot within this scope for this name.
|
Var |
getVar(java.lang.String name)
Returns the variable, may be null
|
int |
getVarCount()
Returns number of variables in this scope (excluding the special 'arguments' variable)
|
(package private) java.lang.Iterable<Var> |
getVarIterable()
Return an iterable over all of the variables declared in this scope
(except the special 'arguments' variable).
|
<T extends Var> |
getVars()
Return an iterator over all of the variables declared in this scope.
|
boolean |
isBlockScope() |
boolean |
isDeclared(java.lang.String name,
boolean recurse)
Returns true if a variable is declared.
|
boolean |
isFunctionBlockScope() |
boolean |
isFunctionScope() |
boolean |
isGlobal()
Returns whether this is the global scope.
|
boolean |
isLocal()
Returns whether this is a local scope (i.e.
|
java.lang.String |
toString() |
(package private) void |
undeclare(Var var)
Undeclares a variable, to be used when the compiler optimizes out
a variable and removes it from the scope.
|
private final java.util.Map<java.lang.String,Var> vars
private final Scope parent
protected final int depth
protected final Node rootNode
private Var arguments
Scope(Scope parent, Node rootNode)
parent - The parent Scope. Cannot be null.rootNode - Typically the FUNCTION node.protected Scope(Node rootNode)
public java.lang.String toString()
toString in class java.lang.Objectpublic int getDepth()
public Node getRootNode()
getRootNode in interface StaticScopepublic Scope getParent()
Scope getGlobalScope()
public StaticScope getParentScope()
StaticScopegetParentScope in interface StaticScopeVar declare(java.lang.String name, Node nameNode, CompilerInput input)
name - name of the variablenameNode - the NAME node declaring the variableinput - the input in which this variable is defined.void undeclare(Var var)
public Var getSlot(java.lang.String name)
StaticScopegetSlot in interface StaticScopename - The name of the variable slot to look up.null if no
definition exists.public Var getOwnSlot(java.lang.String name)
StaticScopegetSlot but does not recurse into parent scopes.getOwnSlot in interface StaticScopepublic Var getVar(java.lang.String name)
public Var getArgumentsVar()
public boolean isDeclared(java.lang.String name,
boolean recurse)
public <T extends Var> java.util.Iterator<T> getVars()
java.lang.Iterable<Var> getVarIterable()
public java.lang.Iterable<? extends Var> getAllSymbols()
public int getVarCount()
public boolean isGlobal()
public boolean isLocal()
public boolean isBlockScope()
public boolean isFunctionBlockScope()
public boolean isFunctionScope()
public Scope getClosestHoistScope()