diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2010-07-22 14:19:23 +0200 |
---|---|---|
committer | Reinier Zwitserloot <reinier@zwitserloot.com> | 2010-07-22 14:19:23 +0200 |
commit | ceda2e5efe229650d4e95de6b8a2632d9f616592 (patch) | |
tree | 1af7964267dc2ce40e0efb02ee767d58303bfab5 /src/core/lombok/javac/handlers/HandleData.java | |
parent | 868d8b0f93c0801f638b8c5523291aacd35d9ce2 (diff) | |
download | lombok-ceda2e5efe229650d4e95de6b8a2632d9f616592.tar.gz lombok-ceda2e5efe229650d4e95de6b8a2632d9f616592.tar.bz2 lombok-ceda2e5efe229650d4e95de6b8a2632d9f616592.zip |
toString(), equals(), and hashCode() now use getX() instead of x if either it exists OR it will be generated by some other lombok annotation, addressing issue #110.
code deduplication by removing HandleData's scanning for fields, which is now no longer done; the sub-parts of Data (Getter, Setter, RequiredArgsConstructor, etc) take care of it now.
fix for class-level @Getter/@Setter, which used to go for every field. Now they skip the usual fields (static, for setters final, and $ prefixed fields).
Bugfix for @Data not recognizing that it should let field-level @Getter/@Setter take care of generating the getter/setter for multi field declarations (@Getter int x, y);
Diffstat (limited to 'src/core/lombok/javac/handlers/HandleData.java')
-rw-r--r-- | src/core/lombok/javac/handlers/HandleData.java | 37 |
1 files changed, 5 insertions, 32 deletions
diff --git a/src/core/lombok/javac/handlers/HandleData.java b/src/core/lombok/javac/handlers/HandleData.java index e20b230e..2087c133 100644 --- a/src/core/lombok/javac/handlers/HandleData.java +++ b/src/core/lombok/javac/handlers/HandleData.java @@ -21,16 +21,10 @@ */ package lombok.javac.handlers; -import static lombok.javac.handlers.JavacHandlerUtil.*; - -import java.util.LinkedHashMap; -import java.util.Map; - +import static lombok.javac.handlers.JavacHandlerUtil.markAnnotationAsProcessed; import lombok.AccessLevel; import lombok.Data; -import lombok.core.AST.Kind; import lombok.core.AnnotationValues; -import lombok.core.handlers.TransformationsUtil; import lombok.javac.JavacAnnotationHandler; import lombok.javac.JavacNode; @@ -39,8 +33,6 @@ import org.mangosdk.spi.ProviderFor; import com.sun.tools.javac.code.Flags; import com.sun.tools.javac.tree.JCTree.JCAnnotation; import com.sun.tools.javac.tree.JCTree.JCClassDecl; -import com.sun.tools.javac.tree.JCTree.JCVariableDecl; -import com.sun.tools.javac.util.List; /** * Handles the {@code lombok.Data} annotation for javac. @@ -60,31 +52,12 @@ public class HandleData implements JavacAnnotationHandler<Data> { return false; } - 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(); - //Skip fields that start with $ - if (fieldDecl.name.toString().startsWith("$")) continue; - long fieldFlags = fieldDecl.mods.flags; - //Skip static fields. - if ((fieldFlags & Flags.STATIC) != 0) continue; - 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); - gettersAndSetters.put(child, !isFinal); - } - String staticConstructorName = annotation.getInstance().staticConstructor(); - new HandleConstructor().generateConstructor(AccessLevel.PUBLIC, typeNode, nodesForConstructor, staticConstructorName, true, false); - - for (Map.Entry<JavacNode, Boolean> field : gettersAndSetters.entrySet()) { - new HandleGetter().generateGetterForField(field.getKey(), annotationNode.get(), AccessLevel.PUBLIC, true); - if (field.getValue()) new HandleSetter().generateSetterForField(field.getKey(), annotationNode.get(), AccessLevel.PUBLIC, true); - } - + // TODO move this to the end OR move it to the top in eclipse. + new HandleConstructor().generateRequiredArgsConstructor(typeNode, AccessLevel.PUBLIC, staticConstructorName, true); + new HandleGetter().generateGetterForType(typeNode, annotationNode, AccessLevel.PUBLIC, true); + new HandleSetter().generateSetterForType(typeNode, annotationNode, AccessLevel.PUBLIC, true); new HandleEqualsAndHashCode().generateEqualsAndHashCodeForType(typeNode, annotationNode); new HandleToString().generateToStringForType(typeNode, annotationNode); |