mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-13 22:16:11 +00:00
EqualsAndHashCode no longer worked right when working on a class with 0 fileds. Fixed. Thanks to Philipp Eichhorn for spotting this problem!
This commit is contained in:
1 parent
c88ae3af74
commit
186b16c28c
2 files changed
+20
-18
No files matched your search
@@ -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);
|
||||
|
||||
@@ -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 (!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))));
|
||||
}
|
||||
|
||||
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))));
|
||||
}
|
||||
|
||||
/* if (!other.canEqual(this)) return false; */ {
|
||||
|
||||
Reference in new issue
Block a user