public class Scope extends Object implements StaticScope, Serializable
NodeTraversal
,
Serialized FormModifier and Type | Field and Description |
---|---|
protected int |
depth |
protected Scope |
parent |
protected Node |
rootNode |
protected Map<String,Var> |
vars |
Modifier | Constructor and Description |
---|---|
protected |
Scope(Node rootNode) |
Modifier and Type | Method and Description |
---|---|
Iterable<? extends Var> |
getAllAccessibleVariables()
Return an iterable over all of the variables accessible to this scope (i.e.
|
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.
|
Var |
getOwnSlot(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(String name)
Returns any defined slot within this scope for this name.
|
Var |
getVar(String name)
Returns the variable, may be null
|
int |
getVarCount()
Returns number of variables in this scope (excluding the special 'arguments' variable)
|
Iterable<? extends Var> |
getVarIterable()
Return an iterable over all of the variables declared in this scope
(except the special 'arguments' variable).
|
boolean |
isBlockScope() |
boolean |
isCatchScope() |
boolean |
isDeclared(String name,
boolean recurse)
Returns true if a variable is declared.
|
boolean |
isDeclaredInFunctionBlockOrParameter(String name)
Use only when in a function block scope and want to tell if a name is either at the top of the
function block scope or the function parameter scope
|
boolean |
isFunctionBlockScope() |
boolean |
isFunctionScope() |
boolean |
isGlobal()
Returns whether this is the global scope.
|
static boolean |
isHoistScopeRootNode(Node n) |
boolean |
isLocal()
Returns whether this is a local scope (i.e.
|
boolean |
isModuleScope() |
String |
toString() |
protected Scope parent
protected int depth
protected final Node rootNode
protected Scope(Node rootNode)
public int getDepth()
public Node getRootNode()
getRootNode
in interface StaticScope
public Scope getParent()
public StaticScope getParentScope()
StaticScope
getParentScope
in interface StaticScope
public Var getSlot(String name)
StaticScope
getSlot
in interface StaticScope
name
- The name of the variable slot to look up.null
if no
definition exists.public Var getOwnSlot(String name)
StaticScope
getSlot
but does not recurse into parent scopes.getOwnSlot
in interface StaticScope
public Var getArgumentsVar()
public boolean isDeclaredInFunctionBlockOrParameter(String name)
public boolean isDeclared(String name, boolean recurse)
public Iterable<? extends Var> getVarIterable()
public Iterable<? extends Var> getAllAccessibleVariables()
The iterable contains variables from inner scopes before adding variables from outer parent scopes.
We do not include the special 'arguments' variable.
public int getVarCount()
public boolean isGlobal()
public boolean isLocal()
public boolean isBlockScope()
public boolean isFunctionBlockScope()
public boolean isFunctionScope()
public boolean isModuleScope()
public boolean isCatchScope()
public static boolean isHoistScopeRootNode(Node n)
public Scope getClosestHoistScope()
Copyright © 2009-2017 Google. All Rights Reserved.