aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java')
-rw-r--r--src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java66
1 files changed, 33 insertions, 33 deletions
diff --git a/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java
index f5f1bbd6..88ab3871 100644
--- a/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java
+++ b/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java
@@ -34,6 +34,7 @@ import lombok.core.AnnotationValues;
import lombok.javac.Javac;
import lombok.javac.JavacAnnotationHandler;
import lombok.javac.JavacNode;
+import lombok.javac.JavacTreeMaker;
import lombok.javac.handlers.JavacHandlerUtil.FieldAccess;
import lombok.javac.handlers.JavacHandlerUtil.MemberExistsResult;
@@ -57,7 +58,6 @@ 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;
@@ -219,11 +219,11 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
}
private JCMethodDecl createHashCode(JavacNode typeNode, List<JavacNode> fields, boolean callSuper, FieldAccess fieldAccess, JCTree source) {
- TreeMaker maker = typeNode.getTreeMaker();
+ JavacTreeMaker maker = typeNode.getTreeMaker();
JCAnnotation overrideAnnotation = maker.Annotation(chainDots(typeNode, "java", "lang", "Override"), List.<JCExpression>nil());
JCModifiers mods = maker.Modifiers(Flags.PUBLIC, List.of(overrideAnnotation));
- JCExpression returnType = Javac.makeTypeIdent(maker, CTC_INT);
+ JCExpression returnType = maker.TypeIdent(CTC_INT);
ListBuffer<JCStatement> statements = ListBuffer.lb();
Name primeName = typeNode.toName(PRIME_NAME);
@@ -231,12 +231,12 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
/* final int PRIME = 31; */ {
if (!fields.isEmpty() || callSuper) {
statements.append(maker.VarDef(maker.Modifiers(Flags.FINAL),
- primeName, Javac.makeTypeIdent(maker, CTC_INT), maker.Literal(31)));
+ primeName, maker.TypeIdent(CTC_INT), maker.Literal(31)));
}
}
/* int result = 1; */ {
- statements.append(maker.VarDef(maker.Modifiers(0), resultName, Javac.makeTypeIdent(maker, CTC_INT), maker.Literal(1)));
+ statements.append(maker.VarDef(maker.Modifiers(0), resultName, maker.TypeIdent(CTC_INT), maker.Literal(1)));
}
if (callSuper) {
@@ -258,7 +258,7 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
break;
case LONG: {
Name dollarFieldName = dollar.append(((JCVariableDecl)fieldNode.get()).name);
- statements.append(maker.VarDef(maker.Modifiers(Flags.FINAL), dollarFieldName, Javac.makeTypeIdent(maker, CTC_LONG), fieldAccessor));
+ statements.append(maker.VarDef(maker.Modifiers(Flags.FINAL), dollarFieldName, maker.TypeIdent(CTC_LONG), fieldAccessor));
statements.append(createResultCalculation(typeNode, longToIntForHashCode(maker, maker.Ident(dollarFieldName), maker.Ident(dollarFieldName))));
}
break;
@@ -276,7 +276,7 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
List.<JCExpression>nil(),
chainDots(typeNode, "java", "lang", "Double", "doubleToLongBits"),
List.of(fieldAccessor));
- statements.append(maker.VarDef(maker.Modifiers(Flags.FINAL), dollarFieldName, Javac.makeTypeIdent(maker, CTC_LONG), init));
+ statements.append(maker.VarDef(maker.Modifiers(Flags.FINAL), dollarFieldName, maker.TypeIdent(CTC_LONG), init));
statements.append(createResultCalculation(typeNode, longToIntForHashCode(maker, maker.Ident(dollarFieldName), maker.Ident(dollarFieldName))));
}
break;
@@ -306,7 +306,7 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
JCExpression hcCall = maker.Apply(List.<JCExpression>nil(), maker.Select(maker.Ident(dollarFieldName), typeNode.toName("hashCode")),
List.<JCExpression>nil());
- JCExpression thisEqualsNull = Javac.makeBinary(maker, CTC_EQUAL, maker.Ident(dollarFieldName), Javac.makeLiteral(maker, CTC_BOT, null));
+ JCExpression thisEqualsNull = maker.Binary(CTC_EQUAL, maker.Ident(dollarFieldName), maker.Literal(CTC_BOT, null));
statements.append(createResultCalculation(typeNode, maker.Conditional(thisEqualsNull, maker.Literal(0), hcCall)));
}
}
@@ -322,19 +322,19 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
private JCExpressionStatement createResultCalculation(JavacNode typeNode, JCExpression expr) {
/* result = result * PRIME + (expr); */
- TreeMaker maker = typeNode.getTreeMaker();
+ JavacTreeMaker maker = typeNode.getTreeMaker();
Name resultName = typeNode.toName(RESULT_NAME);
- JCExpression mult = Javac.makeBinary(maker, CTC_MUL, maker.Ident(resultName), maker.Ident(typeNode.toName(PRIME_NAME)));
- JCExpression add = Javac.makeBinary(maker, CTC_PLUS, mult, expr);
+ JCExpression mult = maker.Binary(CTC_MUL, maker.Ident(resultName), maker.Ident(typeNode.toName(PRIME_NAME)));
+ JCExpression add = maker.Binary(CTC_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) {
+ private JCExpression longToIntForHashCode(JavacTreeMaker maker, JCExpression ref1, JCExpression ref2) {
/* (int)(ref >>> 32 ^ ref) */
- JCExpression shift = Javac.makeBinary(maker, CTC_UNSIGNED_SHIFT_RIGHT, ref1, maker.Literal(32));
- JCExpression xorBits = Javac.makeBinary(maker, CTC_BITXOR, shift, ref2);
- return maker.TypeCast(Javac.makeTypeIdent(maker, CTC_INT), xorBits);
+ JCExpression shift = maker.Binary(CTC_UNSIGNED_SHIFT_RIGHT, ref1, maker.Literal(32));
+ JCExpression xorBits = maker.Binary(CTC_BITXOR, shift, ref2);
+ return maker.TypeCast(maker.TypeIdent(CTC_INT), xorBits);
}
private JCExpression createTypeReference(JavacNode type) {
@@ -347,7 +347,7 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
}
Collections.reverse(list);
- TreeMaker maker = type.getTreeMaker();
+ JavacTreeMaker maker = type.getTreeMaker();
JCExpression chain = maker.Ident(type.toName(list.get(0)));
for (int i = 1; i < list.size(); i++) {
@@ -358,7 +358,7 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
}
private JCMethodDecl createEquals(JavacNode typeNode, List<JavacNode> fields, boolean callSuper, FieldAccess fieldAccess, boolean needsCanEqual, JCTree source) {
- TreeMaker maker = typeNode.getTreeMaker();
+ JavacTreeMaker maker = typeNode.getTreeMaker();
JCClassDecl type = (JCClassDecl) typeNode.get();
Name oName = typeNode.toName("o");
@@ -368,19 +368,19 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
JCAnnotation overrideAnnotation = maker.Annotation(chainDots(typeNode, "java", "lang", "Override"), List.<JCExpression>nil());
JCModifiers mods = maker.Modifiers(Flags.PUBLIC, List.of(overrideAnnotation));
JCExpression objectType = chainDots(typeNode, "java", "lang", "Object");
- JCExpression returnType = Javac.makeTypeIdent(maker, CTC_BOOLEAN);
+ JCExpression returnType = maker.TypeIdent(CTC_BOOLEAN);
ListBuffer<JCStatement> statements = ListBuffer.lb();
final List<JCVariableDecl> params = List.of(maker.VarDef(maker.Modifiers(Flags.FINAL), oName, objectType, null));
/* if (o == this) return true; */ {
- statements.append(maker.If(Javac.makeBinary(maker, CTC_EQUAL, maker.Ident(oName),
+ statements.append(maker.If(maker.Binary(CTC_EQUAL, maker.Ident(oName),
maker.Ident(thisName)), returnBool(maker, true), null));
}
/* if (!(o instanceof Outer.Inner.MyType) return false; */ {
- JCUnary notInstanceOf = Javac.makeUnary(maker, CTC_NOT, maker.TypeTest(maker.Ident(oName), createTypeReference(typeNode)));
+ JCUnary notInstanceOf = maker.Unary(CTC_NOT, maker.TypeTest(maker.Ident(oName), createTypeReference(typeNode)));
statements.append(maker.If(notInstanceOf, returnBool(maker, false), null));
}
@@ -415,7 +415,7 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
JCExpression equalityCheck = maker.Apply(exprNil,
maker.Select(maker.Ident(otherName), typeNode.toName("canEqual")),
List.of(castThisRef));
- statements.append(maker.If(Javac.makeUnary(maker, CTC_NOT, equalityCheck), returnBool(maker, false), null));
+ statements.append(maker.If(maker.Unary(CTC_NOT, equalityCheck), returnBool(maker, false), null));
}
}
@@ -424,7 +424,7 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
JCMethodInvocation callToSuper = maker.Apply(List.<JCExpression>nil(),
maker.Select(maker.Ident(typeNode.toName("super")), typeNode.toName("equals")),
List.<JCExpression>of(maker.Ident(oName)));
- JCUnary superNotEqual = Javac.makeUnary(maker, CTC_NOT, callToSuper);
+ JCUnary superNotEqual = maker.Unary(CTC_NOT, callToSuper);
statements.append(maker.If(superNotEqual, returnBool(maker, false), null));
}
@@ -447,7 +447,7 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
default:
/* if (this.fieldName != other.fieldName) return false; */
statements.append(
- maker.If(Javac.makeBinary(maker, CTC_NOT_EQUAL, thisFieldAccessor, otherFieldAccessor), returnBool(maker, false), null));
+ maker.If(maker.Binary(CTC_NOT_EQUAL, thisFieldAccessor, otherFieldAccessor), returnBool(maker, false), null));
break;
}
} else if (fType instanceof JCArrayTypeTree) {
@@ -458,7 +458,7 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
JCExpression eqMethod = chainDots(typeNode, "java", "util", "Arrays", useDeepEquals ? "deepEquals" : "equals");
List<JCExpression> args = List.of(thisFieldAccessor, otherFieldAccessor);
- statements.append(maker.If(Javac.makeUnary(maker, CTC_NOT,
+ statements.append(maker.If(maker.Unary(CTC_NOT,
maker.Apply(List.<JCExpression>nil(), eqMethod, args)), returnBool(maker, false), null));
} else /* objects */ {
/* final java.lang.Object this$fieldName = this.fieldName; */
@@ -471,12 +471,12 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
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 = Javac.makeBinary(maker, CTC_EQUAL, maker.Ident(thisDollarFieldName), Javac.makeLiteral(maker, CTC_BOT, null));
- JCExpression otherNotEqualsNull = Javac.makeBinary(maker, CTC_NOT_EQUAL, maker.Ident(otherDollarFieldName), Javac.makeLiteral(maker, CTC_BOT, null));
+ JCExpression thisEqualsNull = maker.Binary(CTC_EQUAL, maker.Ident(thisDollarFieldName), maker.Literal(CTC_BOT, null));
+ JCExpression otherNotEqualsNull = maker.Binary(CTC_NOT_EQUAL, maker.Ident(otherDollarFieldName), maker.Literal(CTC_BOT, null));
JCExpression thisEqualsThat = maker.Apply(List.<JCExpression>nil(),
maker.Select(maker.Ident(thisDollarFieldName), typeNode.toName("equals")),
List.<JCExpression>of(maker.Ident(otherDollarFieldName)));
- JCExpression fieldsAreNotEqual = maker.Conditional(thisEqualsNull, otherNotEqualsNull, Javac.makeUnary(maker, CTC_NOT, thisEqualsThat));
+ JCExpression fieldsAreNotEqual = maker.Conditional(thisEqualsNull, otherNotEqualsNull, maker.Unary(CTC_NOT, thisEqualsThat));
statements.append(maker.If(fieldsAreNotEqual, returnBool(maker, false), null));
}
}
@@ -494,10 +494,10 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
* return other instanceof Outer.Inner.MyType;
* }
*/
- TreeMaker maker = typeNode.getTreeMaker();
+ JavacTreeMaker maker = typeNode.getTreeMaker();
JCModifiers mods = maker.Modifiers(Flags.PUBLIC, List.<JCAnnotation>nil());
- JCExpression returnType = Javac.makeTypeIdent(maker, CTC_BOOLEAN);
+ JCExpression returnType = maker.TypeIdent(CTC_BOOLEAN);
Name canEqualName = typeNode.toName("canEqual");
JCExpression objectType = chainDots(typeNode, "java", "lang", "Object");
Name otherName = typeNode.toName("other");
@@ -510,16 +510,16 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
}
private JCStatement generateCompareFloatOrDouble(JCExpression thisDotField, JCExpression otherDotField,
- TreeMaker maker, JavacNode node, boolean isDouble) {
+ JavacTreeMaker maker, JavacNode node, boolean isDouble) {
/* if (Float.compare(fieldName, other.fieldName) != 0) return false; */
JCExpression clazz = chainDots(node, "java", "lang", isDouble ? "Double" : "Float");
List<JCExpression> args = List.of(thisDotField, otherDotField);
- JCBinary compareCallEquals0 = Javac.makeBinary(maker, CTC_NOT_EQUAL, maker.Apply(
+ JCBinary compareCallEquals0 = maker.Binary(CTC_NOT_EQUAL, maker.Apply(
List.<JCExpression>nil(), maker.Select(clazz, node.toName("compare")), args), maker.Literal(0));
return maker.If(compareCallEquals0, returnBool(maker, false), null);
}
- private JCStatement returnBool(TreeMaker maker, boolean bool) {
- return maker.Return(Javac.makeLiteral(maker, CTC_BOOLEAN, bool ? 1 : 0));
+ private JCStatement returnBool(JavacTreeMaker maker, boolean bool) {
+ return maker.Return(maker.Literal(CTC_BOOLEAN, bool ? 1 : 0));
}
}