aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/changelog.markdown1
-rw-r--r--src/core/lombok/core/LombokNode.java26
-rw-r--r--src/core/lombok/eclipse/EclipseNode.java10
-rw-r--r--src/core/lombok/eclipse/handlers/HandleGetter.java12
-rw-r--r--src/core/lombok/eclipse/handlers/HandleSetter.java10
-rw-r--r--src/core/lombok/javac/DeleteLombokAnnotations.java (renamed from src/delombok/lombok/delombok/DeleteLombokAnnotations.java)2
-rw-r--r--src/core/lombok/javac/JavacNode.java11
-rw-r--r--src/core/lombok/javac/handlers/HandleGetter.java14
-rw-r--r--src/core/lombok/javac/handlers/HandleSetter.java13
-rw-r--r--src/delombok/lombok/delombok/CommentPreservingParser.java1
10 files changed, 94 insertions, 6 deletions
diff --git a/doc/changelog.markdown b/doc/changelog.markdown
index 180ba4f3..9816cfde 100644
--- a/doc/changelog.markdown
+++ b/doc/changelog.markdown
@@ -16,6 +16,7 @@ Lombok Changelog
* FEATURE: Constructors generated by lombok now include a `@java.beans.ConstructorProperties` annotation. This does mean these constructors no longer work in java 1.5, as this is a java 1.6 feature. The annotation can be suppressed by setting `suppressConstructorProperties` to `true` in a `@RequiredArgsConstructor` or `@AllArgsConstructor` annotation. [Issue #122](http://code.google.com/p/projectlombok/issues/detail?id=122)
* BUGFIX: delombok now no longer forgets to remove `import lombok.AccessLevel;`. In netbeans, that import will no longer be flagged erroneously as being unused. [Issue #100](http://code.google.com/p/projectlombok/issues/detail?id=100) and [Issue #103](http://code.google.com/p/projectlombok/issues/detail?id=103)
* BUGFIX: While its discouraged, `import lombok.*;` is supposed to work in the vast majority of cases. In eclipse, however, it didn't. Now it does. [Issue #102](http://code.google.com/p/projectlombok/issues/detail?id=102)
+* BUGFIX: When `@Getter` or `@Setter` is applied to a multiple field declaration, such as `@Getter int x, y;`, the annotation now applies to all fields, not just the first. [Issue #54](http://code.google.com/p/projectlombok/issues/detail?id=54)
### v0.9.2 "Hailbunny" (December 15th, 2009)
* preliminary support for lombok on NetBeans! - thanks go to Jan Lahoda from NetBeans. [Issue #20](http://code.google.com/p/projectlombok/issues/detail?id=20)
diff --git a/src/core/lombok/core/LombokNode.java b/src/core/lombok/core/LombokNode.java
index c58eadf3..211092ec 100644
--- a/src/core/lombok/core/LombokNode.java
+++ b/src/core/lombok/core/LombokNode.java
@@ -23,6 +23,7 @@ package lombok.core;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
@@ -168,6 +169,31 @@ public abstract class LombokNode<A extends AST<A, L, N>, L extends LombokNode<A,
}
/**
+ * {@code @Foo int x, y;} is stored in both javac and ecj as 2 FieldDeclarations, both with the same annotation as child.
+ * The normal {@code up()} method can't handle having multiple parents, but this one can.
+ */
+ public Collection<L> upFromAnnotationToFields() {
+ if (getKind() != Kind.ANNOTATION) return Collections.emptyList();
+ L field = up();
+ if (field == null || field.getKind() != Kind.FIELD) return Collections.emptyList();
+ L type = field.up();
+ if (type == null || type.getKind() != Kind.TYPE) return Collections.emptyList();
+
+ List<L> fields = new ArrayList<L>();
+ for (L potentialField : type.down()) {
+ if (potentialField.getKind() != Kind.FIELD) continue;
+ if (fieldContainsAnnotation(potentialField.get(), get())) fields.add(potentialField);
+ }
+
+ return fields;
+ }
+
+ /**
+ * Return {@code true} if the annotation is attached to the field.
+ */
+ protected abstract boolean fieldContainsAnnotation(N field, N annotation);
+
+ /**
* Returns the direct parent node in the AST tree of this node. For example, a local variable declaration's
* direct parent can be e.g. an If block, but its {@code up()} {@code LombokNode} is the {@code Method} that contains it.
*/
diff --git a/src/core/lombok/eclipse/EclipseNode.java b/src/core/lombok/eclipse/EclipseNode.java
index 668e6a6e..335845b5 100644
--- a/src/core/lombok/eclipse/EclipseNode.java
+++ b/src/core/lombok/eclipse/EclipseNode.java
@@ -122,6 +122,16 @@ public class EclipseNode extends lombok.core.LombokNode<EclipseAST, EclipseNode,
}
}
+ @Override protected boolean fieldContainsAnnotation(ASTNode field, ASTNode annotation) {
+ if (!(field instanceof FieldDeclaration)) return false;
+ FieldDeclaration f = (FieldDeclaration) field;
+ if (f.annotations == null) return false;
+ for (Annotation childAnnotation : f.annotations) {
+ if (childAnnotation == annotation) return true;
+ }
+ return false;
+ }
+
/** {@inheritDoc} */
@Override public String getName() {
final char[] n;
diff --git a/src/core/lombok/eclipse/handlers/HandleGetter.java b/src/core/lombok/eclipse/handlers/HandleGetter.java
index 9a676eb5..70423fbf 100644
--- a/src/core/lombok/eclipse/handlers/HandleGetter.java
+++ b/src/core/lombok/eclipse/handlers/HandleGetter.java
@@ -23,6 +23,9 @@ package lombok.eclipse.handlers;
import static lombok.eclipse.Eclipse.*;
import static lombok.eclipse.handlers.EclipseHandlerUtil.*;
+
+import java.util.Collection;
+
import lombok.AccessLevel;
import lombok.Getter;
import lombok.core.AnnotationValues;
@@ -94,7 +97,7 @@ public class HandleGetter implements EclipseAnnotationHandler<Getter> {
if (node == null) return false;
if (node.getKind() == Kind.FIELD) {
- return createGetterForField(level, node, annotationNode, annotationNode.get(), true);
+ return createGetterForFields(level, annotationNode.upFromAnnotationToFields(), annotationNode, annotationNode.get(), true);
}
if (node.getKind() == Kind.TYPE) {
TypeDeclaration typeDecl = null;
@@ -117,6 +120,13 @@ public class HandleGetter implements EclipseAnnotationHandler<Getter> {
return false;
}
+ private boolean createGetterForFields(AccessLevel level, Collection<EclipseNode> fieldNodes, EclipseNode errorNode, ASTNode source, boolean whineIfExists) {
+ for (EclipseNode fieldNode : fieldNodes) {
+ createGetterForField(level, fieldNode, errorNode, source, whineIfExists);
+ }
+ return true;
+ }
+
private boolean createGetterForField(AccessLevel level,
EclipseNode fieldNode, EclipseNode errorNode, ASTNode source, boolean whineIfExists) {
if (fieldNode.getKind() != Kind.FIELD) {
diff --git a/src/core/lombok/eclipse/handlers/HandleSetter.java b/src/core/lombok/eclipse/handlers/HandleSetter.java
index 3dbbb2b5..ccdbbb2c 100644
--- a/src/core/lombok/eclipse/handlers/HandleSetter.java
+++ b/src/core/lombok/eclipse/handlers/HandleSetter.java
@@ -25,6 +25,7 @@ import static lombok.eclipse.Eclipse.*;
import static lombok.eclipse.handlers.EclipseHandlerUtil.*;
import java.lang.reflect.Modifier;
+import java.util.Collection;
import lombok.AccessLevel;
import lombok.Setter;
@@ -101,7 +102,7 @@ public class HandleSetter implements EclipseAnnotationHandler<Setter> {
if (node == null) return false;
if (node.getKind() == Kind.FIELD) {
- return createSetterForField(level, node, annotationNode, annotationNode.get(), true);
+ return createSetterForFields(level, annotationNode.upFromAnnotationToFields(), annotationNode, annotationNode.get(), true);
}
if (node.getKind() == Kind.TYPE) {
TypeDeclaration typeDecl = null;
@@ -124,6 +125,13 @@ public class HandleSetter implements EclipseAnnotationHandler<Setter> {
return false;
}
+ private boolean createSetterForFields(AccessLevel level, Collection<EclipseNode> fieldNodes, EclipseNode errorNode, ASTNode source, boolean whineIfExists) {
+ for (EclipseNode fieldNode : fieldNodes) {
+ createSetterForField(level, fieldNode, errorNode, source, whineIfExists);
+ }
+ return true;
+ }
+
private boolean createSetterForField(AccessLevel level,
EclipseNode fieldNode, EclipseNode errorNode, ASTNode pos, boolean whineIfExists) {
if (fieldNode.getKind() != Kind.FIELD) {
diff --git a/src/delombok/lombok/delombok/DeleteLombokAnnotations.java b/src/core/lombok/javac/DeleteLombokAnnotations.java
index 335cf6e9..425c4365 100644
--- a/src/delombok/lombok/delombok/DeleteLombokAnnotations.java
+++ b/src/core/lombok/javac/DeleteLombokAnnotations.java
@@ -19,7 +19,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-package lombok.delombok;
+package lombok.javac;
/** Used as marker in javac's Context object when delombok is running to signal that all lombok annotations should be deleted as they are processed. */
public class DeleteLombokAnnotations {
diff --git a/src/core/lombok/javac/JavacNode.java b/src/core/lombok/javac/JavacNode.java
index 3d7ce73f..286672d8 100644
--- a/src/core/lombok/javac/JavacNode.java
+++ b/src/core/lombok/javac/JavacNode.java
@@ -26,7 +26,6 @@ import java.util.List;
import javax.tools.Diagnostic;
import lombok.core.AST.Kind;
-import lombok.delombok.DeleteLombokAnnotations;
import com.sun.tools.javac.code.Symtab;
import com.sun.tools.javac.tree.JCTree;
@@ -147,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) {
diff --git a/src/delombok/lombok/delombok/CommentPreservingParser.java b/src/delombok/lombok/delombok/CommentPreservingParser.java
index 8536075d..d48c5bf0 100644
--- a/src/delombok/lombok/delombok/CommentPreservingParser.java
+++ b/src/delombok/lombok/delombok/CommentPreservingParser.java
@@ -33,6 +33,7 @@ import javax.lang.model.element.Element;
import javax.tools.JavaFileObject;
import javax.tools.Diagnostic.Kind;
+import lombok.javac.DeleteLombokAnnotations;
import lombok.javac.JavacTransformer;
import com.sun.tools.javac.main.JavaCompiler;