From 4e0ffbc32913001082dd2387a20b480076ddd20a Mon Sep 17 00:00:00 2001 From: Andre Brait Date: Mon, 13 Jul 2020 17:15:03 +0200 Subject: Eclipse impl and tests --- .../after-delombok/EqualsAndHashCodeCache.java | 151 +++++++++++++++++++ .../resource/after-ecj/EqualsAndHashCodeCache.java | 167 +++++++++++++++++++++ .../resource/before/EqualsAndHashCodeCache.java | 29 ++++ 3 files changed, 347 insertions(+) create mode 100644 test/transform/resource/after-delombok/EqualsAndHashCodeCache.java create mode 100644 test/transform/resource/after-ecj/EqualsAndHashCodeCache.java create mode 100644 test/transform/resource/before/EqualsAndHashCodeCache.java (limited to 'test/transform/resource') diff --git a/test/transform/resource/after-delombok/EqualsAndHashCodeCache.java b/test/transform/resource/after-delombok/EqualsAndHashCodeCache.java new file mode 100644 index 00000000..e3e266aa --- /dev/null +++ b/test/transform/resource/after-delombok/EqualsAndHashCodeCache.java @@ -0,0 +1,151 @@ +class EqualsAndHashCode { + int x; + boolean[] y; + Object[] z; + String a; + 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 EqualsAndHashCode)) return false; + final EqualsAndHashCode other = (EqualsAndHashCode) o; + if (!other.canEqual((java.lang.Object) this)) return false; + if (this.x != other.x) return false; + if (!java.util.Arrays.equals(this.y, other.y)) return false; + if (!java.util.Arrays.deepEquals(this.z, other.z)) 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 EqualsAndHashCode; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public int hashCode() { + final int PRIME = 59; + int result = 1; + result = result * PRIME + this.x; + result = result * PRIME + java.util.Arrays.hashCode(this.y); + result = result * PRIME + java.util.Arrays.deepHashCode(this.z); + 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; + } +} +final class EqualsAndHashCode2 { + int x; + long y; + float f; + double d; + boolean b; + private transient int $hashCodeCache = 0; + @java.lang.Override + @java.lang.SuppressWarnings("all") + public boolean equals(final java.lang.Object o) { + if (o == this) return true; + if (!(o instanceof EqualsAndHashCode2)) return false; + final EqualsAndHashCode2 other = (EqualsAndHashCode2) o; + if (this.x != other.x) return false; + if (this.y != other.y) return false; + if (java.lang.Float.compare(this.f, other.f) != 0) return false; + if (java.lang.Double.compare(this.d, other.d) != 0) return false; + if (this.b != other.b) return false; + return true; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public int hashCode() { + if ($hashCodeCache != 0) return $hashCodeCache; + final int PRIME = 59; + int result = 1; + result = result * PRIME + this.x; + final long $y = this.y; + result = result * PRIME + (int) ($y >>> 32 ^ $y); + result = result * PRIME + java.lang.Float.floatToIntBits(this.f); + final long $d = java.lang.Double.doubleToLongBits(this.d); + result = result * PRIME + (int) ($d >>> 32 ^ $d); + result = result * PRIME + (this.b ? 79 : 97); + $hashCodeCache = result; + return result; + } +} +final class EqualsAndHashCode3 extends EqualsAndHashCode { + private transient int $hashCodeCache = 0; + @java.lang.Override + @java.lang.SuppressWarnings("all") + public boolean equals(final java.lang.Object o) { + if (o == this) return true; + if (!(o instanceof EqualsAndHashCode3)) return false; + final EqualsAndHashCode3 other = (EqualsAndHashCode3) o; + if (!other.canEqual((java.lang.Object) this)) return false; + return true; + } + @java.lang.SuppressWarnings("all") + protected boolean canEqual(final java.lang.Object other) { + return other instanceof EqualsAndHashCode3; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public int hashCode() { + if ($hashCodeCache != 0) return $hashCodeCache; + final int result = 1; + $hashCodeCache = result; + return result; + } +} +class EqualsAndHashCode4 extends EqualsAndHashCode { + @java.lang.Override + @java.lang.SuppressWarnings("all") + public boolean equals(final java.lang.Object o) { + if (o == this) return true; + if (!(o instanceof EqualsAndHashCode4)) return false; + final EqualsAndHashCode4 other = (EqualsAndHashCode4) o; + if (!other.canEqual((java.lang.Object) this)) return false; + if (!super.equals(o)) return false; + return true; + } + @java.lang.SuppressWarnings("all") + protected boolean canEqual(final java.lang.Object other) { + return other instanceof EqualsAndHashCode4; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public int hashCode() { + final int result = super.hashCode(); + return result; + } +} +class EqualsAndHashCode5 extends EqualsAndHashCode { + private transient int $hashCodeCache = 0; + @java.lang.Override + @java.lang.SuppressWarnings("all") + public boolean equals(final java.lang.Object o) { + if (o == this) return true; + if (!(o instanceof EqualsAndHashCode5)) return false; + final EqualsAndHashCode5 other = (EqualsAndHashCode4) o; + if (!other.canEqual((java.lang.Object) this)) return false; + if (!super.equals(o)) return false; + return true; + } + @java.lang.SuppressWarnings("all") + protected boolean canEqual(final java.lang.Object other) { + return other instanceof EqualsAndHashCode5; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public int hashCode() { + if ($hashCodeCache != 0) return $hashCodeCache; + final int result = super.hashCode(); + $hashCodeCache = result; + return result; + } +} diff --git a/test/transform/resource/after-ecj/EqualsAndHashCodeCache.java b/test/transform/resource/after-ecj/EqualsAndHashCodeCache.java new file mode 100644 index 00000000..4eb4fbb3 --- /dev/null +++ b/test/transform/resource/after-ecj/EqualsAndHashCodeCache.java @@ -0,0 +1,167 @@ +@lombok.EqualsAndHashCode(cacheStrategy = lombok.EqualsAndHashCode.CacheStrategy.LAZY) class EqualsAndHashCode { + int x; + boolean[] y; + Object[] z; + String a; + String b; + EqualsAndHashCode() { + super(); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + if ((o == this)) + return true; + if ((! (o instanceof EqualsAndHashCode))) + return false; + final EqualsAndHashCode other = (EqualsAndHashCode) o; + if ((! other.canEqual((java.lang.Object) this))) + return false; + if ((this.x != other.x)) + return false; + if ((! java.util.Arrays.equals(this.y, other.y))) + return false; + if ((! java.util.Arrays.deepEquals(this.z, other.z))) + 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 EqualsAndHashCode); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + final int PRIME = 59; + int result = 1; + result = ((result * PRIME) + this.x); + result = ((result * PRIME) + java.util.Arrays.hashCode(this.y)); + result = ((result * PRIME) + java.util.Arrays.deepHashCode(this.z)); + 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; + } +} +final @lombok.EqualsAndHashCode(cacheStrategy = lombok.EqualsAndHashCode.CacheStrategy.LAZY) class EqualsAndHashCode2 { + int x; + long y; + float f; + double d; + boolean b; + private transient int $hashCodeCache = 0; + EqualsAndHashCode2() { + super(); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + if ((o == this)) + return true; + if ((! (o instanceof EqualsAndHashCode2))) + return false; + final EqualsAndHashCode2 other = (EqualsAndHashCode2) o; + if ((this.x != other.x)) + return false; + if ((this.y != other.y)) + return false; + if ((java.lang.Float.compare(this.f, other.f) != 0)) + return false; + if ((java.lang.Double.compare(this.d, other.d) != 0)) + return false; + if ((this.b != other.b)) + return false; + return true; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + if ($hashCodeCache != 0) + return $hashCodeCache; + final int PRIME = 59; + int result = 1; + result = ((result * PRIME) + this.x); + final long $y = this.y; + result = ((result * PRIME) + (int) ($y ^ ($y >>> 32))); + result = ((result * PRIME) + java.lang.Float.floatToIntBits(this.f)); + final long $d = java.lang.Double.doubleToLongBits(this.d); + result = ((result * PRIME) + (int) ($d ^ ($d >>> 32))); + result = ((result * PRIME) + (this.b ? 79 : 97)); + $hashCodeCache = result; + return result; + } +} +final @lombok.EqualsAndHashCode(callSuper=false, cacheStrategy = lombok.EqualsAndHashCode.CacheStrategy.LAZY) class EqualsAndHashCode3 extends EqualsAndHashCode { + EqualsAndHashCode3() { + super(); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + if ((o == this)) + return true; + if ((! (o instanceof EqualsAndHashCode3))) + return false; + final EqualsAndHashCode3 other = (EqualsAndHashCode3) o; + if ((! other.canEqual((java.lang.Object) this))) + return false; + return true; + } + protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) { + return (other instanceof EqualsAndHashCode3); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + final int result = 1; + return result; + } +} +@lombok.EqualsAndHashCode(callSuper=true, cacheStrategy = lombok.EqualsAndHashCode.CacheStrategy.LAZY) class EqualsAndHashCode4 extends EqualsAndHashCode { + EqualsAndHashCode4() { + super(); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + if ((o == this)) + return true; + if ((! (o instanceof EqualsAndHashCode4))) + return false; + final EqualsAndHashCode4 other = (EqualsAndHashCode4) o; + if ((! other.canEqual((java.lang.Object) this))) + return false; + if ((! super.equals(o))) + return false; + return true; + } + protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) { + return (other instanceof EqualsAndHashCode4); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + final int result = super.hashCode(); + return result; + } +} +@lombok.EqualsAndHashCode(callSuper=true, cacheStrategy = lombok.EqualsAndHashCode.CacheStrategy.LAZY) class EqualsAndHashCode5 extends EqualsAndHashCode { + private transient int $hashCodeCache = 0; + EqualsAndHashCode5() { + super(); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + if ((o == this)) + return true; + if ((! (o instanceof EqualsAndHashCode5))) + return false; + final EqualsAndHashCode5 other = (EqualsAndHashCode5) o; + if ((! other.canEqual((java.lang.Object) this))) + return false; + if ((! super.equals(o))) + return false; + return true; + } + protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) { + return (other instanceof EqualsAndHashCode5); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + if ($hashCodeCache != 0) + return $hashCodeCache; + final int result = super.hashCode(); + $hashCodeCache = result; + return result; + } +} diff --git a/test/transform/resource/before/EqualsAndHashCodeCache.java b/test/transform/resource/before/EqualsAndHashCodeCache.java new file mode 100644 index 00000000..3c84ee59 --- /dev/null +++ b/test/transform/resource/before/EqualsAndHashCodeCache.java @@ -0,0 +1,29 @@ +@lombok.EqualsAndHashCode(cacheStrategy = lombok.EqualsAndHashCode.CacheStrategy.LAZY) +class EqualsAndHashCode { + int x; + boolean[] y; + Object[] z; + String a; + String b; +} + +@lombok.EqualsAndHashCode(cacheStrategy = lombok.EqualsAndHashCode.CacheStrategy.LAZY) +final class EqualsAndHashCode2 { + int x; + long y; + float f; + double d; + boolean b; +} + +@lombok.EqualsAndHashCode(callSuper=false, cacheStrategy = lombok.EqualsAndHashCode.CacheStrategy.LAZY) +final class EqualsAndHashCode3 extends EqualsAndHashCode { +} + +@lombok.EqualsAndHashCode(callSuper=true, cacheStrategy = lombok.EqualsAndHashCode.CacheStrategy.LAZY) +class EqualsAndHashCode4 extends EqualsAndHashCode { +} + +@lombok.EqualsAndHashCode(callSuper=true, cacheStrategy = lombok.EqualsAndHashCode.CacheStrategy.LAZY) +final class EqualsAndHashCode5 extends EqualsAndHashCode { +} \ No newline at end of file -- cgit From d00ab552e199410c283049cd8d9359a69855f1f2 Mon Sep 17 00:00:00 2001 From: Andre Brait Date: Mon, 13 Jul 2020 18:50:12 +0200 Subject: Finish implementation, add tests --- .../eclipse/handlers/HandleEqualsAndHashCode.java | 9 ++++-- .../javac/handlers/HandleEqualsAndHashCode.java | 18 +++++++----- .../after-delombok/EqualsAndHashCodeCache.java | 19 +++++++----- .../resource/after-ecj/EqualsAndHashCodeCache.java | 34 ++++++++++++---------- .../EqualsAndHashCodeCache.java.messages | 2 ++ 5 files changed, 50 insertions(+), 32 deletions(-) create mode 100644 test/transform/resource/messages-ecj/EqualsAndHashCodeCache.java.messages (limited to 'test/transform/resource') diff --git a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java index 76a46814..6e9423d5 100755 --- a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java +++ b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java @@ -62,6 +62,7 @@ import org.eclipse.jdt.internal.compiler.ast.EqualExpression; import org.eclipse.jdt.internal.compiler.ast.Expression; import org.eclipse.jdt.internal.compiler.ast.FalseLiteral; import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; +import org.eclipse.jdt.internal.compiler.ast.FieldReference; import org.eclipse.jdt.internal.compiler.ast.IfStatement; import org.eclipse.jdt.internal.compiler.ast.InstanceOfExpression; import org.eclipse.jdt.internal.compiler.ast.IntLiteral; @@ -305,8 +306,10 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler>> 32 ^ $d); result = result * PRIME + (this.b ? 79 : 97); - $hashCodeCache = result; + this.$hashCodeCache = result; return result; } } final class EqualsAndHashCode3 extends EqualsAndHashCode { + @java.lang.SuppressWarnings("all") private transient int $hashCodeCache = 0; @java.lang.Override @java.lang.SuppressWarnings("all") @@ -96,9 +98,9 @@ final class EqualsAndHashCode3 extends EqualsAndHashCode { @java.lang.Override @java.lang.SuppressWarnings("all") public int hashCode() { - if ($hashCodeCache != 0) return $hashCodeCache; + if (this.$hashCodeCache != 0) return this.$hashCodeCache; final int result = 1; - $hashCodeCache = result; + this.$hashCodeCache = result; return result; } } @@ -125,13 +127,14 @@ class EqualsAndHashCode4 extends EqualsAndHashCode { } } class EqualsAndHashCode5 extends EqualsAndHashCode { + @java.lang.SuppressWarnings("all") private transient int $hashCodeCache = 0; @java.lang.Override @java.lang.SuppressWarnings("all") public boolean equals(final java.lang.Object o) { if (o == this) return true; if (!(o instanceof EqualsAndHashCode5)) return false; - final EqualsAndHashCode5 other = (EqualsAndHashCode4) o; + final EqualsAndHashCode5 other = (EqualsAndHashCode5) o; if (!other.canEqual((java.lang.Object) this)) return false; if (!super.equals(o)) return false; return true; @@ -143,9 +146,9 @@ class EqualsAndHashCode5 extends EqualsAndHashCode { @java.lang.Override @java.lang.SuppressWarnings("all") public int hashCode() { - if ($hashCodeCache != 0) return $hashCodeCache; + if (this.$hashCodeCache != 0) return this.$hashCodeCache; final int result = super.hashCode(); - $hashCodeCache = result; + this.$hashCodeCache = result; return result; } } diff --git a/test/transform/resource/after-ecj/EqualsAndHashCodeCache.java b/test/transform/resource/after-ecj/EqualsAndHashCodeCache.java index 4eb4fbb3..3c4d0daa 100644 --- a/test/transform/resource/after-ecj/EqualsAndHashCodeCache.java +++ b/test/transform/resource/after-ecj/EqualsAndHashCodeCache.java @@ -48,12 +48,12 @@ } } final @lombok.EqualsAndHashCode(cacheStrategy = lombok.EqualsAndHashCode.CacheStrategy.LAZY) class EqualsAndHashCode2 { + private transient @java.lang.SuppressWarnings("all") int $hashCodeCache = 0; int x; long y; float f; double d; boolean b; - private transient int $hashCodeCache = 0; EqualsAndHashCode2() { super(); } @@ -76,8 +76,8 @@ final @lombok.EqualsAndHashCode(cacheStrategy = lombok.EqualsAndHashCode.CacheSt return true; } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { - if ($hashCodeCache != 0) - return $hashCodeCache; + if ((this.$hashCodeCache != 0)) + return this.$hashCodeCache; final int PRIME = 59; int result = 1; result = ((result * PRIME) + this.x); @@ -87,11 +87,12 @@ final @lombok.EqualsAndHashCode(cacheStrategy = lombok.EqualsAndHashCode.CacheSt final long $d = java.lang.Double.doubleToLongBits(this.d); result = ((result * PRIME) + (int) ($d ^ ($d >>> 32))); result = ((result * PRIME) + (this.b ? 79 : 97)); - $hashCodeCache = result; + this.$hashCodeCache = result; return result; } } -final @lombok.EqualsAndHashCode(callSuper=false, cacheStrategy = lombok.EqualsAndHashCode.CacheStrategy.LAZY) class EqualsAndHashCode3 extends EqualsAndHashCode { +final @lombok.EqualsAndHashCode(callSuper = false,cacheStrategy = lombok.EqualsAndHashCode.CacheStrategy.LAZY) class EqualsAndHashCode3 extends EqualsAndHashCode { + private transient @java.lang.SuppressWarnings("all") int $hashCodeCache = 0; EqualsAndHashCode3() { super(); } @@ -109,11 +110,14 @@ final @lombok.EqualsAndHashCode(callSuper=false, cacheStrategy = lombok.EqualsAn return (other instanceof EqualsAndHashCode3); } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + if ((this.$hashCodeCache != 0)) + return this.$hashCodeCache; final int result = 1; + this.$hashCodeCache = result; return result; } } -@lombok.EqualsAndHashCode(callSuper=true, cacheStrategy = lombok.EqualsAndHashCode.CacheStrategy.LAZY) class EqualsAndHashCode4 extends EqualsAndHashCode { +@lombok.EqualsAndHashCode(callSuper = true,cacheStrategy = lombok.EqualsAndHashCode.CacheStrategy.LAZY) class EqualsAndHashCode4 extends EqualsAndHashCode { EqualsAndHashCode4() { super(); } @@ -137,10 +141,10 @@ final @lombok.EqualsAndHashCode(callSuper=false, cacheStrategy = lombok.EqualsAn return result; } } -@lombok.EqualsAndHashCode(callSuper=true, cacheStrategy = lombok.EqualsAndHashCode.CacheStrategy.LAZY) class EqualsAndHashCode5 extends EqualsAndHashCode { - private transient int $hashCodeCache = 0; +final @lombok.EqualsAndHashCode(callSuper = true,cacheStrategy = lombok.EqualsAndHashCode.CacheStrategy.LAZY) class EqualsAndHashCode5 extends EqualsAndHashCode { + private transient @java.lang.SuppressWarnings("all") int $hashCodeCache = 0; EqualsAndHashCode5() { - super(); + super(); } public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { if ((o == this)) @@ -149,19 +153,19 @@ final @lombok.EqualsAndHashCode(callSuper=false, cacheStrategy = lombok.EqualsAn return false; final EqualsAndHashCode5 other = (EqualsAndHashCode5) o; if ((! other.canEqual((java.lang.Object) this))) - return false; + return false; if ((! super.equals(o))) - return false; - return true; + return false; + return true; } protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) { return (other instanceof EqualsAndHashCode5); } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { - if ($hashCodeCache != 0) - return $hashCodeCache; + if ((this.$hashCodeCache != 0)) + return this.$hashCodeCache; final int result = super.hashCode(); - $hashCodeCache = result; + this.$hashCodeCache = result; return result; } } diff --git a/test/transform/resource/messages-ecj/EqualsAndHashCodeCache.java.messages b/test/transform/resource/messages-ecj/EqualsAndHashCodeCache.java.messages new file mode 100644 index 00000000..24d202bd --- /dev/null +++ b/test/transform/resource/messages-ecj/EqualsAndHashCodeCache.java.messages @@ -0,0 +1,2 @@ +1 Not caching the result of hashCode: Annotated type is not final. +23 Not caching the result of hashCode: Annotated type is not final. \ No newline at end of file -- cgit From 2aea0cb3d2bdc1d52a90dc52e44029e9b213f1be Mon Sep 17 00:00:00 2001 From: Andre Brait Date: Mon, 13 Jul 2020 19:01:21 +0200 Subject: Fix delombok tests --- test/transform/resource/after-delombok/EqualsAndHashCodeCache.java | 2 +- .../resource/messages-delombok/EqualsAndHashCodeCache.java.messages | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 test/transform/resource/messages-delombok/EqualsAndHashCodeCache.java.messages (limited to 'test/transform/resource') diff --git a/test/transform/resource/after-delombok/EqualsAndHashCodeCache.java b/test/transform/resource/after-delombok/EqualsAndHashCodeCache.java index 8fecbdbe..a028cca7 100644 --- a/test/transform/resource/after-delombok/EqualsAndHashCodeCache.java +++ b/test/transform/resource/after-delombok/EqualsAndHashCodeCache.java @@ -126,7 +126,7 @@ class EqualsAndHashCode4 extends EqualsAndHashCode { return result; } } -class EqualsAndHashCode5 extends EqualsAndHashCode { +final class EqualsAndHashCode5 extends EqualsAndHashCode { @java.lang.SuppressWarnings("all") private transient int $hashCodeCache = 0; @java.lang.Override diff --git a/test/transform/resource/messages-delombok/EqualsAndHashCodeCache.java.messages b/test/transform/resource/messages-delombok/EqualsAndHashCodeCache.java.messages new file mode 100644 index 00000000..24d202bd --- /dev/null +++ b/test/transform/resource/messages-delombok/EqualsAndHashCodeCache.java.messages @@ -0,0 +1,2 @@ +1 Not caching the result of hashCode: Annotated type is not final. +23 Not caching the result of hashCode: Annotated type is not final. \ No newline at end of file -- cgit From 8d004c0638e4b865c38527a500c493288328eac8 Mon Sep 17 00:00:00 2001 From: Andre Brait Date: Wed, 19 Aug 2020 17:59:19 +0200 Subject: Allow non-final types, use Integer.MIN_VALUE Allow caching hash code for non-final classes (but will warn) Use Integer.MIN_VALUE to differentiate uncached and 0 cached --- .../eclipse/handlers/HandleEqualsAndHashCode.java | 23 +++++++++++++++------- .../javac/handlers/HandleEqualsAndHashCode.java | 18 ++++++++++------- .../after-delombok/EqualsAndHashCodeCache.java | 14 ++++++++++--- .../resource/after-ecj/EqualsAndHashCodeCache.java | 14 ++++++++++--- .../EqualsAndHashCodeCache.java.messages | 4 ++-- .../EqualsAndHashCodeCache.java.messages | 4 ++-- 6 files changed, 53 insertions(+), 24 deletions(-) (limited to 'test/transform/resource') diff --git a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java index 37379bb9..d5fa5618 100755 --- a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java +++ b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java @@ -231,16 +231,16 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler>> 32 ^ $d); result = result * PRIME + (this.b ? 79 : 97); - this.$hashCodeCache = result; + this.$hashCodeCache = result != 0 ? result : java.lang.Integer.MIN_VALUE; return result; } } @@ -100,11 +104,13 @@ final class EqualsAndHashCode3 extends EqualsAndHashCode { public int hashCode() { if (this.$hashCodeCache != 0) return this.$hashCodeCache; final int result = 1; - this.$hashCodeCache = result; + this.$hashCodeCache = result != 0 ? result : java.lang.Integer.MIN_VALUE; return result; } } class EqualsAndHashCode4 extends EqualsAndHashCode { + @java.lang.SuppressWarnings("all") + private transient int $hashCodeCache = 0; @java.lang.Override @java.lang.SuppressWarnings("all") public boolean equals(final java.lang.Object o) { @@ -122,7 +128,9 @@ class EqualsAndHashCode4 extends EqualsAndHashCode { @java.lang.Override @java.lang.SuppressWarnings("all") public int hashCode() { + if (this.$hashCodeCache != 0) return this.$hashCodeCache; final int result = super.hashCode(); + this.$hashCodeCache = result != 0 ? result : java.lang.Integer.MIN_VALUE; return result; } } @@ -148,7 +156,7 @@ final class EqualsAndHashCode5 extends EqualsAndHashCode { public int hashCode() { if (this.$hashCodeCache != 0) return this.$hashCodeCache; final int result = super.hashCode(); - this.$hashCodeCache = result; + this.$hashCodeCache = result != 0 ? result : java.lang.Integer.MIN_VALUE; return result; } } diff --git a/test/transform/resource/after-ecj/EqualsAndHashCodeCache.java b/test/transform/resource/after-ecj/EqualsAndHashCodeCache.java index 3c4d0daa..b29fd6b3 100644 --- a/test/transform/resource/after-ecj/EqualsAndHashCodeCache.java +++ b/test/transform/resource/after-ecj/EqualsAndHashCodeCache.java @@ -1,4 +1,5 @@ @lombok.EqualsAndHashCode(cacheStrategy = lombok.EqualsAndHashCode.CacheStrategy.LAZY) class EqualsAndHashCode { + private transient @java.lang.SuppressWarnings("all") int $hashCodeCache = 0; int x; boolean[] y; Object[] z; @@ -35,6 +36,8 @@ return (other instanceof EqualsAndHashCode); } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + if ((this.$hashCodeCache != 0)) + return this.$hashCodeCache; final int PRIME = 59; int result = 1; result = ((result * PRIME) + this.x); @@ -44,6 +47,7 @@ result = ((result * PRIME) + (($a == null) ? 43 : $a.hashCode())); final java.lang.Object $b = this.b; result = ((result * PRIME) + (($b == null) ? 43 : $b.hashCode())); + this.$hashCodeCache = ((result != 0) ? result : java.lang.Integer.MIN_VALUE); return result; } } @@ -87,7 +91,7 @@ final @lombok.EqualsAndHashCode(cacheStrategy = lombok.EqualsAndHashCode.CacheSt final long $d = java.lang.Double.doubleToLongBits(this.d); result = ((result * PRIME) + (int) ($d ^ ($d >>> 32))); result = ((result * PRIME) + (this.b ? 79 : 97)); - this.$hashCodeCache = result; + this.$hashCodeCache = ((result != 0) ? result : java.lang.Integer.MIN_VALUE); return result; } } @@ -113,11 +117,12 @@ final @lombok.EqualsAndHashCode(callSuper = false,cacheStrategy = lombok.EqualsA if ((this.$hashCodeCache != 0)) return this.$hashCodeCache; final int result = 1; - this.$hashCodeCache = result; + this.$hashCodeCache = ((result != 0) ? result : java.lang.Integer.MIN_VALUE); return result; } } @lombok.EqualsAndHashCode(callSuper = true,cacheStrategy = lombok.EqualsAndHashCode.CacheStrategy.LAZY) class EqualsAndHashCode4 extends EqualsAndHashCode { + private transient @java.lang.SuppressWarnings("all") int $hashCodeCache = 0; EqualsAndHashCode4() { super(); } @@ -137,7 +142,10 @@ final @lombok.EqualsAndHashCode(callSuper = false,cacheStrategy = lombok.EqualsA return (other instanceof EqualsAndHashCode4); } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + if ((this.$hashCodeCache != 0)) + return this.$hashCodeCache; final int result = super.hashCode(); + this.$hashCodeCache = ((result != 0) ? result : java.lang.Integer.MIN_VALUE); return result; } } @@ -165,7 +173,7 @@ final @lombok.EqualsAndHashCode(callSuper = true,cacheStrategy = lombok.EqualsAn if ((this.$hashCodeCache != 0)) return this.$hashCodeCache; final int result = super.hashCode(); - this.$hashCodeCache = result; + this.$hashCodeCache = ((result != 0) ? result : java.lang.Integer.MIN_VALUE); return result; } } diff --git a/test/transform/resource/messages-delombok/EqualsAndHashCodeCache.java.messages b/test/transform/resource/messages-delombok/EqualsAndHashCodeCache.java.messages index 24d202bd..f1686a6e 100644 --- a/test/transform/resource/messages-delombok/EqualsAndHashCodeCache.java.messages +++ b/test/transform/resource/messages-delombok/EqualsAndHashCodeCache.java.messages @@ -1,2 +1,2 @@ -1 Not caching the result of hashCode: Annotated type is not final. -23 Not caching the result of hashCode: Annotated type is not final. \ No newline at end of file +1 Caching the result of hashCode for non-final type. +23 Caching the result of hashCode for non-final type. \ No newline at end of file diff --git a/test/transform/resource/messages-ecj/EqualsAndHashCodeCache.java.messages b/test/transform/resource/messages-ecj/EqualsAndHashCodeCache.java.messages index 24d202bd..f1686a6e 100644 --- a/test/transform/resource/messages-ecj/EqualsAndHashCodeCache.java.messages +++ b/test/transform/resource/messages-ecj/EqualsAndHashCodeCache.java.messages @@ -1,2 +1,2 @@ -1 Not caching the result of hashCode: Annotated type is not final. -23 Not caching the result of hashCode: Annotated type is not final. \ No newline at end of file +1 Caching the result of hashCode for non-final type. +23 Caching the result of hashCode for non-final type. \ No newline at end of file -- cgit From ee6c0ca7f2274b24571afdc8586eff9052f5eda1 Mon Sep 17 00:00:00 2001 From: Andre Brait Date: Mon, 14 Sep 2020 19:59:54 +0200 Subject: Remove warning for final classes --- src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java | 4 ---- src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java | 4 ---- .../resource/messages-delombok/EqualsAndHashCodeCache.java.messages | 2 -- .../resource/messages-ecj/EqualsAndHashCodeCache.java.messages | 2 -- 4 files changed, 12 deletions(-) delete mode 100644 test/transform/resource/messages-delombok/EqualsAndHashCodeCache.java.messages delete mode 100644 test/transform/resource/messages-ecj/EqualsAndHashCodeCache.java.messages (limited to 'test/transform/resource') diff --git a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java index d5fa5618..2f0ce227 100755 --- a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java +++ b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java @@ -237,10 +237,6 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler Date: Fri, 25 Sep 2020 00:13:50 +0200 Subject: Cache hashCode: - Fix bug where 0 would be returned once - Fix Eclipse position error - Don't initialize field with default value 0 --- .../eclipse/handlers/HandleEqualsAndHashCode.java | 44 +++++++++++++++------- .../javac/handlers/HandleEqualsAndHashCode.java | 22 ++++++----- .../after-delombok/EqualsAndHashCodeCache.java | 31 ++++++++------- .../resource/after-ecj/EqualsAndHashCodeCache.java | 36 +++++++++++------- 4 files changed, 84 insertions(+), 49 deletions(-) (limited to 'test/transform/resource') diff --git a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java index 2f0ce227..deb19c00 100755 --- a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java +++ b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java @@ -246,12 +246,11 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler member : members) { @@ -345,14 +344,17 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler>> 32 ^ $d); result = result * PRIME + (this.b ? 79 : 97); - this.$hashCodeCache = result != 0 ? result : java.lang.Integer.MIN_VALUE; + if (result == 0) result = java.lang.Integer.MIN_VALUE; + this.$hashCodeCache = result; return result; } } final class EqualsAndHashCode3 extends EqualsAndHashCode { @java.lang.SuppressWarnings("all") - private transient int $hashCodeCache = 0; + private transient int $hashCodeCache; @java.lang.Override @java.lang.SuppressWarnings("all") public boolean equals(final java.lang.Object o) { @@ -103,14 +105,15 @@ final class EqualsAndHashCode3 extends EqualsAndHashCode { @java.lang.SuppressWarnings("all") public int hashCode() { if (this.$hashCodeCache != 0) return this.$hashCodeCache; - final int result = 1; - this.$hashCodeCache = result != 0 ? result : java.lang.Integer.MIN_VALUE; + int result = 1; + if (result == 0) result = java.lang.Integer.MIN_VALUE; + this.$hashCodeCache = result; return result; } } class EqualsAndHashCode4 extends EqualsAndHashCode { @java.lang.SuppressWarnings("all") - private transient int $hashCodeCache = 0; + private transient int $hashCodeCache; @java.lang.Override @java.lang.SuppressWarnings("all") public boolean equals(final java.lang.Object o) { @@ -129,14 +132,15 @@ class EqualsAndHashCode4 extends EqualsAndHashCode { @java.lang.SuppressWarnings("all") public int hashCode() { if (this.$hashCodeCache != 0) return this.$hashCodeCache; - final int result = super.hashCode(); - this.$hashCodeCache = result != 0 ? result : java.lang.Integer.MIN_VALUE; + int result = super.hashCode(); + if (result == 0) result = java.lang.Integer.MIN_VALUE; + this.$hashCodeCache = result; return result; } } final class EqualsAndHashCode5 extends EqualsAndHashCode { @java.lang.SuppressWarnings("all") - private transient int $hashCodeCache = 0; + private transient int $hashCodeCache; @java.lang.Override @java.lang.SuppressWarnings("all") public boolean equals(final java.lang.Object o) { @@ -155,8 +159,9 @@ final class EqualsAndHashCode5 extends EqualsAndHashCode { @java.lang.SuppressWarnings("all") public int hashCode() { if (this.$hashCodeCache != 0) return this.$hashCodeCache; - final int result = super.hashCode(); - this.$hashCodeCache = result != 0 ? result : java.lang.Integer.MIN_VALUE; + int result = super.hashCode(); + if (result == 0) result = java.lang.Integer.MIN_VALUE; + this.$hashCodeCache = result; return result; } } diff --git a/test/transform/resource/after-ecj/EqualsAndHashCodeCache.java b/test/transform/resource/after-ecj/EqualsAndHashCodeCache.java index b29fd6b3..7094b636 100644 --- a/test/transform/resource/after-ecj/EqualsAndHashCodeCache.java +++ b/test/transform/resource/after-ecj/EqualsAndHashCodeCache.java @@ -1,5 +1,5 @@ @lombok.EqualsAndHashCode(cacheStrategy = lombok.EqualsAndHashCode.CacheStrategy.LAZY) class EqualsAndHashCode { - private transient @java.lang.SuppressWarnings("all") int $hashCodeCache = 0; + private transient @java.lang.SuppressWarnings("all") int $hashCodeCache; int x; boolean[] y; Object[] z; @@ -47,12 +47,14 @@ result = ((result * PRIME) + (($a == null) ? 43 : $a.hashCode())); final java.lang.Object $b = this.b; result = ((result * PRIME) + (($b == null) ? 43 : $b.hashCode())); - this.$hashCodeCache = ((result != 0) ? result : java.lang.Integer.MIN_VALUE); + if ((result == 0)) + result = java.lang.Integer.MIN_VALUE; + this.$hashCodeCache = result; return result; } } final @lombok.EqualsAndHashCode(cacheStrategy = lombok.EqualsAndHashCode.CacheStrategy.LAZY) class EqualsAndHashCode2 { - private transient @java.lang.SuppressWarnings("all") int $hashCodeCache = 0; + private transient @java.lang.SuppressWarnings("all") int $hashCodeCache; int x; long y; float f; @@ -91,12 +93,14 @@ final @lombok.EqualsAndHashCode(cacheStrategy = lombok.EqualsAndHashCode.CacheSt final long $d = java.lang.Double.doubleToLongBits(this.d); result = ((result * PRIME) + (int) ($d ^ ($d >>> 32))); result = ((result * PRIME) + (this.b ? 79 : 97)); - this.$hashCodeCache = ((result != 0) ? result : java.lang.Integer.MIN_VALUE); + if ((result == 0)) + result = java.lang.Integer.MIN_VALUE; + this.$hashCodeCache = result; return result; } } final @lombok.EqualsAndHashCode(callSuper = false,cacheStrategy = lombok.EqualsAndHashCode.CacheStrategy.LAZY) class EqualsAndHashCode3 extends EqualsAndHashCode { - private transient @java.lang.SuppressWarnings("all") int $hashCodeCache = 0; + private transient @java.lang.SuppressWarnings("all") int $hashCodeCache; EqualsAndHashCode3() { super(); } @@ -116,13 +120,15 @@ final @lombok.EqualsAndHashCode(callSuper = false,cacheStrategy = lombok.EqualsA public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { if ((this.$hashCodeCache != 0)) return this.$hashCodeCache; - final int result = 1; - this.$hashCodeCache = ((result != 0) ? result : java.lang.Integer.MIN_VALUE); + int result = 1; + if ((result == 0)) + result = java.lang.Integer.MIN_VALUE; + this.$hashCodeCache = result; return result; } } @lombok.EqualsAndHashCode(callSuper = true,cacheStrategy = lombok.EqualsAndHashCode.CacheStrategy.LAZY) class EqualsAndHashCode4 extends EqualsAndHashCode { - private transient @java.lang.SuppressWarnings("all") int $hashCodeCache = 0; + private transient @java.lang.SuppressWarnings("all") int $hashCodeCache; EqualsAndHashCode4() { super(); } @@ -144,13 +150,15 @@ final @lombok.EqualsAndHashCode(callSuper = false,cacheStrategy = lombok.EqualsA public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { if ((this.$hashCodeCache != 0)) return this.$hashCodeCache; - final int result = super.hashCode(); - this.$hashCodeCache = ((result != 0) ? result : java.lang.Integer.MIN_VALUE); + int result = super.hashCode(); + if ((result == 0)) + result = java.lang.Integer.MIN_VALUE; + this.$hashCodeCache = result; return result; } } final @lombok.EqualsAndHashCode(callSuper = true,cacheStrategy = lombok.EqualsAndHashCode.CacheStrategy.LAZY) class EqualsAndHashCode5 extends EqualsAndHashCode { - private transient @java.lang.SuppressWarnings("all") int $hashCodeCache = 0; + private transient @java.lang.SuppressWarnings("all") int $hashCodeCache; EqualsAndHashCode5() { super(); } @@ -172,8 +180,10 @@ final @lombok.EqualsAndHashCode(callSuper = true,cacheStrategy = lombok.EqualsAn public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { if ((this.$hashCodeCache != 0)) return this.$hashCodeCache; - final int result = super.hashCode(); - this.$hashCodeCache = ((result != 0) ? result : java.lang.Integer.MIN_VALUE); + int result = super.hashCode(); + if ((result == 0)) + result = java.lang.Integer.MIN_VALUE; + this.$hashCodeCache = result; return result; } } -- cgit