public class TypedScope extends Scope implements StaticTypedScope<JSType>
TypedScope 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,
Several methods in this class, such as {@code isBlockScope} throw an exception when called.
The reason for this is that we want to shadow methods from the parent class, to avoid calling
them accidentally.| Modifier and Type | Method and Description |
|---|---|
Iterable<TypedVar> |
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.
|
Iterator<TypedVar> |
getDeclarativelyUnboundVarsWithoutTypes() |
int |
getDepth()
The depth of the scope.
|
TypedVar |
getOwnSlot(String name)
Like
getSlot but does not recurse into parent scopes. |
TypedScope |
getParent() |
StaticTypedScope<JSType> |
getParentScope()
Returns the scope enclosing this one or null if none.
|
Node |
getRootNode()
Gets the container node of the scope.
|
TypedVar |
getSlot(String name)
Returns any defined slot within this scope for this name.
|
JSType |
getTypeOfThis()
Gets the type of
this in the current scope. |
TypedVar |
getVar(String name)
Returns the variable, may be null
|
int |
getVarCount()
Returns number of variables in this scope (excluding the special 'arguments' variable)
|
Iterator<TypedVar> |
getVars()
Return an iterator over all of the variables declared in this scope.
|
boolean |
isBlockScope() |
boolean |
isDeclared(String name,
boolean recurse)
Returns true if a variable is declared.
|
boolean |
isFunctionBlockScope() |
boolean |
isGlobal()
Returns whether this is the global scope.
|
boolean |
isLocal()
Returns whether this is a local scope (i.e.
|
isFunctionScope, toStringpublic int getDepth()
Scopepublic Node getRootNode()
ScopegetRootNode in interface StaticScopegetRootNode in class Scopepublic TypedScope getParent()
public StaticTypedScope<JSType> getParentScope()
StaticScopegetParentScope in interface StaticTypedScope<JSType>getParentScope in interface StaticScopegetParentScope in class Scopepublic JSType getTypeOfThis()
this in the current scope.getTypeOfThis in interface StaticTypedScope<JSType>public TypedVar getSlot(String name)
StaticScopegetSlot in interface StaticTypedScope<JSType>getSlot in interface StaticScopegetSlot in class Scopename - The name of the variable slot to look up.null if no
definition exists.public TypedVar getOwnSlot(String name)
StaticScopegetSlot but does not recurse into parent scopes.getOwnSlot in interface StaticTypedScope<JSType>getOwnSlot in interface StaticScopegetOwnSlot in class Scopepublic TypedVar getVar(String name)
Scopepublic Var getArgumentsVar()
ScopegetArgumentsVar in class Scopepublic boolean isDeclared(String name, boolean recurse)
ScopeisDeclared in class Scopepublic Iterator<TypedVar> getVars()
Scopepublic Iterable<TypedVar> getAllSymbols()
getAllSymbols in class Scopepublic int getVarCount()
ScopegetVarCount in class Scopepublic boolean isGlobal()
Scopepublic boolean isLocal()
Scopepublic Iterator<TypedVar> getDeclarativelyUnboundVarsWithoutTypes()
public boolean isBlockScope()
isBlockScope in class Scopepublic boolean isFunctionBlockScope()
isFunctionBlockScope in class Scopepublic Scope getClosestHoistScope()
ScopegetClosestHoistScope in class ScopeCopyright © 2009-2016 Google. All Rights Reserved.