mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 00:16:47 +00:00
Transient fields should by default be excluded from equals and hashCode. Fixes #1724
This commit is contained in:
1 parent
2264ce492c
commit
f241ef8c30
7 files changed
+207
-3
No files matched your search
@@ -106,7 +106,7 @@ public class InclusionExclusionUtils {
|
||||
return name;
|
||||
}
|
||||
|
||||
public static <A extends AST<A, L, N>, L extends LombokNode<A, L, N>, N, I extends Annotation> List<Included<L, I>> handleIncludeExcludeMarking(Class<I> inclType, String replaceName, Class<? extends Annotation> exclType, LombokNode<A, L, N> typeNode, AnnotationValues<?> annotation, LombokNode<A, L, N> annotationNode) {
|
||||
public static <A extends AST<A, L, N>, L extends LombokNode<A, L, N>, N, I extends Annotation> List<Included<L, I>> handleIncludeExcludeMarking(Class<I> inclType, String replaceName, Class<? extends Annotation> exclType, LombokNode<A, L, N> typeNode, AnnotationValues<?> annotation, LombokNode<A, L, N> annotationNode, boolean includeTransient) {
|
||||
List<String> oldExcludes = (annotation != null && annotation.isExplicit("exclude")) ? annotation.getAsStringList("exclude") : null;
|
||||
List<String> 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<L, I>(child, null, true));
|
||||
@@ -200,7 +201,7 @@ public class InclusionExclusionUtils {
|
||||
}
|
||||
|
||||
public static <A extends AST<A, L, N>, L extends LombokNode<A, L, N>, N> List<Included<L, ToString.Include>> handleToStringMarking(LombokNode<A, L, N> typeNode, AnnotationValues<ToString> annotation, LombokNode<A, L, N> annotationNode) {
|
||||
List<Included<L, ToString.Include>> members = handleIncludeExcludeMarking(ToString.Include.class, "name", ToString.Exclude.class, typeNode, annotation, annotationNode);
|
||||
List<Included<L, ToString.Include>> members = handleIncludeExcludeMarking(ToString.Include.class, "name", ToString.Exclude.class, typeNode, annotation, annotationNode, true);
|
||||
|
||||
Collections.sort(members, new Comparator<Included<L, ToString.Include>>() {
|
||||
@Override public int compare(Included<L, ToString.Include> a, Included<L, ToString.Include> b) {
|
||||
@@ -222,6 +223,6 @@ public class InclusionExclusionUtils {
|
||||
}
|
||||
|
||||
public static <A extends AST<A, L, N>, L extends LombokNode<A, L, N>, N> List<Included<L, EqualsAndHashCode.Include>> handleEqualsAndHashCodeMarking(LombokNode<A, L, N> typeNode, AnnotationValues<EqualsAndHashCode> annotation, LombokNode<A, L, N> 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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
class EqualsAndHashCodeAutoExclude {
|
||||
int x;
|
||||
String $a;
|
||||
transient String b;
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public boolean equals(final java.lang.Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof EqualsAndHashCodeAutoExclude)) return false;
|
||||
final EqualsAndHashCodeAutoExclude other = (EqualsAndHashCodeAutoExclude) o;
|
||||
if (!other.canEqual((java.lang.Object) this)) return false;
|
||||
if (this.x != other.x) return false;
|
||||
return true;
|
||||
}
|
||||
@java.lang.SuppressWarnings("all")
|
||||
protected boolean canEqual(final java.lang.Object other) {
|
||||
return other instanceof EqualsAndHashCodeAutoExclude;
|
||||
}
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public int hashCode() {
|
||||
final int PRIME = 59;
|
||||
int result = 1;
|
||||
result = result * PRIME + this.x;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
class EqualsAndHashCodeAutoExclude2 {
|
||||
int x;
|
||||
String $a;
|
||||
transient String b;
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public boolean equals(final java.lang.Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof EqualsAndHashCodeAutoExclude2)) return false;
|
||||
final EqualsAndHashCodeAutoExclude2 other = (EqualsAndHashCodeAutoExclude2) o;
|
||||
if (!other.canEqual((java.lang.Object) this)) return false;
|
||||
if (this.x != other.x) return false;
|
||||
final java.lang.Object this$$a = this.$a;
|
||||
final java.lang.Object other$$a = other.$a;
|
||||
if (this$$a == null ? other$$a != null : !this$$a.equals(other$$a)) return false;
|
||||
final java.lang.Object this$b = this.b;
|
||||
final java.lang.Object other$b = other.b;
|
||||
if (this$b == null ? other$b != null : !this$b.equals(other$b)) return false;
|
||||
return true;
|
||||
}
|
||||
@java.lang.SuppressWarnings("all")
|
||||
protected boolean canEqual(final java.lang.Object other) {
|
||||
return other instanceof EqualsAndHashCodeAutoExclude2;
|
||||
}
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public int hashCode() {
|
||||
final int PRIME = 59;
|
||||
int result = 1;
|
||||
result = result * PRIME + this.x;
|
||||
final java.lang.Object $$a = this.$a;
|
||||
result = result * PRIME + ($$a == null ? 43 : $$a.hashCode());
|
||||
final java.lang.Object $b = this.b;
|
||||
result = result * PRIME + ($b == null ? 43 : $b.hashCode());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
class ToStringAutoExclude {
|
||||
int x;
|
||||
String $a;
|
||||
transient String b;
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public java.lang.String toString() {
|
||||
return "ToStringAutoExclude(x=" + this.x + ", b=" + this.b + ")";
|
||||
}
|
||||
}
|
||||
class ToStringAutoExclude2 {
|
||||
int x;
|
||||
String $a;
|
||||
transient String b;
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public java.lang.String toString() {
|
||||
return "ToStringAutoExclude2(x=" + this.x + ", $a=" + this.$a + ", b=" + this.b + ")";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
@lombok.EqualsAndHashCode class EqualsAndHashCodeAutoExclude {
|
||||
int x;
|
||||
String $a;
|
||||
transient String b;
|
||||
EqualsAndHashCodeAutoExclude() {
|
||||
super();
|
||||
}
|
||||
public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) {
|
||||
if ((o == this))
|
||||
return true;
|
||||
if ((! (o instanceof EqualsAndHashCodeAutoExclude)))
|
||||
return false;
|
||||
final EqualsAndHashCodeAutoExclude other = (EqualsAndHashCodeAutoExclude) o;
|
||||
if ((! other.canEqual((java.lang.Object) this)))
|
||||
return false;
|
||||
if ((this.x != other.x))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
|
||||
return (other instanceof EqualsAndHashCodeAutoExclude);
|
||||
}
|
||||
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
|
||||
final int PRIME = 59;
|
||||
int result = 1;
|
||||
result = ((result * PRIME) + this.x);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@lombok.EqualsAndHashCode class EqualsAndHashCodeAutoExclude2 {
|
||||
int x;
|
||||
@lombok.EqualsAndHashCode.Include String $a;
|
||||
transient @lombok.EqualsAndHashCode.Include String b;
|
||||
EqualsAndHashCodeAutoExclude2() {
|
||||
super();
|
||||
}
|
||||
public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) {
|
||||
if ((o == this))
|
||||
return true;
|
||||
if ((! (o instanceof EqualsAndHashCodeAutoExclude2)))
|
||||
return false;
|
||||
final EqualsAndHashCodeAutoExclude2 other = (EqualsAndHashCodeAutoExclude2) o;
|
||||
if ((! other.canEqual((java.lang.Object) this)))
|
||||
return false;
|
||||
if ((this.x != other.x))
|
||||
return false;
|
||||
final java.lang.Object this$$a = this.$a;
|
||||
final java.lang.Object other$$a = other.$a;
|
||||
if (((this$$a == null) ? (other$$a != null) : (! this$$a.equals(other$$a))))
|
||||
return false;
|
||||
final java.lang.Object this$b = this.b;
|
||||
final java.lang.Object other$b = other.b;
|
||||
if (((this$b == null) ? (other$b != null) : (! this$b.equals(other$b))))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
|
||||
return (other instanceof EqualsAndHashCodeAutoExclude2);
|
||||
}
|
||||
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
|
||||
final int PRIME = 59;
|
||||
int result = 1;
|
||||
result = ((result * PRIME) + this.x);
|
||||
final java.lang.Object $$a = this.$a;
|
||||
result = ((result * PRIME) + (($$a == null) ? 43 : $$a.hashCode()));
|
||||
final java.lang.Object $b = this.b;
|
||||
result = ((result * PRIME) + (($b == null) ? 43 : $b.hashCode()));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
@lombok.ToString class ToStringAutoExclude {
|
||||
int x;
|
||||
String $a;
|
||||
transient String b;
|
||||
ToStringAutoExclude() {
|
||||
super();
|
||||
}
|
||||
public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
|
||||
return (((("ToStringAutoExclude(x=" + this.x) + ", b=") + this.b) + ")");
|
||||
}
|
||||
}
|
||||
@lombok.ToString class ToStringAutoExclude2 {
|
||||
int x;
|
||||
@lombok.ToString.Include String $a;
|
||||
transient String b;
|
||||
ToStringAutoExclude2() {
|
||||
super();
|
||||
}
|
||||
public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
|
||||
return (((((("ToStringAutoExclude2(x=" + this.x) + ", $a=") + this.$a) + ", b=") + this.b) + ")");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
@lombok.EqualsAndHashCode
|
||||
class EqualsAndHashCodeAutoExclude {
|
||||
int x;
|
||||
String $a;
|
||||
transient String b;
|
||||
}
|
||||
@lombok.EqualsAndHashCode
|
||||
class EqualsAndHashCodeAutoExclude2 {
|
||||
int x;
|
||||
@lombok.EqualsAndHashCode.Include
|
||||
String $a;
|
||||
@lombok.EqualsAndHashCode.Include
|
||||
transient String b;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
@lombok.ToString
|
||||
class ToStringAutoExclude {
|
||||
int x;
|
||||
String $a;
|
||||
transient String b;
|
||||
}
|
||||
@lombok.ToString
|
||||
class ToStringAutoExclude2 {
|
||||
int x;
|
||||
@lombok.ToString.Include
|
||||
String $a;
|
||||
transient String b;
|
||||
}
|
||||
Reference in new issue
Block a user