diff options
Diffstat (limited to 'src/lombok/javac/handlers/HandlePrintAST.java')
-rw-r--r-- | src/lombok/javac/handlers/HandlePrintAST.java | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/lombok/javac/handlers/HandlePrintAST.java b/src/lombok/javac/handlers/HandlePrintAST.java index 3a738b4f..6becb7b8 100644 --- a/src/lombok/javac/handlers/HandlePrintAST.java +++ b/src/lombok/javac/handlers/HandlePrintAST.java @@ -1,9 +1,14 @@ package lombok.javac.handlers; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintStream; + import org.mangosdk.spi.ProviderFor; import com.sun.tools.javac.tree.JCTree.JCAnnotation; +import lombok.Lombok; import lombok.core.AnnotationValues; import lombok.core.PrintAST; import lombok.javac.JavacASTVisitor; @@ -13,7 +18,16 @@ import lombok.javac.JavacAST.Node; @ProviderFor(JavacAnnotationHandler.class) public class HandlePrintAST implements JavacAnnotationHandler<PrintAST> { @Override public boolean handle(AnnotationValues<PrintAST> annotation, JCAnnotation ast, Node annotationNode) { - annotationNode.up().traverse(new JavacASTVisitor.JavacASTPrinter()); + PrintStream stream = System.out; + String fileName = annotation.getInstance().outfile(); + if ( fileName.length() > 0 ) try { + stream = new PrintStream(new File(fileName)); + } catch ( FileNotFoundException e ) { + Lombok.sneakyThrow(e); + } + + annotationNode.up().traverse(new JavacASTVisitor.Printer(stream)); + return true; } } |