diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2018-11-08 15:51:08 +0100 |
---|---|---|
committer | Reinier Zwitserloot <reinier@zwitserloot.com> | 2018-11-08 15:51:08 +0100 |
commit | db19327cb4b9f5a08665b85d4cb953118ce69c13 (patch) | |
tree | 4271b44e0d4c2737d54744ad7e8f0222d5c7b3d2 /test/transform | |
parent | a685d0828c3cda044073054c203d17bcf6ab1096 (diff) | |
download | lombok-db19327cb4b9f5a08665b85d4cb953118ce69c13.tar.gz lombok-db19327cb4b9f5a08665b85d4cb953118ce69c13.tar.bz2 lombok-db19327cb4b9f5a08665b85d4cb953118ce69c13.zip |
[fixes #1628] Lombok now marks the `result` field used in the generated hashCode method as final if it isn’t modified. This doesn’t change its behavior whatsoever, but some linters and especially eclipse save actions (specifically: ‘mark local variables final if possible’) cause issues when they try to mess with generated code. Of course, now any save action with ‘remove useless modifiers’ would cause an issue but those don’t (yet…) exist.
Diffstat (limited to 'test/transform')
23 files changed, 124 insertions, 28 deletions
diff --git a/test/transform/resource/after-delombok/ConflictingStaticConstructorNames.java b/test/transform/resource/after-delombok/ConflictingStaticConstructorNames.java index 30aefaa0..ced4f3f2 100644 --- a/test/transform/resource/after-delombok/ConflictingStaticConstructorNames.java +++ b/test/transform/resource/after-delombok/ConflictingStaticConstructorNames.java @@ -15,7 +15,7 @@ class ConflictingStaticConstructorNames { @java.lang.Override @java.lang.SuppressWarnings("all") public int hashCode() { - int result = 1; + final int result = 1; return result; } @java.lang.Override diff --git a/test/transform/resource/after-delombok/DataPlain.java b/test/transform/resource/after-delombok/DataPlain.java index d54baef1..e7d452b6 100644 --- a/test/transform/resource/after-delombok/DataPlain.java +++ b/test/transform/resource/after-delombok/DataPlain.java @@ -210,7 +210,7 @@ class Data5 { @java.lang.Override @java.lang.SuppressWarnings("all") public int hashCode() { - int result = 1; + final int result = 1; return result; } @java.lang.Override @@ -233,7 +233,7 @@ final class Data6 { @java.lang.Override @java.lang.SuppressWarnings("all") public int hashCode() { - int result = 1; + final int result = 1; return result; } @java.lang.Override diff --git a/test/transform/resource/after-delombok/EqualsAndHashCode.java b/test/transform/resource/after-delombok/EqualsAndHashCode.java index eed77b39..4eb02ebd 100644 --- a/test/transform/resource/after-delombok/EqualsAndHashCode.java +++ b/test/transform/resource/after-delombok/EqualsAndHashCode.java @@ -92,7 +92,7 @@ final class EqualsAndHashCode3 extends EqualsAndHashCode { @java.lang.Override @java.lang.SuppressWarnings("all") public int hashCode() { - int result = 1; + final int result = 1; return result; } } @@ -114,7 +114,7 @@ class EqualsAndHashCode4 extends EqualsAndHashCode { @java.lang.Override @java.lang.SuppressWarnings("all") public int hashCode() { - int result = super.hashCode(); + final int result = super.hashCode(); return result; } } diff --git a/test/transform/resource/after-delombok/EqualsAndHashCodeConfigKeys1.java b/test/transform/resource/after-delombok/EqualsAndHashCodeConfigKeys1.java index 82a5a42d..80a26cee 100644 --- a/test/transform/resource/after-delombok/EqualsAndHashCodeConfigKeys1.java +++ b/test/transform/resource/after-delombok/EqualsAndHashCodeConfigKeys1.java @@ -15,7 +15,7 @@ class EqualsAndHashCodeConfigKeys1Parent { @java.lang.Override @java.lang.SuppressWarnings("all") public int hashCode() { - int result = 1; + final int result = 1; return result; } } diff --git a/test/transform/resource/after-delombok/EqualsAndHashCodeConfigKeys2.java b/test/transform/resource/after-delombok/EqualsAndHashCodeConfigKeys2.java index c46c7f1c..2ff5e388 100644 --- a/test/transform/resource/after-delombok/EqualsAndHashCodeConfigKeys2.java +++ b/test/transform/resource/after-delombok/EqualsAndHashCodeConfigKeys2.java @@ -15,7 +15,7 @@ class EqualsAndHashCodeConfigKeys2Object extends Object { @java.lang.Override @java.lang.SuppressWarnings("all") public int hashCode() { - int result = 1; + final int result = 1; return result; } } @@ -36,7 +36,7 @@ class EqualsAndHashCodeConfigKeys2Parent { @java.lang.Override @java.lang.SuppressWarnings("all") public int hashCode() { - int result = 1; + final int result = 1; return result; } } diff --git a/test/transform/resource/after-delombok/EqualsAndHashCodeEmpty.java b/test/transform/resource/after-delombok/EqualsAndHashCodeEmpty.java new file mode 100644 index 00000000..ce3bfcb5 --- /dev/null +++ b/test/transform/resource/after-delombok/EqualsAndHashCodeEmpty.java @@ -0,0 +1,43 @@ +class EqualsAndHashCodeEmpty { + @java.lang.Override + @java.lang.SuppressWarnings("all") + public boolean equals(final java.lang.Object o) { + if (o == this) return true; + if (!(o instanceof EqualsAndHashCodeEmpty)) return false; + final EqualsAndHashCodeEmpty other = (EqualsAndHashCodeEmpty) 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 EqualsAndHashCodeEmpty; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public int hashCode() { + final int result = 1; + return result; + } +} +class EqualsAndHashCodeEmptyWithSuper extends EqualsAndHashCodeEmpty { + @java.lang.Override + @java.lang.SuppressWarnings("all") + public boolean equals(final java.lang.Object o) { + if (o == this) return true; + if (!(o instanceof EqualsAndHashCodeEmptyWithSuper)) return false; + final EqualsAndHashCodeEmptyWithSuper other = (EqualsAndHashCodeEmptyWithSuper) 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 EqualsAndHashCodeEmptyWithSuper; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public int hashCode() { + final int result = super.hashCode(); + return result; + } +} diff --git a/test/transform/resource/after-delombok/EqualsAndHashCodeExplicitInclude.java b/test/transform/resource/after-delombok/EqualsAndHashCodeExplicitInclude.java index 7de3d5fe..2d64e2fd 100644 --- a/test/transform/resource/after-delombok/EqualsAndHashCodeExplicitInclude.java +++ b/test/transform/resource/after-delombok/EqualsAndHashCodeExplicitInclude.java @@ -16,7 +16,7 @@ class EqualsAndHashCodeExplicitInclude { @java.lang.Override @java.lang.SuppressWarnings("all") public int hashCode() { - int result = 1; + final int result = 1; return result; } }
\ No newline at end of file diff --git a/test/transform/resource/after-delombok/EqualsAndHashCodeNestedShadow.java b/test/transform/resource/after-delombok/EqualsAndHashCodeNestedShadow.java index 0b479c2d..8ed883eb 100644 --- a/test/transform/resource/after-delombok/EqualsAndHashCodeNestedShadow.java +++ b/test/transform/resource/after-delombok/EqualsAndHashCodeNestedShadow.java @@ -19,7 +19,7 @@ interface EqualsAndHashCodeNestedShadow { @java.lang.Override @java.lang.SuppressWarnings("all") public int hashCode() { - int result = 1; + final int result = 1; return result; } } @@ -42,7 +42,7 @@ interface EqualsAndHashCodeNestedShadow { @java.lang.Override @java.lang.SuppressWarnings("all") public int hashCode() { - int result = 1; + final int result = 1; return result; } } diff --git a/test/transform/resource/after-delombok/PrivateNoArgsConstructor.java b/test/transform/resource/after-delombok/PrivateNoArgsConstructor.java index 18e6f211..cf3b0a15 100644 --- a/test/transform/resource/after-delombok/PrivateNoArgsConstructor.java +++ b/test/transform/resource/after-delombok/PrivateNoArgsConstructor.java @@ -224,7 +224,7 @@ public class PrivateNoArgsConstructor { @java.lang.Override @java.lang.SuppressWarnings("all") public int hashCode() { - int result = 1; + final int result = 1; return result; } @java.lang.Override diff --git a/test/transform/resource/after-delombok/ValueCallSuper.java b/test/transform/resource/after-delombok/ValueCallSuper.java index 63a536cd..5598779f 100644 --- a/test/transform/resource/after-delombok/ValueCallSuper.java +++ b/test/transform/resource/after-delombok/ValueCallSuper.java @@ -21,7 +21,7 @@ final class ValueCallSuper extends ValueParent { @java.lang.Override @java.lang.SuppressWarnings("all") public int hashCode() { - int result = super.hashCode(); + final int result = super.hashCode(); return result; } @java.lang.Override diff --git a/test/transform/resource/after-delombok/ValueStaticField.java b/test/transform/resource/after-delombok/ValueStaticField.java index 2b489a1a..3ba53faf 100644 --- a/test/transform/resource/after-delombok/ValueStaticField.java +++ b/test/transform/resource/after-delombok/ValueStaticField.java @@ -14,7 +14,7 @@ final class ValueStaticField { @java.lang.Override @java.lang.SuppressWarnings("all") public int hashCode() { - int result = 1; + final int result = 1; return result; } @java.lang.Override diff --git a/test/transform/resource/after-ecj/ConflictingStaticConstructorNames.java b/test/transform/resource/after-ecj/ConflictingStaticConstructorNames.java index 0d234d36..a7a53ac0 100644 --- a/test/transform/resource/after-ecj/ConflictingStaticConstructorNames.java +++ b/test/transform/resource/after-ecj/ConflictingStaticConstructorNames.java @@ -13,7 +13,7 @@ return (other instanceof ConflictingStaticConstructorNames); } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { - int result = 1; + final int result = 1; return result; } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { diff --git a/test/transform/resource/after-ecj/DataPlain.java b/test/transform/resource/after-ecj/DataPlain.java index eaeef509..d9119388 100644 --- a/test/transform/resource/after-ecj/DataPlain.java +++ b/test/transform/resource/after-ecj/DataPlain.java @@ -188,7 +188,7 @@ final @Data @lombok.EqualsAndHashCode(callSuper = true) class Data4 extends java return (other instanceof Data5); } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { - int result = 1; + final int result = 1; return result; } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { @@ -207,7 +207,7 @@ final @Data class Data6 { return true; } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { - int result = 1; + final int result = 1; return result; } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { diff --git a/test/transform/resource/after-ecj/EqualsAndHashCode.java b/test/transform/resource/after-ecj/EqualsAndHashCode.java index 8baa61f2..10c2c7da 100644 --- a/test/transform/resource/after-ecj/EqualsAndHashCode.java +++ b/test/transform/resource/after-ecj/EqualsAndHashCode.java @@ -105,7 +105,7 @@ final @lombok.EqualsAndHashCode(callSuper = false) class EqualsAndHashCode3 exte return (other instanceof EqualsAndHashCode3); } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { - int result = 1; + final int result = 1; return result; } } @@ -129,7 +129,7 @@ final @lombok.EqualsAndHashCode(callSuper = false) class EqualsAndHashCode3 exte return (other instanceof EqualsAndHashCode4); } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { - int result = super.hashCode(); + final int result = super.hashCode(); return result; } } diff --git a/test/transform/resource/after-ecj/EqualsAndHashCodeConfigKeys1.java b/test/transform/resource/after-ecj/EqualsAndHashCodeConfigKeys1.java index 1561962c..4a265d9c 100644 --- a/test/transform/resource/after-ecj/EqualsAndHashCodeConfigKeys1.java +++ b/test/transform/resource/after-ecj/EqualsAndHashCodeConfigKeys1.java @@ -16,7 +16,7 @@ return (other instanceof EqualsAndHashCodeConfigKeys1Parent); } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { - int result = 1; + final int result = 1; return result; } } diff --git a/test/transform/resource/after-ecj/EqualsAndHashCodeConfigKeys2.java b/test/transform/resource/after-ecj/EqualsAndHashCodeConfigKeys2.java index 0245eae0..1257de32 100644 --- a/test/transform/resource/after-ecj/EqualsAndHashCodeConfigKeys2.java +++ b/test/transform/resource/after-ecj/EqualsAndHashCodeConfigKeys2.java @@ -16,7 +16,7 @@ return (other instanceof EqualsAndHashCodeConfigKeys2Object); } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { - int result = 1; + final int result = 1; return result; } } @@ -38,7 +38,7 @@ return (other instanceof EqualsAndHashCodeConfigKeys2Parent); } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { - int result = 1; + final int result = 1; return result; } } diff --git a/test/transform/resource/after-ecj/EqualsAndHashCodeEmpty.java b/test/transform/resource/after-ecj/EqualsAndHashCodeEmpty.java new file mode 100644 index 00000000..5b7dd624 --- /dev/null +++ b/test/transform/resource/after-ecj/EqualsAndHashCodeEmpty.java @@ -0,0 +1,46 @@ +@lombok.EqualsAndHashCode class EqualsAndHashCodeEmpty { + EqualsAndHashCodeEmpty() { + super(); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + if ((o == this)) + return true; + if ((! (o instanceof EqualsAndHashCodeEmpty))) + return false; + final EqualsAndHashCodeEmpty other = (EqualsAndHashCodeEmpty) 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 EqualsAndHashCodeEmpty); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + final int result = 1; + return result; + } +} +@lombok.EqualsAndHashCode(callSuper = true) class EqualsAndHashCodeEmptyWithSuper extends EqualsAndHashCodeEmpty { + EqualsAndHashCodeEmptyWithSuper() { + super(); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + if ((o == this)) + return true; + if ((! (o instanceof EqualsAndHashCodeEmptyWithSuper))) + return false; + final EqualsAndHashCodeEmptyWithSuper other = (EqualsAndHashCodeEmptyWithSuper) 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 EqualsAndHashCodeEmptyWithSuper); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + final int result = super.hashCode(); + return result; + } +}
\ No newline at end of file diff --git a/test/transform/resource/after-ecj/EqualsAndHashCodeExplicitInclude.java b/test/transform/resource/after-ecj/EqualsAndHashCodeExplicitInclude.java index 01d1526c..96b54039 100644 --- a/test/transform/resource/after-ecj/EqualsAndHashCodeExplicitInclude.java +++ b/test/transform/resource/after-ecj/EqualsAndHashCodeExplicitInclude.java @@ -17,7 +17,7 @@ return (other instanceof EqualsAndHashCodeExplicitInclude); } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { - int result = 1; + final int result = 1; return result; } }
\ No newline at end of file diff --git a/test/transform/resource/after-ecj/EqualsAndHashCodeNestedShadow.java b/test/transform/resource/after-ecj/EqualsAndHashCodeNestedShadow.java index e08f523d..3f0cfc80 100644 --- a/test/transform/resource/after-ecj/EqualsAndHashCodeNestedShadow.java +++ b/test/transform/resource/after-ecj/EqualsAndHashCodeNestedShadow.java @@ -20,7 +20,7 @@ interface EqualsAndHashCodeNestedShadow { return (other instanceof EqualsAndHashCodeNestedShadow.Bar.Foo); } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { - int result = 1; + final int result = 1; return result; } } @@ -47,7 +47,7 @@ interface EqualsAndHashCodeNestedShadow { return (other instanceof EqualsAndHashCodeNestedShadow.Baz.Foo); } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { - int result = 1; + final int result = 1; return result; } } diff --git a/test/transform/resource/after-ecj/PrivateNoArgsConstructor.java b/test/transform/resource/after-ecj/PrivateNoArgsConstructor.java index f746ec9a..f0927bf8 100644 --- a/test/transform/resource/after-ecj/PrivateNoArgsConstructor.java +++ b/test/transform/resource/after-ecj/PrivateNoArgsConstructor.java @@ -203,7 +203,7 @@ public class PrivateNoArgsConstructor { return (other instanceof PrivateNoArgsConstructor.PrivateNoArgsConstructorNoFields); } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { - int result = 1; + final int result = 1; return result; } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { diff --git a/test/transform/resource/after-ecj/ValueCallSuper.java b/test/transform/resource/after-ecj/ValueCallSuper.java index 0c28b9b6..2fef08ab 100644 --- a/test/transform/resource/after-ecj/ValueCallSuper.java +++ b/test/transform/resource/after-ecj/ValueCallSuper.java @@ -20,7 +20,7 @@ final @lombok.Value class ValueCallSuper extends ValueParent { return (other instanceof ValueCallSuper);
}
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
- int result = super.hashCode();
+ final int result = super.hashCode();
return result;
}
public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
diff --git a/test/transform/resource/after-ecj/ValueStaticField.java b/test/transform/resource/after-ecj/ValueStaticField.java index dd116fc7..d1e74708 100644 --- a/test/transform/resource/after-ecj/ValueStaticField.java +++ b/test/transform/resource/after-ecj/ValueStaticField.java @@ -12,7 +12,7 @@ final @Value class ValueStaticField { return true; } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { - int result = 1; + final int result = 1; return result; } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { diff --git a/test/transform/resource/before/EqualsAndHashCodeEmpty.java b/test/transform/resource/before/EqualsAndHashCodeEmpty.java new file mode 100644 index 00000000..763c7b37 --- /dev/null +++ b/test/transform/resource/before/EqualsAndHashCodeEmpty.java @@ -0,0 +1,7 @@ +@lombok.EqualsAndHashCode +class EqualsAndHashCodeEmpty { +} + +@lombok.EqualsAndHashCode(callSuper = true) +class EqualsAndHashCodeEmptyWithSuper extends EqualsAndHashCodeEmpty { +} |