com.google.javascript.jscomp
Class Scope

java.lang.Object
  extended by com.google.javascript.jscomp.Scope
All Implemented Interfaces:
StaticScope<JSType>

public class Scope
extends Object
implements StaticScope<JSType>

Scope contains information about a variable scope in javascript. Scopes can be nested, a scope points back to its parent scope. A Scope contains information about variables defined in that scope.

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.

See Also:
NodeTraversal, DataFlowAnalysis

Nested Class Summary
static class Scope.Var
          Stores info about a variable
 
Method Summary
 StaticSlot<JSType> 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.
 Node getRootNode()
          Gets the container node of the scope.
 StaticSlot<JSType> getSlot(String name)
          Returns any defined slot within this scope for this name.
 ObjectType 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getRootNode

public Node getRootNode()
Gets the container node of the scope. This is typically the FUNCTION node or the global BLOCK/SCRIPT node.


getParent

public Scope getParent()

getParentScope

public StaticScope<JSType> getParentScope()
Description copied from interface: StaticScope
Returns the scope enclosing this one or null if none.

Specified by:
getParentScope in interface StaticScope<JSType>

getTypeOfThis

public ObjectType getTypeOfThis()
Gets the type of this in the current scope.

Specified by:
getTypeOfThis in interface StaticScope<JSType>

getSlot

public StaticSlot<JSType> getSlot(String name)
Description copied from interface: StaticScope
Returns any defined slot within this scope for this name. This call continues searching through parent scopes if a slot with this name is not found in the current scope.

Specified by:
getSlot in interface StaticScope<JSType>
Parameters:
name - The name of the variable slot to look up.
Returns:
The defined slot for the variable, or null if no definition exists.

getOwnSlot

public StaticSlot<JSType> getOwnSlot(String name)
Description copied from interface: StaticScope
Like getSlot but does not recurse into parent scopes.

Specified by:
getOwnSlot in interface StaticScope<JSType>

getVar

public Scope.Var getVar(String name)
Returns the variable, may be null


isDeclared

public boolean isDeclared(String name,
                          boolean recurse)
Returns true if a variable is declared.


getVars

public Iterator<Scope.Var> getVars()
Return an iterator over all of the variables declared in this scope.


getVarCount

public int getVarCount()
Returns number of variables in this scope


isGlobal

public boolean isGlobal()
Returns whether this is the global scope.


isLocal

public boolean isLocal()
Returns whether this is a local scope (i.e. not the global scope).