From 9f69893ce2efd6ca0a6ef64022e48e49fc2b33f0 Mon Sep 17 00:00:00 2001 From: Roel Spilker Date: Wed, 2 Dec 2009 04:21:31 +0100 Subject: Changed the order of the generated methods in for @Data - Constructor(s) - Getters/Setters per field - equals - hashCode - toString Added first test for @Data --- src/core/lombok/javac/handlers/HandleData.java | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'src/core/lombok/javac') 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 { } List nodesForConstructor = List.nil(); + Map gettersAndSetters = new LinkedHashMap(); 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 { 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 { injectMethod(typeNode, staticConstructor); } + for (Map.Entry 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; } -- cgit