Package com.google.javascript.jscomp
Class TypeCheck
- java.lang.Object
-
- com.google.javascript.jscomp.TypeCheck
-
- All Implemented Interfaces:
CompilerPass
,NodeTraversal.Callback
public class TypeCheck extends java.lang.Object implements NodeTraversal.Callback, CompilerPass
Checks the types of JS expressions against any declared type information.
-
-
Field Summary
Fields Modifier and Type Field Description protected static DiagnosticType
NOT_A_CONSTRUCTOR
protected static java.lang.String
OVERRIDING_PROTOTYPE_WITH_NON_OBJECT
-
Constructor Summary
Constructors Constructor Description TypeCheck(AbstractCompiler compiler, ReverseAbstractInterpreter reverseInterpreter, JSTypeRegistry typeRegistry, CheckLevel reportMissingOverride, CheckLevel reportUnknownTypes)
TypeCheck(AbstractCompiler compiler, ReverseAbstractInterpreter reverseInterpreter, JSTypeRegistry typeRegistry, Scope topScope, com.google.javascript.jscomp.MemoizedScopeCreator scopeCreator, CheckLevel reportMissingOverride, CheckLevel reportUnknownTypes)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.
-
-
-
Field Detail
-
OVERRIDING_PROTOTYPE_WITH_NON_OBJECT
protected static final java.lang.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, ReverseAbstractInterpreter reverseInterpreter, JSTypeRegistry typeRegistry, Scope topScope, com.google.javascript.jscomp.MemoizedScopeCreator scopeCreator, CheckLevel reportMissingOverride, CheckLevel reportUnknownTypes)
-
TypeCheck
public TypeCheck(AbstractCompiler compiler, 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 interfaceCompilerPass
- 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 interfaceNodeTraversal.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 interfaceNodeTraversal.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.
-
-