aboutsummaryrefslogtreecommitdiff
path: root/src/lombok/apt/HandleGetter_javac.java
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@tipit.to>2009-06-16 03:04:46 +0200
committerReinier Zwitserloot <reinier@tipit.to>2009-06-16 03:04:46 +0200
commitf36be2eb01bcbff01a513d64bff2d1aba54460b1 (patch)
tree7d49ebe90cb836e054c35d2a4382be6b999ca452 /src/lombok/apt/HandleGetter_javac.java
parentd78a04d74886101c81de77659b067d16cb2d0de2 (diff)
downloadlombok-f36be2eb01bcbff01a513d64bff2d1aba54460b1.tar.gz
lombok-f36be2eb01bcbff01a513d64bff2d1aba54460b1.tar.bz2
lombok-f36be2eb01bcbff01a513d64bff2d1aba54460b1.zip
Implemented a lot of stuff for javac, but we ran into 2 major issues still to be implemented:
1. The visit mode of a lombok handler (does not trigger off of annotations, instead sees every field, method, type, and statement), needs to be coded, 2. triggering off of annotations via APT's annotation handling system skips method-local classes. We'll need to recode this via an AST visitor like we need for issue #1 Other than that, triggering off of annotations works swimmingly!
Diffstat (limited to 'src/lombok/apt/HandleGetter_javac.java')
-rw-r--r--src/lombok/apt/HandleGetter_javac.java77
1 files changed, 0 insertions, 77 deletions
diff --git a/src/lombok/apt/HandleGetter_javac.java b/src/lombok/apt/HandleGetter_javac.java
deleted file mode 100644
index bfa2746d..00000000
--- a/src/lombok/apt/HandleGetter_javac.java
+++ /dev/null
@@ -1,77 +0,0 @@
-package lombok.apt;
-
-import java.lang.reflect.Modifier;
-
-import javax.annotation.processing.Messager;
-import javax.lang.model.element.Element;
-import javax.lang.model.element.TypeElement;
-import javax.tools.Diagnostic;
-
-import lombok.Getter;
-
-import com.sun.source.tree.MethodTree;
-import com.sun.source.util.Trees;
-import com.sun.tools.javac.code.Symbol;
-import com.sun.tools.javac.code.Type;
-import com.sun.tools.javac.processing.JavacProcessingEnvironment;
-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.JCStatement;
-import com.sun.tools.javac.tree.JCTree.JCTypeParameter;
-import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
-import com.sun.tools.javac.util.List;
-import com.sun.tools.javac.util.Name;
-
-class HandleGetter_javac extends HandlerForCompiler<Getter> {
- private final Trees trees;
- private final Messager messager;
- private JavacProcessingEnvironment env;
-
- HandleGetter_javac() {
- this.messager = processEnv.getMessager();
- this.trees = Trees.instance(processEnv);
- }
-
- @Override public void init() {
- this.env = (JavacProcessingEnvironment)processEnv;
- }
-
- @Override public void handle(Element element, Getter getter) {
- if ( !element.getKind().isField() ) {
- messager.printMessage(Diagnostic.Kind.ERROR, "@Getter is only supported on a field.");
- return;
- }
-
- TypeElement classElement = (TypeElement)element.getEnclosingElement();
- JCClassDecl javacClassTree = (JCClassDecl)trees.getTree(classElement);
-
- Name.Table nameTable = Name.Table.instance(env.getContext());
- TreeMaker treeMaker = TreeMaker.instance(env.getContext());
-
- MethodTree getterMethod = createGetter(element, treeMaker, nameTable);
- javacClassTree.defs = javacClassTree.defs.append((JCTree)getterMethod);
- }
-
- private MethodTree createGetter(Element field, TreeMaker treeMaker, Name.Table nameTable) {
- JCStatement returnStatement = treeMaker.Return(treeMaker.Ident((Symbol)field));
-
- //TODO Trab the position in the source file of the field by looking it up in the JCClassDecl,
- //and copy it into the 'position' info for the Ident and Return AST Nodes.
-
- JCBlock methodBody = treeMaker.Block(0, List.of(returnStatement));
- Name methodName = Name.fromString(nameTable, PKG.toGetterName(field));
- JCExpression methodType = treeMaker.Type((Type)field.asType());
-
- List<JCTypeParameter> methodGenericParams = List.nil();
- List<JCVariableDecl> parameters = List.nil();
- List<JCExpression> throwsClauses = List.nil();
- JCExpression annotationMethodDefaultValue = null;
-
- return treeMaker.MethodDef(treeMaker.Modifiers(Modifier.PUBLIC, List.<JCAnnotation>nil()), methodName, methodType,
- methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue);
- }
-}