net.intelie.pipes.ast.AutomatonVisitor 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 net.intelie.pipes.util.AutomatonRepr;
public class AutomatonVisitor extends AstVisitor {
private AutomatonRepr.LabelLines makeLabel(SourceLocation location, Object value) {
AutomatonRepr.LabelLines label = new AutomatonRepr.LabelLines();
if (location != null && location.getCode() != null) {
String code = location.getCode();
if (code.length() > 43)
code = code.substring(0, 30) + "..." + code.substring(code.length() - 10);
label.setTooltip(code);
}
label.addLine(6, location != null && location.getType() != SourceLocation.Type.NONE ? location.getType() : "");
label.addLine(10, value);
label.addLine(8, location);
return label;
}
@Override
public AutomatonRepr visitRaw(RawNode node) throws PipeException {
AutomatonRepr repr = new AutomatonRepr("x");
repr.addNode("note", "x", makeLabel(node.getLocation(), node.getValue()));
return repr;
}
@Override
public AutomatonRepr visitLiteral(LiteralNode node) throws PipeException {
AutomatonRepr repr = new AutomatonRepr("x");
repr.addNode("rectangle", "x", makeLabel(node.getLocation(), node));
return repr;
}
@Override
public AutomatonRepr visitCall(CallNode node) throws PipeException {
AutomatonRepr repr = new AutomatonRepr("x");
repr.addNode("rectangle", "x", makeLabel(node.getLocation(), node.getName() + "()"));
int i = 0;
for (AstNode child : node.getArgs()) {
repr.addEdge("x", "p" + i++ + "_", visit(child), "");
}
return repr;
}
}