aboutsummaryrefslogtreecommitdiff
path: root/src/lombok/javac/JavacASTVisitor.java
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@tipit.to>2009-06-27 04:00:12 +0200
committerReinier Zwitserloot <reinier@tipit.to>2009-06-27 04:00:12 +0200
commitb4cab3f65c854ba4bda03528a87bff7654ccb817 (patch)
tree0fa16b171032b919ca8592a65a8e26c6f5e6aba0 /src/lombok/javac/JavacASTVisitor.java
parentb9714eae8ced8d22a319a471331be3a522ebccce (diff)
downloadlombok-b4cab3f65c854ba4bda03528a87bff7654ccb817.tar.gz
lombok-b4cab3f65c854ba4bda03528a87bff7654ccb817.tar.bz2
lombok-b4cab3f65c854ba4bda03528a87bff7654ccb817.zip
[IMPROVEMENT]
Eclipse will now also hold off on running @PrintAST handlers until the very end. Simple generators such as @Getter didn't need this, because PrintAST's handler will hold off until eclipse does a full parse, but when changing the innards of methods, you would likely not see what you did. Fixed that. Also, PrintAST has an option to, instead of diving into the ASTNodes of bodies (methods, initializers, etc), to just render the java code, to see if the AST creation/rewriting you've been doing looks like the java code you intended.
Diffstat (limited to 'src/lombok/javac/JavacASTVisitor.java')
-rw-r--r--src/lombok/javac/JavacASTVisitor.java45
1 files changed, 34 insertions, 11 deletions
diff --git a/src/lombok/javac/JavacASTVisitor.java b/src/lombok/javac/JavacASTVisitor.java
index 714ae294..15d848dd 100644
--- a/src/lombok/javac/JavacASTVisitor.java
+++ b/src/lombok/javac/JavacASTVisitor.java
@@ -73,27 +73,34 @@ public interface JavacASTVisitor {
public static class Printer implements JavacASTVisitor {
private final PrintStream out;
+ private final boolean printContent;
+ private int disablePrinting = 0;
+ private int indent = 0;
- public Printer() {
- this(System.out);
+ public Printer(boolean printContent) {
+ this(printContent, System.out);
}
- public Printer(File file) throws FileNotFoundException {
- this(new PrintStream(file));
+ public Printer(boolean printContent, File file) throws FileNotFoundException {
+ this(printContent, new PrintStream(file));
}
- public Printer(PrintStream out) {
+ public Printer(boolean printContent, PrintStream out) {
+ this.printContent = printContent;
this.out = out;
}
- int indent = 0;
- private void print(String text, Object... params) {
+ private void forcePrint(String text, Object... params) {
StringBuilder sb = new StringBuilder();
for ( int i = 0 ; i < indent ; i++ ) sb.append(" ");
out.printf(sb.append(text).append('\n').toString(), params);
out.flush();
}
+ private void print(String text, Object... params) {
+ if ( disablePrinting == 0 ) forcePrint(text, params);
+ }
+
@Override public void visitCompilationUnit(Node Node, JCCompilationUnit unit) {
out.println("---------------------------------------------------------");
@@ -112,7 +119,7 @@ public interface JavacASTVisitor {
}
@Override public void visitAnnotationOnType(JCClassDecl type, Node node, JCAnnotation annotation) {
- print("<ANNOTATION: %s />", annotation);
+ forcePrint("<ANNOTATION: %s />", annotation);
}
@Override public void endVisitType(Node node, JCClassDecl type) {
@@ -124,9 +131,14 @@ public interface JavacASTVisitor {
print("<%s INITIALIZER>",
initializer.isStatic() ? "static" : "instance");
indent++;
+ if ( printContent ) {
+ print("%s", initializer);
+ disablePrinting++;
+ }
}
@Override public void endVisitInitializer(Node node, JCBlock initializer) {
+ if ( printContent ) disablePrinting--;
indent--;
print("</%s INITIALIZER>", initializer.isStatic() ? "static" : "instance");
}
@@ -134,13 +146,18 @@ public interface JavacASTVisitor {
@Override public void visitField(Node node, JCVariableDecl field) {
print("<FIELD %s %s>", field.vartype, field.name);
indent++;
+ if ( printContent ) {
+ if ( field.init != null ) print("%s", field.init);
+ disablePrinting++;
+ }
}
@Override public void visitAnnotationOnField(JCVariableDecl field, Node node, JCAnnotation annotation) {
- print("<ANNOTATION: %s />", annotation);
+ forcePrint("<ANNOTATION: %s />", annotation);
}
@Override public void endVisitField(Node node, JCVariableDecl field) {
+ if ( printContent ) disablePrinting--;
indent--;
print("</FIELD %s %s>", field.vartype, field.name);
}
@@ -154,13 +171,19 @@ public interface JavacASTVisitor {
} else type = "METHOD";
print("<%s %s> returns: %s", type, method.name, method.restype);
indent++;
+ if ( printContent ) {
+ if ( method.body == null ) print("(ABSTRACT)");
+ else print("%s", method.body);
+ disablePrinting++;
+ }
}
@Override public void visitAnnotationOnMethod(JCMethodDecl method, Node node, JCAnnotation annotation) {
- print("<ANNOTATION: %s />", annotation);
+ forcePrint("<ANNOTATION: %s />", annotation);
}
@Override public void endVisitMethod(Node node, JCMethodDecl method) {
+ if ( printContent ) disablePrinting--;
indent--;
print("</%s %s>", "XMETHOD", method.name);
}
@@ -171,7 +194,7 @@ public interface JavacASTVisitor {
}
@Override public void visitAnnotationOnMethodArgument(JCVariableDecl arg, JCMethodDecl method, Node nodeAnnotation, JCAnnotation annotation) {
- print("<ANNOTATION: %s />", annotation);
+ forcePrint("<ANNOTATION: %s />", annotation);
}
@Override public void endVisitMethodArgument(Node node, JCVariableDecl arg, JCMethodDecl method) {