class CheckMissingReturn extends java.lang.Object implements NodeTraversal.ScopedCallback
Modifier and Type | Field and Description |
---|---|
private AbstractCompiler |
compiler |
private CodingConvention |
convention |
private static com.google.common.base.Predicate<DiGraph.DiGraphEdge<Node,ControlFlowGraph.Branch>> |
GOES_THROUGH_TRUE_CONDITION_PREDICATE |
private static com.google.common.base.Predicate<Node> |
IS_RETURN |
(package private) static DiagnosticType |
MISSING_RETURN_STATEMENT |
Constructor and Description |
---|
CheckMissingReturn(AbstractCompiler compiler) |
Modifier and Type | Method and Description |
---|---|
void |
enterScope(NodeTraversal t)
Called immediately after entering a new scope.
|
void |
exitScope(NodeTraversal t)
Called immediately before exiting a scope.
|
private JSType |
explicitReturnExpected(Node scope)
Determines if the given scope should explicitly return.
|
private boolean |
fastAllPathsReturnCheck(ControlFlowGraph<Node> cfg)
Fast check to see if all execution paths contain a return statement.
|
private static boolean |
isEmptyFunction(Node function) |
private boolean |
isVoidOrUnknown(JSType returnType) |
boolean |
shouldTraverse(NodeTraversal nodeTraversal,
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)
Visits a node in postorder (after its children have been visited).
|
static final DiagnosticType MISSING_RETURN_STATEMENT
private final AbstractCompiler compiler
private final CodingConvention convention
private static final com.google.common.base.Predicate<Node> IS_RETURN
private static final com.google.common.base.Predicate<DiGraph.DiGraphEdge<Node,ControlFlowGraph.Branch>> GOES_THROUGH_TRUE_CONDITION_PREDICATE
CheckMissingReturn(AbstractCompiler compiler)
public void enterScope(NodeTraversal t)
NodeTraversal.ScopedCallback
enterScope
in interface NodeTraversal.ScopedCallback
private boolean fastAllPathsReturnCheck(ControlFlowGraph<Node> cfg)
public void exitScope(NodeTraversal t)
NodeTraversal.ScopedCallback
exitScope
in interface NodeTraversal.ScopedCallback
public boolean shouldTraverse(NodeTraversal nodeTraversal, Node n, Node parent)
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 postorder.
Implementations can have side effects (e.g. modifying the parse tree).
shouldTraverse
in interface NodeTraversal.Callback
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).
visit
in interface NodeTraversal.Callback
private JSType explicitReturnExpected(Node scope)
private static boolean isEmptyFunction(Node function)
true
if function represents a JavaScript function
with an empty bodyprivate boolean isVoidOrUnknown(JSType returnType)
true
if returnType is void, unknown, or a union
containing void or unknown