From f241ef8c309b90faacabe66431b9deaebfd7087a Mon Sep 17 00:00:00 2001 From: Roel Spilker Date: Mon, 18 Jun 2018 23:46:42 +0200 Subject: Transient fields should by default be excluded from equals and hashCode. Fixes #1724 --- src/core/lombok/core/handlers/InclusionExclusionUtils.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/core') diff --git a/src/core/lombok/core/handlers/InclusionExclusionUtils.java b/src/core/lombok/core/handlers/InclusionExclusionUtils.java index 8d6c717f..368b51fc 100644 --- a/src/core/lombok/core/handlers/InclusionExclusionUtils.java +++ b/src/core/lombok/core/handlers/InclusionExclusionUtils.java @@ -106,7 +106,7 @@ public class InclusionExclusionUtils { return name; } - public static , L extends LombokNode, N, I extends Annotation> List> handleIncludeExcludeMarking(Class inclType, String replaceName, Class exclType, LombokNode typeNode, AnnotationValues annotation, LombokNode annotationNode) { + public static , L extends LombokNode, N, I extends Annotation> List> handleIncludeExcludeMarking(Class inclType, String replaceName, Class exclType, LombokNode typeNode, AnnotationValues annotation, LombokNode annotationNode, boolean includeTransient) { List oldExcludes = (annotation != null && annotation.isExplicit("exclude")) ? annotation.getAsStringList("exclude") : null; List oldIncludes = (annotation != null && annotation.isExplicit("of")) ? annotation.getAsStringList("of") : null; @@ -175,6 +175,7 @@ public class InclusionExclusionUtils { } if (child.getKind() != Kind.FIELD) continue; if (child.isStatic()) continue; + if (child.isTransient() && !includeTransient) continue; if (name.startsWith("$")) continue; if (child.isEnumMember()) continue; members.add(new Included(child, null, true)); @@ -200,7 +201,7 @@ public class InclusionExclusionUtils { } public static , L extends LombokNode, N> List> handleToStringMarking(LombokNode typeNode, AnnotationValues annotation, LombokNode annotationNode) { - List> members = handleIncludeExcludeMarking(ToString.Include.class, "name", ToString.Exclude.class, typeNode, annotation, annotationNode); + List> members = handleIncludeExcludeMarking(ToString.Include.class, "name", ToString.Exclude.class, typeNode, annotation, annotationNode, true); Collections.sort(members, new Comparator>() { @Override public int compare(Included a, Included b) { @@ -222,6 +223,6 @@ public class InclusionExclusionUtils { } public static , L extends LombokNode, N> List> handleEqualsAndHashCodeMarking(LombokNode typeNode, AnnotationValues annotation, LombokNode annotationNode) { - return handleIncludeExcludeMarking(EqualsAndHashCode.Include.class, "replaces", EqualsAndHashCode.Exclude.class, typeNode, annotation, annotationNode); + return handleIncludeExcludeMarking(EqualsAndHashCode.Include.class, "replaces", EqualsAndHashCode.Exclude.class, typeNode, annotation, annotationNode, false); } } -- cgit