aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/javac
diff options
context:
space:
mode:
authorRoel Spilker <r.spilker@gmail.com>2009-12-02 04:21:31 +0100
committerRoel Spilker <r.spilker@gmail.com>2009-12-02 04:21:31 +0100
commit9f69893ce2efd6ca0a6ef64022e48e49fc2b33f0 (patch)
tree46586ab9cbef48f10b06f841c5234ffb03f6c98a /src/core/lombok/javac
parente3d9e116af1c573b27ba35ac07f0111aaa1882ac (diff)
downloadlombok-9f69893ce2efd6ca0a6ef64022e48e49fc2b33f0.tar.gz
lombok-9f69893ce2efd6ca0a6ef64022e48e49fc2b33f0.tar.bz2
lombok-9f69893ce2efd6ca0a6ef64022e48e49fc2b33f0.zip
Changed the order of the generated methods in for @Data
- Constructor(s) - Getters/Setters per field - equals - hashCode - toString Added first test for @Data
Diffstat (limited to 'src/core/lombok/javac')
-rw-r--r--src/core/lombok/javac/handlers/HandleData.java24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/core/lombok/javac/handlers/HandleData.java b/src/core/lombok/javac/handlers/HandleData.java
index 54dd8dd2..128db8b0 100644
--- a/src/core/lombok/javac/handlers/HandleData.java
+++ b/src/core/lombok/javac/handlers/HandleData.java
@@ -21,9 +21,16 @@
*/
package lombok.javac.handlers;
-import static lombok.javac.handlers.JavacHandlerUtil.*;
+import static lombok.javac.handlers.JavacHandlerUtil.constructorExists;
+import static lombok.javac.handlers.JavacHandlerUtil.findAnnotations;
+import static lombok.javac.handlers.JavacHandlerUtil.generateNullCheck;
+import static lombok.javac.handlers.JavacHandlerUtil.injectMethod;
+import static lombok.javac.handlers.JavacHandlerUtil.markAnnotationAsProcessed;
+import static lombok.javac.handlers.JavacHandlerUtil.methodExists;
import java.lang.reflect.Modifier;
+import java.util.LinkedHashMap;
+import java.util.Map;
import lombok.Data;
import lombok.core.AnnotationValues;
@@ -72,6 +79,7 @@ public class HandleData implements JavacAnnotationHandler<Data> {
}
List<JavacNode> nodesForConstructor = List.nil();
+ Map<JavacNode, Boolean> gettersAndSetters = new LinkedHashMap<JavacNode, Boolean>();
for (JavacNode child : typeNode.down()) {
if (child.getKind() != Kind.FIELD) continue;
JCVariableDecl fieldDecl = (JCVariableDecl) child.get();
@@ -83,13 +91,9 @@ public class HandleData implements JavacAnnotationHandler<Data> {
boolean isFinal = (fieldFlags & Flags.FINAL) != 0;
boolean isNonNull = !findAnnotations(child, TransformationsUtil.NON_NULL_PATTERN).isEmpty();
if ((isFinal || isNonNull) && fieldDecl.init == null) nodesForConstructor = nodesForConstructor.append(child);
- new HandleGetter().generateGetterForField(child, annotationNode.get());
- if (!isFinal) new HandleSetter().generateSetterForField(child, annotationNode.get());
+ gettersAndSetters.put(child, !isFinal);
}
- new HandleToString().generateToStringForType(typeNode, annotationNode);
- new HandleEqualsAndHashCode().generateEqualsAndHashCodeForType(typeNode, annotationNode);
-
String staticConstructorName = annotation.getInstance().staticConstructor();
if (constructorExists(typeNode) == MemberExistsResult.NOT_EXISTS) {
@@ -102,6 +106,14 @@ public class HandleData implements JavacAnnotationHandler<Data> {
injectMethod(typeNode, staticConstructor);
}
+ for (Map.Entry<JavacNode, Boolean> field : gettersAndSetters.entrySet()) {
+ new HandleGetter().generateGetterForField(field.getKey(), annotationNode.get());
+ if (field.getValue()) new HandleSetter().generateSetterForField(field.getKey(), annotationNode.get());
+ }
+
+ new HandleEqualsAndHashCode().generateEqualsAndHashCodeForType(typeNode, annotationNode);
+ new HandleToString().generateToStringForType(typeNode, annotationNode);
+
return true;
}