[i660] canEqual is now protected instead of public.

Also fixed the total lack of canEqual in the usage examples.
This commit is contained in:
Roel Spilker
2014-03-26 21:11:30 +01:00
parent db71f39c27
commit 4d24542dac
42 changed files with 160 additions and 81 deletions
+1
View File
@@ -2,6 +2,7 @@ Lombok Changelog
----------------
### v1.12.7 "Edgy Guinea Pig"
* CHANGE: The `canEqual` method generated by `@EqualsAndHashCode`, `@Value` and `@Data` is now `protected` instead of `public`. [Issue #660](https://code.google.com/p/projectlombok/issues/detail?id=660)
* BUGFIX: Deadlocks would occasionally occur in eclipse when using lazy getters [Issue #590](https://code.google.com/p/projectlombok/issues/detail?id=590)
### v1.12.6 (March 6th, 2014)
@@ -212,21 +212,20 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler<EqualsAndH
MemberExistsResult equalsExists = methodExists("equals", typeNode, 1);
MemberExistsResult hashCodeExists = methodExists("hashCode", typeNode, 0);
MemberExistsResult canEqualExists = methodExists("canEqual", typeNode, 1);
switch (Collections.max(Arrays.asList(equalsExists, hashCodeExists, canEqualExists))) {
switch (Collections.max(Arrays.asList(equalsExists, hashCodeExists))) {
case EXISTS_BY_LOMBOK:
return;
case EXISTS_BY_USER:
if (whineIfExists) {
String msg = String.format("Not generating equals%s: A method with one of those names already exists. (Either all or none of these methods will be generated).", needsCanEqual ? ", hashCode and canEquals" : " and hashCode");
String msg = "Not generating equals and hashCode: A method with one of those names already exists. (Either both or none of these methods will be generated).";
errorNode.addWarning(msg);
} else if (equalsExists == MemberExistsResult.NOT_EXISTS || hashCodeExists == MemberExistsResult.NOT_EXISTS) {
// This means equals OR hashCode exists and not both (or neither, but canEqual is there).
// This means equals OR hashCode exists and not both.
// Even though we should suppress the message about not generating these, this is such a weird and surprising situation we should ALWAYS generate a warning.
// The user code couldn't possibly (barring really weird subclassing shenanigans) be in a shippable state anyway; the implementations of these 3 methods are
// The user code couldn't possibly (barring really weird subclassing shenanigans) be in a shippable state anyway; the implementations of these 2 methods are
// all inter-related and should be written by the same entity.
String msg = String.format("Not generating %s: One of equals, hashCode, and canEqual exists. " +
"You should either write all of these or none of these (in the latter case, lombok generates them).",
equalsExists == MemberExistsResult.NOT_EXISTS && hashCodeExists == MemberExistsResult.NOT_EXISTS ? "equals and hashCode" :
String msg = String.format("Not generating %s: One of equals or hashCode exists. " +
"You should either write both of these or none of these (in the latter case, lombok generates them).",
equalsExists == MemberExistsResult.NOT_EXISTS ? "equals" : "hashCode");
errorNode.addWarning(msg);
}
@@ -240,7 +239,7 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler<EqualsAndH
equalsMethod.traverse(new SetGeneratedByVisitor(errorNode.get()), ((TypeDeclaration)typeNode.get()).scope);
injectMethod(typeNode, equalsMethod);
if (needsCanEqual) {
if (needsCanEqual && canEqualExists == MemberExistsResult.NOT_EXISTS) {
MethodDeclaration canEqualMethod = createCanEqual(typeNode, errorNode.get());
canEqualMethod.traverse(new SetGeneratedByVisitor(errorNode.get()), ((TypeDeclaration)typeNode.get()).scope);
injectMethod(typeNode, canEqualMethod);
@@ -734,7 +733,7 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler<EqualsAndH
MethodDeclaration method = new MethodDeclaration(
((CompilationUnitDeclaration) type.top().get()).compilationResult);
setGeneratedBy(method, source);
method.modifiers = toEclipseModifier(AccessLevel.PUBLIC);
method.modifiers = toEclipseModifier(AccessLevel.PROTECTED);
method.returnType = TypeReference.baseTypeReference(TypeIds.T_boolean, 0);
method.returnType.sourceStart = pS; method.returnType.sourceEnd = pE;
setGeneratedBy(method.returnType, source);
@@ -187,21 +187,20 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
MemberExistsResult equalsExists = methodExists("equals", typeNode, 1);
MemberExistsResult hashCodeExists = methodExists("hashCode", typeNode, 0);
MemberExistsResult canEqualExists = methodExists("canEqual", typeNode, 1);
switch (Collections.max(Arrays.asList(equalsExists, hashCodeExists, canEqualExists))) {
switch (Collections.max(Arrays.asList(equalsExists, hashCodeExists))) {
case EXISTS_BY_LOMBOK:
return;
case EXISTS_BY_USER:
if (whineIfExists) {
String msg = String.format("Not generating equals%s: A method with one of those names already exists. (Either all or none of these methods will be generated).", needsCanEqual ? ", hashCode and canEquals" : " and hashCode");
String msg = "Not generating equals and hashCode: A method with one of those names already exists. (Either both or none of these methods will be generated).";
source.addWarning(msg);
} else if (equalsExists == MemberExistsResult.NOT_EXISTS || hashCodeExists == MemberExistsResult.NOT_EXISTS) {
// This means equals OR hashCode exists and not both (or neither, but canEqual is there).
// This means equals OR hashCode exists and not both.
// Even though we should suppress the message about not generating these, this is such a weird and surprising situation we should ALWAYS generate a warning.
// The user code couldn't possibly (barring really weird subclassing shenanigans) be in a shippable state anyway; the implementations of these 3 methods are
// The user code couldn't possibly (barring really weird subclassing shenanigans) be in a shippable state anyway; the implementations of these 2 methods are
// all inter-related and should be written by the same entity.
String msg = String.format("Not generating %s: One of equals, hashCode, and canEqual exists. " +
"You should either write all of these or none of these (in the latter case, lombok generates them).",
equalsExists == MemberExistsResult.NOT_EXISTS && hashCodeExists == MemberExistsResult.NOT_EXISTS ? "equals and hashCode" :
String msg = String.format("Not generating %s: One of equals or hashCode exists. " +
"You should either write both of these or none of these (in the latter case, lombok generates them).",
equalsExists == MemberExistsResult.NOT_EXISTS ? "equals" : "hashCode");
source.addWarning(msg);
}
@@ -214,7 +213,7 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
JCMethodDecl equalsMethod = createEquals(typeNode, nodesForEquality.toList(), callSuper, fieldAccess, needsCanEqual, source.get());
injectMethod(typeNode, equalsMethod);
if (needsCanEqual) {
if (needsCanEqual && canEqualExists == MemberExistsResult.NOT_EXISTS) {
JCMethodDecl canEqualMethod = createCanEqual(typeNode, source.get());
injectMethod(typeNode, canEqualMethod);
}
@@ -505,7 +504,7 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
*/
JavacTreeMaker maker = typeNode.getTreeMaker();
JCModifiers mods = maker.Modifiers(Flags.PUBLIC, List.<JCAnnotation>nil());
JCModifiers mods = maker.Modifiers(Flags.PROTECTED, List.<JCAnnotation>nil());
JCExpression returnType = maker.TypeIdent(CTC_BOOLEAN);
Name canEqualName = typeNode.toName("canEqual");
JCExpression objectType = genJavaLangTypeRef(typeNode, "Object");
@@ -78,7 +78,7 @@ class AccessorsPrefix3 {
return true;
}
@java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) {
protected boolean canEqual(final java.lang.Object other) {
return other instanceof AccessorsPrefix3;
}
@java.lang.Override
@@ -9,7 +9,7 @@ class ConflictingStaticConstructorNames {
return true;
}
@java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) {
protected boolean canEqual(final java.lang.Object other) {
return other instanceof ConflictingStaticConstructorNames;
}
@java.lang.Override
@@ -22,7 +22,7 @@ class DataExtended {
return true;
}
@java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) {
protected boolean canEqual(final java.lang.Object other) {
return other instanceof DataExtended;
}
@java.lang.Override
@@ -21,7 +21,7 @@ class DataIgnore {
return true;
}
@java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) {
protected boolean canEqual(final java.lang.Object other) {
return other instanceof DataIgnore;
}
@java.lang.Override
@@ -33,7 +33,7 @@ class DataOnLocalClass1 {
return true;
}
@java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) {
protected boolean canEqual(final java.lang.Object other) {
return other instanceof Local;
}
@java.lang.Override
@@ -93,7 +93,7 @@ class DataOnLocalClass2 {
return true;
}
@java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) {
protected boolean canEqual(final java.lang.Object other) {
return other instanceof Local.InnerLocal;
}
@java.lang.Override
@@ -130,7 +130,7 @@ class DataOnLocalClass2 {
return true;
}
@java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) {
protected boolean canEqual(final java.lang.Object other) {
return other instanceof Local;
}
@java.lang.Override
@@ -32,7 +32,7 @@ class Data1 {
return true;
}
@java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) {
protected boolean canEqual(final java.lang.Object other) {
return other instanceof Data1;
}
@java.lang.Override
@@ -85,7 +85,7 @@ class Data2 {
return true;
}
@java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) {
protected boolean canEqual(final java.lang.Object other) {
return other instanceof Data2;
}
@java.lang.Override
@@ -181,7 +181,7 @@ final class Data4 extends java.util.Timer {
return true;
}
@java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) {
protected boolean canEqual(final java.lang.Object other) {
return other instanceof Data4;
}
@java.lang.Override
@@ -208,7 +208,7 @@ class Data5 {
return true;
}
@java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) {
protected boolean canEqual(final java.lang.Object other) {
return other instanceof Data5;
}
@java.lang.Override
@@ -30,7 +30,7 @@ class DataWithGetter {
return true;
}
@java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) {
protected boolean canEqual(final java.lang.Object other) {
return other instanceof DataWithGetter;
}
@java.lang.Override
@@ -30,7 +30,7 @@ class DataWithGetterNone {
return true;
}
@java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) {
protected boolean canEqual(final java.lang.Object other) {
return other instanceof DataWithGetterNone;
}
@java.lang.Override
@@ -23,7 +23,7 @@ class EqualsAndHashCode {
return true;
}
@java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) {
protected boolean canEqual(final java.lang.Object other) {
return other instanceof EqualsAndHashCode;
}
@java.lang.Override
@@ -86,7 +86,7 @@ final class EqualsAndHashCode3 extends EqualsAndHashCode {
return true;
}
@java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) {
protected boolean canEqual(final java.lang.Object other) {
return other instanceof EqualsAndHashCode3;
}
@java.lang.Override
@@ -108,7 +108,7 @@ class EqualsAndHashCode4 extends EqualsAndHashCode {
return true;
}
@java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) {
protected boolean canEqual(final java.lang.Object other) {
return other instanceof EqualsAndHashCode4;
}
@java.lang.Override
@@ -12,7 +12,27 @@ final class EqualsAndHashCodeWithExistingMethods2 {
}
final class EqualsAndHashCodeWithExistingMethods3 extends EqualsAndHashCodeWithExistingMethods {
int x;
public boolean canEqual(Object other) {
private boolean canEqual(Object other) {
return true;
}
@java.lang.Override
@java.lang.SuppressWarnings("all")
public boolean equals(final java.lang.Object o) {
if (o == this) return true;
if (!(o instanceof EqualsAndHashCodeWithExistingMethods3)) return false;
final EqualsAndHashCodeWithExistingMethods3 other = (EqualsAndHashCodeWithExistingMethods3)o;
if (!other.canEqual((java.lang.Object)this)) return false;
if (!super.equals(o)) return false;
if (this.x != other.x) return false;
return true;
}
@java.lang.Override
@java.lang.SuppressWarnings("all")
public int hashCode() {
final int PRIME = 59;
int result = 1;
result = result * PRIME + super.hashCode();
result = result * PRIME + this.x;
return result;
}
}
@@ -17,7 +17,7 @@ class EqualsAndHashCodeWithSomeExistingMethods {
}
class EqualsAndHashCodeWithSomeExistingMethods2 {
int x;
public boolean canEqual(Object other) {
protected boolean canEqual(Object other) {
return false;
}
@java.lang.SuppressWarnings("all")
@@ -25,6 +25,24 @@ class EqualsAndHashCodeWithSomeExistingMethods2 {
}
@java.lang.Override
@java.lang.SuppressWarnings("all")
public boolean equals(final java.lang.Object o) {
if (o == this) return true;
if (!(o instanceof EqualsAndHashCodeWithSomeExistingMethods2)) return false;
final EqualsAndHashCodeWithSomeExistingMethods2 other = (EqualsAndHashCodeWithSomeExistingMethods2)o;
if (!other.canEqual((java.lang.Object)this)) return false;
if (this.x != other.x) return false;
return true;
}
@java.lang.Override
@java.lang.SuppressWarnings("all")
public int hashCode() {
final int PRIME = 59;
int result = 1;
result = result * PRIME + this.x;
return result;
}
@java.lang.Override
@java.lang.SuppressWarnings("all")
public java.lang.String toString() {
return "EqualsAndHashCodeWithSomeExistingMethods2(x=" + this.x + ")";
}
@@ -63,7 +81,7 @@ class EqualsAndHashCodeWithNoExistingMethods {
return true;
}
@java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) {
protected boolean canEqual(final java.lang.Object other) {
return other instanceof EqualsAndHashCodeWithNoExistingMethods;
}
@java.lang.Override
@@ -15,7 +15,7 @@ class GetterLazyBoolean {
return true;
}
@java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) {
protected boolean canEqual(final java.lang.Object other) {
return other instanceof GetterLazyBoolean;
}
@java.lang.Override
@@ -20,7 +20,7 @@ class GetterLazyEahcToString {
}
@java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) {
protected boolean canEqual(final java.lang.Object other) {
return other instanceof GetterLazyEahcToString;
}
@@ -35,7 +35,7 @@ class GetterSetterJavadoc1 {
return true;
}
@java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) {
protected boolean canEqual(final java.lang.Object other) {
return other instanceof GetterSetterJavadoc1;
}
@java.lang.Override
@@ -74,7 +74,7 @@ class Value2 {
return true;
}
@java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) {
protected boolean canEqual(final java.lang.Object other) {
return other instanceof Value2;
}
@java.lang.Override
@@ -86,7 +86,7 @@ class AccessorsChain {
return false;
return true;
}
public @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
return (other instanceof AccessorsPrefix3);
}
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
@@ -9,7 +9,7 @@
return false;
return true;
}
public @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
return (other instanceof ConflictingStaticConstructorNames);
}
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
@@ -18,7 +18,7 @@
return false;
return true;
}
public @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
return (other instanceof DataExtended);
}
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
@@ -16,7 +16,7 @@
return false;
return true;
}
public @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
return (other instanceof DataIgnore);
}
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
@@ -32,7 +32,7 @@ class DataOnLocalClass1 {
return false;
return true;
}
public @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
return (other instanceof Local);
}
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
@@ -82,7 +82,7 @@ class DataOnLocalClass2 {
return false;
return true;
}
public @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
return (other instanceof Local.InnerLocal);
}
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
@@ -120,7 +120,7 @@ class DataOnLocalClass2 {
return false;
return true;
}
public @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
return (other instanceof Local);
}
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
@@ -27,7 +27,7 @@ import lombok.Data;
return false;
return true;
}
public @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
return (other instanceof Data1);
}
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
@@ -74,7 +74,7 @@ import lombok.Data;
return false;
return true;
}
public @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
return (other instanceof Data2);
}
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
@@ -163,7 +163,7 @@ final @Data @lombok.EqualsAndHashCode(callSuper = true) class Data4 extends java
return false;
return true;
}
public @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
return (other instanceof Data4);
}
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
@@ -185,7 +185,7 @@ final @Data @lombok.EqualsAndHashCode(callSuper = true) class Data4 extends java
return false;
return true;
}
public @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
return (other instanceof Data5);
}
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
@@ -26,7 +26,7 @@
return false;
return true;
}
public @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
return (other instanceof DataWithGetter);
}
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
@@ -26,7 +26,7 @@
return false;
return true;
}
public @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
return (other instanceof DataWithGetterNone);
}
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
@@ -31,7 +31,7 @@
return false;
return true;
}
public @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
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() {
@@ -101,7 +101,7 @@ final @lombok.EqualsAndHashCode(callSuper = false) class EqualsAndHashCode3 exte
return false;
return true;
}
public @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
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() {
@@ -125,7 +125,7 @@ final @lombok.EqualsAndHashCode(callSuper = false) class EqualsAndHashCode3 exte
return false;
return true;
}
public @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
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() {
@@ -21,7 +21,28 @@ final @lombok.EqualsAndHashCode(callSuper = true) class EqualsAndHashCodeWithExi
EqualsAndHashCodeWithExistingMethods3() {
super();
}
public boolean canEqual(Object other) {
private boolean canEqual(Object other) {
return true;
}
public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) {
if ((o == this))
return true;
if ((! (o instanceof EqualsAndHashCodeWithExistingMethods3)))
return false;
final @java.lang.SuppressWarnings("all") EqualsAndHashCodeWithExistingMethods3 other = (EqualsAndHashCodeWithExistingMethods3) o;
if ((! other.canEqual((java.lang.Object) this)))
return false;
if ((! super.equals(o)))
return false;
if ((this.x != other.x))
return false;
return true;
}
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
final int PRIME = 59;
int result = 1;
result = ((result * PRIME) + super.hashCode());
result = ((result * PRIME) + this.x);
return result;
}
}
@@ -14,9 +14,27 @@ import static lombok.AccessLevel.NONE;
}
@Data @Getter(NONE) @Setter(NONE) class EqualsAndHashCodeWithSomeExistingMethods2 {
int x;
public boolean canEqual(Object other) {
protected boolean canEqual(Object other) {
return false;
}
public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) {
if ((o == this))
return true;
if ((! (o instanceof EqualsAndHashCodeWithSomeExistingMethods2)))
return false;
final @java.lang.SuppressWarnings("all") EqualsAndHashCodeWithSomeExistingMethods2 other = (EqualsAndHashCodeWithSomeExistingMethods2) o;
if ((! other.canEqual((java.lang.Object) this)))
return false;
if ((this.x != other.x))
return false;
return true;
}
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
final int PRIME = 59;
int result = 1;
result = ((result * PRIME) + this.x);
return result;
}
public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
return (("EqualsAndHashCodeWithSomeExistingMethods2(x=" + this.x) + ")");
}
@@ -53,7 +71,7 @@ import static lombok.AccessLevel.NONE;
return false;
return true;
}
public @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
return (other instanceof EqualsAndHashCodeWithNoExistingMethods);
}
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
@@ -53,7 +53,7 @@
return false;
return true;
}
public @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
return (other instanceof GetterLazyBoolean);
}
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
@@ -42,7 +42,7 @@
return false;
return true;
}
public @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
return (other instanceof GetterLazyEahcToString);
}
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
@@ -18,7 +18,7 @@
return false;
return true;
}
public @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
return (other instanceof GetterSetterJavadoc1);
}
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
@@ -64,7 +64,7 @@ final @lombok.Value class Value1 {
return false;
return true;
}
public @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
return (other instanceof Value2);
}
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
@@ -20,7 +20,7 @@ final class EqualsAndHashCodeWithExistingMethods2 {
final class EqualsAndHashCodeWithExistingMethods3 extends EqualsAndHashCodeWithExistingMethods {
int x;
public boolean canEqual(Object other) {
private boolean canEqual(Object other) {
return true;
}
}
@@ -18,7 +18,7 @@ class EqualsAndHashCodeWithSomeExistingMethods {
class EqualsAndHashCodeWithSomeExistingMethods2 {
int x;
public boolean canEqual(Object other) {
protected boolean canEqual(Object other) {
return false;
}
}
@@ -1,3 +1,2 @@
1 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 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 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).
1 Not generating equals and hashCode: A method with one of those names already exists. (Either both or none of these methods will be generated).
10 Not generating equals and hashCode: A method with one of those names already exists. (Either both or none of these methods will be generated).
@@ -1,2 +1 @@
4 Not generating equals: One of equals, hashCode, and canEqual exists. You should either write all of these or none of these (in the latter case, lombok generates them).
15 Not generating equals and hashCode: One of equals, hashCode, and canEqual exists. You should either write all of these or none of these (in the latter case, lombok generates them).
4 Not generating equals: One of equals or hashCode exists. You should either write both of these or none of these (in the latter case, lombok generates them).
@@ -1,3 +1,2 @@
1 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 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 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).
1 Not generating equals and hashCode: A method with one of those names already exists. (Either both or none of these methods will be generated).
10 Not generating equals and hashCode: A method with one of those names already exists. (Either both or none of these methods will be generated).
@@ -1,2 +1 @@
4 Not generating equals: One of equals, hashCode, and canEqual exists. You should either write all of these or none of these (in the latter case, lombok generates them).
15 Not generating equals and hashCode: One of equals, hashCode, and canEqual exists. You should either write all of these or none of these (in the latter case, lombok generates them).
4 Not generating equals: One of equals or hashCode exists. You should either write both of these or none of these (in the latter case, lombok generates them).
+8
View File
@@ -42,6 +42,10 @@ public class DataExample {
return "DataExample(" + this.getName() + ", " + this.getAge() + ", " + this.getScore() + ", " + Arrays.deepToString(this.getTags()) + ")";
}
protected boolean canEqual(Object other) {
return other instanceof DataExample;
}
@Override public boolean equals(Object o) {
if (o == this) return true;
if (!(o instanceof DataExample)) return false;
@@ -90,6 +94,10 @@ public class DataExample {
return "Exercise(name=" + this.getName() + ", value=" + this.getValue() + ")";
}
protected boolean canEqual(Object other) {
return other instanceof Exercise;
}
@Override public boolean equals(Object o) {
if (o == this) return true;
if (!(o instanceof Exercise)) return false;
@@ -33,7 +33,7 @@ public class EqualsAndHashCodeExample {
return result;
}
public boolean canEqual(Object other) {
protected boolean canEqual(Object other) {
return other instanceof EqualsAndHashCodeExample;
}
@@ -65,7 +65,7 @@ public class EqualsAndHashCodeExample {
return result;
}
public boolean canEqual(Object other) {
protected boolean canEqual(Object other) {
return other instanceof Square;
}
}
+2 -3
View File
@@ -65,9 +65,8 @@
return false. This is analogous to <code>java.lang.Double</code>'s equals method, and is in fact required to ensure that comparing an object
to an exact copy of itself returns <code>true</code> for equality.
</p><p>
If there is <em>any</em> method named either <code>hashCode</code>, <code>equals</code> or <code>canEqual</code>, regardless of
parameters or return type, no methods will be generated, and a warning is emitted instead. These 3 methods need to be in sync with
each other, which lombok cannot guarantee unless it generates all the methods, hence you always get a warning if one <em>or</em> more
If there is <em>any</em> method named either <code>hashCode</code> or <code>equals</code>, regardless of return type, no methods will be generated, and a warning is emitted instead. These 2 methods need to be in sync with
each other, which lombok cannot guarantee unless it generates all the methods, hence you always get a warning if one <em>or</em> both
of the methods already exist.
</p><p>
Attempting to exclude fields that don't exist or would have been excluded anyway (because they are static or transient) results in warnings on the named fields.