102 lines
2.0 KiB
Java
102 lines
2.0 KiB
Java
package com.dbgen;
|
|
|
|
import java.io.PrintStream;
|
|
import java.util.Collection;
|
|
|
|
public class Construct implements Visitor {
|
|
private final PrintStream ps;
|
|
private final String variable;
|
|
private final String varname;
|
|
private final String prefix;
|
|
|
|
private static void make(Collection<Variable> variables, String name, PrintStream ps, String prefix, Naming variableParent) {
|
|
ps.println(prefix + "public " + name + "() {");
|
|
if (!variableParent.baseclass.isEmpty()) {
|
|
ps.println(prefix + prefix + "super();");
|
|
}
|
|
for (Variable var : variables)
|
|
make(var, ps, prefix + " ");
|
|
ps.println(prefix + "}");
|
|
ps.println();
|
|
}
|
|
|
|
|
|
public static void make(Jbean bean, PrintStream ps, String prefix) {
|
|
make(bean.getVariables(), bean.getLastName(), ps, prefix,bean);
|
|
}
|
|
|
|
|
|
public static void make(Variable var, PrintStream ps, String prefix) {
|
|
var.getType().accept(new Construct(var.getName(), ps, prefix));
|
|
}
|
|
|
|
public Construct(String varname, PrintStream ps, String prefix) {
|
|
this.variable = varname;
|
|
this.varname = varname;
|
|
this.ps = ps;
|
|
this.prefix = prefix;
|
|
}
|
|
|
|
private void initial() {
|
|
}
|
|
|
|
private void newVariable(Type type) {
|
|
ps.println(prefix + variable + " = new " + TypeName.getName(type) + "();");
|
|
}
|
|
|
|
@Override
|
|
public void visit(TypeFloat type) {
|
|
initial();
|
|
}
|
|
|
|
@Override
|
|
public void visit(TypeDouble type) {
|
|
initial();
|
|
}
|
|
|
|
@Override
|
|
public void visit(TypeBoolean type) {
|
|
initial();
|
|
}
|
|
@Override
|
|
public void visit(TypeInt type) {
|
|
initial();
|
|
}
|
|
|
|
@Override
|
|
public void visit(TypeShort type) {
|
|
initial();
|
|
}
|
|
|
|
@Override
|
|
public void visit(TypeLong type) {
|
|
initial();
|
|
}
|
|
|
|
@Override
|
|
public void visit(TypeString type) {
|
|
ps.println(prefix + variable + " = \"\";");
|
|
}
|
|
|
|
@Override
|
|
public void visit(TypeList type) {
|
|
newVariable(type);
|
|
}
|
|
|
|
|
|
@Override
|
|
public void visit(TypeSet type) {
|
|
newVariable(type);
|
|
}
|
|
|
|
@Override
|
|
public void visit(TypeMap type) {
|
|
newVariable(type);
|
|
}
|
|
|
|
@Override
|
|
public void visit(Jbean type) {
|
|
ps.println(prefix + variable + " = new " + type.getName() + "(this, " + StringUtils.quote(varname) + ");");
|
|
}
|
|
}
|