Exemplo n.º 1
0
 public static void main(String argv[]) {
   /*  	Avatar u=new Avatar();
   //    Unicorn u=new Unicorn();
     	JooFrame jf=new JooFrame(u);
     	jf.show();                  */
   for (int i = 0; i < argv.length; i++) {
     String filename = argv[i];
     JavaParser jw = new JavaParser(filename);
     jw.read();
     // ((Class)jw.classes.get(0)).jooify();
     jw.jooify();
     jw.write();
   }
 }
Exemplo n.º 2
0
  @SuppressWarnings({"ConstantConditions"})
  protected void run(String[] args) {
    System.out.println("parboiled Java parser, performance test");
    System.out.println("---------------------------------------");

    System.out.print("Creating parser... :");
    long start = System.currentTimeMillis();
    Parboiled.createParser(JavaParser.class);
    time(start);

    System.out.print("Creating 100 more parser instances... :");
    JavaParser parser = null;
    start = System.currentTimeMillis();
    for (int i = 0; i < 100; i++) {
      parser = Parboiled.createParser(JavaParser.class);
    }
    time(start);

    System.out.print("Creating 100 more parser instances using BaseParser.newInstance() ... :");
    start = System.currentTimeMillis();
    for (int i = 0; i < 100; i++) {
      parser = parser.newInstance();
    }
    time(start);

    start = System.currentTimeMillis();
    File baseDir = args.length == 1 ? new File(args[0]) : null;
    if (baseDir == null || !baseDir.exists()) baseDir = new File(".");
    System.out.printf("Retrieving file list from '%s'", baseDir);
    List<File> sources = recursiveGetAllJavaSources(baseDir, new ArrayList<File>());
    time(start);

    System.out.printf("Parsing all %s given java sources", sources.size());
    Rule rootRule =
        parser.CompilationUnit().suppressNode(); // we want to see the parse-tree-less performance
    start = System.currentTimeMillis();
    long lines = 0, characters = 0;
    for (File sourceFile : sources) {
      long dontCountStart = System.currentTimeMillis();
      String sourceText = readAllText(sourceFile);
      start +=
          System.currentTimeMillis()
              - dontCountStart; // do not count the time for reading the text file

      ParsingResult<?> result = null;
      try {
        result = run(rootRule, sourceText);
      } catch (Exception e) {
        System.out.printf("\nException while parsing file '%s':\n%s", sourceFile, e);
        System.exit(1);
      }
      if (!result.matched) {
        System.out.printf(
            "\nParse error(s) in file '%s':\n%s", sourceFile, printParseErrors(result));
        System.exit(1);
      } else {
        System.out.print('.');
      }
      lines += result.inputBuffer.getLineCount();
      characters += sourceText.length();
    }
    long time = time(start);

    System.out.println("Parsing performance:");
    System.out.printf(
        "    %6d Files -> %6.2f Files/sec\n", sources.size(), sources.size() * 1000.0 / time);
    System.out.printf("    %6d Lines -> %6d Lines/sec\n", lines, lines * 1000 / time);
    System.out.printf("    %6d Chars -> %6d Chars/sec\n", characters, characters * 1000 / time);
  }