package com.dbgen; import java.io.PrintStream; import java.util.Collection; public class ClassDeclare implements Visitor { public enum Type { PUBLIC, PRIVATE } private final String varname; private final String comment; private String text; public String getVarname() { return varname; } public String getComment() { return comment; } public String getText() { return text; } public ClassDeclare(String varname, String comment) { this.varname = varname; this.comment = comment; } public void make(Variable var, Type type) { text =(type == Type.PUBLIC ? "public " : "private ") + TypeName.getName(var.getType()) + " " + getVarname() + "; " + getComment(); } public void make0(com.dbgen.Type type) { text ="private " + TypeName.getName(type) + " "+ getVarname() + "; " + getComment(); } public void make1(com.dbgen.Type type) { text ="private " + TypeName.getName(type) + " "+ getVarname() + " = new " + TypeName.getName(type) + "();" + getComment(); } public static void make(Collection variables, PrintStream ps, String prefix) { variables.forEach(var -> { ClassDeclare e = new ClassDeclare(var.getName(),var.getComment()); var.getType().accept(e); ps.println(prefix + e.getText()); if(var.getType() instanceof TypeSet || var.getType() instanceof TypeList){ e.visitWrop(var.getType(),ps, prefix); ps.println(); } if( var.getType() instanceof TypeMap){ String kn = TypeName.getBoxingName( ((TypeMap)var.getType()).getKeyType()); String vn = TypeName.getBoxingName( ((TypeMap)var.getType()).getValueType()); String tn = "HashMap"; ps.print(prefix+ "@Transient"); ps.println(); ps.print(prefix+ "private " + "Log"+"" + tn + "<" + kn + ", " + vn + ", " + "Map<" + kn + ", " + vn + ">"+ ">" + " "+ var.getName()+ "Log ;"); ps.println(); } }); } @Override public void visit(TypeBoolean type) { make0(type); } @Override public void visit(TypeShort type) { make0(type); } @Override public void visit(TypeInt type) { make0(type); } @Override public void visit(TypeLong type) { make0(type); } @Override public void visit(TypeFloat type) { make0(type); } @Override public void visit(TypeDouble type) { make0(type); } @Override public void visit(TypeString type) { make0(type); } @Override public void visit(TypeList type) { make1(type); } @Override public void visit(TypeSet type) { make1(type); } @Override public void visit(TypeMap type) { make1(type); } @Override public void visit(Jbean type) { make0(type); } public void visitWrop(com.dbgen.Type type, PrintStream ps, String prefix) { ps.print(prefix+ "private " + "Log"+TypeName.getName(type) + " "+ getVarname()+ "Log ;"); } }