aboutsummaryrefslogtreecommitdiff
path: root/src/lombok/javac
diff options
context:
space:
mode:
Diffstat (limited to 'src/lombok/javac')
-rw-r--r--src/lombok/javac/JavacASTVisitor.java25
-rw-r--r--src/lombok/javac/handlers/HandlePrintAST.java16
2 files changed, 37 insertions, 4 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++;
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;
}
}