sqlancer.common.visitor.ToStringVisitor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sqlancer Show documentation
Show all versions of sqlancer Show documentation
SQLancer finds logic bugs in Database Management Systems through automatic testing
package sqlancer.common.visitor;
import java.util.List;
import sqlancer.common.visitor.UnaryOperation.OperatorKind;
public abstract class ToStringVisitor extends NodeVisitor {
protected final StringBuilder sb = new StringBuilder();
public void visit(BinaryOperation op) {
sb.append('(');
sb.append('(');
visit(op.getLeft());
sb.append(')');
sb.append(op.getOperatorRepresentation());
sb.append('(');
visit(op.getRight());
sb.append(')');
sb.append(')');
}
public void visit(UnaryOperation op) {
if (!op.omitBracketsWhenPrinting()) {
sb.append('(');
}
if (op.getOperatorKind() == OperatorKind.PREFIX) {
sb.append(op.getOperatorRepresentation());
sb.append(' ');
}
if (!op.omitBracketsWhenPrinting()) {
sb.append('(');
}
visit(op.getExpression());
if (!op.omitBracketsWhenPrinting()) {
sb.append(')');
}
if (op.getOperatorKind() == OperatorKind.POSTFIX) {
sb.append(' ');
sb.append(op.getOperatorRepresentation());
}
if (!op.omitBracketsWhenPrinting()) {
sb.append(')');
}
}
@SuppressWarnings("unchecked")
public void visit(T expr) {
assert expr != null;
if (expr instanceof BinaryOperation>) {
visit((BinaryOperation) expr);
} else if (expr instanceof UnaryOperation>) {
visit((UnaryOperation) expr);
} else {
visitSpecific(expr);
}
}
public abstract void visitSpecific(T expr);
public void visit(List expressions) {
for (int i = 0; i < expressions.size(); i++) {
if (i != 0) {
sb.append(", ");
}
visit(expressions.get(i));
}
}
public String get() {
return sb.toString();
}
}