Add a visitor method for statement blocks to SyntaxTreeVisitor
This allows to do an action after every statement in a block
(e.g. an else-block) without having to override all visit(...)
methods related to statements.
RELNOTES: None
@@ -28,12 +28,25 @@ public class SyntaxTreeVisitor {
node.accept(this);
}
+ // methods dealing with sequences of nodes
public void visitAll(List<? extends ASTNode> nodes) {
for (ASTNode node : nodes) {
visit(node);
}
}
+ /**
+ * Visit a sequence ("block") of statements (e.g. an if branch, for block, function block etc.)
+ *
+ * This method allows subclasses to handle statement blocks more easily, like doing an action
+ * after every statement in a block without having to override visit(...) for all statements.
+ *
+ * @param statements list of statements in the block
+ */
+ public void visitBlock(List<Statement> statements) {
+ visitAll(statements);
+ }
+
// node specific visit methods
public void visit(Argument.Passed node) {
visit(node.getValue());
@@ -46,7 +59,7 @@ public class SyntaxTreeVisitor {
}
public void visit(BuildFileAST node) {
- visitAll(node.getStatements());
+ visitBlock(node.getStatements());
visitAll(node.getComments());
}
@@ -75,7 +88,7 @@ public class SyntaxTreeVisitor {
public void visit(ForStatement node) {
visit(node.getVariable());
visit(node.getCollection());
- visitAll(node.getBlock());
+ visitBlock(node.getBlock());
}
public void visit(LoadStatement node) {
@@ -110,12 +123,12 @@ public class SyntaxTreeVisitor {
public void visit(IfStatement node) {
visitAll(node.getThenBlocks());
- visitAll(node.getElseBlock());
+ visitBlock(node.getElseBlock());
}
public void visit(ConditionalStatements node) {
visit(node.getCondition());
- visitAll(node.getStatements());
+ visitBlock(node.getStatements());
}
public void visit(FunctionDefStatement node) {
@@ -125,7 +138,7 @@ public class SyntaxTreeVisitor {
for (Parameter<Expression, Expression> param : node.getParameters()) {
visit(param);
}
- visitAll(node.getStatements());
+ visitBlock(node.getStatements());
}
public void visit(ReturnStatement node) {
