com.google.javascript.jscomp
Class TypeCheck

java.lang.Object
  extended by com.google.javascript.jscomp.TypeCheck
All Implemented Interfaces:
CompilerPass, NodeTraversal.Callback

public class TypeCheck
extends Object
implements NodeTraversal.Callback, CompilerPass

Checks the types of JS expressions against any declared type information.


Field Summary
protected static DiagnosticType NOT_A_CONSTRUCTOR
           
protected static String OVERRIDING_PROTOTYPE_WITH_NON_OBJECT
           
 
Constructor Summary
TypeCheck(AbstractCompiler compiler, com.google.javascript.jscomp.ReverseAbstractInterpreter reverseInterpreter, JSTypeRegistry typeRegistry, CheckLevel reportMissingOverride, CheckLevel reportUnknownTypes)
           
TypeCheck(AbstractCompiler compiler, com.google.javascript.jscomp.ReverseAbstractInterpreter reverseInterpreter, JSTypeRegistry typeRegistry, Scope topScope, com.google.javascript.jscomp.ScopeCreator scopeCreator, CheckLevel reportMissingOverride, CheckLevel reportUnknownTypes)
           
 
Method Summary
 void check(Node node, boolean externs)
           
 void process(Node externsRoot, Node jsRoot)
          Main entry point for this phase of processing.
 Scope processForTesting(Node externsRoot, Node jsRoot)
          Main entry point of this phase for testing code.
 boolean shouldTraverse(NodeTraversal t, Node n, Node parent)
          Visits a node in pre order (before visiting its children) and decides whether this node's children should be traversed.
 void visit(NodeTraversal t, Node n, Node parent)
          This is the meat of the type checking.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OVERRIDING_PROTOTYPE_WITH_NON_OBJECT

protected static final String OVERRIDING_PROTOTYPE_WITH_NON_OBJECT
See Also:
Constant Field Values

NOT_A_CONSTRUCTOR

protected static final DiagnosticType NOT_A_CONSTRUCTOR
Constructor Detail

TypeCheck

public TypeCheck(AbstractCompiler compiler,
                 com.google.javascript.jscomp.ReverseAbstractInterpreter reverseInterpreter,
                 JSTypeRegistry typeRegistry,
                 Scope topScope,
                 com.google.javascript.jscomp.ScopeCreator scopeCreator,
                 CheckLevel reportMissingOverride,
                 CheckLevel reportUnknownTypes)

TypeCheck

public TypeCheck(AbstractCompiler compiler,
                 com.google.javascript.jscomp.ReverseAbstractInterpreter reverseInterpreter,
                 JSTypeRegistry typeRegistry,
                 CheckLevel reportMissingOverride,
                 CheckLevel reportUnknownTypes)
Method Detail

process

public void process(Node externsRoot,
                    Node jsRoot)
Main entry point for this phase of processing. This follows the pattern for JSCompiler phases.

Specified by:
process in interface CompilerPass
Parameters:
externsRoot - The root of the externs parse tree.
jsRoot - The root of the input parse tree to be checked.

processForTesting

public Scope processForTesting(Node externsRoot,
                               Node jsRoot)
Main entry point of this phase for testing code.


check

public void check(Node node,
                  boolean externs)

shouldTraverse

public boolean shouldTraverse(NodeTraversal t,
                              Node n,
                              Node parent)
Description copied from interface: NodeTraversal.Callback

Visits a node in pre order (before visiting its children) and decides whether this node's children should be traversed. If children are traversed, they will be visited by NodeTraversal.Callback.visit(NodeTraversal, Node, Node) in post order.

Implementations can have side effects (e.g. modifying the parse tree).

Specified by:
shouldTraverse in interface NodeTraversal.Callback
Returns:
whether the children of this node should be visited

visit

public void visit(NodeTraversal t,
                  Node n,
                  Node parent)
This is the meat of the type checking. It is basically one big switch, with each case representing one type of parse tree node. The individual cases are usually pretty straightforward.

Specified by:
visit in interface NodeTraversal.Callback
Parameters:
t - The node traversal object that supplies context, such as the scope chain to use in name lookups as well as error reporting.
n - The node being visited.
parent - The parent of the node n.