aboutsummaryrefslogtreecommitdiff
path: root/src/lombok/eclipse
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@tipit.to>2009-06-18 01:17:03 +0200
committerReinier Zwitserloot <reinier@tipit.to>2009-06-18 01:17:03 +0200
commit6254337948180140a47c872cb046cdff7e1326c4 (patch)
tree59c859e43589130892d962ee67dd166f10b031a6 /src/lombok/eclipse
parenteca3cd7ccc6e8c5736f5a70c3b1c095bd949689d (diff)
downloadlombok-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/eclipse')
-rw-r--r--src/lombok/eclipse/EclipseASTVisitor.java21
-rw-r--r--src/lombok/eclipse/handlers/HandlePrintAST.java16
2 files changed, 34 insertions, 3 deletions
diff --git a/src/lombok/eclipse/EclipseASTVisitor.java b/src/lombok/eclipse/EclipseASTVisitor.java
index 0e07162c..d5fece8f 100644
--- a/src/lombok/eclipse/EclipseASTVisitor.java
+++ b/src/lombok/eclipse/EclipseASTVisitor.java
@@ -1,5 +1,8 @@
package lombok.eclipse;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.PrintStream;
import java.lang.reflect.Modifier;
import lombok.eclipse.EclipseAST.Node;
@@ -79,12 +82,26 @@ public interface EclipseASTVisitor {
void visitStatement(Node statementNode, Statement statement);
void endVisitStatement(Node statementNode, Statement statement);
- public static class EclipseASTPrinter implements EclipseASTVisitor {
+ public static class Printer implements EclipseASTVisitor {
+ 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();
}
private String str(char[] c) {
diff --git a/src/lombok/eclipse/handlers/HandlePrintAST.java b/src/lombok/eclipse/handlers/HandlePrintAST.java
index 4438f4e4..ae34c5c2 100644
--- a/src/lombok/eclipse/handlers/HandlePrintAST.java
+++ b/src/lombok/eclipse/handlers/HandlePrintAST.java
@@ -1,8 +1,13 @@
package lombok.eclipse.handlers;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.PrintStream;
+
import org.eclipse.jdt.internal.compiler.ast.Annotation;
import org.mangosdk.spi.ProviderFor;
+import lombok.Lombok;
import lombok.core.AnnotationValues;
import lombok.core.PrintAST;
import lombok.eclipse.EclipseASTVisitor;
@@ -13,7 +18,16 @@ import lombok.eclipse.EclipseAST.Node;
public class HandlePrintAST implements EclipseAnnotationHandler<PrintAST> {
@Override public boolean handle(AnnotationValues<PrintAST> annotation, Annotation ast, Node annotationNode) {
if ( !annotationNode.isCompleteParse() ) return false;
- annotationNode.up().traverse(new EclipseASTVisitor.EclipseASTPrinter());
+
+ 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 EclipseASTVisitor.Printer(stream));
return true;
}
}