[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 committed 2014-03-26 21:11:30 +01:00
1 parent db71f39c27
commit 4d24542dac
42 files changed
+160 -81

No files matched your search

+1
View File
@@ -2,6 +2,7 @@ Lombok Changelog
---------------- ----------------
### v1.12.7 "Edgy Guinea Pig" ### 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) * 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) ### v1.12.6 (March 6th, 2014)
@@ -212,21 +212,20 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler<EqualsAndH
MemberExistsResult equalsExists = methodExists("equals", typeNode, 1); MemberExistsResult equalsExists = methodExists("equals", typeNode, 1);
MemberExistsResult hashCodeExists = methodExists("hashCode", typeNode, 0); MemberExistsResult hashCodeExists = methodExists("hashCode", typeNode, 0);
MemberExistsResult canEqualExists = methodExists("canEqual", typeNode, 1); 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: case EXISTS_BY_LOMBOK:
return; return;
case EXISTS_BY_USER: case EXISTS_BY_USER:
if (whineIfExists) { 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); errorNode.addWarning(msg);
} else if (equalsExists == MemberExistsResult.NOT_EXISTS || hashCodeExists == MemberExistsResult.NOT_EXISTS) { } 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. // 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. // 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. " + String msg = String.format("Not generating %s: One of equals or hashCode exists. " +
"You should either write all of these or none of these (in the latter case, lombok generates them).", "You should either write both of these or none of these (in the latter case, lombok generates them).",
equalsExists == MemberExistsResult.NOT_EXISTS && hashCodeExists == MemberExistsResult.NOT_EXISTS ? "equals and hashCode" :
equalsExists == MemberExistsResult.NOT_EXISTS ? "equals" : "hashCode"); equalsExists == MemberExistsResult.NOT_EXISTS ? "equals" : "hashCode");
errorNode.addWarning(msg); errorNode.addWarning(msg);
} }
@@ -240,7 +239,7 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler<EqualsAndH
equalsMethod.traverse(new SetGeneratedByVisitor(errorNode.get()), ((TypeDeclaration)typeNode.get()).scope); equalsMethod.traverse(new SetGeneratedByVisitor(errorNode.get()), ((TypeDeclaration)typeNode.get()).scope);
injectMethod(typeNode, equalsMethod); injectMethod(typeNode, equalsMethod);
if (needsCanEqual) { if (needsCanEqual && canEqualExists == MemberExistsResult.NOT_EXISTS) {
MethodDeclaration canEqualMethod = createCanEqual(typeNode, errorNode.get()); MethodDeclaration canEqualMethod = createCanEqual(typeNode, errorNode.get());
canEqualMethod.traverse(new SetGeneratedByVisitor(errorNode.get()), ((TypeDeclaration)typeNode.get()).scope); canEqualMethod.traverse(new SetGeneratedByVisitor(errorNode.get()), ((TypeDeclaration)typeNode.get()).scope);
injectMethod(typeNode, canEqualMethod); injectMethod(typeNode, canEqualMethod);
@@ -734,7 +733,7 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler<EqualsAndH
MethodDeclaration method = new MethodDeclaration( MethodDeclaration method = new MethodDeclaration(
((CompilationUnitDeclaration) type.top().get()).compilationResult); ((CompilationUnitDeclaration) type.top().get()).compilationResult);
setGeneratedBy(method, source); setGeneratedBy(method, source);
method.modifiers = toEclipseModifier(AccessLevel.PUBLIC); method.modifiers = toEclipseModifier(AccessLevel.PROTECTED);
method.returnType = TypeReference.baseTypeReference(TypeIds.T_boolean, 0); method.returnType = TypeReference.baseTypeReference(TypeIds.T_boolean, 0);
method.returnType.sourceStart = pS; method.returnType.sourceEnd = pE; method.returnType.sourceStart = pS; method.returnType.sourceEnd = pE;
setGeneratedBy(method.returnType, source); setGeneratedBy(method.returnType, source);
@@ -187,21 +187,20 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
MemberExistsResult equalsExists = methodExists("equals", typeNode, 1); MemberExistsResult equalsExists = methodExists("equals", typeNode, 1);
MemberExistsResult hashCodeExists = methodExists("hashCode", typeNode, 0); MemberExistsResult hashCodeExists = methodExists("hashCode", typeNode, 0);
MemberExistsResult canEqualExists = methodExists("canEqual", typeNode, 1); 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: case EXISTS_BY_LOMBOK:
return; return;
case EXISTS_BY_USER: case EXISTS_BY_USER:
if (whineIfExists) { 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); source.addWarning(msg);
} else if (equalsExists == MemberExistsResult.NOT_EXISTS || hashCodeExists == MemberExistsResult.NOT_EXISTS) { } 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. // 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. // 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. " + String msg = String.format("Not generating %s: One of equals or hashCode exists. " +
"You should either write all of these or none of these (in the latter case, lombok generates them).", "You should either write both of these or none of these (in the latter case, lombok generates them).",
equalsExists == MemberExistsResult.NOT_EXISTS && hashCodeExists == MemberExistsResult.NOT_EXISTS ? "equals and hashCode" :
equalsExists == MemberExistsResult.NOT_EXISTS ? "equals" : "hashCode"); equalsExists == MemberExistsResult.NOT_EXISTS ? "equals" : "hashCode");
source.addWarning(msg); source.addWarning(msg);
} }
@@ -214,7 +213,7 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
JCMethodDecl equalsMethod = createEquals(typeNode, nodesForEquality.toList(), callSuper, fieldAccess, needsCanEqual, source.get()); JCMethodDecl equalsMethod = createEquals(typeNode, nodesForEquality.toList(), callSuper, fieldAccess, needsCanEqual, source.get());
injectMethod(typeNode, equalsMethod); injectMethod(typeNode, equalsMethod);
if (needsCanEqual) { if (needsCanEqual && canEqualExists == MemberExistsResult.NOT_EXISTS) {
JCMethodDecl canEqualMethod = createCanEqual(typeNode, source.get()); JCMethodDecl canEqualMethod = createCanEqual(typeNode, source.get());
injectMethod(typeNode, canEqualMethod); injectMethod(typeNode, canEqualMethod);
} }
@@ -505,7 +504,7 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
*/ */
JavacTreeMaker maker = typeNode.getTreeMaker(); 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); JCExpression returnType = maker.TypeIdent(CTC_BOOLEAN);
Name canEqualName = typeNode.toName("canEqual"); Name canEqualName = typeNode.toName("canEqual");
JCExpression objectType = genJavaLangTypeRef(typeNode, "Object"); JCExpression objectType = genJavaLangTypeRef(typeNode, "Object");
@@ -78,7 +78,7 @@ class AccessorsPrefix3 {
return true; return true;
} }
@java.lang.SuppressWarnings("all") @java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) { protected boolean canEqual(final java.lang.Object other) {
return other instanceof AccessorsPrefix3; return other instanceof AccessorsPrefix3;
} }
@java.lang.Override @java.lang.Override
@@ -9,7 +9,7 @@ class ConflictingStaticConstructorNames {
return true; return true;
} }
@java.lang.SuppressWarnings("all") @java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) { protected boolean canEqual(final java.lang.Object other) {
return other instanceof ConflictingStaticConstructorNames; return other instanceof ConflictingStaticConstructorNames;
} }
@java.lang.Override @java.lang.Override
@@ -22,7 +22,7 @@ class DataExtended {
return true; return true;
} }
@java.lang.SuppressWarnings("all") @java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) { protected boolean canEqual(final java.lang.Object other) {
return other instanceof DataExtended; return other instanceof DataExtended;
} }
@java.lang.Override @java.lang.Override
@@ -21,7 +21,7 @@ class DataIgnore {
return true; return true;
} }
@java.lang.SuppressWarnings("all") @java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) { protected boolean canEqual(final java.lang.Object other) {
return other instanceof DataIgnore; return other instanceof DataIgnore;
} }
@java.lang.Override @java.lang.Override
@@ -33,7 +33,7 @@ class DataOnLocalClass1 {
return true; return true;
} }
@java.lang.SuppressWarnings("all") @java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) { protected boolean canEqual(final java.lang.Object other) {
return other instanceof Local; return other instanceof Local;
} }
@java.lang.Override @java.lang.Override
@@ -93,7 +93,7 @@ class DataOnLocalClass2 {
return true; return true;
} }
@java.lang.SuppressWarnings("all") @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; return other instanceof Local.InnerLocal;
} }
@java.lang.Override @java.lang.Override
@@ -130,7 +130,7 @@ class DataOnLocalClass2 {
return true; return true;
} }
@java.lang.SuppressWarnings("all") @java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) { protected boolean canEqual(final java.lang.Object other) {
return other instanceof Local; return other instanceof Local;
} }
@java.lang.Override @java.lang.Override
@@ -32,7 +32,7 @@ class Data1 {
return true; return true;
} }
@java.lang.SuppressWarnings("all") @java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) { protected boolean canEqual(final java.lang.Object other) {
return other instanceof Data1; return other instanceof Data1;
} }
@java.lang.Override @java.lang.Override
@@ -85,7 +85,7 @@ class Data2 {
return true; return true;
} }
@java.lang.SuppressWarnings("all") @java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) { protected boolean canEqual(final java.lang.Object other) {
return other instanceof Data2; return other instanceof Data2;
} }
@java.lang.Override @java.lang.Override
@@ -181,7 +181,7 @@ final class Data4 extends java.util.Timer {
return true; return true;
} }
@java.lang.SuppressWarnings("all") @java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) { protected boolean canEqual(final java.lang.Object other) {
return other instanceof Data4; return other instanceof Data4;
} }
@java.lang.Override @java.lang.Override
@@ -208,7 +208,7 @@ class Data5 {
return true; return true;
} }
@java.lang.SuppressWarnings("all") @java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) { protected boolean canEqual(final java.lang.Object other) {
return other instanceof Data5; return other instanceof Data5;
} }
@java.lang.Override @java.lang.Override
@@ -30,7 +30,7 @@ class DataWithGetter {
return true; return true;
} }
@java.lang.SuppressWarnings("all") @java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) { protected boolean canEqual(final java.lang.Object other) {
return other instanceof DataWithGetter; return other instanceof DataWithGetter;
} }
@java.lang.Override @java.lang.Override
@@ -30,7 +30,7 @@ class DataWithGetterNone {
return true; return true;
} }
@java.lang.SuppressWarnings("all") @java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) { protected boolean canEqual(final java.lang.Object other) {
return other instanceof DataWithGetterNone; return other instanceof DataWithGetterNone;
} }
@java.lang.Override @java.lang.Override
@@ -23,7 +23,7 @@ class EqualsAndHashCode {
return true; return true;
} }
@java.lang.SuppressWarnings("all") @java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) { protected boolean canEqual(final java.lang.Object other) {
return other instanceof EqualsAndHashCode; return other instanceof EqualsAndHashCode;
} }
@java.lang.Override @java.lang.Override
@@ -86,7 +86,7 @@ final class EqualsAndHashCode3 extends EqualsAndHashCode {
return true; return true;
} }
@java.lang.SuppressWarnings("all") @java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) { protected boolean canEqual(final java.lang.Object other) {
return other instanceof EqualsAndHashCode3; return other instanceof EqualsAndHashCode3;
} }
@java.lang.Override @java.lang.Override
@@ -108,7 +108,7 @@ class EqualsAndHashCode4 extends EqualsAndHashCode {
return true; return true;
} }
@java.lang.SuppressWarnings("all") @java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) { protected boolean canEqual(final java.lang.Object other) {
return other instanceof EqualsAndHashCode4; return other instanceof EqualsAndHashCode4;
} }
@java.lang.Override @java.lang.Override
@@ -12,7 +12,27 @@ final class EqualsAndHashCodeWithExistingMethods2 {
} }
final class EqualsAndHashCodeWithExistingMethods3 extends EqualsAndHashCodeWithExistingMethods { final class EqualsAndHashCodeWithExistingMethods3 extends EqualsAndHashCodeWithExistingMethods {
int x; int x;
public boolean canEqual(Object other) { private boolean canEqual(Object other) {
return true; 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 { class EqualsAndHashCodeWithSomeExistingMethods2 {
int x; int x;
public boolean canEqual(Object other) { protected boolean canEqual(Object other) {
return false; return false;
} }
@java.lang.SuppressWarnings("all") @java.lang.SuppressWarnings("all")
@@ -25,6 +25,24 @@ class EqualsAndHashCodeWithSomeExistingMethods2 {
} }
@java.lang.Override @java.lang.Override
@java.lang.SuppressWarnings("all") @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() { public java.lang.String toString() {
return "EqualsAndHashCodeWithSomeExistingMethods2(x=" + this.x + ")"; return "EqualsAndHashCodeWithSomeExistingMethods2(x=" + this.x + ")";
} }
@@ -63,7 +81,7 @@ class EqualsAndHashCodeWithNoExistingMethods {
return true; return true;
} }
@java.lang.SuppressWarnings("all") @java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) { protected boolean canEqual(final java.lang.Object other) {
return other instanceof EqualsAndHashCodeWithNoExistingMethods; return other instanceof EqualsAndHashCodeWithNoExistingMethods;
} }
@java.lang.Override @java.lang.Override
@@ -15,7 +15,7 @@ class GetterLazyBoolean {
return true; return true;
} }
@java.lang.SuppressWarnings("all") @java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) { protected boolean canEqual(final java.lang.Object other) {
return other instanceof GetterLazyBoolean; return other instanceof GetterLazyBoolean;
} }
@java.lang.Override @java.lang.Override
@@ -20,7 +20,7 @@ class GetterLazyEahcToString {
} }
@java.lang.SuppressWarnings("all") @java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) { protected boolean canEqual(final java.lang.Object other) {
return other instanceof GetterLazyEahcToString; return other instanceof GetterLazyEahcToString;
} }
@@ -35,7 +35,7 @@ class GetterSetterJavadoc1 {
return true; return true;
} }
@java.lang.SuppressWarnings("all") @java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) { protected boolean canEqual(final java.lang.Object other) {
return other instanceof GetterSetterJavadoc1; return other instanceof GetterSetterJavadoc1;
} }
@java.lang.Override @java.lang.Override
@@ -74,7 +74,7 @@ class Value2 {
return true; return true;
} }
@java.lang.SuppressWarnings("all") @java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) { protected boolean canEqual(final java.lang.Object other) {
return other instanceof Value2; return other instanceof Value2;
} }
@java.lang.Override @java.lang.Override
@@ -86,7 +86,7 @@ class AccessorsChain {
return false; return false;
return true; 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); return (other instanceof AccessorsPrefix3);
} }
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
@@ -9,7 +9,7 @@
return false; return false;
return true; 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); return (other instanceof ConflictingStaticConstructorNames);
} }
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
@@ -18,7 +18,7 @@
return false; return false;
return true; 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); return (other instanceof DataExtended);
} }
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
@@ -16,7 +16,7 @@
return false; return false;
return true; 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); return (other instanceof DataIgnore);
} }
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
@@ -32,7 +32,7 @@ class DataOnLocalClass1 {
return false; return false;
return true; 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); return (other instanceof Local);
} }
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
@@ -82,7 +82,7 @@ class DataOnLocalClass2 {
return false; return false;
return true; 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); return (other instanceof Local.InnerLocal);
} }
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
@@ -120,7 +120,7 @@ class DataOnLocalClass2 {
return false; return false;
return true; 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); return (other instanceof Local);
} }
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
@@ -27,7 +27,7 @@ import lombok.Data;
return false; return false;
return true; 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); return (other instanceof Data1);
} }
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
@@ -74,7 +74,7 @@ import lombok.Data;
return false; return false;
return true; 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); return (other instanceof Data2);
} }
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { 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 false;
return true; 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); return (other instanceof Data4);
} }
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { 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 false;
return true; 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); return (other instanceof Data5);
} }
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
@@ -26,7 +26,7 @@
return false; return false;
return true; 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); return (other instanceof DataWithGetter);
} }
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
@@ -26,7 +26,7 @@
return false; return false;
return true; 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); return (other instanceof DataWithGetterNone);
} }
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
@@ -31,7 +31,7 @@
return false; return false;
return true; 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); return (other instanceof EqualsAndHashCode);
} }
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { 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 false;
return true; 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); return (other instanceof EqualsAndHashCode3);
} }
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { 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 false;
return true; 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); return (other instanceof EqualsAndHashCode4);
} }
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
@@ -21,7 +21,28 @@ final @lombok.EqualsAndHashCode(callSuper = true) class EqualsAndHashCodeWithExi
EqualsAndHashCodeWithExistingMethods3() { EqualsAndHashCodeWithExistingMethods3() {
super(); super();
} }
public boolean canEqual(Object other) { private boolean canEqual(Object other) {
return true; 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 { @Data @Getter(NONE) @Setter(NONE) class EqualsAndHashCodeWithSomeExistingMethods2 {
int x; int x;
public boolean canEqual(Object other) { protected boolean canEqual(Object other) {
return false; 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() { public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
return (("EqualsAndHashCodeWithSomeExistingMethods2(x=" + this.x) + ")"); return (("EqualsAndHashCodeWithSomeExistingMethods2(x=" + this.x) + ")");
} }
@@ -53,7 +71,7 @@ import static lombok.AccessLevel.NONE;
return false; return false;
return true; 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); return (other instanceof EqualsAndHashCodeWithNoExistingMethods);
} }
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
@@ -53,7 +53,7 @@
return false; return false;
return true; 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); return (other instanceof GetterLazyBoolean);
} }
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
@@ -42,7 +42,7 @@
return false; return false;
return true; 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); return (other instanceof GetterLazyEahcToString);
} }
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
@@ -18,7 +18,7 @@
return false; return false;
return true; 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); return (other instanceof GetterSetterJavadoc1);
} }
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
@@ -64,7 +64,7 @@ final @lombok.Value class Value1 {
return false; return false;
return true; 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); return (other instanceof Value2);
} }
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
@@ -20,7 +20,7 @@ final class EqualsAndHashCodeWithExistingMethods2 {
final class EqualsAndHashCodeWithExistingMethods3 extends EqualsAndHashCodeWithExistingMethods { final class EqualsAndHashCodeWithExistingMethods3 extends EqualsAndHashCodeWithExistingMethods {
int x; int x;
public boolean canEqual(Object other) { private boolean canEqual(Object other) {
return true; return true;
} }
} }
@@ -18,7 +18,7 @@ class EqualsAndHashCodeWithSomeExistingMethods {
class EqualsAndHashCodeWithSomeExistingMethods2 { class EqualsAndHashCodeWithSomeExistingMethods2 {
int x; int x;
public boolean canEqual(Object other) { protected boolean canEqual(Object other) {
return false; 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). 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 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 both 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,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). 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).
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).
@@ -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). 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 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 both 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,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). 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).
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).
+8
View File
@@ -42,6 +42,10 @@ public class DataExample {
return "DataExample(" + this.getName() + ", " + this.getAge() + ", " + this.getScore() + ", " + Arrays.deepToString(this.getTags()) + ")"; 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) { @Override public boolean equals(Object o) {
if (o == this) return true; if (o == this) return true;
if (!(o instanceof DataExample)) return false; if (!(o instanceof DataExample)) return false;
@@ -90,6 +94,10 @@ public class DataExample {
return "Exercise(name=" + this.getName() + ", value=" + this.getValue() + ")"; return "Exercise(name=" + this.getName() + ", value=" + this.getValue() + ")";
} }
protected boolean canEqual(Object other) {
return other instanceof Exercise;
}
@Override public boolean equals(Object o) { @Override public boolean equals(Object o) {
if (o == this) return true; if (o == this) return true;
if (!(o instanceof Exercise)) return false; if (!(o instanceof Exercise)) return false;
@@ -33,7 +33,7 @@ public class EqualsAndHashCodeExample {
return result; return result;
} }
public boolean canEqual(Object other) { protected boolean canEqual(Object other) {
return other instanceof EqualsAndHashCodeExample; return other instanceof EqualsAndHashCodeExample;
} }
@@ -65,7 +65,7 @@ public class EqualsAndHashCodeExample {
return result; return result;
} }
public boolean canEqual(Object other) { protected boolean canEqual(Object other) {
return other instanceof Square; 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 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. to an exact copy of itself returns <code>true</code> for equality.
</p><p> </p><p>
If there is <em>any</em> method named either <code>hashCode</code>, <code>equals</code> or <code>canEqual</code>, regardless of 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
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> both
each other, which lombok cannot guarantee unless it generates all the methods, hence you always get a warning if one <em>or</em> more
of the methods already exist. of the methods already exist.
</p><p> </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. 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.