Make CreateSyntheticBlocks a Callback so that it's more consistent with the way other passes are typically written.
@@ -20,19 +20,17 @@ import com.google.common.base.Preconditions;
import com.google.javascript.jscomp.NodeTraversal.AbstractPostOrderCallback;
import com.google.javascript.rhino.IR;
import com.google.javascript.rhino.Node;
-
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;
/**
- * Creates synthetic blocks to optimizations from moving code
- * past markers in the source.
+ * Creates synthetic blocks to optimizations from moving code past markers in the source.
*
* @author johnlenz@google.com (John Lenz)
*/
-class CreateSyntheticBlocks implements CompilerPass {
+class CreateSyntheticBlocks extends AbstractPostOrderCallback implements CompilerPass {
static final DiagnosticType UNMATCHED_START_MARKER = DiagnosticType.error(
"JSC_UNMATCHED_START_MARKER", "Unmatched {0}");
@@ -77,7 +75,7 @@ class CreateSyntheticBlocks implements CompilerPass {
@Override
public void process(Node externs, Node root) {
// Find and validate the markers.
- NodeTraversal.traverseEs6(compiler, root, new Callback());
+ NodeTraversal.traverseEs6(compiler, root, this);
// Complain about any unmatched markers.
for (Node node : markerStack) {
@@ -140,7 +138,6 @@ class CreateSyntheticBlocks implements CompilerPass {
}
}
- private class Callback extends AbstractPostOrderCallback {
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
if (!n.isCall() || !n.getFirstChild().isName()) {
@@ -152,8 +149,7 @@ class CreateSyntheticBlocks implements CompilerPass {
if (startMarkerName.equals(callName)) {
if (!parent.isExprResult()) {
- compiler.report(
- t.makeError(n, INVALID_MARKER_USAGE, startMarkerName));
+ compiler.report(t.makeError(n, INVALID_MARKER_USAGE, startMarkerName));
return;
}
markerStack.push(parent);
@@ -166,22 +162,19 @@ class CreateSyntheticBlocks implements CompilerPass {
Node endMarkerNode = parent;
if (!endMarkerNode.isExprResult()) {
- compiler.report(
- t.makeError(n, INVALID_MARKER_USAGE, endMarkerName));
+ compiler.report(t.makeError(n, INVALID_MARKER_USAGE, endMarkerName));
return;
}
if (markerStack.isEmpty()) {
- compiler.report(t.makeError(n, UNMATCHED_END_MARKER,
- startMarkerName, endMarkerName));
+ compiler.report(t.makeError(n, UNMATCHED_END_MARKER, startMarkerName, endMarkerName));
return;
}
Node startMarkerNode = markerStack.pop();
if (endMarkerNode.getParent() != startMarkerNode.getParent()) {
// The end marker isn't in the same block as the start marker.
- compiler.report(t.makeError(n, UNMATCHED_END_MARKER,
- startMarkerName, endMarkerName));
+ compiler.report(t.makeError(n, UNMATCHED_END_MARKER, startMarkerName, endMarkerName));
return;
}
@@ -189,4 +182,3 @@ class CreateSyntheticBlocks implements CompilerPass {
validMarkers.add(new Marker(startMarkerNode, endMarkerNode));
}
}
-}
