コード例 #1
0
  public static void gen() {
    Compiler c = new Compiler();
    // VisitorBaseGen baseGen = new VisitorBaseGen(true);
    VisitorBaseGen baseGen = new VisitorBaseGen(false);

    for (int nest = 0; nest <= 1; nest++) {
      for (int len = 1; len <= 3; len++) {
        List<MethodDecl> decls;
        if (nest == 1) {
          decls = getMethodDecls(nest, len, true);
          baseGen.addAll(decls);
        } else {
          decls = getMethodDecls(nest, len, false);
          baseGen.addAll(decls);
        }
      }
    }
    String visitorImpl = VisitorCodeGen.visitorPackage + ".VisitorImpl";
    boolean success = c.compile(visitorImpl, baseGen.generate());
    if (!success) {
      String msg = "Cannot compile VisitorImpl class";
      System.out.println(c.getErrorMsg());
      throw new SociaLiteException(msg);
    }
  }
コード例 #2
0
  public static LinkedHashMap<String, byte[]> generate(Config conf, List<Table> tables) {
    LinkedHashMap<String, byte[]> generatedClasses = new LinkedHashMap<String, byte[]>();
    for (Table t : tables) {
      if (t.numColumns() <= 3) continue;

      MethodDecls decls = new MethodDecls();
      for (int i = 0; i < t.getColumnGroups().size(); i++) {
        ColumnGroup cg = t.getColumnGroups().get(i);
        if (i == 0 && cg.size() <= 3) continue;
        if (i == 1 && cg.size() == 1) continue;

        boolean last = (i == t.getColumnGroups().size() - 1);
        if (last && cg.size() <= 3) continue;

        decls.add(new MethodDecl(cg.columns(), last));
      }
      if (decls.isEmpty()) continue;

      Compiler c = new Compiler(conf.isVerbose());
      VisitorBaseGen baseGen = new VisitorBaseGen(false);
      String fullname = VisitorCodeGen.visitorPackage + "." + baseGen.name();
      t.setVisitorInterface(fullname);
      for (MethodDecl d : decls) baseGen.add(d);
      boolean success = c.compile(fullname, baseGen.generate());
      if (!success) {
        String msg = "Cannot compile " + fullname + ".class";
        throw new SociaLiteException(msg);
      }
      generatedClasses.putAll(c.getCompiledClasses());
    }
    return generatedClasses;
  }