aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorAndre Brait <andrebrait@gmail.com>2020-07-13 18:50:12 +0200
committerRoel Spilker <r.spilker@gmail.com>2020-09-24 22:25:15 +0200
commitd00ab552e199410c283049cd8d9359a69855f1f2 (patch)
treed625204bafff70f938e8bc34c08cb5a3289fd235 /src/core
parent4e0ffbc32913001082dd2387a20b480076ddd20a (diff)
downloadlombok-d00ab552e199410c283049cd8d9359a69855f1f2.tar.gz
lombok-d00ab552e199410c283049cd8d9359a69855f1f2.tar.bz2
lombok-d00ab552e199410c283049cd8d9359a69855f1f2.zip
Finish implementation, add tests
Diffstat (limited to 'src/core')
-rwxr-xr-xsrc/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java9
-rw-r--r--src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java18
2 files changed, 18 insertions, 9 deletions
diff --git a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java
index 76a46814..6e9423d5 100755
--- a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java
+++ b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java
@@ -62,6 +62,7 @@ import org.eclipse.jdt.internal.compiler.ast.EqualExpression;
import org.eclipse.jdt.internal.compiler.ast.Expression;
import org.eclipse.jdt.internal.compiler.ast.FalseLiteral;
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration;
+import org.eclipse.jdt.internal.compiler.ast.FieldReference;
import org.eclipse.jdt.internal.compiler.ast.IfStatement;
import org.eclipse.jdt.internal.compiler.ast.InstanceOfExpression;
import org.eclipse.jdt.internal.compiler.ast.IntLiteral;
@@ -305,8 +306,10 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler<EqualsAndH
/* if ($hashCodeCache != 0) return $hashCodeCache; */ {
if (cacheHashCode) {
- SingleNameReference hashCodeCacheRef = new SingleNameReference(HASH_CODE_CACHE_NAME_ARR, p);
+ FieldReference hashCodeCacheRef = new FieldReference(HASH_CODE_CACHE_NAME_ARR, p);
+ hashCodeCacheRef.receiver = new ThisReference(pS, pE);
setGeneratedBy(hashCodeCacheRef, source);
+ setGeneratedBy(hashCodeCacheRef.receiver, source);
EqualExpression cacheNotZero = new EqualExpression(hashCodeCacheRef, makeIntLiteral("0".toCharArray(), source), OperatorIds.NOT_EQUAL);
setGeneratedBy(cacheNotZero, source);
ReturnStatement returnCache = new ReturnStatement(hashCodeCacheRef, pS, pS);
@@ -448,8 +451,10 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler<EqualsAndH
/* $hashCodeCache = result; */ {
if (cacheHashCode) {
- SingleNameReference hashCodeCacheRef = new SingleNameReference(HASH_CODE_CACHE_NAME_ARR, p);
+ FieldReference hashCodeCacheRef = new FieldReference(HASH_CODE_CACHE_NAME_ARR, p);
+ hashCodeCacheRef.receiver = new ThisReference(pS, pE);
setGeneratedBy(hashCodeCacheRef, source);
+ setGeneratedBy(hashCodeCacheRef.receiver, source);
SingleNameReference resultRef = new SingleNameReference(RESULT, p);
setGeneratedBy(resultRef, source);
Assignment cacheResult = new Assignment(hashCodeCacheRef, resultRef, pE);
diff --git a/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java
index 19f6d750..063fb780 100644
--- a/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java
+++ b/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java
@@ -42,6 +42,8 @@ import com.sun.tools.javac.tree.JCTree.JCBlock;
import com.sun.tools.javac.tree.JCTree.JCClassDecl;
import com.sun.tools.javac.tree.JCTree.JCExpression;
import com.sun.tools.javac.tree.JCTree.JCExpressionStatement;
+import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
+import com.sun.tools.javac.tree.JCTree.JCIdent;
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
import com.sun.tools.javac.tree.JCTree.JCMethodInvocation;
import com.sun.tools.javac.tree.JCTree.JCModifiers;
@@ -244,11 +246,12 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
boolean isEmpty = members.isEmpty();
- /* if ($hashCodeCache != 0) return $hashCodeCache; */ {
+ /* if (this.$hashCodeCache != 0) return this.$hashCodeCache; */ {
if (cacheHashCode) {
- Name cacheHashCodeName = typeNode.toName(HASH_CODE_CACHE_NAME);
- JCExpression cacheNotZero = maker.Binary(CTC_NOT_EQUAL, maker.Ident(cacheHashCodeName), maker.Literal(CTC_INT, 0));
- statements.append(maker.If(cacheNotZero, maker.Return(maker.Ident(cacheHashCodeName)), null));
+ JCIdent receiver = maker.Ident(typeNode.toName("this"));
+ JCFieldAccess cacheHashCodeFieldAccess = maker.Select(receiver, typeNode.toName(HASH_CODE_CACHE_NAME));
+ JCExpression cacheNotZero = maker.Binary(CTC_NOT_EQUAL, cacheHashCodeFieldAccess, maker.Literal(CTC_INT, 0));
+ statements.append(maker.If(cacheNotZero, maker.Return(cacheHashCodeFieldAccess), null));
}
}
@@ -341,10 +344,11 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
}
}
- /* $hashCodeCache = result; */ {
+ /* this.$hashCodeCache = result; */ {
if (cacheHashCode) {
- Name cacheHashCodeName = typeNode.toName(HASH_CODE_CACHE_NAME);
- statements.append(maker.Exec(maker.Assign(maker.Ident(cacheHashCodeName), maker.Ident(resultName))));
+ JCIdent receiver = maker.Ident(typeNode.toName("this"));
+ JCFieldAccess cacheHashCodeFieldAccess = maker.Select(receiver, typeNode.toName(HASH_CODE_CACHE_NAME));
+ statements.append(maker.Exec(maker.Assign(cacheHashCodeFieldAccess, maker.Ident(resultName))));
}
}