diff options
author | Reinier Zwitserloot <reinier@tipit.to> | 2009-10-16 09:32:36 +0200 |
---|---|---|
committer | Reinier Zwitserloot <reinier@tipit.to> | 2009-10-16 09:32:36 +0200 |
commit | b5c8b725655d2ad8a715cfb1fbbdf25dbdcd4ceb (patch) | |
tree | 571d13cd7028a6b7d1ebfe84180a4328a20c42d7 /src/lombok/javac/JavacASTVisitor.java | |
parent | 8629a651a66aa5fba9e0ada7df00803528b0e34f (diff) | |
download | lombok-b5c8b725655d2ad8a715cfb1fbbdf25dbdcd4ceb.tar.gz lombok-b5c8b725655d2ad8a715cfb1fbbdf25dbdcd4ceb.tar.bz2 lombok-b5c8b725655d2ad8a715cfb1fbbdf25dbdcd4ceb.zip |
Fixed issue #24 by refactoring the AST.Node class - taken it out, and in the process fixed a lot of type annoyance by adding more generics.
Also changed coding style from for/while/if/switch/catch/do ( expr ) {} to for (expr) {}, hence the changes _everywhere_.
Diffstat (limited to 'src/lombok/javac/JavacASTVisitor.java')
-rw-r--r-- | src/lombok/javac/JavacASTVisitor.java | 118 |
1 files changed, 58 insertions, 60 deletions
diff --git a/src/lombok/javac/JavacASTVisitor.java b/src/lombok/javac/JavacASTVisitor.java index d0902006..3c5887a7 100644 --- a/src/lombok/javac/JavacASTVisitor.java +++ b/src/lombok/javac/JavacASTVisitor.java @@ -23,8 +23,6 @@ package lombok.javac; import java.io.PrintStream; -import lombok.javac.JavacAST.Node; - import com.sun.tools.javac.code.Flags; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.JCAnnotation; @@ -35,64 +33,64 @@ import com.sun.tools.javac.tree.JCTree.JCMethodDecl; import com.sun.tools.javac.tree.JCTree.JCVariableDecl; /** - * Implement so you can ask any JavacAST.Node to traverse depth-first through all children, + * Implement so you can ask any JavacAST.LombokNode to traverse depth-first through all children, * calling the appropriate visit and endVisit methods. */ public interface JavacASTVisitor { /** * Called at the very beginning and end. */ - void visitCompilationUnit(Node top, JCCompilationUnit unit); - void endVisitCompilationUnit(Node top, JCCompilationUnit unit); + void visitCompilationUnit(JavacNode top, JCCompilationUnit unit); + void endVisitCompilationUnit(JavacNode top, JCCompilationUnit unit); /** * Called when visiting a type (a class, interface, annotation, enum, etcetera). */ - void visitType(Node typeNode, JCClassDecl type); - void visitAnnotationOnType(JCClassDecl type, Node annotationNode, JCAnnotation annotation); - void endVisitType(Node typeNode, JCClassDecl type); + void visitType(JavacNode typeNode, JCClassDecl type); + void visitAnnotationOnType(JCClassDecl type, JavacNode annotationNode, JCAnnotation annotation); + void endVisitType(JavacNode typeNode, JCClassDecl type); /** * Called when visiting a field of a class. */ - void visitField(Node fieldNode, JCVariableDecl field); - void visitAnnotationOnField(JCVariableDecl field, Node annotationNode, JCAnnotation annotation); - void endVisitField(Node fieldNode, JCVariableDecl field); + void visitField(JavacNode fieldNode, JCVariableDecl field); + void visitAnnotationOnField(JCVariableDecl field, JavacNode annotationNode, JCAnnotation annotation); + void endVisitField(JavacNode fieldNode, JCVariableDecl field); /** * Called for static and instance initializers. You can tell the difference via the isStatic() method. */ - void visitInitializer(Node initializerNode, JCBlock initializer); - void endVisitInitializer(Node initializerNode, JCBlock initializer); + void visitInitializer(JavacNode initializerNode, JCBlock initializer); + void endVisitInitializer(JavacNode initializerNode, JCBlock initializer); /** * Called for both methods and constructors. */ - void visitMethod(Node methodNode, JCMethodDecl method); - void visitAnnotationOnMethod(JCMethodDecl method, Node annotationNode, JCAnnotation annotation); - void endVisitMethod(Node methodNode, JCMethodDecl method); + void visitMethod(JavacNode methodNode, JCMethodDecl method); + void visitAnnotationOnMethod(JCMethodDecl method, JavacNode annotationNode, JCAnnotation annotation); + void endVisitMethod(JavacNode methodNode, JCMethodDecl method); /** * Visits a method argument. */ - void visitMethodArgument(Node argumentNode, JCVariableDecl argument, JCMethodDecl method); - void visitAnnotationOnMethodArgument(JCVariableDecl argument, JCMethodDecl method, Node annotationNode, JCAnnotation annotation); - void endVisitMethodArgument(Node argumentNode, JCVariableDecl argument, JCMethodDecl method); + void visitMethodArgument(JavacNode argumentNode, JCVariableDecl argument, JCMethodDecl method); + void visitAnnotationOnMethodArgument(JCVariableDecl argument, JCMethodDecl method, JavacNode annotationNode, JCAnnotation annotation); + void endVisitMethodArgument(JavacNode argumentNode, JCVariableDecl argument, JCMethodDecl method); /** * Visits a local declaration - that is, something like 'int x = 10;' on the method level. Also called * for method parameters. */ - void visitLocal(Node localNode, JCVariableDecl local); - void visitAnnotationOnLocal(JCVariableDecl local, Node annotationNode, JCAnnotation annotation); - void endVisitLocal(Node localNode, JCVariableDecl local); + void visitLocal(JavacNode localNode, JCVariableDecl local); + void visitAnnotationOnLocal(JCVariableDecl local, JavacNode annotationNode, JCAnnotation annotation); + void endVisitLocal(JavacNode localNode, JCVariableDecl local); /** * Visits a statement that isn't any of the other visit methods (e.g. JCClassDecl). * The statement object is guaranteed to be either a JCStatement or a JCExpression. */ - void visitStatement(Node statementNode, JCTree statement); - void endVisitStatement(Node statementNode, JCTree statement); + void visitStatement(JavacNode statementNode, JCTree statement); + void endVisitStatement(JavacNode statementNode, JCTree statement); /** * Prints the structure of an AST. @@ -125,142 +123,142 @@ public interface JavacASTVisitor { private void forcePrint(String text, Object... params) { StringBuilder sb = new StringBuilder(); - for ( int i = 0 ; i < indent ; i++ ) sb.append(" "); + 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); + if (disablePrinting == 0) forcePrint(text, params); } - @Override public void visitCompilationUnit(Node Node, JCCompilationUnit unit) { + @Override public void visitCompilationUnit(JavacNode LombokNode, JCCompilationUnit unit) { out.println("---------------------------------------------------------"); - print("<CU %s>", Node.getFileName()); + print("<CU %s>", LombokNode.getFileName()); indent++; } - @Override public void endVisitCompilationUnit(Node node, JCCompilationUnit unit) { + @Override public void endVisitCompilationUnit(JavacNode node, JCCompilationUnit unit) { indent--; print("</CUD>"); } - @Override public void visitType(Node node, JCClassDecl type) { + @Override public void visitType(JavacNode node, JCClassDecl type) { print("<TYPE %s>", type.name); indent++; - if ( printContent ) { + if (printContent) { print("%s", type); disablePrinting++; } } - @Override public void visitAnnotationOnType(JCClassDecl type, Node node, JCAnnotation annotation) { + @Override public void visitAnnotationOnType(JCClassDecl type, JavacNode node, JCAnnotation annotation) { forcePrint("<ANNOTATION: %s />", annotation); } - @Override public void endVisitType(Node node, JCClassDecl type) { - if ( printContent ) disablePrinting--; + @Override public void endVisitType(JavacNode node, JCClassDecl type) { + if (printContent) disablePrinting--; indent--; print("</TYPE %s>", type.name); } - @Override public void visitInitializer(Node node, JCBlock initializer) { + @Override public void visitInitializer(JavacNode node, JCBlock initializer) { print("<%s INITIALIZER>", initializer.isStatic() ? "static" : "instance"); indent++; - if ( printContent ) { + if (printContent) { print("%s", initializer); disablePrinting++; } } - @Override public void endVisitInitializer(Node node, JCBlock initializer) { - if ( printContent ) disablePrinting--; + @Override public void endVisitInitializer(JavacNode node, JCBlock initializer) { + if (printContent) disablePrinting--; indent--; print("</%s INITIALIZER>", initializer.isStatic() ? "static" : "instance"); } - @Override public void visitField(Node node, JCVariableDecl field) { + @Override public void visitField(JavacNode node, JCVariableDecl field) { print("<FIELD %s %s>", field.vartype, field.name); indent++; - if ( printContent ) { - if ( field.init != null ) print("%s", field.init); + if (printContent) { + if (field.init != null) print("%s", field.init); disablePrinting++; } } - @Override public void visitAnnotationOnField(JCVariableDecl field, Node node, JCAnnotation annotation) { + @Override public void visitAnnotationOnField(JCVariableDecl field, JavacNode node, JCAnnotation annotation) { forcePrint("<ANNOTATION: %s />", annotation); } - @Override public void endVisitField(Node node, JCVariableDecl field) { - if ( printContent ) disablePrinting--; + @Override public void endVisitField(JavacNode node, JCVariableDecl field) { + if (printContent) disablePrinting--; indent--; print("</FIELD %s %s>", field.vartype, field.name); } - @Override public void visitMethod(Node node, JCMethodDecl method) { + @Override public void visitMethod(JavacNode node, JCMethodDecl method) { final String type; - if ( method.name.contentEquals("<init>") ) { - if ( (method.mods.flags & Flags.GENERATEDCONSTR) != 0 ) { + if (method.name.contentEquals("<init>")) { + if ((method.mods.flags & Flags.GENERATEDCONSTR) != 0) { type = "DEFAULTCONSTRUCTOR"; } else type = "CONSTRUCTOR"; } else type = "METHOD"; print("<%s %s> returns: %s", type, method.name, method.restype); indent++; - if ( printContent ) { - if ( method.body == null ) print("(ABSTRACT)"); + if (printContent) { + if (method.body == null) print("(ABSTRACT)"); else print("%s", method.body); disablePrinting++; } } - @Override public void visitAnnotationOnMethod(JCMethodDecl method, Node node, JCAnnotation annotation) { + @Override public void visitAnnotationOnMethod(JCMethodDecl method, JavacNode node, JCAnnotation annotation) { forcePrint("<ANNOTATION: %s />", annotation); } - @Override public void endVisitMethod(Node node, JCMethodDecl method) { - if ( printContent ) disablePrinting--; + @Override public void endVisitMethod(JavacNode node, JCMethodDecl method) { + if (printContent) disablePrinting--; indent--; print("</%s %s>", "XMETHOD", method.name); } - @Override public void visitMethodArgument(Node node, JCVariableDecl arg, JCMethodDecl method) { + @Override public void visitMethodArgument(JavacNode node, JCVariableDecl arg, JCMethodDecl method) { print("<METHODARG %s %s>", arg.vartype, arg.name); indent++; } - @Override public void visitAnnotationOnMethodArgument(JCVariableDecl arg, JCMethodDecl method, Node nodeAnnotation, JCAnnotation annotation) { + @Override public void visitAnnotationOnMethodArgument(JCVariableDecl arg, JCMethodDecl method, JavacNode nodeAnnotation, JCAnnotation annotation) { forcePrint("<ANNOTATION: %s />", annotation); } - @Override public void endVisitMethodArgument(Node node, JCVariableDecl arg, JCMethodDecl method) { + @Override public void endVisitMethodArgument(JavacNode node, JCVariableDecl arg, JCMethodDecl method) { indent--; print("</METHODARG %s %s>", arg.vartype, arg.name); } - @Override public void visitLocal(Node node, JCVariableDecl local) { + @Override public void visitLocal(JavacNode node, JCVariableDecl local) { print("<LOCAL %s %s>", local.vartype, local.name); indent++; } - @Override public void visitAnnotationOnLocal(JCVariableDecl local, Node node, JCAnnotation annotation) { + @Override public void visitAnnotationOnLocal(JCVariableDecl local, JavacNode node, JCAnnotation annotation) { print("<ANNOTATION: %s />", annotation); } - @Override public void endVisitLocal(Node node, JCVariableDecl local) { + @Override public void endVisitLocal(JavacNode node, JCVariableDecl local) { indent--; print("</LOCAL %s %s>", local.vartype, local.name); } - @Override public void visitStatement(Node node, JCTree statement) { + @Override public void visitStatement(JavacNode node, JCTree statement) { print("<%s>", statement.getClass()); indent++; print("%s", statement); } - @Override public void endVisitStatement(Node node, JCTree statement) { + @Override public void endVisitStatement(JavacNode node, JCTree statement) { indent--; print("</%s>", statement.getClass()); } |