diff options
author | Reinier Zwitserloot <reinier@tipit.to> | 2009-06-17 21:27:27 +0200 |
---|---|---|
committer | Reinier Zwitserloot <reinier@tipit.to> | 2009-06-17 21:27:27 +0200 |
commit | 1929a28c9def0dd276dcf3fdb70ada8b84b1c64a (patch) | |
tree | 7d0b7b7c6bdcce6fcde7973b4cf2d8f46b854b79 /src/lombok/javac/handlers/HandleGetter.java | |
parent | 7c65e0fdff6a015b9773a0f6d6b5d8adf8cd9434 (diff) | |
download | lombok-1929a28c9def0dd276dcf3fdb70ada8b84b1c64a.tar.gz lombok-1929a28c9def0dd276dcf3fdb70ada8b84b1c64a.tar.bz2 lombok-1929a28c9def0dd276dcf3fdb70ada8b84b1c64a.zip |
Added the SetterHandler for javac. Also added a way to get the SymbolTable on a JavacAST.Node, because you need it to e.g. access constant types like 'void'.
Diffstat (limited to 'src/lombok/javac/handlers/HandleGetter.java')
-rw-r--r-- | src/lombok/javac/handlers/HandleGetter.java | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/lombok/javac/handlers/HandleGetter.java b/src/lombok/javac/handlers/HandleGetter.java index ef4d9755..781598a2 100644 --- a/src/lombok/javac/handlers/HandleGetter.java +++ b/src/lombok/javac/handlers/HandleGetter.java @@ -10,13 +10,12 @@ import lombok.javac.JavacAST; import org.mangosdk.spi.ProviderFor; -import com.sun.source.tree.MethodTree; -import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.TreeMaker; import com.sun.tools.javac.tree.JCTree.JCAnnotation; import com.sun.tools.javac.tree.JCTree.JCBlock; import com.sun.tools.javac.tree.JCTree.JCClassDecl; import com.sun.tools.javac.tree.JCTree.JCExpression; +import com.sun.tools.javac.tree.JCTree.JCMethodDecl; import com.sun.tools.javac.tree.JCTree.JCStatement; import com.sun.tools.javac.tree.JCTree.JCTypeParameter; import com.sun.tools.javac.tree.JCTree.JCVariableDecl; @@ -26,6 +25,7 @@ import com.sun.tools.javac.util.Name; @ProviderFor(JavacAnnotationHandler.class) public class HandleGetter implements JavacAnnotationHandler<Getter> { @Override public void handle(AnnotationValues<Getter> annotation, JCAnnotation ast, JavacAST.Node annotationNode) { + //TODO Check for existence of the getter and skip it (+ warn) if it's already there. if ( annotationNode.up().getKind() != Kind.FIELD ) { annotationNode.addError("@Getter is only supported on a field."); return; @@ -37,16 +37,16 @@ public class HandleGetter implements JavacAnnotationHandler<Getter> { int access = toJavacModifier(getter.value()); - MethodTree getterMethod = createGetter(access, annotationNode.up(), annotationNode.getTreeMaker()); - javacClassTree.defs = javacClassTree.defs.append((JCTree)getterMethod); + JCMethodDecl getterMethod = createGetter(access, annotationNode.up(), annotationNode.getTreeMaker()); + javacClassTree.defs = javacClassTree.defs.append(getterMethod); } - private MethodTree createGetter(int access, JavacAST.Node field, TreeMaker treeMaker) { + private JCMethodDecl createGetter(int access, JavacAST.Node field, TreeMaker treeMaker) { JCVariableDecl fieldNode = (JCVariableDecl) field.get(); JCStatement returnStatement = treeMaker.Return(treeMaker.Ident(fieldNode.getName())); JCBlock methodBody = treeMaker.Block(0, List.of(returnStatement)); - Name methodName = field.toName(toGetterName((JCVariableDecl)field.get())); + Name methodName = field.toName(toGetterName(fieldNode)); JCExpression methodType = fieldNode.type != null ? treeMaker.Type(fieldNode.type) : fieldNode.vartype; List<JCTypeParameter> methodGenericParams = List.nil(); |