private class RuntimeTypeCheck.AddChecks extends NodeTraversal.AbstractPostOrderCallback
checkType
, which
takes an expression to check and a list of checkers (one of which must
match). It returns the expression back to facilitate checking of return
values. We have checkers for value types, class types (user-defined and
externed), and interface types.Modifier | Constructor and Description |
---|---|
private |
AddChecks() |
Modifier and Type | Method and Description |
---|---|
private Node |
createCheckerNode(JSType type)
Creates a node which evaluates to a checker for the given type (which
must not be a union).
|
private Node |
createCheckTypeCallNode(JSType type,
Node expr)
Creates a function call to check that the given expression matches the
given type at runtime.
|
void |
visit(NodeTraversal t,
Node n,
Node parent)
Visits a node in postorder (after its children have been visited).
|
private void |
visitFunction(Node n)
Insert checks for the parameters of the function.
|
private void |
visitReturn(NodeTraversal t,
Node n) |
shouldTraverse
public void visit(NodeTraversal t, Node n, Node parent)
NodeTraversal.Callback
Visits a node in postorder (after its children have been visited).
A node is visited only if all its parents should be traversed
(NodeTraversal.Callback.shouldTraverse(NodeTraversal, Node, Node)
).
Implementations can have side effects (e.g. modifying the parse tree).
private void visitFunction(Node n)
private void visitReturn(NodeTraversal t, Node n)
private Node createCheckTypeCallNode(JSType type, Node expr)
For example, if the type is (string|Foo)
, the function call is
checkType(expr, [valueChecker('string'), classChecker('Foo')])
.
null
if the type is not checked