From 6254337948180140a47c872cb046cdff7e1326c4 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Thu, 18 Jun 2009 01:17:03 +0200 Subject: 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). --- src/lombok/eclipse/handlers/HandlePrintAST.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/lombok/eclipse/handlers') 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 { @Override public boolean handle(AnnotationValues 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; } } -- cgit