aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/javac
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2010-07-20 11:58:56 +0200
committerReinier Zwitserloot <reinier@zwitserloot.com>2010-07-20 11:58:56 +0200
commitd7ee0bc8a5a36e5968741e0e0a445a165b32f1e5 (patch)
treee5479876073490c3ea86ee5f24e2017ee749341a /src/core/lombok/javac
parentba7406f05a7b88e06bb1d4c52e9000c85e65387c (diff)
downloadlombok-d7ee0bc8a5a36e5968741e0e0a445a165b32f1e5.tar.gz
lombok-d7ee0bc8a5a36e5968741e0e0a445a165b32f1e5.tar.bz2
lombok-d7ee0bc8a5a36e5968741e0e0a445a165b32f1e5.zip
@Getter int x, y; used to only apply to 'x', now it applies to both x and y.
Fixes issue #54
Diffstat (limited to 'src/core/lombok/javac')
-rw-r--r--src/core/lombok/javac/JavacNode.java10
-rw-r--r--src/core/lombok/javac/handlers/HandleGetter.java14
-rw-r--r--src/core/lombok/javac/handlers/HandleSetter.java13
3 files changed, 35 insertions, 2 deletions
diff --git a/src/core/lombok/javac/JavacNode.java b/src/core/lombok/javac/JavacNode.java
index 4981a24e..286672d8 100644
--- a/src/core/lombok/javac/JavacNode.java
+++ b/src/core/lombok/javac/JavacNode.java
@@ -146,6 +146,16 @@ public class JavacNode extends lombok.core.LombokNode<JavacAST, JavacNode, JCTre
return false;
}
+ @Override protected boolean fieldContainsAnnotation(JCTree field, JCTree annotation) {
+ if (!(field instanceof JCVariableDecl)) return false;
+ JCVariableDecl f = (JCVariableDecl) field;
+ if (f.mods.annotations == null) return false;
+ for (JCAnnotation childAnnotation : f.mods.annotations) {
+ if (childAnnotation == annotation) return true;
+ }
+ return false;
+ }
+
/**
* Convenient shortcut to the owning JavacAST object's getTreeMaker method.
*
diff --git a/src/core/lombok/javac/handlers/HandleGetter.java b/src/core/lombok/javac/handlers/HandleGetter.java
index 9c0ce32f..582aa02b 100644
--- a/src/core/lombok/javac/handlers/HandleGetter.java
+++ b/src/core/lombok/javac/handlers/HandleGetter.java
@@ -22,6 +22,9 @@
package lombok.javac.handlers;
import static lombok.javac.handlers.JavacHandlerUtil.*;
+
+import java.util.Collection;
+
import lombok.AccessLevel;
import lombok.Getter;
import lombok.core.AnnotationValues;
@@ -94,6 +97,7 @@ public class HandleGetter implements JavacAnnotationHandler<Getter> {
}
@Override public boolean handle(AnnotationValues<Getter> annotation, JCAnnotation ast, JavacNode annotationNode) {
+ Collection<JavacNode> fields = annotationNode.upFromAnnotationToFields();
markAnnotationAsProcessed(annotationNode, Getter.class);
deleteImportFromCompilationUnit(annotationNode, "lombok.AccessLevel");
JavacNode node = annotationNode.up();
@@ -102,7 +106,7 @@ public class HandleGetter implements JavacAnnotationHandler<Getter> {
if (node == null) return false;
if (node.getKind() == Kind.FIELD) {
- return createGetterForField(level, node, annotationNode, true);
+ return createGetterForFields(level, fields, annotationNode, true);
}
if (node.getKind() == Kind.TYPE) {
JCClassDecl typeDecl = null;
@@ -124,6 +128,14 @@ public class HandleGetter implements JavacAnnotationHandler<Getter> {
return false;
}
+ private boolean createGetterForFields(AccessLevel level, Collection<JavacNode> fieldNodes, JavacNode errorNode, boolean whineIfExists) {
+ for (JavacNode fieldNode : fieldNodes) {
+ createGetterForField(level, fieldNode, errorNode, whineIfExists);
+ }
+
+ return true;
+ }
+
private boolean createGetterForField(AccessLevel level,
JavacNode fieldNode, JavacNode errorNode, boolean whineIfExists) {
if (fieldNode.getKind() != Kind.FIELD) {
diff --git a/src/core/lombok/javac/handlers/HandleSetter.java b/src/core/lombok/javac/handlers/HandleSetter.java
index dfc9c8ba..8728ceb3 100644
--- a/src/core/lombok/javac/handlers/HandleSetter.java
+++ b/src/core/lombok/javac/handlers/HandleSetter.java
@@ -24,6 +24,8 @@ package lombok.javac.handlers;
import static com.sun.tools.javac.code.TypeTags.*;
import static lombok.javac.handlers.JavacHandlerUtil.*;
+import java.util.Collection;
+
import javax.lang.model.type.NoType;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeVisitor;
@@ -103,6 +105,7 @@ public class HandleSetter implements JavacAnnotationHandler<Setter> {
}
@Override public boolean handle(AnnotationValues<Setter> annotation, JCAnnotation ast, JavacNode annotationNode) {
+ Collection<JavacNode> fields = annotationNode.upFromAnnotationToFields();
markAnnotationAsProcessed(annotationNode, Setter.class);
deleteImportFromCompilationUnit(annotationNode, "lombok.AccessLevel");
JavacNode node = annotationNode.up();
@@ -112,7 +115,7 @@ public class HandleSetter implements JavacAnnotationHandler<Setter> {
if (node == null) return false;
if (node.getKind() == Kind.FIELD) {
- return createSetterForField(level, node, annotationNode, true);
+ return createSetterForFields(level, fields, annotationNode, true);
}
if (node.getKind() == Kind.TYPE) {
JCClassDecl typeDecl = null;
@@ -134,6 +137,14 @@ public class HandleSetter implements JavacAnnotationHandler<Setter> {
return false;
}
+ private boolean createSetterForFields(AccessLevel level, Collection<JavacNode> fieldNodes, JavacNode errorNode, boolean whineIfExists) {
+ for (JavacNode fieldNode : fieldNodes) {
+ createSetterForField(level, fieldNode, errorNode, whineIfExists);
+ }
+
+ return true;
+ }
+
private boolean createSetterForField(AccessLevel level,
JavacNode fieldNode, JavacNode errorNode, boolean whineIfExists) {
if (fieldNode.getKind() != Kind.FIELD) {