diff options
Diffstat (limited to 'src/core/lombok/javac/handlers')
-rw-r--r-- | src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java index 2c998f48..05244f3b 100644 --- a/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java +++ b/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java @@ -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"); |