net.intelie.pipes.ast.AstVisitorBase Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pipes-api Show documentation
Show all versions of pipes-api Show documentation
Intelie Pipes' API classes and interfaces
package net.intelie.pipes.ast;
import net.intelie.pipes.PipeException;
import java.util.ArrayList;
import java.util.List;
public class AstVisitorBase extends AstVisitor {
@Override
public List visitList(List nodes) throws PipeException {
List list = null;
for (int i = 0; i < nodes.size(); i++) {
AstNode node = nodes.get(i);
List expanded = visitExpanding(node);
if (expanded != null) {
if (list == null)
list = new ArrayList<>(nodes.subList(0, i));
list.addAll(expanded);
} else {
AstNode visited = visit(node);
if (node != visited || list != null) {
if (list == null)
list = new ArrayList<>(nodes.subList(0, i));
list.add(visited);
}
}
}
return list != null ? list : nodes;
}
public List visitExpanding(AstNode node) throws PipeException {
return null;
}
@Override
public AstNode visitRaw(RawNode node) {
return node;
}
@Override
public AstNode visitLiteral(LiteralNode node) {
return node;
}
@Override
public AstNode visitCall(CallNode node) throws PipeException {
List children = node.getArgs();
List newChildren = visitList(children);
if (children == newChildren)
return node;
return new CallNode(node.getLocation(), node.getName(), newChildren);
}
}