diff options
author | Reinier Zwitserloot <reinier@tipit.to> | 2009-06-17 10:43:39 +0200 |
---|---|---|
committer | Reinier Zwitserloot <reinier@tipit.to> | 2009-06-17 10:43:39 +0200 |
commit | 024d8ffa9801f463fecadd16f42d51bbed46dea7 (patch) | |
tree | acb0b85f79eafb517e3472bd3d906235d1541ade /src/lombok/javac/handlers | |
parent | aa6d2e262f3d6c43f6d89220cdc10c6954bb2bdd (diff) | |
download | lombok-024d8ffa9801f463fecadd16f42d51bbed46dea7.tar.gz lombok-024d8ffa9801f463fecadd16f42d51bbed46dea7.tar.bz2 lombok-024d8ffa9801f463fecadd16f42d51bbed46dea7.zip |
Massive refactors. This list isn't complete, but should give you an idea:
A) many things in lombok.eclipse moved to lombok.core to enable reuse with lombok.javac.
B) lombok.javac works now similarly to eclipse's model: We first make big ASTs that are bidirectionally traversable, then we walk through that for annotations.
C) Instead of getting an annotation instance, you now get an object that is more flexible and can e.g. give you class values in an enum as a string instead of a Class object, which may fail if that class isn't on the classpath of lombok.
D) sources to the internal sun classes for javac added to /contrib.
Diffstat (limited to 'src/lombok/javac/handlers')
-rw-r--r-- | src/lombok/javac/handlers/HandleGetter_javac.java | 27 | ||||
-rw-r--r-- | src/lombok/javac/handlers/PKG.java | 9 |
2 files changed, 18 insertions, 18 deletions
diff --git a/src/lombok/javac/handlers/HandleGetter_javac.java b/src/lombok/javac/handlers/HandleGetter_javac.java index 7863a097..8501b65f 100644 --- a/src/lombok/javac/handlers/HandleGetter_javac.java +++ b/src/lombok/javac/handlers/HandleGetter_javac.java @@ -2,17 +2,15 @@ package lombok.javac.handlers; import static lombok.javac.handlers.PKG.*; -import javax.lang.model.element.Element; - import lombok.Getter; +import lombok.core.AnnotationValues; +import lombok.core.AST.Kind; import lombok.javac.JavacAnnotationHandler; -import lombok.javac.JavacNode; +import lombok.javac.JavacAST; import org.mangosdk.spi.ProviderFor; import com.sun.source.tree.MethodTree; -import com.sun.tools.javac.code.Symbol; -import com.sun.tools.javac.code.Type; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.TreeMaker; import com.sun.tools.javac.tree.JCTree.JCAnnotation; @@ -27,26 +25,29 @@ import com.sun.tools.javac.util.Name; @ProviderFor(JavacAnnotationHandler.class) public class HandleGetter_javac implements JavacAnnotationHandler<Getter> { - @Override public void handle(JavacNode node, Getter getter) { - if ( !node.getJavacAST().getKind().isField() ) { + @Override public void handle(AnnotationValues<Getter> annotation, JCAnnotation ast, JavacAST.Node node) { + if ( node.up().getKind() != Kind.FIELD ) { node.addError("@Getter is only supported on a field."); return; } - JCClassDecl javacClassTree = node.getEnclosingType(); + Getter getter = annotation.getInstance(); + + JCClassDecl javacClassTree = (JCClassDecl) node.up().up().get(); int access = toJavacModifier(getter.value()); - MethodTree getterMethod = createGetter(access, node.getJavacAST(), node.createTreeMaker(), node.createNameTable()); + MethodTree getterMethod = createGetter(access, node.up(), node.getTreeMaker()); javacClassTree.defs = javacClassTree.defs.append((JCTree)getterMethod); } - private MethodTree createGetter(int access, Element field, TreeMaker treeMaker, Name.Table nameTable) { - JCStatement returnStatement = treeMaker.Return(treeMaker.Ident((Symbol)field)); + private MethodTree 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 = Name.fromString(nameTable, toGetterName(field)); - JCExpression methodType = treeMaker.Type((Type)field.asType()); + Name methodName = field.toName(toGetterName((JCVariableDecl)field.get())); + JCExpression methodType = fieldNode.type != null ? treeMaker.Type(fieldNode.type) : fieldNode.vartype; List<JCTypeParameter> methodGenericParams = List.nil(); List<JCVariableDecl> parameters = List.nil(); diff --git a/src/lombok/javac/handlers/PKG.java b/src/lombok/javac/handlers/PKG.java index 4622c3ee..9ba3765a 100644 --- a/src/lombok/javac/handlers/PKG.java +++ b/src/lombok/javac/handlers/PKG.java @@ -2,17 +2,16 @@ package lombok.javac.handlers; import java.lang.reflect.Modifier; -import javax.lang.model.element.Element; -import javax.lang.model.type.TypeKind; +import com.sun.tools.javac.tree.JCTree.JCVariableDecl; import lombok.AccessLevel; import lombok.core.TransformationsUtil; class PKG { - static String toGetterName(Element field) { - CharSequence fieldName = field.getSimpleName(); + static String toGetterName(JCVariableDecl field) { + CharSequence fieldName = field.name; - boolean isBoolean = field.asType().getKind() == TypeKind.BOOLEAN; + boolean isBoolean = field.vartype.toString().equals("boolean"); return TransformationsUtil.toGetterName(fieldName, isBoolean); } |