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, toString
public int getDepth()
Scope
public Node getRootNode()
Scope
getRootNode
in interface StaticScope
getRootNode
in class Scope
public TypedScope getParent()
public StaticTypedScope<JSType> getParentScope()
StaticScope
getParentScope
in interface StaticTypedScope<JSType>
getParentScope
in interface StaticScope
getParentScope
in class Scope
public JSType getTypeOfThis()
this
in the current scope.getTypeOfThis
in interface StaticTypedScope<JSType>
public TypedVar getSlot(String name)
StaticScope
getSlot
in interface StaticTypedScope<JSType>
getSlot
in interface StaticScope
getSlot
in class Scope
name
- The name of the variable slot to look up.null
if no
definition exists.public TypedVar getOwnSlot(String name)
StaticScope
getSlot
but does not recurse into parent scopes.getOwnSlot
in interface StaticTypedScope<JSType>
getOwnSlot
in interface StaticScope
getOwnSlot
in class Scope
public TypedVar getVar(String name)
Scope
public Var getArgumentsVar()
Scope
getArgumentsVar
in class Scope
public boolean isDeclared(String name, boolean recurse)
Scope
isDeclared
in class Scope
public Iterator<TypedVar> getVars()
Scope
public Iterable<TypedVar> getAllSymbols()
getAllSymbols
in class Scope
public int getVarCount()
Scope
getVarCount
in class Scope
public boolean isGlobal()
Scope
public boolean isLocal()
Scope
public Iterator<TypedVar> getDeclarativelyUnboundVarsWithoutTypes()
public boolean isBlockScope()
isBlockScope
in class Scope
public boolean isFunctionBlockScope()
isFunctionBlockScope
in class Scope
public Scope getClosestHoistScope()
Scope
getClosestHoistScope
in class Scope
Copyright © 2009–2023 Google. All rights reserved.