104 lines
2.1 KiB
Java
104 lines
2.1 KiB
Java
package com.dbgen;
|
|
|
|
import java.io.PrintStream;
|
|
|
|
class VarCopyFrom implements Visitor {
|
|
|
|
static void make(Variable var, PrintStream ps, String prefix) {
|
|
var.getType().accept(new VarCopyFrom(var, ps, prefix));
|
|
}
|
|
|
|
private static String getCopy(Type type, String fullvarname, String parentVarname) {
|
|
if (type instanceof Jbean) {
|
|
return "new " + type.getName() + "(" + fullvarname + ")";
|
|
} else {
|
|
return fullvarname;
|
|
}
|
|
}
|
|
|
|
private PrintStream ps;
|
|
private String prefix;
|
|
private String varname;
|
|
private String this_varname;
|
|
|
|
private VarCopyFrom(Variable var, PrintStream ps, String prefix) {
|
|
this.ps = ps;
|
|
this.prefix = prefix;
|
|
this.varname = var.getName();
|
|
this.this_varname = "this." + this.varname;
|
|
}
|
|
|
|
private void simple() {
|
|
ps.println(prefix + this_varname + " = _o_." + varname + ";");
|
|
}
|
|
|
|
@Override
|
|
public void visit(TypeBoolean type) {
|
|
simple();
|
|
}
|
|
|
|
@Override
|
|
public void visit(TypeShort type) {
|
|
simple();
|
|
}
|
|
|
|
@Override
|
|
public void visit(TypeInt type) {
|
|
simple();
|
|
}
|
|
|
|
@Override
|
|
public void visit(TypeLong type) {
|
|
simple();
|
|
}
|
|
|
|
@Override
|
|
public void visit(TypeFloat type) {
|
|
simple();
|
|
}
|
|
|
|
@Override
|
|
public void visit(TypeDouble type) {
|
|
simple();
|
|
}
|
|
|
|
|
|
private void collection(Type type, Type value, String posttype) {
|
|
ps.println(prefix + "_o_." + varname + ".forEach(_v_ -> this_" + varname + ".add("
|
|
+ getCopy(value, "_v_", varname) + "));");
|
|
}
|
|
|
|
@Override
|
|
public void visit(TypeString type) {
|
|
simple();
|
|
}
|
|
|
|
@Override
|
|
public void visit(TypeList type) {
|
|
collection(type, type.getValueType(), "List");
|
|
}
|
|
|
|
@Override
|
|
public void visit(TypeSet type) {
|
|
collection(type, type.getValueType(), "Set");
|
|
}
|
|
|
|
@Override
|
|
public void visit(TypeMap type) {
|
|
Type key = type.getKeyType();
|
|
Type value = type.getValueType();
|
|
String keycopy = getCopy(key, "_k_", varname);
|
|
String valuecopy = getCopy(value, "_v_", varname);
|
|
ps.println(prefix + "_o_." + varname + ".forEach((_k_, _v_) -> this." + varname + ".put(" + keycopy + ", "
|
|
+ valuecopy + "));");
|
|
}
|
|
|
|
|
|
@Override
|
|
public void visit(Jbean type) {
|
|
ps.println(prefix + this_varname + ".copyFrom(_o_." + varname + ");");
|
|
}
|
|
|
|
|
|
}
|