diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2010-11-09 23:52:54 +0100 |
---|---|---|
committer | Reinier Zwitserloot <reinier@zwitserloot.com> | 2010-11-09 23:53:21 +0100 |
commit | 57de0c3f6636181541a7712e8d506828420c13d1 (patch) | |
tree | f27545806eccd2169c24e315ea840317998b6559 /src | |
parent | 16f992c5adea8ed8ad183d27c247901d61b0635d (diff) | |
download | lombok-57de0c3f6636181541a7712e8d506828420c13d1.tar.gz lombok-57de0c3f6636181541a7712e8d506828420c13d1.tar.bz2 lombok-57de0c3f6636181541a7712e8d506828420c13d1.zip |
EqualsAndHashCode no longer worked right when working on a class with 0 fileds. Fixed. Thanks to Philipp Eichhorn for spotting this problem!
Diffstat (limited to 'src')
-rw-r--r-- | src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java | 2 | ||||
-rw-r--r-- | src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java | 36 |
2 files changed, 20 insertions, 18 deletions
diff --git a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java index 23d24fb0..2b830241 100644 --- a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java +++ b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java @@ -505,7 +505,7 @@ public class HandleEqualsAndHashCode implements EclipseAnnotationHandler<EqualsA char[] otherName = "other".toCharArray(); /* MyType<?> other = (MyType<?>) o; */ { - if (!fields.isEmpty()) { + if (!fields.isEmpty() || needsCanEqual) { LocalDeclaration other = new LocalDeclaration(otherName, pS, pE); other.modifiers |= ClassFileConstants.AccFinal; Eclipse.setGeneratedBy(other, source); diff --git a/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java index 96113bc4..60b0f89f 100644 --- a/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java +++ b/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java @@ -356,24 +356,26 @@ public class HandleEqualsAndHashCode implements JavacAnnotationHandler<EqualsAnd } /* MyType<?> other = (MyType<?>) o; */ { - final JCExpression selfType1, selfType2; - List<JCExpression> wildcards1 = List.nil(); - List<JCExpression> wildcards2 = List.nil(); - for (int i = 0 ; i < type.typarams.length() ; i++) { - wildcards1 = wildcards1.append(maker.Wildcard(maker.TypeBoundKind(BoundKind.UNBOUND), null)); - wildcards2 = wildcards2.append(maker.Wildcard(maker.TypeBoundKind(BoundKind.UNBOUND), null)); - } - - if (type.typarams.isEmpty()) { - selfType1 = maker.Ident(type.name); - selfType2 = maker.Ident(type.name); - } else { - selfType1 = maker.TypeApply(maker.Ident(type.name), wildcards1); - selfType2 = maker.TypeApply(maker.Ident(type.name), wildcards2); + if (!fields.isEmpty() || needsCanEqual) { + final JCExpression selfType1, selfType2; + List<JCExpression> wildcards1 = List.nil(); + List<JCExpression> wildcards2 = List.nil(); + for (int i = 0 ; i < type.typarams.length() ; i++) { + wildcards1 = wildcards1.append(maker.Wildcard(maker.TypeBoundKind(BoundKind.UNBOUND), null)); + wildcards2 = wildcards2.append(maker.Wildcard(maker.TypeBoundKind(BoundKind.UNBOUND), null)); + } + + if (type.typarams.isEmpty()) { + selfType1 = maker.Ident(type.name); + selfType2 = maker.Ident(type.name); + } else { + selfType1 = maker.TypeApply(maker.Ident(type.name), wildcards1); + selfType2 = maker.TypeApply(maker.Ident(type.name), wildcards2); + } + + statements = statements.append( + maker.VarDef(maker.Modifiers(Flags.FINAL), otherName, selfType1, maker.TypeCast(selfType2, maker.Ident(oName)))); } - - statements = statements.append( - maker.VarDef(maker.Modifiers(Flags.FINAL), otherName, selfType1, maker.TypeCast(selfType2, maker.Ident(oName)))); } /* if (!other.canEqual(this)) return false; */ { |