aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/javac
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2010-11-09 23:52:54 +0100
committerReinier Zwitserloot <reinier@zwitserloot.com>2010-11-09 23:52:54 +0100
commit186b16c28cf461f88a3b5eecd2fa4523af2949d9 (patch)
treebe2e008970c2e8bdc4606a39d8940ab141cfa85a /src/core/lombok/javac
parentc88ae3af7432513987eafaf13c178baa77cb0667 (diff)
downloadlombok-186b16c28cf461f88a3b5eecd2fa4523af2949d9.tar.gz
lombok-186b16c28cf461f88a3b5eecd2fa4523af2949d9.tar.bz2
lombok-186b16c28cf461f88a3b5eecd2fa4523af2949d9.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/core/lombok/javac')
-rw-r--r--src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java36
1 files changed, 19 insertions, 17 deletions
diff --git a/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java
index f824986c..8d524964 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; */ {