aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoel Spilker <r.spilker@gmail.com>2012-04-29 22:24:59 +0200
committerRoel Spilker <r.spilker@gmail.com>2012-04-29 23:57:47 +0200
commit5a13db5dc967367b9e3ec85bb5f07e65a1df09b7 (patch)
tree3efc9cd7bd106745d158054b103d20d6478114ab
parentd8e933223fb162175f550bee69b5a0153e11ff66 (diff)
downloadlombok-5a13db5dc967367b9e3ec85bb5f07e65a1df09b7.tar.gz
lombok-5a13db5dc967367b9e3ec85bb5f07e65a1df09b7.tar.bz2
lombok-5a13db5dc967367b9e3ec85bb5f07e65a1df09b7.zip
Issue 366: don't call the getter twice, fixed for javac.
-rw-r--r--src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java116
-rw-r--r--test/transform/resource/after-delombok/Accessors.java28
-rw-r--r--test/transform/resource/after-delombok/DataOnLocalClass.java14
-rw-r--r--test/transform/resource/after-delombok/DataPlain.java21
-rw-r--r--test/transform/resource/after-delombok/DataWithGetter.java7
-rw-r--r--test/transform/resource/after-delombok/DataWithGetterNone.java7
-rw-r--r--test/transform/resource/after-delombok/EqualsAndHashCode.java24
-rw-r--r--test/transform/resource/after-delombok/GetterLazyEahcToString.java14
-rw-r--r--test/transform/resource/after-ecj/EqualsAndHashCode.java28
-rw-r--r--test/transform/resource/before/EqualsAndHashCode.java4
10 files changed, 170 insertions, 93 deletions
diff --git a/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java
index 00601b56..9869cf94 100644
--- a/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java
+++ b/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2011 The Project Lombok Authors.
+ * Copyright (C) 2009-2012 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -21,17 +21,19 @@
*/
package lombok.javac.handlers;
-import static lombok.javac.handlers.JavacHandlerUtil.*;
import static lombok.javac.Javac.getCtcInt;
+import static lombok.javac.handlers.JavacHandlerUtil.*;
import java.util.ArrayList;
import java.util.Collections;
import lombok.EqualsAndHashCode;
-import lombok.core.AnnotationValues;
import lombok.core.AST.Kind;
+import lombok.core.AnnotationValues;
import lombok.javac.JavacAnnotationHandler;
import lombok.javac.JavacNode;
+import lombok.javac.handlers.JavacHandlerUtil.FieldAccess;
+import lombok.javac.handlers.JavacHandlerUtil.MemberExistsResult;
import org.mangosdk.spi.ProviderFor;
@@ -39,13 +41,13 @@ import com.sun.tools.javac.code.BoundKind;
import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.code.TypeTags;
import com.sun.tools.javac.tree.JCTree;
-import com.sun.tools.javac.tree.TreeMaker;
import com.sun.tools.javac.tree.JCTree.JCAnnotation;
import com.sun.tools.javac.tree.JCTree.JCArrayTypeTree;
import com.sun.tools.javac.tree.JCTree.JCBinary;
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.JCMethodDecl;
import com.sun.tools.javac.tree.JCTree.JCMethodInvocation;
import com.sun.tools.javac.tree.JCTree.JCModifiers;
@@ -54,6 +56,7 @@ import com.sun.tools.javac.tree.JCTree.JCStatement;
import com.sun.tools.javac.tree.JCTree.JCTypeParameter;
import com.sun.tools.javac.tree.JCTree.JCUnary;
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
+import com.sun.tools.javac.tree.TreeMaker;
import com.sun.tools.javac.util.List;
import com.sun.tools.javac.util.ListBuffer;
import com.sun.tools.javac.util.Name;
@@ -63,6 +66,9 @@ import com.sun.tools.javac.util.Name;
*/
@ProviderFor(JavacAnnotationHandler.class)
public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHashCode> {
+ private static final String RESULT_NAME = "result";
+ private static final String PRIME_NAME = "PRIME";
+
private void checkForBogusFieldNames(JavacNode type, AnnotationValues<EqualsAndHashCode> annotation) {
if (annotation.isExplicit("exclude")) {
for (int i : createListOfNonExistentFields(List.from(annotation.getInstance().exclude()), type, true, true)) {
@@ -214,8 +220,8 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
JCExpression returnType = maker.TypeIdent(getCtcInt(TypeTags.class, "INT"));
ListBuffer<JCStatement> statements = ListBuffer.lb();
- Name primeName = typeNode.toName("PRIME");
- Name resultName = typeNode.toName("result");
+ Name primeName = typeNode.toName(PRIME_NAME);
+ Name resultName = typeNode.toName(RESULT_NAME);
/* final int PRIME = 31; */ {
if (!fields.isEmpty() || callSuper) {
statements.append(maker.VarDef(maker.Modifiers(Flags.FINAL),
@@ -227,16 +233,14 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
statements.append(maker.VarDef(maker.Modifiers(0), resultName, maker.TypeIdent(getCtcInt(TypeTags.class, "INT")), maker.Literal(1)));
}
- ListBuffer<JCExpression> intoResult = ListBuffer.lb();
-
if (callSuper) {
JCMethodInvocation callToSuper = maker.Apply(List.<JCExpression>nil(),
maker.Select(maker.Ident(typeNode.toName("super")), typeNode.toName("hashCode")),
List.<JCExpression>nil());
- intoResult.append(callToSuper);
+ statements.append(createResultCalculation(typeNode, callToSuper));
}
- int tempCounter = 0;
+ Name dollar = typeNode.toName("$");
for (JavacNode fieldNode : fields) {
JCExpression fType = getFieldType(fieldNode, fieldAccess);
JCExpression fieldAccessor = createFieldAccessor(maker, fieldNode, fieldAccess);
@@ -244,28 +248,31 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
switch (((JCPrimitiveTypeTree)fType).getPrimitiveTypeKind()) {
case BOOLEAN:
/* this.fieldName ? 1231 : 1237 */
- intoResult.append(maker.Conditional(fieldAccessor, maker.Literal(1231), maker.Literal(1237)));
+ statements.append(createResultCalculation(typeNode, maker.Conditional(fieldAccessor, maker.Literal(1231), maker.Literal(1237))));
break;
- case LONG:
- intoResult.append(longToIntForHashCode(maker, fieldAccessor, createFieldAccessor(maker, fieldNode, fieldAccess)));
+ case LONG: {
+ Name dollarFieldName = dollar.append(((JCVariableDecl)fieldNode.get()).name);
+ statements.append(maker.VarDef(maker.Modifiers(Flags.FINAL), dollarFieldName, maker.TypeIdent(TypeTags.LONG), fieldAccessor));
+ statements.append(createResultCalculation(typeNode, longToIntForHashCode(maker, maker.Ident(dollarFieldName), maker.Ident(dollarFieldName))));
+ }
break;
case FLOAT:
/* Float.floatToIntBits(this.fieldName) */
- intoResult.append(maker.Apply(
+ statements.append(createResultCalculation(typeNode, maker.Apply(
List.<JCExpression>nil(),
chainDots(typeNode, "java", "lang", "Float", "floatToIntBits"),
- List.of(fieldAccessor)));
+ List.of(fieldAccessor))));
break;
- case DOUBLE:
- /* longToIntForHashCode(Double.doubleToLongBits(this.fieldName)) */
- Name tempVar = typeNode.toName("temp" + (++tempCounter));
- JCExpression init = maker.Apply(
- List.<JCExpression>nil(),
- chainDots(typeNode, "java", "lang", "Double", "doubleToLongBits"),
- List.of(fieldAccessor));
- statements.append(
- maker.VarDef(maker.Modifiers(Flags.FINAL), tempVar, maker.TypeIdent(TypeTags.LONG), init));
- intoResult.append(longToIntForHashCode(maker, maker.Ident(tempVar), maker.Ident(tempVar)));
+ case DOUBLE: {
+ /* longToIntForHashCode(Double.doubleToLongBits(this.fieldName)) */
+ Name dollarFieldName = dollar.append(((JCVariableDecl)fieldNode.get()).name);
+ JCExpression init = maker.Apply(
+ List.<JCExpression>nil(),
+ chainDots(typeNode, "java", "lang", "Double", "doubleToLongBits"),
+ List.of(fieldAccessor));
+ statements.append(maker.VarDef(maker.Modifiers(Flags.FINAL), dollarFieldName, maker.TypeIdent(TypeTags.LONG), init));
+ statements.append(createResultCalculation(typeNode, longToIntForHashCode(maker, maker.Ident(dollarFieldName), maker.Ident(dollarFieldName))));
+ }
break;
default:
case BYTE:
@@ -273,7 +280,7 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
case INT:
case CHAR:
/* just the field */
- intoResult.append(fieldAccessor);
+ statements.append(createResultCalculation(typeNode, fieldAccessor));
break;
}
} else if (fType instanceof JCArrayTypeTree) {
@@ -283,26 +290,21 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
boolean useDeepHC = multiDim || !primitiveArray;
JCExpression hcMethod = chainDots(typeNode, "java", "util", "Arrays", useDeepHC ? "deepHashCode" : "hashCode");
- intoResult.append(
- maker.Apply(List.<JCExpression>nil(), hcMethod, List.of(fieldAccessor)));
+ statements.append(createResultCalculation(typeNode, maker.Apply(List.<JCExpression>nil(), hcMethod, List.of(fieldAccessor))));
} else /* objects */ {
- /* this.fieldName == null ? 0 : this.fieldName.hashCode() */
- JCExpression hcCall = maker.Apply(List.<JCExpression>nil(), maker.Select(createFieldAccessor(maker, fieldNode, fieldAccess), typeNode.toName("hashCode")),
+ /* final java.lang.Object $fieldName = this.fieldName; */
+ /* $fieldName == null ? 0 : $fieldName.hashCode() */
+
+ Name dollarFieldName = dollar.append(((JCVariableDecl)fieldNode.get()).name);
+ statements.append(maker.VarDef(maker.Modifiers(Flags.FINAL), dollarFieldName, chainDots(typeNode, "java", "lang", "Object"), fieldAccessor));
+
+ JCExpression hcCall = maker.Apply(List.<JCExpression>nil(), maker.Select(maker.Ident(dollarFieldName), typeNode.toName("hashCode")),
List.<JCExpression>nil());
- JCExpression thisEqualsNull = maker.Binary(getCtcInt(JCTree.class, "EQ"), fieldAccessor, maker.Literal(getCtcInt(TypeTags.class, "BOT"), null));
- intoResult.append(
- maker.Conditional(thisEqualsNull, maker.Literal(0), hcCall));
+ JCExpression thisEqualsNull = maker.Binary(getCtcInt(JCTree.class, "EQ"), maker.Ident(dollarFieldName), maker.Literal(getCtcInt(TypeTags.class, "BOT"), null));
+ statements.append(createResultCalculation(typeNode, maker.Conditional(thisEqualsNull, maker.Literal(0), hcCall)));
}
}
- /* fold each intoResult entry into:
- result = result * PRIME + (item); */
- for (JCExpression expr : intoResult) {
- JCExpression mult = maker.Binary(getCtcInt(JCTree.class, "MUL"), maker.Ident(resultName), maker.Ident(primeName));
- JCExpression add = maker.Binary(getCtcInt(JCTree.class, "PLUS"), mult, expr);
- statements.append(maker.Exec(maker.Assign(maker.Ident(resultName), add)));
- }
-
/* return result; */ {
statements.append(maker.Return(maker.Ident(resultName)));
}
@@ -311,6 +313,15 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
return recursiveSetGeneratedBy(maker.MethodDef(mods, typeNode.toName("hashCode"), returnType,
List.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), body, null), source);
}
+
+ private JCExpressionStatement createResultCalculation(JavacNode typeNode, JCExpression expr) {
+ /* result = result * PRIME + (expr); */
+ TreeMaker maker = typeNode.getTreeMaker();
+ Name resultName = typeNode.toName(RESULT_NAME);
+ JCExpression mult = maker.Binary(getCtcInt(JCTree.class, "MUL"), maker.Ident(resultName), maker.Ident(typeNode.toName(PRIME_NAME)));
+ JCExpression add = maker.Binary(getCtcInt(JCTree.class, "PLUS"), mult, expr);
+ return maker.Exec(maker.Assign(maker.Ident(resultName), add));
+ }
/** The 2 references must be clones of each other. */
private JCExpression longToIntForHashCode(TreeMaker maker, JCExpression ref1, JCExpression ref2) {
@@ -410,6 +421,8 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
statements.append(maker.If(superNotEqual, returnBool(maker, false), null));
}
+ Name thisDollar = typeNode.toName("this$");
+ Name otherDollar = typeNode.toName("other$");
for (JavacNode fieldNode : fields) {
JCExpression fType = getFieldType(fieldNode, fieldAccess);
JCExpression thisFieldAccessor = createFieldAccessor(maker, fieldNode, fieldAccess);
@@ -441,14 +454,21 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
statements.append(maker.If(maker.Unary(getCtcInt(JCTree.class, "NOT"),
maker.Apply(List.<JCExpression>nil(), eqMethod, args)), returnBool(maker, false), null));
} else /* objects */ {
- /* if (this.fieldName == null ? other.fieldName != null : !this.fieldName.equals(other.fieldName)) return false; */
- JCExpression thisEqualsNull = maker.Binary(getCtcInt(JCTree.class, "EQ"), thisFieldAccessor, maker.Literal(getCtcInt(TypeTags.class, "BOT"), null));
- JCExpression otherNotEqualsNull = maker.Binary(getCtcInt(JCTree.class, "NE"), otherFieldAccessor, maker.Literal(getCtcInt(TypeTags.class, "BOT"), null));
- JCExpression equalsArg = createFieldAccessor(maker, fieldNode, fieldAccess, maker.Ident(otherName));
- JCExpression castEqualsArg = maker.TypeCast(chainDots(typeNode, "java", "lang", "Object"), equalsArg);
+ /* final java.lang.Object this$fieldName = this.fieldName; */
+ /* final java.lang.Object other$fieldName = other.fieldName; */
+ /* if (this$fieldName == null ? other$fieldName != null : !this$fieldName.equals(other$fieldName)) return false;; */
+ Name fieldName = ((JCVariableDecl)fieldNode.get()).name;
+ Name thisDollarFieldName = thisDollar.append(fieldName);
+ Name otherDollarFieldName = otherDollar.append(fieldName);
+
+ statements.append(maker.VarDef(maker.Modifiers(Flags.FINAL), thisDollarFieldName, chainDots(typeNode, "java", "lang", "Object"), thisFieldAccessor));
+ statements.append(maker.VarDef(maker.Modifiers(Flags.FINAL), otherDollarFieldName, chainDots(typeNode, "java", "lang", "Object"), otherFieldAccessor));
+
+ JCExpression thisEqualsNull = maker.Binary(getCtcInt(JCTree.class, "EQ"), maker.Ident(thisDollarFieldName), maker.Literal(getCtcInt(TypeTags.class, "BOT"), null));
+ JCExpression otherNotEqualsNull = maker.Binary(getCtcInt(JCTree.class, "NE"), maker.Ident(otherDollarFieldName), maker.Literal(getCtcInt(TypeTags.class, "BOT"), null));
JCExpression thisEqualsThat = maker.Apply(List.<JCExpression>nil(),
- maker.Select(createFieldAccessor(maker, fieldNode, fieldAccess), typeNode.toName("equals")),
- List.of(castEqualsArg));
+ maker.Select(maker.Ident(thisDollarFieldName), typeNode.toName("equals")),
+ List.<JCExpression>of(maker.Ident(otherDollarFieldName)));
JCExpression fieldsAreNotEqual = maker.Conditional(thisEqualsNull, otherNotEqualsNull, maker.Unary(getCtcInt(JCTree.class, "NOT"), thisEqualsThat));
statements.append(maker.If(fieldsAreNotEqual, returnBool(maker, false), null));
}
diff --git a/test/transform/resource/after-delombok/Accessors.java b/test/transform/resource/after-delombok/Accessors.java
index b21f2de9..28ffc531 100644
--- a/test/transform/resource/after-delombok/Accessors.java
+++ b/test/transform/resource/after-delombok/Accessors.java
@@ -1,89 +1,70 @@
class AccessorsFluent {
private String fieldName = "";
-
@java.lang.SuppressWarnings("all")
public String fieldName() {
return this.fieldName;
}
-
@java.lang.SuppressWarnings("all")
public AccessorsFluent fieldName(final String fieldName) {
this.fieldName = fieldName;
return this;
}
}
-
class AccessorsFluentOnClass {
private String fieldName = "";
private String otherFieldWithOverride = "";
-
@java.lang.SuppressWarnings("all")
public String fieldName() {
return this.fieldName;
}
-
@java.lang.SuppressWarnings("all")
public String getOtherFieldWithOverride() {
return this.otherFieldWithOverride;
}
-
@java.lang.SuppressWarnings("all")
public AccessorsFluentOnClass fieldName(final String fieldName) {
this.fieldName = fieldName;
return this;
}
}
-
class AccessorsChain {
private boolean isRunning;
-
@java.lang.SuppressWarnings("all")
public AccessorsChain setRunning(final boolean isRunning) {
this.isRunning = isRunning;
return this;
}
}
-
class AccessorsPrefix {
-
private String fieldName;
private String fActualField;
-
@java.lang.SuppressWarnings("all")
public void setActualField(final String fActualField) {
this.fActualField = fActualField;
}
}
-
class AccessorsPrefix2 {
-
private String fieldName;
private String fActualField;
-
@java.lang.SuppressWarnings("all")
public void setFieldName(final String fieldName) {
this.fieldName = fieldName;
}
-
@java.lang.SuppressWarnings("all")
public void setActualField(final String fActualField) {
this.fActualField = fActualField;
}
}
-
class AccessorsPrefix3 {
private String fName;
-
private String getName() {
return fName;
}
-
@java.lang.Override
@java.lang.SuppressWarnings("all")
public java.lang.String toString() {
return "AccessorsPrefix3(fName=" + this.getName() + ")";
}
-
@java.lang.Override
@java.lang.SuppressWarnings("all")
public boolean equals(final java.lang.Object o) {
@@ -91,21 +72,22 @@ class AccessorsPrefix3 {
if (!(o instanceof AccessorsPrefix3)) return false;
final AccessorsPrefix3 other = (AccessorsPrefix3)o;
if (!other.canEqual((java.lang.Object)this)) return false;
- if (this.getName() == null ? other.getName() != null : !this.getName().equals((java.lang.Object)other.getName())) return false;
+ final java.lang.Object this$fName = this.getName();
+ final java.lang.Object other$fName = other.getName();
+ if (this$fName == null ? other$fName != null : !this$fName.equals(other$fName)) return false;
return true;
}
-
@java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) {
return other instanceof AccessorsPrefix3;
}
-
@java.lang.Override
@java.lang.SuppressWarnings("all")
public int hashCode() {
final int PRIME = 31;
int result = 1;
- result = result * PRIME + (this.getName() == null ? 0 : this.getName().hashCode());
+ final java.lang.Object $fName = this.getName();
+ result = result * PRIME + ($fName == null ? 0 : $fName.hashCode());
return result;
}
}
diff --git a/test/transform/resource/after-delombok/DataOnLocalClass.java b/test/transform/resource/after-delombok/DataOnLocalClass.java
index af5c12a5..ed4d30ca 100644
--- a/test/transform/resource/after-delombok/DataOnLocalClass.java
+++ b/test/transform/resource/after-delombok/DataOnLocalClass.java
@@ -27,7 +27,9 @@ class DataOnLocalClass1 {
final Local other = (Local)o;
if (!other.canEqual((java.lang.Object)this)) return false;
if (this.getX() != other.getX()) return false;
- if (this.getName() == null ? other.getName() != null : !this.getName().equals((java.lang.Object)other.getName())) return false;
+ final java.lang.Object this$name = this.getName();
+ final java.lang.Object other$name = other.getName();
+ if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false;
return true;
}
@java.lang.SuppressWarnings("all")
@@ -40,7 +42,8 @@ class DataOnLocalClass1 {
final int PRIME = 31;
int result = 1;
result = result * PRIME + this.getX();
- result = result * PRIME + (this.getName() == null ? 0 : this.getName().hashCode());
+ final java.lang.Object $name = this.getName();
+ result = result * PRIME + ($name == null ? 0 : $name.hashCode());
return result;
}
@java.lang.Override
@@ -80,7 +83,9 @@ class DataOnLocalClass2 {
if (!(o instanceof Local.InnerLocal)) return false;
final InnerLocal other = (InnerLocal)o;
if (!other.canEqual((java.lang.Object)this)) return false;
- if (this.getName() == null ? other.getName() != null : !this.getName().equals((java.lang.Object)other.getName())) return false;
+ final java.lang.Object this$name = this.getName();
+ final java.lang.Object other$name = other.getName();
+ if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false;
return true;
}
@java.lang.SuppressWarnings("all")
@@ -92,7 +97,8 @@ class DataOnLocalClass2 {
public int hashCode() {
final int PRIME = 31;
int result = 1;
- result = result * PRIME + (this.getName() == null ? 0 : this.getName().hashCode());
+ final java.lang.Object $name = this.getName();
+ result = result * PRIME + ($name == null ? 0 : $name.hashCode());
return result;
}
@java.lang.Override
diff --git a/test/transform/resource/after-delombok/DataPlain.java b/test/transform/resource/after-delombok/DataPlain.java
index 86d0ec18..cb002e07 100644
--- a/test/transform/resource/after-delombok/DataPlain.java
+++ b/test/transform/resource/after-delombok/DataPlain.java
@@ -26,7 +26,9 @@ class Data1 {
final Data1 other = (Data1)o;
if (!other.canEqual((java.lang.Object)this)) return false;
if (this.getX() != other.getX()) return false;
- if (this.getName() == null ? other.getName() != null : !this.getName().equals((java.lang.Object)other.getName())) return false;
+ final java.lang.Object this$name = this.getName();
+ final java.lang.Object other$name = other.getName();
+ if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false;
return true;
}
@java.lang.SuppressWarnings("all")
@@ -39,7 +41,8 @@ class Data1 {
final int PRIME = 31;
int result = 1;
result = result * PRIME + this.getX();
- result = result * PRIME + (this.getName() == null ? 0 : this.getName().hashCode());
+ final java.lang.Object $name = this.getName();
+ result = result * PRIME + ($name == null ? 0 : $name.hashCode());
return result;
}
@java.lang.Override
@@ -76,7 +79,9 @@ class Data2 {
final Data2 other = (Data2)o;
if (!other.canEqual((java.lang.Object)this)) return false;
if (this.getX() != other.getX()) return false;
- if (this.getName() == null ? other.getName() != null : !this.getName().equals((java.lang.Object)other.getName())) return false;
+ final java.lang.Object this$name = this.getName();
+ final java.lang.Object other$name = other.getName();
+ if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false;
return true;
}
@java.lang.SuppressWarnings("all")
@@ -89,7 +94,8 @@ class Data2 {
final int PRIME = 31;
int result = 1;
result = result * PRIME + this.getX();
- result = result * PRIME + (this.getName() == null ? 0 : this.getName().hashCode());
+ final java.lang.Object $name = this.getName();
+ result = result * PRIME + ($name == null ? 0 : $name.hashCode());
return result;
}
@java.lang.Override
@@ -125,7 +131,9 @@ final class Data3 {
if (!(o instanceof Data3)) return false;
final Data3 other = (Data3)o;
if (this.getX() != other.getX()) return false;
- if (this.getName() == null ? other.getName() != null : !this.getName().equals((java.lang.Object)other.getName())) return false;
+ final java.lang.Object this$name = this.getName();
+ final java.lang.Object other$name = other.getName();
+ if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false;
return true;
}
@java.lang.Override
@@ -134,7 +142,8 @@ final class Data3 {
final int PRIME = 31;
int result = 1;
result = result * PRIME + this.getX();
- result = result * PRIME + (this.getName() == null ? 0 : this.getName().hashCode());
+ final java.lang.Object $name = this.getName();
+ result = result * PRIME + ($name == null ? 0 : $name.hashCode());
return result;
}
@java.lang.Override
diff --git a/test/transform/resource/after-delombok/DataWithGetter.java b/test/transform/resource/after-delombok/DataWithGetter.java
index 79df7aa1..95a4bcbc 100644
--- a/test/transform/resource/after-delombok/DataWithGetter.java
+++ b/test/transform/resource/after-delombok/DataWithGetter.java
@@ -24,7 +24,9 @@ class DataWithGetter {
if (!other.canEqual((java.lang.Object)this)) return false;
if (this.getX() != other.getX()) return false;
if (this.getY() != other.getY()) return false;
- if (this.getZ() == null ? other.getZ() != null : !this.getZ().equals((java.lang.Object)other.getZ())) return false;
+ final java.lang.Object this$z = this.getZ();
+ final java.lang.Object other$z = other.getZ();
+ if (this$z == null ? other$z != null : !this$z.equals(other$z)) return false;
return true;
}
@java.lang.SuppressWarnings("all")
@@ -38,7 +40,8 @@ class DataWithGetter {
int result = 1;
result = result * PRIME + this.getX();
result = result * PRIME + this.getY();
- result = result * PRIME + (this.getZ() == null ? 0 : this.getZ().hashCode());
+ final java.lang.Object $z = this.getZ();
+ result = result * PRIME + ($z == null ? 0 : $z.hashCode());
return result;
}
@java.lang.Override
diff --git a/test/transform/resource/after-delombok/DataWithGetterNone.java b/test/transform/resource/after-delombok/DataWithGetterNone.java
index 6b907d37..2dea5e49 100644
--- a/test/transform/resource/after-delombok/DataWithGetterNone.java
+++ b/test/transform/resource/after-delombok/DataWithGetterNone.java
@@ -24,7 +24,9 @@ class DataWithGetterNone {
if (!other.canEqual((java.lang.Object)this)) return false;
if (this.x != other.x) return false;
if (this.y != other.y) return false;
- if (this.z == null ? other.z != null : !this.z.equals((java.lang.Object)other.z)) return false;
+ final java.lang.Object this$z = this.z;
+ final java.lang.Object other$z = other.z;
+ if (this$z == null ? other$z != null : !this$z.equals(other$z)) return false;
return true;
}
@java.lang.SuppressWarnings("all")
@@ -38,7 +40,8 @@ class DataWithGetterNone {
int result = 1;
result = result * PRIME + this.x;
result = result * PRIME + this.y;
- result = result * PRIME + (this.z == null ? 0 : this.z.hashCode());
+ final java.lang.Object $z = this.z;
+ result = result * PRIME + ($z == null ? 0 : $z.hashCode());
return result;
}
@java.lang.Override
diff --git a/test/transform/resource/after-delombok/EqualsAndHashCode.java b/test/transform/resource/after-delombok/EqualsAndHashCode.java
index e7f701e8..8f84fb22 100644
--- a/test/transform/resource/after-delombok/EqualsAndHashCode.java
+++ b/test/transform/resource/after-delombok/EqualsAndHashCode.java
@@ -3,6 +3,7 @@ class EqualsAndHashCode {
boolean[] y;
Object[] z;
String a;
+ String b;
@java.lang.Override
@java.lang.SuppressWarnings("all")
public boolean equals(final java.lang.Object o) {
@@ -13,7 +14,12 @@ class EqualsAndHashCode {
if (this.x != other.x) return false;
if (!java.util.Arrays.equals(this.y, other.y)) return false;
if (!java.util.Arrays.deepEquals(this.z, other.z)) return false;
- if (this.a == null ? other.a != null : !this.a.equals((java.lang.Object)other.a)) return false;
+ final java.lang.Object this$a = this.a;
+ final java.lang.Object other$a = other.a;
+ if (this$a == null ? other$a != null : !this$a.equals(other$a)) return false;
+ final java.lang.Object this$b = this.b;
+ final java.lang.Object other$b = other.b;
+ if (this$b == null ? other$b != null : !this$b.equals(other$b)) return false;
return true;
}
@java.lang.SuppressWarnings("all")
@@ -28,12 +34,18 @@ class EqualsAndHashCode {
result = result * PRIME + this.x;
result = result * PRIME + java.util.Arrays.hashCode(this.y);
result = result * PRIME + java.util.Arrays.deepHashCode(this.z);
- result = result * PRIME + (this.a == null ? 0 : this.a.hashCode());
+ final java.lang.Object $a = this.a;
+ result = result * PRIME + ($a == null ? 0 : $a.hashCode());
+ final java.lang.Object $b = this.b;
+ result = result * PRIME + ($b == null ? 0 : $b.hashCode());
return result;
}
}
final class EqualsAndHashCode2 {
int x;
+ long y;
+ float f;
+ double d;
@java.lang.Override
@java.lang.SuppressWarnings("all")
public boolean equals(final java.lang.Object o) {
@@ -41,6 +53,9 @@ final class EqualsAndHashCode2 {
if (!(o instanceof EqualsAndHashCode2)) return false;
final EqualsAndHashCode2 other = (EqualsAndHashCode2)o;
if (this.x != other.x) return false;
+ if (this.y != other.y) return false;
+ if (java.lang.Float.compare(this.f, other.f) != 0) return false;
+ if (java.lang.Double.compare(this.d, other.d) != 0) return false;
return true;
}
@java.lang.Override
@@ -49,6 +64,11 @@ final class EqualsAndHashCode2 {
final int PRIME = 31;
int result = 1;
result = result * PRIME + this.x;
+ final long $y = this.y;
+ result = result * PRIME + (int)($y >>> 32 ^ $y);
+ result = result * PRIME + java.lang.Float.floatToIntBits(this.f);
+ final long $d = java.lang.Double.doubleToLongBits(this.d);
+ result = result * PRIME + (int)($d >>> 32 ^ $d);
return result;
}
}
diff --git a/test/transform/resource/after-delombok/GetterLazyEahcToString.java b/test/transform/resource/after-delombok/GetterLazyEahcToString.java
index a542061d..ce3555fe 100644
--- a/test/transform/resource/after-delombok/GetterLazyEahcToString.java
+++ b/test/transform/resource/after-delombok/GetterLazyEahcToString.java
@@ -10,8 +10,12 @@ class GetterLazyEahcToString {
if (!(o instanceof GetterLazyEahcToString)) return false;
final GetterLazyEahcToString other = (GetterLazyEahcToString)o;
if (!other.canEqual((java.lang.Object)this)) return false;
- if (this.getValue() == null ? other.getValue() != null : !this.getValue().equals((java.lang.Object)other.getValue())) return false;
- if (this.value2 == null ? other.value2 != null : !this.value2.equals((java.lang.Object)other.value2)) return false;
+ final java.lang.Object this$value = this.getValue();
+ final java.lang.Object other$value = other.getValue();
+ if (this$value == null ? other$value != null : !this$value.equals(other$value)) return false;
+ final java.lang.Object this$value2 = this.value2;
+ final java.lang.Object other$value2 = other.value2;
+ if (this$value2 == null ? other$value2 != null : !this$value2.equals(other$value2)) return false;
return true;
}
@@ -25,8 +29,10 @@ class GetterLazyEahcToString {
public int hashCode() {
final int PRIME = 31;
int result = 1;
- result = result * PRIME + (this.getValue() == null ? 0 : this.getValue().hashCode());
- result = result * PRIME + (this.value2 == null ? 0 : this.value2.hashCode());
+ final java.lang.Object $value = this.getValue();
+ result = result * PRIME + ($value == null ? 0 : $value.hashCode());
+ final java.lang.Object $value2 = this.value2;
+ result = result * PRIME + ($value2 == null ? 0 : $value2.hashCode());
return result;
}
diff --git a/test/transform/resource/after-ecj/EqualsAndHashCode.java b/test/transform/resource/after-ecj/EqualsAndHashCode.java
index eeda5867..0417f54c 100644
--- a/test/transform/resource/after-ecj/EqualsAndHashCode.java
+++ b/test/transform/resource/after-ecj/EqualsAndHashCode.java
@@ -3,6 +3,7 @@
boolean[] y;
Object[] z;
String a;
+ String b;
public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) {
if ((o == this))
return true;
@@ -17,8 +18,14 @@
return false;
if ((! java.util.Arrays.deepEquals(this.z, other.z)))
return false;
- if (((this.a == null) ? (other.a != null) : (! this.a.equals((java.lang.Object) other.a))))
+ final java.lang.Object this$a = this.a;
+ final java.lang.Object other$a = other.a;
+ if (((this$a == null) ? (other$a != null) : (! this$a.equals(other$a))))
return false;
+ final java.lang.Object this$b = this.b;
+ final java.lang.Object other$b = other.b;
+ if (((this$b == null) ? (other$b != null) : (! this$b.equals(other$b))))
+ return false;
return true;
}
public @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
@@ -30,7 +37,10 @@
result = ((result * PRIME) + this.x);
result = ((result * PRIME) + java.util.Arrays.hashCode(this.y));
result = ((result * PRIME) + java.util.Arrays.deepHashCode(this.z));
- result = ((result * PRIME) + ((this.a == null) ? 0 : this.a.hashCode()));
+ final java.lang.Object $a = this.a;
+ result = ((result * PRIME) + (($a == null) ? 0 : $a.hashCode()));
+ final java.lang.Object $b = this.b;
+ result = ((result * PRIME) + (($b == null) ? 0 : $b.hashCode()));
return result;
}
EqualsAndHashCode() {
@@ -39,6 +49,9 @@
}
final @lombok.EqualsAndHashCode class EqualsAndHashCode2 {
int x;
+ long y;
+ float f;
+ double d;
public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) {
if ((o == this))
return true;
@@ -47,12 +60,23 @@ final @lombok.EqualsAndHashCode class EqualsAndHashCode2 {
final @java.lang.SuppressWarnings("all") EqualsAndHashCode2 other = (EqualsAndHashCode2) o;
if ((this.x != other.x))
return false;
+ if ((this.y != other.y))
+ return false;
+ if ((java.lang.Float.compare(this.f, other.f) != 0))
+ return false;
+ if ((java.lang.Double.compare(this.d, other.d) != 0))
+ return false;
return true;
}
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
final int PRIME = 31;
int result = 1;
result = ((result * PRIME) + this.x);
+ final long $y = this.y;
+ result = ((result * PRIME) + (int) ($y ^ ($y >>> 32)));
+ result = ((result * PRIME) + java.lang.Float.floatToIntBits(this.f));
+ final long $d = java.lang.Double.doubleToLongBits(this.d);
+ result = ((result * PRIME) + (int) ($d ^ ($d >>> 32)));
return result;
}
EqualsAndHashCode2() {
diff --git a/test/transform/resource/before/EqualsAndHashCode.java b/test/transform/resource/before/EqualsAndHashCode.java
index 1688c1fc..0a1e3290 100644
--- a/test/transform/resource/before/EqualsAndHashCode.java
+++ b/test/transform/resource/before/EqualsAndHashCode.java
@@ -4,11 +4,15 @@ class EqualsAndHashCode {
boolean[] y;
Object[] z;
String a;
+ String b;
}
@lombok.EqualsAndHashCode
final class EqualsAndHashCode2 {
int x;
+ long y;
+ float f;
+ double d;
}
@lombok.EqualsAndHashCode(callSuper=false)