コード例 #1
0
  /**
   * Translates the body of the package and writes it to the output stream.
   *
   * @param out The output stream.
   * @return The output stream.
   */
  public Printer translate(Printer out) {
    // Include the header file
    out.p("#include \"").p(getFilename()).pln(".h\"").pln();

    // Print the array template specializations for the classes in this package
    out.pln("namespace __rt {").incr();
    for (JavaFile f : files) {
      for (JavaClass cls : f.getClasses()) {
        cls.translateArrayTemplate(out);
      }
    }
    out.decr().pln("}").pln();

    // Add the namespace
    for (String part : pkg) {
      out.indent().p("namespace ").p(part).pln(" {").incr();
    }

    // Print all the files in the package
    for (JavaFile f : files) {
      for (JavaClass cls : f.getClasses()) {
        cls.translate(out).pln();
      }
      out.pln();
    }

    // Close the namespace
    for (int i = 0; i < pkg.size(); i++) {
      out.decr().indent().pln("}");
    }

    // If this package contains the main file, print the main method here
    if (null != main) {
      out.pln("int main(int argc, char *argv[]) {").incr();
      out.indent().pln("__rt::Ptr<__rt::Array<String> > args = new __rt::Array<String>(argc-1);");
      out.indent().pln("for (int i = 1; i < argc; i++) {").incr();
      out.indent().pln("(*args)[i-1] = __rt::literal(argv[i]);");
      out.decr().indent().pln("}");
      out.indent();
      if (!getNamespace().equals("")) out.p(getNamespace()).p("::");
      out.p("__").p(main.getPublicClass().getName()).pln("::main$array1_String(args);");
      out.decr().pln("}");
    }

    return out;
  }
コード例 #2
0
 /**
  * Recursively orders files based on dependencies.
  *
  * @param file The file to add to the list.
  */
 private void order(JavaFile file) {
   if (file.isMain()) main = file;
   if (files.contains(file)) return;
   if (file.getPublicClass().hasParent()) order(file.getPublicClass().getParent().getFile());
   files.add(file);
 }