From 1c2556b1f7b26ea0b70d356d9eeefb638560a46f Mon Sep 17 00:00:00 2001 From: Roel Spilker Date: Mon, 15 Nov 2010 00:44:16 +0100 Subject: In javac, use ListBuffer to append --- .../javac/handlers/HandleEqualsAndHashCode.java | 83 +++++++++++----------- 1 file changed, 42 insertions(+), 41 deletions(-) (limited to 'src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java') diff --git a/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java index 8799f2e1..59689614 100644 --- a/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java +++ b/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java @@ -51,6 +51,7 @@ 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.util.List; +import com.sun.tools.javac.util.ListBuffer; import com.sun.tools.javac.util.Name; /** @@ -146,12 +147,12 @@ public class HandleEqualsAndHashCode implements JavacAnnotationHandler nodesForEquality = List.nil(); + ListBuffer nodesForEquality = ListBuffer.lb(); if (includes != null) { for (JavacNode child : typeNode.down()) { if (child.getKind() != Kind.FIELD) continue; JCVariableDecl fieldDecl = (JCVariableDecl) child.get(); - if (includes.contains(fieldDecl.name.toString())) nodesForEquality = nodesForEquality.append(child); + if (includes.contains(fieldDecl.name.toString())) nodesForEquality.append(child); } } else { for (JavacNode child : typeNode.down()) { @@ -165,7 +166,7 @@ public class HandleEqualsAndHashCode implements JavacAnnotationHandlernil()); JCModifiers mods = maker.Modifiers(Flags.PUBLIC, List.of(overrideAnnotation)); JCExpression returnType = maker.TypeIdent(TypeTags.INT); - List statements = List.nil(); + ListBuffer statements = ListBuffer.lb(); Name primeName = typeNode.toName("PRIME"); Name resultName = typeNode.toName("result"); /* final int PRIME = 31; */ { if (!fields.isEmpty() || callSuper) { - statements = statements.append(maker.VarDef(maker.Modifiers(Flags.FINAL), + statements.append(maker.VarDef(maker.Modifiers(Flags.FINAL), primeName, maker.TypeIdent(TypeTags.INT), maker.Literal(31))); } } /* int result = 1; */ { - statements = statements.append(maker.VarDef(maker.Modifiers(0), resultName, maker.TypeIdent(TypeTags.INT), maker.Literal(1))); + statements.append(maker.VarDef(maker.Modifiers(0), resultName, maker.TypeIdent(TypeTags.INT), maker.Literal(1))); } - List intoResult = List.nil(); + ListBuffer intoResult = ListBuffer.lb(); if (callSuper) { JCMethodInvocation callToSuper = maker.Apply(List.nil(), maker.Select(maker.Ident(typeNode.toName("super")), typeNode.toName("hashCode")), List.nil()); - intoResult = intoResult.append(callToSuper); + intoResult.append(callToSuper); } int tempCounter = 0; @@ -255,14 +256,14 @@ public class HandleEqualsAndHashCode implements JavacAnnotationHandlernil(), chainDots(maker, typeNode, "java", "lang", "Float", "floatToIntBits"), List.of(fieldAccessor))); @@ -274,9 +275,9 @@ public class HandleEqualsAndHashCode implements JavacAnnotationHandlernil(), chainDots(maker, typeNode, "java", "lang", "Double", "doubleToLongBits"), List.of(fieldAccessor)); - statements = statements.append( + statements.append( maker.VarDef(maker.Modifiers(Flags.FINAL), tempVar, maker.TypeIdent(TypeTags.LONG), init)); - intoResult = intoResult.append(longToIntForHashCode(maker, maker.Ident(tempVar), maker.Ident(tempVar))); + intoResult.append(longToIntForHashCode(maker, maker.Ident(tempVar), maker.Ident(tempVar))); break; default: case BYTE: @@ -284,7 +285,7 @@ public class HandleEqualsAndHashCode implements JavacAnnotationHandlernil(), hcMethod, List.of(fieldAccessor))); } else /* objects */ { /* this.fieldName == null ? 0 : this.fieldName.hashCode() */ JCExpression hcCall = maker.Apply(List.nil(), maker.Select(createFieldAccessor(maker, fieldNode, fieldAccess), typeNode.toName("hashCode")), List.nil()); JCExpression thisEqualsNull = maker.Binary(JCTree.EQ, fieldAccessor, maker.Literal(TypeTags.BOT, null)); - intoResult = intoResult.append( + intoResult.append( maker.Conditional(thisEqualsNull, maker.Literal(0), hcCall)); } } @@ -311,14 +312,14 @@ public class HandleEqualsAndHashCode implements JavacAnnotationHandlernil(), List.nil(), List.nil(), body, null); } @@ -344,38 +345,38 @@ public class HandleEqualsAndHashCode implements JavacAnnotationHandler statements = List.nil(); - List params = List.of(maker.VarDef(maker.Modifiers(Flags.FINAL), oName, objectType, null)); + ListBuffer statements = ListBuffer.lb(); + final List params = List.of(maker.VarDef(maker.Modifiers(Flags.FINAL), oName, objectType, null)); /* if (o == this) return true; */ { - statements = statements.append(maker.If(maker.Binary(JCTree.EQ, maker.Ident(oName), + statements.append(maker.If(maker.Binary(JCTree.EQ, maker.Ident(oName), maker.Ident(thisName)), returnBool(maker, true), null)); } /* if (!(o instanceof MyType) return false; */ { JCUnary notInstanceOf = maker.Unary(JCTree.NOT, maker.TypeTest(maker.Ident(oName), maker.Ident(type.name))); - statements = statements.append(maker.If(notInstanceOf, returnBool(maker, false), null)); + statements.append(maker.If(notInstanceOf, returnBool(maker, false), null)); } /* MyType other = (MyType) o; */ { if (!fields.isEmpty() || needsCanEqual) { final JCExpression selfType1, selfType2; - List wildcards1 = List.nil(); - List wildcards2 = List.nil(); + ListBuffer wildcards1 = ListBuffer.lb(); + ListBuffer wildcards2 = ListBuffer.lb(); 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)); + wildcards1.append(maker.Wildcard(maker.TypeBoundKind(BoundKind.UNBOUND), null)); + 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); + selfType1 = maker.TypeApply(maker.Ident(type.name), wildcards1.toList()); + selfType2 = maker.TypeApply(maker.Ident(type.name), wildcards2.toList()); } - statements = statements.append( + statements.append( maker.VarDef(maker.Modifiers(Flags.FINAL), otherName, selfType1, maker.TypeCast(selfType2, maker.Ident(oName)))); } } @@ -386,7 +387,7 @@ public class HandleEqualsAndHashCode implements JavacAnnotationHandlerof(maker.Ident(thisName))); - statements = statements.append(maker.If(maker.Unary(JCTree.NOT, equalityCheck), returnBool(maker, false), null)); + statements.append(maker.If(maker.Unary(JCTree.NOT, equalityCheck), returnBool(maker, false), null)); } } @@ -396,7 +397,7 @@ public class HandleEqualsAndHashCode implements JavacAnnotationHandlerof(maker.Ident(oName))); JCUnary superNotEqual = maker.Unary(JCTree.NOT, callToSuper); - statements = statements.append(maker.If(superNotEqual, returnBool(maker, false), null)); + statements.append(maker.If(superNotEqual, returnBool(maker, false), null)); } for (JavacNode fieldNode : fields) { @@ -407,15 +408,15 @@ public class HandleEqualsAndHashCode implements JavacAnnotationHandler args = List.of(thisFieldAccessor, otherFieldAccessor); - statements = statements.append(maker.If(maker.Unary(JCTree.NOT, + statements.append(maker.If(maker.Unary(JCTree.NOT, maker.Apply(List.nil(), eqMethod, args)), returnBool(maker, false), null)); } else /* objects */ { /* if (this.fieldName == null ? other.fieldName != null : !this.fieldName.equals(other.fieldName)) return false; */ @@ -437,15 +438,15 @@ public class HandleEqualsAndHashCode implements JavacAnnotationHandlernil(), params, List.nil(), body, null); } -- cgit