diff options
author | Reinier Zwitserloot <reinier@tipit.to> | 2009-06-18 01:17:03 +0200 |
---|---|---|
committer | Reinier Zwitserloot <reinier@tipit.to> | 2009-06-18 01:17:03 +0200 |
commit | 6254337948180140a47c872cb046cdff7e1326c4 (patch) | |
tree | 59c859e43589130892d962ee67dd166f10b031a6 /src/lombok/javac/JavacASTVisitor.java | |
parent | eca3cd7ccc6e8c5736f5a70c3b1c095bd949689d (diff) | |
download | lombok-6254337948180140a47c872cb046cdff7e1326c4.tar.gz lombok-6254337948180140a47c872cb046cdff7e1326c4.tar.bz2 lombok-6254337948180140a47c872cb046cdff7e1326c4.zip |
Expanded the AST printers to support a target PrintStream, and expanded the @PrintAST annotation to let you supply an optional filename. Useful particularly for IDEs, which don't usually have a viewable console.
Also renamed the printers to just 'Printer', as they are already inner classes of a specifically named type (JavacASTVisitor & co).
Diffstat (limited to 'src/lombok/javac/JavacASTVisitor.java')
-rw-r--r-- | src/lombok/javac/JavacASTVisitor.java | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/lombok/javac/JavacASTVisitor.java b/src/lombok/javac/JavacASTVisitor.java index 5c9c736f..4dc40784 100644 --- a/src/lombok/javac/JavacASTVisitor.java +++ b/src/lombok/javac/JavacASTVisitor.java @@ -1,5 +1,9 @@ package lombok.javac; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintStream; + import lombok.javac.JavacAST.Node; import com.sun.tools.javac.tree.JCTree; @@ -66,16 +70,31 @@ public interface JavacASTVisitor { void visitStatement(Node statementNode, JCTree statement); void endVisitStatement(Node statementNode, JCTree statement); - public static class JavacASTPrinter implements JavacASTVisitor { + public static class Printer implements JavacASTVisitor { + private final PrintStream out; + + public Printer() { + this(System.out); + } + + public Printer(File file) throws FileNotFoundException { + this(new PrintStream(file)); + } + + public Printer(PrintStream out) { + this.out = out; + } + int indent = 0; private void print(String text, Object... params) { StringBuilder sb = new StringBuilder(); for ( int i = 0 ; i < indent ; i++ ) sb.append(" "); - System.out.printf(sb.append(text).append('\n').toString(), params); + out.printf(sb.append(text).append('\n').toString(), params); + out.flush(); } @Override public void visitCompilationUnit(Node Node, JCCompilationUnit unit) { - System.out.println("---------------------------------------------------------"); + out.println("---------------------------------------------------------"); print("<CU %s>", Node.getFileName()); indent++; |