From 49100b43c084f6774d43d93eee98440253965047 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Fri, 31 Dec 2010 01:09:07 +0100 Subject: calls to canEqual and equals are now fored to go to the version that has 1 Object as parameter (creating new equals methods by giving them non-object parameterized is a _really_ bad idea, but if someone did do that, obviously lombok shouldn't call those!) Fixes #165. --- .../lombok/eclipse/handlers/HandleEqualsAndHashCode.java | 15 +++++++++++---- .../lombok/javac/handlers/HandleEqualsAndHashCode.java | 14 +++++++++----- 2 files changed, 20 insertions(+), 9 deletions(-) (limited to 'src/core') diff --git a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java index d906d85d..adcb8e6a 100644 --- a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java +++ b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java @@ -536,7 +536,7 @@ public class HandleEqualsAndHashCode implements EclipseAnnotationHandler exprNil = List.nil(); + JCExpression thisRef = maker.Ident(thisName); + JCExpression castThisRef = maker.TypeCast(chainDots(maker, typeNode, "java", "lang", "Object"), thisRef); JCExpression equalityCheck = maker.Apply(exprNil, maker.Select(maker.Ident(otherName), typeNode.toName("canEqual")), - List.of(maker.Ident(thisName))); + List.of(castThisRef)); statements.append(maker.If(maker.Unary(Javac.getCTCint(JCTree.class, "NOT"), equalityCheck), returnBool(maker, false), null)); } } @@ -434,9 +436,11 @@ public class HandleEqualsAndHashCode implements JavacAnnotationHandlernil(), maker.Select(createFieldAccessor(maker, fieldNode, fieldAccess), typeNode.toName("equals")), - List.of(createFieldAccessor(maker, fieldNode, fieldAccess, maker.Ident(otherName)))); + List.of(castEqualsArg)); JCExpression fieldsAreNotEqual = maker.Conditional(thisEqualsNull, otherNotEqualsNull, maker.Unary(Javac.getCTCint(JCTree.class, "NOT"), thisEqualsThat)); statements.append(maker.If(fieldsAreNotEqual, returnBool(maker, false), null)); } @@ -451,7 +455,7 @@ public class HandleEqualsAndHashCode implements JavacAnnotationHandler