From 83e2fb5e00e1868f0b4f0fe38b1ea1383119f8ee Mon Sep 17 00:00:00 2001 From: Roel Spilker Date: Mon, 18 Jul 2011 20:59:52 +0200 Subject: Now either all or none of equals/hashCode/canEqual is generated. Fixes issue 240. --- .../resource/after-delombok/EqualsAndHashCode.java | 99 +++++++++++++++++++ .../EqualsAndHashCodeWithExistingMethods.java | 18 ++++ .../resource/after-ecj/EqualsAndHashCode.java | 109 +++++++++++++++++++++ .../EqualsAndHashCodeWithExistingMethods.java | 27 +++++ .../resource/after-eclipse/EqualsAndHashCode.java | 109 +++++++++++++++++++++ .../EqualsAndHashCodeWithExistingMethods.java | 27 +++++ .../resource/before/EqualsAndHashCode.java | 20 ++++ .../EqualsAndHashCodeWithExistingMethods.java | 26 +++++ ...alsAndHashCodeWithExistingMethods.java.messages | 3 + ...alsAndHashCodeWithExistingMethods.java.messages | 3 + ...alsAndHashCodeWithExistingMethods.java.messages | 3 + 11 files changed, 444 insertions(+) create mode 100644 test/transform/resource/after-delombok/EqualsAndHashCode.java create mode 100644 test/transform/resource/after-delombok/EqualsAndHashCodeWithExistingMethods.java create mode 100644 test/transform/resource/after-ecj/EqualsAndHashCode.java create mode 100644 test/transform/resource/after-ecj/EqualsAndHashCodeWithExistingMethods.java create mode 100644 test/transform/resource/after-eclipse/EqualsAndHashCode.java create mode 100644 test/transform/resource/after-eclipse/EqualsAndHashCodeWithExistingMethods.java create mode 100644 test/transform/resource/before/EqualsAndHashCode.java create mode 100644 test/transform/resource/before/EqualsAndHashCodeWithExistingMethods.java create mode 100644 test/transform/resource/messages-delombok/EqualsAndHashCodeWithExistingMethods.java.messages create mode 100644 test/transform/resource/messages-ecj/EqualsAndHashCodeWithExistingMethods.java.messages create mode 100644 test/transform/resource/messages-eclipse/EqualsAndHashCodeWithExistingMethods.java.messages (limited to 'test/transform/resource') diff --git a/test/transform/resource/after-delombok/EqualsAndHashCode.java b/test/transform/resource/after-delombok/EqualsAndHashCode.java new file mode 100644 index 00000000..e7f701e8 --- /dev/null +++ b/test/transform/resource/after-delombok/EqualsAndHashCode.java @@ -0,0 +1,99 @@ +class EqualsAndHashCode { + int x; + boolean[] y; + Object[] z; + String a; + @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; + if (this.a == null ? other.a != null : !this.a.equals((java.lang.Object)other.a)) return false; + return true; + } + @java.lang.SuppressWarnings("all") + public boolean canEqual(final java.lang.Object other) { + return other instanceof EqualsAndHashCode; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public int hashCode() { + final int PRIME = 31; + 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); + result = result * PRIME + (this.a == null ? 0 : this.a.hashCode()); + return result; + } +} +final class EqualsAndHashCode2 { + int x; + @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; + return true; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public int hashCode() { + final int PRIME = 31; + int result = 1; + result = result * PRIME + this.x; + return result; + } +} +final class EqualsAndHashCode3 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 EqualsAndHashCode3)) return false; + final EqualsAndHashCode3 other = (EqualsAndHashCode3)o; + if (!other.canEqual((java.lang.Object)this)) return false; + return true; + } + @java.lang.SuppressWarnings("all") + public boolean canEqual(final java.lang.Object other) { + return other instanceof EqualsAndHashCode3; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public int hashCode() { + int result = 1; + 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") + public boolean canEqual(final java.lang.Object other) { + return other instanceof EqualsAndHashCode4; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public int hashCode() { + final int PRIME = 31; + int result = 1; + result = result * PRIME + super.hashCode(); + return result; + } +} \ No newline at end of file diff --git a/test/transform/resource/after-delombok/EqualsAndHashCodeWithExistingMethods.java b/test/transform/resource/after-delombok/EqualsAndHashCodeWithExistingMethods.java new file mode 100644 index 00000000..93b20e25 --- /dev/null +++ b/test/transform/resource/after-delombok/EqualsAndHashCodeWithExistingMethods.java @@ -0,0 +1,18 @@ +class EqualsAndHashCodeWithExistingMethods { + int x; + public int hashCode() { + return 42; + } +} +final class EqualsAndHashCodeWithExistingMethods2 { + int x; + public boolean equals(Object other) { + return false; + } +} +final class EqualsAndHashCodeWithExistingMethods3 extends EqualsAndHashCodeWithExistingMethods { + int x; + public boolean canEqual(Object other) { + return true; + } +} \ No newline at end of file diff --git a/test/transform/resource/after-ecj/EqualsAndHashCode.java b/test/transform/resource/after-ecj/EqualsAndHashCode.java new file mode 100644 index 00000000..bb757b00 --- /dev/null +++ b/test/transform/resource/after-ecj/EqualsAndHashCode.java @@ -0,0 +1,109 @@ +@lombok.EqualsAndHashCode class EqualsAndHashCode { + int x; + boolean[] y; + Object[] z; + String a; + 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; + if (((this.a == null) ? (other.a != null) : (! this.a.equals((java.lang.Object) other.a)))) + return false; + return true; + } + public @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 = 31; + 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)); + result = ((result * PRIME) + ((this.a == null) ? 0 : this.a.hashCode())); + return result; + } + EqualsAndHashCode() { + super(); + } +} +final @lombok.EqualsAndHashCode class EqualsAndHashCode2 { + int x; + 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; + return true; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + final int PRIME = 31; + int result = 1; + result = ((result * PRIME) + this.x); + return result; + } + EqualsAndHashCode2() { + super(); + } +} +final @lombok.EqualsAndHashCode(callSuper = false) class EqualsAndHashCode3 extends EqualsAndHashCode { + 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; + } + public @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() { + int result = 1; + return result; + } + EqualsAndHashCode3() { + super(); + } +} +@lombok.EqualsAndHashCode(callSuper = true) class EqualsAndHashCode4 extends EqualsAndHashCode { + 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; + } + public @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 PRIME = 31; + int result = 1; + result = ((result * PRIME) + super.hashCode()); + return result; + } + EqualsAndHashCode4() { + super(); + } +} diff --git a/test/transform/resource/after-ecj/EqualsAndHashCodeWithExistingMethods.java b/test/transform/resource/after-ecj/EqualsAndHashCodeWithExistingMethods.java new file mode 100644 index 00000000..50b219f1 --- /dev/null +++ b/test/transform/resource/after-ecj/EqualsAndHashCodeWithExistingMethods.java @@ -0,0 +1,27 @@ +@lombok.EqualsAndHashCode class EqualsAndHashCodeWithExistingMethods { + int x; + EqualsAndHashCodeWithExistingMethods() { + super(); + } + public int hashCode() { + return 42; + } +} +final @lombok.EqualsAndHashCode class EqualsAndHashCodeWithExistingMethods2 { + int x; + EqualsAndHashCodeWithExistingMethods2() { + super(); + } + public boolean equals(Object other) { + return false; + } +} +final @lombok.EqualsAndHashCode(callSuper = true) class EqualsAndHashCodeWithExistingMethods3 extends EqualsAndHashCodeWithExistingMethods { + int x; + EqualsAndHashCodeWithExistingMethods3() { + super(); + } + public boolean canEqual(Object other) { + return true; + } +} \ No newline at end of file diff --git a/test/transform/resource/after-eclipse/EqualsAndHashCode.java b/test/transform/resource/after-eclipse/EqualsAndHashCode.java new file mode 100644 index 00000000..bb757b00 --- /dev/null +++ b/test/transform/resource/after-eclipse/EqualsAndHashCode.java @@ -0,0 +1,109 @@ +@lombok.EqualsAndHashCode class EqualsAndHashCode { + int x; + boolean[] y; + Object[] z; + String a; + 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; + if (((this.a == null) ? (other.a != null) : (! this.a.equals((java.lang.Object) other.a)))) + return false; + return true; + } + public @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 = 31; + 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)); + result = ((result * PRIME) + ((this.a == null) ? 0 : this.a.hashCode())); + return result; + } + EqualsAndHashCode() { + super(); + } +} +final @lombok.EqualsAndHashCode class EqualsAndHashCode2 { + int x; + 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; + return true; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + final int PRIME = 31; + int result = 1; + result = ((result * PRIME) + this.x); + return result; + } + EqualsAndHashCode2() { + super(); + } +} +final @lombok.EqualsAndHashCode(callSuper = false) class EqualsAndHashCode3 extends EqualsAndHashCode { + 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; + } + public @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() { + int result = 1; + return result; + } + EqualsAndHashCode3() { + super(); + } +} +@lombok.EqualsAndHashCode(callSuper = true) class EqualsAndHashCode4 extends EqualsAndHashCode { + 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; + } + public @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 PRIME = 31; + int result = 1; + result = ((result * PRIME) + super.hashCode()); + return result; + } + EqualsAndHashCode4() { + super(); + } +} diff --git a/test/transform/resource/after-eclipse/EqualsAndHashCodeWithExistingMethods.java b/test/transform/resource/after-eclipse/EqualsAndHashCodeWithExistingMethods.java new file mode 100644 index 00000000..50b219f1 --- /dev/null +++ b/test/transform/resource/after-eclipse/EqualsAndHashCodeWithExistingMethods.java @@ -0,0 +1,27 @@ +@lombok.EqualsAndHashCode class EqualsAndHashCodeWithExistingMethods { + int x; + EqualsAndHashCodeWithExistingMethods() { + super(); + } + public int hashCode() { + return 42; + } +} +final @lombok.EqualsAndHashCode class EqualsAndHashCodeWithExistingMethods2 { + int x; + EqualsAndHashCodeWithExistingMethods2() { + super(); + } + public boolean equals(Object other) { + return false; + } +} +final @lombok.EqualsAndHashCode(callSuper = true) class EqualsAndHashCodeWithExistingMethods3 extends EqualsAndHashCodeWithExistingMethods { + int x; + EqualsAndHashCodeWithExistingMethods3() { + super(); + } + public boolean canEqual(Object other) { + return true; + } +} \ No newline at end of file diff --git a/test/transform/resource/before/EqualsAndHashCode.java b/test/transform/resource/before/EqualsAndHashCode.java new file mode 100644 index 00000000..1688c1fc --- /dev/null +++ b/test/transform/resource/before/EqualsAndHashCode.java @@ -0,0 +1,20 @@ +@lombok.EqualsAndHashCode +class EqualsAndHashCode { + int x; + boolean[] y; + Object[] z; + String a; +} + +@lombok.EqualsAndHashCode +final class EqualsAndHashCode2 { + int x; +} + +@lombok.EqualsAndHashCode(callSuper=false) +final class EqualsAndHashCode3 extends EqualsAndHashCode { +} + +@lombok.EqualsAndHashCode(callSuper=true) +class EqualsAndHashCode4 extends EqualsAndHashCode { +} \ No newline at end of file diff --git a/test/transform/resource/before/EqualsAndHashCodeWithExistingMethods.java b/test/transform/resource/before/EqualsAndHashCodeWithExistingMethods.java new file mode 100644 index 00000000..be90d871 --- /dev/null +++ b/test/transform/resource/before/EqualsAndHashCodeWithExistingMethods.java @@ -0,0 +1,26 @@ +@lombok.EqualsAndHashCode +class EqualsAndHashCodeWithExistingMethods { + int x; + + public int hashCode() { + return 42; + } +} + +@lombok.EqualsAndHashCode +final class EqualsAndHashCodeWithExistingMethods2 { + int x; + + public boolean equals(Object other) { + return false; + } +} + +@lombok.EqualsAndHashCode(callSuper=true) +final class EqualsAndHashCodeWithExistingMethods3 extends EqualsAndHashCodeWithExistingMethods { + int x; + + public boolean canEqual(Object other) { + return true; + } +} \ No newline at end of file diff --git a/test/transform/resource/messages-delombok/EqualsAndHashCodeWithExistingMethods.java.messages b/test/transform/resource/messages-delombok/EqualsAndHashCodeWithExistingMethods.java.messages new file mode 100644 index 00000000..dd78e67f --- /dev/null +++ b/test/transform/resource/messages-delombok/EqualsAndHashCodeWithExistingMethods.java.messages @@ -0,0 +1,3 @@ +1:1 WARNING Not generating equals, hashCode and canEquals: A method with one of those names already exists. (Either all or none of these methods will be generated). +10:1 WARNING Not generating equals and hashCode: A method with one of those names already exists. (Either all or none of these methods will be generated). +19:1 WARNING Not generating equals, hashCode and canEquals: A method with one of those names already exists. (Either all or none of these methods will be generated). diff --git a/test/transform/resource/messages-ecj/EqualsAndHashCodeWithExistingMethods.java.messages b/test/transform/resource/messages-ecj/EqualsAndHashCodeWithExistingMethods.java.messages new file mode 100644 index 00000000..3ad31311 --- /dev/null +++ b/test/transform/resource/messages-ecj/EqualsAndHashCodeWithExistingMethods.java.messages @@ -0,0 +1,3 @@ +1 warning Not generating equals, hashCode and canEquals: A method with one of those names already exists. (Either all or none of these methods will be generated). +10 warning Not generating equals and hashCode: A method with one of those names already exists. (Either all or none of these methods will be generated). +19 warning Not generating equals, hashCode and canEquals: A method with one of those names already exists. (Either all or none of these methods will be generated). diff --git a/test/transform/resource/messages-eclipse/EqualsAndHashCodeWithExistingMethods.java.messages b/test/transform/resource/messages-eclipse/EqualsAndHashCodeWithExistingMethods.java.messages new file mode 100644 index 00000000..3ad31311 --- /dev/null +++ b/test/transform/resource/messages-eclipse/EqualsAndHashCodeWithExistingMethods.java.messages @@ -0,0 +1,3 @@ +1 warning Not generating equals, hashCode and canEquals: A method with one of those names already exists. (Either all or none of these methods will be generated). +10 warning Not generating equals and hashCode: A method with one of those names already exists. (Either all or none of these methods will be generated). +19 warning Not generating equals, hashCode and canEquals: A method with one of those names already exists. (Either all or none of these methods will be generated). -- cgit