aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/javac
diff options
context:
space:
mode:
authorRoel Spilker <r.spilker@gmail.com>2017-11-06 23:45:52 +0100
committerRoel Spilker <r.spilker@gmail.com>2017-11-06 23:46:09 +0100
commit045638ec1f79f68747f135061d2e026faa719642 (patch)
treedebabf20d4cb9af4c8c6ed20d6044744c537705f /src/core/lombok/javac
parent7fad34b0a6fbda12f07c62a571cbe870b550be97 (diff)
downloadlombok-045638ec1f79f68747f135061d2e026faa719642.tar.gz
lombok-045638ec1f79f68747f135061d2e026faa719642.tar.bz2
lombok-045638ec1f79f68747f135061d2e026faa719642.zip
Generate correct hashCode when callSuper and no fields included. Fixes #1505
Diffstat (limited to 'src/core/lombok/javac')
-rw-r--r--src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java
index 4bd1ce4b..da2db909 100644
--- a/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java
+++ b/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java
@@ -258,20 +258,23 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
long finalFlag = JavacHandlerUtil.addFinalIfNeeded(0L, typeNode.getContext());
/* final int PRIME = X; */ {
- if (!fields.isEmpty() || callSuper) {
+ if (!fields.isEmpty()) {
statements.append(maker.VarDef(maker.Modifiers(finalFlag), primeName, maker.TypeIdent(CTC_INT), maker.Literal(HandlerUtil.primeForHashcode())));
}
}
- /* int result = 1; */ {
- statements.append(maker.VarDef(maker.Modifiers(0), resultName, maker.TypeIdent(CTC_INT), maker.Literal(1)));
- }
-
- if (callSuper) {
- JCMethodInvocation callToSuper = maker.Apply(List.<JCExpression>nil(),
- maker.Select(maker.Ident(typeNode.toName("super")), typeNode.toName("hashCode")),
- List.<JCExpression>nil());
- statements.append(createResultCalculation(typeNode, callToSuper));
+ /* int result = ... */ {
+ final JCExpression init;
+ if (callSuper) {
+ /* ... super.hashCode(); */
+ init = maker.Apply(List.<JCExpression>nil(),
+ maker.Select(maker.Ident(typeNode.toName("super")), typeNode.toName("hashCode")),
+ List.<JCExpression>nil());
+ } else {
+ /* ... 1; */
+ init = maker.Literal(1);
+ }
+ statements.append(maker.VarDef(maker.Modifiers(0), resultName, maker.TypeIdent(CTC_INT), init));
}
Name dollar = typeNode.toName("$");