public class Scope extends Object implements StaticScope<JSType>, StaticSymbolTable<Scope.Var,Scope.Var>
A Scope is also used as a lattice element for flow-sensitive type inference.
As a lattice element, a Scope is viewed as a map from names to types. A name
not in the map is considered to have the bottom type. The join of two maps m1
and m2 is the map of the union of names with JSType.getLeastSupertype(com.google.javascript.rhino.jstype.JSType)
to meet the m1 type and m2 type.
NodeTraversal
,
DataFlowAnalysis
Modifier and Type | Class and Description |
---|---|
static class |
Scope.Arguments
A special subclass of Var used to distinguish "arguments" in the current
scope.
|
static class |
Scope.Var
Stores info about a variable
|
Modifier and Type | Method and Description |
---|---|
Iterable<Scope.Var> |
getAllSymbols()
Returns all variables in this symbol table.
|
Scope.Var |
getArgumentsVar()
Get a unique VAR object to represents "arguments" within this scope
|
Iterator<Scope.Var> |
getDeclarativelyUnboundVarsWithoutTypes()
Gets all variables declared with "var" but without declared types attached.
|
Scope.Var |
getOwnSlot(String name)
Like
getSlot but does not recurse into parent scopes. |
Scope |
getParent() |
StaticScope<JSType> |
getParentScope()
Returns the scope enclosing this one or null if none.
|
Iterable<Scope.Var> |
getReferences(Scope.Var var)
Returns the references that point to the given symbol.
|
Node |
getRootNode()
Gets the container node of the scope.
|
StaticScope<JSType> |
getScope(Scope.Var var)
Returns the scope for a given symbol.
|
Scope.Var |
getSlot(String name)
Returns any defined slot within this scope for this name.
|
JSType |
getTypeOfThis()
Gets the type of
this in the current scope. |
Scope.Var |
getVar(String name)
Returns the variable, may be null
|
int |
getVarCount()
Returns number of variables in this scope
|
Iterator<Scope.Var> |
getVars()
Return an iterator over all of the variables declared in this scope.
|
boolean |
isDeclared(String name,
boolean recurse)
Returns true if a variable is declared.
|
boolean |
isGlobal()
Returns whether this is the global scope.
|
boolean |
isLocal()
Returns whether this is a local scope (i.e.
|
public Node getRootNode()
getRootNode
in interface StaticScope<JSType>
public Scope getParent()
public StaticScope<JSType> getParentScope()
StaticScope
getParentScope
in interface StaticScope<JSType>
public JSType getTypeOfThis()
this
in the current scope.getTypeOfThis
in interface StaticScope<JSType>
public Scope.Var getSlot(String name)
StaticScope
getSlot
in interface StaticScope<JSType>
name
- The name of the variable slot to look up.null
if no
definition exists.public Scope.Var getOwnSlot(String name)
StaticScope
getSlot
but does not recurse into parent scopes.getOwnSlot
in interface StaticScope<JSType>
public Scope.Var getArgumentsVar()
public boolean isDeclared(String name, boolean recurse)
public Iterator<Scope.Var> getVars()
public Iterable<Scope.Var> getReferences(Scope.Var var)
StaticSymbolTable
getReferences
in interface StaticSymbolTable<Scope.Var,Scope.Var>
public StaticScope<JSType> getScope(Scope.Var var)
StaticSymbolTable
getScope
in interface StaticSymbolTable<Scope.Var,Scope.Var>
public Iterable<Scope.Var> getAllSymbols()
StaticSymbolTable
getAllSymbols
in interface StaticSymbolTable<Scope.Var,Scope.Var>
public int getVarCount()
public boolean isGlobal()
public boolean isLocal()
Copyright © 2009-2014 Google. All Rights Reserved.