com.google.javascript.jscomp
Class SymbolTable

java.lang.Object
  extended by com.google.javascript.jscomp.SymbolTable
All Implemented Interfaces:
StaticSymbolTable<SymbolTable.Symbol,SymbolTable.Reference>

public final class SymbolTable
extends Object
implements StaticSymbolTable<SymbolTable.Symbol,SymbolTable.Reference>

A symbol table for people that want to use Closure Compiler as an indexer. Contains an index of all the symbols in the code within a compilation job. The API is designed for people who want to visit all the symbols, rather than people who want to lookup a specific symbol by a certain key. We can use this to combine different types of symbol tables. For example, one class might have a StaticSymbolTable of all variable references, and another class might have a StaticSymbolTable of all type names in JSDoc comments. This class allows you to combine them into a unified index. Most passes build their own "partial" symbol table that implements the same interface (StaticSymbolTable, StaticSlot, and friends). Individual compiler passes usually need more or less metadata about the certainty of symbol information. Building a complete symbol table with all the necessary metadata for all passes would be too slow. However, as long as these "partial" symbol tables implement the proper interfaces, we should be able to add them to this symbol table to make it more complete. If clients want fast lookup, they should build their own wrapper around this symbol table that indexes symbols or references by the desired lookup key.

See Also:
For more information on how to write plugins for this symbol table.

Nested Class Summary
static class SymbolTable.Reference
           
static class SymbolTable.Symbol
           
static class SymbolTable.SymbolScope
           
 
Method Summary
 Iterable<SymbolTable.Symbol> getAllSymbols()
          Returns all variables in this symbol table.
 SymbolTable.SymbolScope getEnclosingScope(Node n)
          Gets the scope that contains the given node.
 Iterable<SymbolTable.Reference> getReferences(SymbolTable.Symbol symbol)
          Returns the references that point to the given symbol.
 SymbolTable.SymbolScope getScope(SymbolTable.Symbol slot)
          Returns the scope for a given symbol.
 SymbolTable.Symbol getSymbolForScope(SymbolTable.SymbolScope scope)
          All local scopes are associated with a function, and some functions are associated with a symbol.
 String toDebugString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getReferences

public Iterable<SymbolTable.Reference> getReferences(SymbolTable.Symbol symbol)
Description copied from interface: StaticSymbolTable
Returns the references that point to the given symbol.

Specified by:
getReferences in interface StaticSymbolTable<SymbolTable.Symbol,SymbolTable.Reference>

getAllSymbols

public Iterable<SymbolTable.Symbol> getAllSymbols()
Description copied from interface: StaticSymbolTable
Returns all variables in this symbol table.

Specified by:
getAllSymbols in interface StaticSymbolTable<SymbolTable.Symbol,SymbolTable.Reference>

getScope

public SymbolTable.SymbolScope getScope(SymbolTable.Symbol slot)
Description copied from interface: StaticSymbolTable
Returns the scope for a given symbol.

Specified by:
getScope in interface StaticSymbolTable<SymbolTable.Symbol,SymbolTable.Reference>

getEnclosingScope

public SymbolTable.SymbolScope getEnclosingScope(Node n)
Gets the scope that contains the given node. If n is a function name, we return the scope that contains the function, not the function itself.


getSymbolForScope

public SymbolTable.Symbol getSymbolForScope(SymbolTable.SymbolScope scope)
All local scopes are associated with a function, and some functions are associated with a symbol. Returns the symbol associated with the given scope.


toDebugString

public String toDebugString()