private List<Diagnostic<? extends JavaFileObject>> doCompile() {
    List<VolatileJavaFile> sources = packager.getEmitter().getEmitted();
    if (dump) {
      for (JavaFileObject java : sources) {
        try {
          System.out.println("====" + java.getName());
          System.out.println(java.getCharContent(true));
        } catch (IOException e) {
          // ignore.
        }
      }
    }

    for (JavaFileObject java : sources) {
      javaCompiler.addSource(java);
    }
    if (sources.isEmpty()) {
      javaCompiler.addSource(new VolatileJavaFile("A", "public class A {}"));
    }
    List<Diagnostic<? extends JavaFileObject>> diagnostics = javaCompiler.doCompile();
    if (dump) {
      for (Diagnostic<? extends JavaFileObject> d : diagnostics) {
        System.out.println("====");
        System.out.println(d);
      }
    }
    return diagnostics;
  }
 // PROVIDED FOR EXTREME BACKWARDS COMPATIBILITY
 // There are some very obscure errors that can arise while translating
 // the contents of a file from bytes to characters. In Tiger, these
 // diagnostics were ignored. This method provides compatibility with
 // that behavior. It would be better to honor those diagnostics, in which
 // case, this method can be deleted.
 @Override
 public CharSequence readSource(JavaFileObject filename) {
   try {
     inputFiles.add(filename);
     boolean prev = bark.setDiagnosticsIgnored(true);
     try {
       return filename.getCharContent(false);
     } finally {
       bark.setDiagnosticsIgnored(prev);
     }
   } catch (IOException e) {
     bark.error(Position.NOPOS, "cant.read.file", filename);
     return null;
   }
 }
Exemplo n.º 3
0
  public void print(Writer out) throws IOException {
    if (!changed) {
      JavaFileObject sourceFile = compilationUnit.getSourceFile();
      if (sourceFile != null) {
        out.write(sourceFile.getCharContent(true).toString());
        return;
      }
    }

    out.write("// Generated by delombok at ");
    out.write(String.valueOf(new Date()));
    out.write(System.getProperty("line.separator"));

    com.sun.tools.javac.util.List<Comment> comments_;
    if (comments instanceof com.sun.tools.javac.util.List)
      comments_ = (com.sun.tools.javac.util.List<Comment>) comments;
    else comments_ = com.sun.tools.javac.util.List.from(comments.toArray(new Comment[0]));

    compilationUnit.accept(new PrettyCommentsPrinter(out, compilationUnit, comments_));
  }