95 lines
1.9 KiB
Java
95 lines
1.9 KiB
Java
package com.dbgen;
|
|
|
|
import java.io.PrintStream;
|
|
import java.util.Collection;
|
|
|
|
class Trace implements Visitor {
|
|
private final String varname;
|
|
private final PrintStream ps;
|
|
private final String prefix;
|
|
|
|
|
|
public static void make(Jbean bean, PrintStream ps, String prefix) {
|
|
make(bean.getVariables(), ps, prefix);
|
|
}
|
|
|
|
public static void make(Collection<Variable> variables, PrintStream ps, String prefix) {
|
|
ps.println(prefix + "@Override");
|
|
ps.println(prefix + "public String toString() {");
|
|
ps.println(prefix + " StringBuilder _sb_ = new StringBuilder(super.toString());");
|
|
ps.println(prefix + " _sb_.append(\"=(\");");
|
|
variables.forEach(var -> var.getType().accept(new Trace(var.getName(), ps, prefix + " ")));
|
|
ps.println(prefix + " _sb_.append(\")\");");
|
|
ps.println(prefix + " return _sb_.toString();");
|
|
ps.println(prefix + "}");
|
|
ps.println();
|
|
}
|
|
|
|
private Trace(String varname, PrintStream ps, String prefix) {
|
|
this.varname = "this." + varname;
|
|
this.ps = ps;
|
|
this.prefix = prefix;
|
|
}
|
|
|
|
private void simple() {
|
|
ps.println(prefix + "_sb_.append(" + varname + ").append(\",\");");
|
|
}
|
|
|
|
|
|
@Override
|
|
public void visit(TypeFloat type) {
|
|
simple();
|
|
}
|
|
|
|
@Override
|
|
public void visit(TypeDouble type) {
|
|
simple();
|
|
}
|
|
|
|
@Override
|
|
public void visit(TypeInt type) {
|
|
simple();
|
|
}
|
|
|
|
@Override
|
|
public void visit(TypeShort type) {
|
|
simple();
|
|
}
|
|
|
|
@Override
|
|
public void visit(TypeList type) {
|
|
simple();
|
|
}
|
|
|
|
@Override
|
|
public void visit(TypeLong type) {
|
|
simple();
|
|
}
|
|
|
|
@Override
|
|
public void visit(TypeMap type) {
|
|
simple();
|
|
}
|
|
|
|
|
|
@Override
|
|
public void visit(TypeSet type) {
|
|
simple();
|
|
}
|
|
|
|
@Override
|
|
public void visit(TypeString type) {
|
|
ps.println(prefix + "_sb_.append(\"T\").append(" + varname + ".length()).append(\",\");");
|
|
}
|
|
@Override
|
|
public void visit(Jbean type) {
|
|
simple();
|
|
}
|
|
|
|
@Override
|
|
public void visit(TypeBoolean type) {
|
|
simple();
|
|
}
|
|
|
|
}
|