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 --- src/core/lombok/javac/JavacResolution.java | 7 +- src/core/lombok/javac/handlers/HandleCleanup.java | 20 +++--- .../lombok/javac/handlers/HandleConstructor.java | 67 ++++++++--------- .../javac/handlers/HandleEqualsAndHashCode.java | 83 +++++++++++----------- src/core/lombok/javac/handlers/HandleGetter.java | 27 +++---- src/core/lombok/javac/handlers/HandleToString.java | 9 +-- .../lombok/javac/handlers/JavacHandlerUtil.java | 43 +++++------ src/delombok/lombok/delombok/Delombok.java | 6 +- 8 files changed, 134 insertions(+), 128 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/JavacResolution.java b/src/core/lombok/javac/JavacResolution.java index 2845328d..653e6d6d 100644 --- a/src/core/lombok/javac/JavacResolution.java +++ b/src/core/lombok/javac/JavacResolution.java @@ -34,6 +34,7 @@ import com.sun.tools.javac.tree.JCTree.JCVariableDecl; import com.sun.tools.javac.tree.TreeMaker; import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.List; +import com.sun.tools.javac.util.ListBuffer; import com.sun.tools.javac.util.Log; public class JavacResolution { @@ -378,9 +379,9 @@ public class JavacResolution { } if (generics != null && !generics.isEmpty()) { - List args = List.nil(); - for (Type t : generics) args = args.append(typeToJCTree(t, maker, ast, true)); - replacement = maker.TypeApply(replacement, args); + ListBuffer args = ListBuffer.lb(); + for (Type t : generics) args.append(typeToJCTree(t, maker, ast, true)); + replacement = maker.TypeApply(replacement, args.toList()); } return replacement; diff --git a/src/core/lombok/javac/handlers/HandleCleanup.java b/src/core/lombok/javac/handlers/HandleCleanup.java index cbbdc007..bfe357ef 100644 --- a/src/core/lombok/javac/handlers/HandleCleanup.java +++ b/src/core/lombok/javac/handlers/HandleCleanup.java @@ -50,6 +50,7 @@ import com.sun.tools.javac.tree.JCTree.JCStatement; import com.sun.tools.javac.tree.JCTree.JCTypeCast; 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; /** @@ -93,14 +94,14 @@ public class HandleCleanup implements JavacAnnotationHandler { } boolean seenDeclaration = false; - List tryBlock = List.nil(); - List newStatements = List.nil(); + ListBuffer newStatements = ListBuffer.lb(); + ListBuffer tryBlock = ListBuffer.lb(); for (JCStatement statement : statements) { if (!seenDeclaration) { if (statement == decl) seenDeclaration = true; - newStatements = newStatements.append(statement); + newStatements.append(statement); } else { - tryBlock = tryBlock.append(statement); + tryBlock.append(statement); } } @@ -108,8 +109,7 @@ public class HandleCleanup implements JavacAnnotationHandler { annotationNode.addError("LOMBOK BUG: Can't find this local variable declaration inside its parent."); return true; } - - doAssignmentCheck(annotationNode, tryBlock, decl.name); + doAssignmentCheck(annotationNode, tryBlock.toList(), decl.name); TreeMaker maker = annotationNode.getTreeMaker(); JCFieldAccess cleanupMethod = maker.Select(maker.Ident(decl.name), annotationNode.toName(cleanupName)); @@ -123,14 +123,14 @@ public class HandleCleanup implements JavacAnnotationHandler { JCBlock finalizer = maker.Block(0, List.of(ifNotNullCleanup)); - newStatements = newStatements.append(maker.Try(maker.Block(0, tryBlock), List.nil(), finalizer)); + newStatements.append(maker.Try(maker.Block(0, tryBlock.toList()), List.nil(), finalizer)); if (blockNode instanceof JCBlock) { - ((JCBlock)blockNode).stats = newStatements; + ((JCBlock)blockNode).stats = newStatements.toList(); } else if (blockNode instanceof JCCase) { - ((JCCase)blockNode).stats = newStatements; + ((JCCase)blockNode).stats = newStatements.toList(); } else if (blockNode instanceof JCMethodDecl) { - ((JCMethodDecl)blockNode).body.stats = newStatements; + ((JCMethodDecl)blockNode).body.stats = newStatements.toList(); } else throw new AssertionError("Should not get here"); ancestor.rebuild(); diff --git a/src/core/lombok/javac/handlers/HandleConstructor.java b/src/core/lombok/javac/handlers/HandleConstructor.java index d56c976f..3370685e 100644 --- a/src/core/lombok/javac/handlers/HandleConstructor.java +++ b/src/core/lombok/javac/handlers/HandleConstructor.java @@ -53,6 +53,7 @@ import com.sun.tools.javac.tree.JCTree.JCTypeApply; import com.sun.tools.javac.tree.JCTree.JCTypeParameter; import com.sun.tools.javac.tree.JCTree.JCVariableDecl; import com.sun.tools.javac.util.List; +import com.sun.tools.javac.util.ListBuffer; public class HandleConstructor { @ProviderFor(JavacAnnotationHandler.class) @@ -97,7 +98,7 @@ public class HandleConstructor { } private static List findRequiredFields(JavacNode typeNode) { - List fields = List.nil(); + ListBuffer fields = ListBuffer.lb(); for (JavacNode child : typeNode.down()) { if (child.getKind() != Kind.FIELD) continue; JCVariableDecl fieldDecl = (JCVariableDecl) child.get(); @@ -108,9 +109,9 @@ public class HandleConstructor { if ((fieldFlags & Flags.STATIC) != 0) continue; boolean isFinal = (fieldFlags & Flags.FINAL) != 0; boolean isNonNull = !findAnnotations(child, TransformationsUtil.NON_NULL_PATTERN).isEmpty(); - if ((isFinal || isNonNull) && fieldDecl.init == null) fields = fields.append(child); + if ((isFinal || isNonNull) && fieldDecl.init == null) fields.append(child); } - return fields; + return fields.toList(); } @ProviderFor(JavacAnnotationHandler.class) @@ -125,7 +126,7 @@ public class HandleConstructor { @SuppressWarnings("deprecation") boolean suppressConstructorProperties = ann.suppressConstructorProperties(); if (level == AccessLevel.NONE) return true; - List fields = List.nil(); + ListBuffer fields = ListBuffer.lb(); for (JavacNode child : typeNode.down()) { if (child.getKind() != Kind.FIELD) continue; JCVariableDecl fieldDecl = (JCVariableDecl) child.get(); @@ -134,9 +135,9 @@ public class HandleConstructor { long fieldFlags = fieldDecl.mods.flags; //Skip static fields. if ((fieldFlags & Flags.STATIC) != 0) continue; - fields = fields.append(child); + fields.append(child); } - new HandleConstructor().generateConstructor(typeNode, level, fields, staticName, false, suppressConstructorProperties); + new HandleConstructor().generateConstructor(typeNode, level, fields.toList(), staticName, false, suppressConstructorProperties); return true; } @@ -176,11 +177,11 @@ public class HandleConstructor { if (fields.isEmpty()) return; TreeMaker maker = node.getTreeMaker(); JCExpression constructorPropertiesType = chainDots(maker, node, "java", "beans", "ConstructorProperties"); - List fieldNames = List.nil(); + ListBuffer fieldNames = ListBuffer.lb(); for (JavacNode field : fields) { - fieldNames = fieldNames.append(maker.Literal(field.getName())); + fieldNames.append(maker.Literal(field.getName())); } - JCExpression fieldNamesArray = maker.NewArray(null, List.nil(), fieldNames); + JCExpression fieldNamesArray = maker.NewArray(null, List.nil(), fieldNames.toList()); JCAnnotation annotation = maker.Annotation(constructorPropertiesType, List.of(fieldNamesArray)); mods.annotations = mods.annotations.append(annotation); } @@ -188,23 +189,23 @@ public class HandleConstructor { private JCMethodDecl createConstructor(AccessLevel level, JavacNode typeNode, List fields, boolean suppressConstructorProperties) { TreeMaker maker = typeNode.getTreeMaker(); - List nullChecks = List.nil(); - List assigns = List.nil(); - List params = List.nil(); + ListBuffer nullChecks = ListBuffer.lb(); + ListBuffer assigns = ListBuffer.lb(); + ListBuffer params = ListBuffer.lb(); for (JavacNode fieldNode : fields) { JCVariableDecl field = (JCVariableDecl) fieldNode.get(); List nonNulls = findAnnotations(fieldNode, TransformationsUtil.NON_NULL_PATTERN); List nullables = findAnnotations(fieldNode, TransformationsUtil.NULLABLE_PATTERN); JCVariableDecl param = maker.VarDef(maker.Modifiers(Flags.FINAL, nonNulls.appendList(nullables)), field.name, field.vartype, null); - params = params.append(param); + params.append(param); JCFieldAccess thisX = maker.Select(maker.Ident(fieldNode.toName("this")), field.name); JCAssign assign = maker.Assign(thisX, maker.Ident(field.name)); - assigns = assigns.append(maker.Exec(assign)); + assigns.append(maker.Exec(assign)); if (!nonNulls.isEmpty()) { JCStatement nullCheck = generateNullCheck(maker, fieldNode); - if (nullCheck != null) nullChecks = nullChecks.append(nullCheck); + if (nullCheck != null) nullChecks.append(nullCheck); } } @@ -214,7 +215,7 @@ public class HandleConstructor { } return maker.MethodDef(mods, typeNode.toName(""), - null, List.nil(), params, List.nil(), maker.Block(0L, nullChecks.appendList(assigns)), null); + null, List.nil(), params.toList(), List.nil(), maker.Block(0L, nullChecks.appendList(assigns).toList()), null); } private boolean isLocalType(JavacNode type) { @@ -232,20 +233,20 @@ public class HandleConstructor { JCExpression returnType, constructorType; - List typeParams = List.nil(); - List params = List.nil(); - List typeArgs1 = List.nil(); - List typeArgs2 = List.nil(); - List args = List.nil(); + ListBuffer typeParams = ListBuffer.lb(); + ListBuffer params = ListBuffer.lb(); + ListBuffer typeArgs1 = ListBuffer.lb(); + ListBuffer typeArgs2 = ListBuffer.lb(); + ListBuffer args = ListBuffer.lb(); if (!type.typarams.isEmpty()) { for (JCTypeParameter param : type.typarams) { - typeArgs1 = typeArgs1.append(maker.Ident(param.name)); - typeArgs2 = typeArgs2.append(maker.Ident(param.name)); - typeParams = typeParams.append(maker.TypeParameter(param.name, param.bounds)); + typeArgs1.append(maker.Ident(param.name)); + typeArgs2.append(maker.Ident(param.name)); + typeParams.append(maker.TypeParameter(param.name, param.bounds)); } - returnType = maker.TypeApply(maker.Ident(type.name), typeArgs1); - constructorType = maker.TypeApply(maker.Ident(type.name), typeArgs2); + returnType = maker.TypeApply(maker.Ident(type.name), typeArgs1.toList()); + constructorType = maker.TypeApply(maker.Ident(type.name), typeArgs2.toList()); } else { returnType = maker.Ident(type.name); constructorType = maker.Ident(type.name); @@ -257,21 +258,21 @@ public class HandleConstructor { if (field.vartype instanceof JCIdent) pType = maker.Ident(((JCIdent)field.vartype).name); else if (field.vartype instanceof JCTypeApply) { JCTypeApply typeApply = (JCTypeApply) field.vartype; - List tArgs = List.nil(); - for (JCExpression arg : typeApply.arguments) tArgs = tArgs.append(arg); - pType = maker.TypeApply(typeApply.clazz, tArgs); + ListBuffer tArgs = ListBuffer.lb(); + for (JCExpression arg : typeApply.arguments) tArgs.append(arg); + pType = maker.TypeApply(typeApply.clazz, tArgs.toList()); } else { pType = field.vartype; } List nonNulls = findAnnotations(fieldNode, TransformationsUtil.NON_NULL_PATTERN); List nullables = findAnnotations(fieldNode, TransformationsUtil.NULLABLE_PATTERN); JCVariableDecl param = maker.VarDef(maker.Modifiers(Flags.FINAL, nonNulls.appendList(nullables)), field.name, pType, null); - params = params.append(param); - args = args.append(maker.Ident(field.name)); + params.append(param); + args.append(maker.Ident(field.name)); } - JCReturn returnStatement = maker.Return(maker.NewClass(null, List.nil(), constructorType, args, null)); + JCReturn returnStatement = maker.Return(maker.NewClass(null, List.nil(), constructorType, args.toList(), null)); JCBlock body = maker.Block(0, List.of(returnStatement)); - return maker.MethodDef(mods, typeNode.toName(name), returnType, typeParams, params, List.nil(), body, null); + return maker.MethodDef(mods, typeNode.toName(name), returnType, typeParams.toList(), params.toList(), List.nil(), body, null); } } 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); } diff --git a/src/core/lombok/javac/handlers/HandleGetter.java b/src/core/lombok/javac/handlers/HandleGetter.java index be1bc49a..85387684 100644 --- a/src/core/lombok/javac/handlers/HandleGetter.java +++ b/src/core/lombok/javac/handlers/HandleGetter.java @@ -61,6 +61,7 @@ import com.sun.tools.javac.tree.JCTree.JCTypeApply; import com.sun.tools.javac.tree.JCTree.JCTypeParameter; 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; import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; @@ -287,7 +288,7 @@ public class HandleGetter implements JavacAnnotationHandler { return value.get(); */ - List statements = List.nil(); + ListBuffer statements = ListBuffer.lb(); JCVariableDecl field = (JCVariableDecl) fieldNode.get(); field.type = null; @@ -302,46 +303,46 @@ public class HandleGetter implements JavacAnnotationHandler { /* java.util.concurrent.atomic.AtomicReference value = this.fieldName.get();*/ { JCTypeApply valueVarType = maker.TypeApply(chainDotsString(maker, fieldNode, AR), List.of(copyType(maker, field))); - statements = statements.append(maker.VarDef(maker.Modifiers(0), valueName, valueVarType, callGet(fieldNode, createFieldAccessor(maker, fieldNode, FieldAccess.ALWAYS_FIELD)))); + statements.append(maker.VarDef(maker.Modifiers(0), valueName, valueVarType, callGet(fieldNode, createFieldAccessor(maker, fieldNode, FieldAccess.ALWAYS_FIELD)))); } /* if (value == null) { */ { JCSynchronized synchronizedStatement; /* synchronized (this.fieldName) { */ { - List synchronizedStatements = List.nil(); + ListBuffer synchronizedStatements = ListBuffer.lb(); /* value = this.fieldName.get(); */ { JCExpressionStatement newAssign = maker.Exec(maker.Assign(maker.Ident(valueName), callGet(fieldNode, createFieldAccessor(maker, fieldNode, FieldAccess.ALWAYS_FIELD)))); - synchronizedStatements = synchronizedStatements.append(newAssign); + synchronizedStatements.append(newAssign); } /* if (value == null) { */ { - List innerIfStatements = List.nil(); + ListBuffer innerIfStatements = ListBuffer.lb(); /* value = new java.util.concurrent.atomic.AtomicReference(new ValueType());*/ { JCTypeApply valueVarType = maker.TypeApply(chainDotsString(maker, fieldNode, AR), List.of(copyType(maker, field))); JCNewClass newInstance = maker.NewClass(null, NIL_EXPRESSION, valueVarType, List.of(field.init), null); JCStatement statement = maker.Exec(maker.Assign(maker.Ident(valueName), newInstance)); - innerIfStatements = innerIfStatements.append(statement); + innerIfStatements.append(statement); } /* this.fieldName.set(value); */ { JCStatement statement = callSet(fieldNode, createFieldAccessor(maker, fieldNode, FieldAccess.ALWAYS_FIELD), maker.Ident(valueName)); - innerIfStatements = innerIfStatements.append(statement); + innerIfStatements.append(statement); } JCBinary isNull = maker.Binary(JCTree.EQ, maker.Ident(valueName), maker.Literal(TypeTags.BOT, null)); - JCIf ifStatement = maker.If(isNull, maker.Block(0, innerIfStatements), null); - synchronizedStatements = synchronizedStatements.append(ifStatement); + JCIf ifStatement = maker.If(isNull, maker.Block(0, innerIfStatements.toList()), null); + synchronizedStatements.append(ifStatement); } - synchronizedStatement = maker.Synchronized(createFieldAccessor(maker, fieldNode, FieldAccess.ALWAYS_FIELD), maker.Block(0, synchronizedStatements)); + synchronizedStatement = maker.Synchronized(createFieldAccessor(maker, fieldNode, FieldAccess.ALWAYS_FIELD), maker.Block(0, synchronizedStatements.toList())); } JCBinary isNull = maker.Binary(JCTree.EQ, maker.Ident(valueName), maker.Literal(TypeTags.BOT, null)); JCIf ifStatement = maker.If(isNull, maker.Block(0, List.of(synchronizedStatement)), null); - statements = statements.append(ifStatement); + statements.append(ifStatement); } /* return value.get(); */ - statements = statements.append(maker.Return(callGet(fieldNode, maker.Ident(valueName)))); + statements.append(maker.Return(callGet(fieldNode, maker.Ident(valueName)))); // update the field type and init last @@ -350,7 +351,7 @@ public class HandleGetter implements JavacAnnotationHandler { field.init = maker.NewClass(null, NIL_EXPRESSION, copyType(maker, field), NIL_EXPRESSION, null); } - return statements; + return statements.toList(); } private JCMethodInvocation callGet(JavacNode source, JCExpression receiver) { diff --git a/src/core/lombok/javac/handlers/HandleToString.java b/src/core/lombok/javac/handlers/HandleToString.java index 82e32c06..183658c2 100644 --- a/src/core/lombok/javac/handlers/HandleToString.java +++ b/src/core/lombok/javac/handlers/HandleToString.java @@ -49,6 +49,7 @@ import com.sun.tools.javac.tree.JCTree.JCStatement; import com.sun.tools.javac.tree.JCTree.JCTypeParameter; import com.sun.tools.javac.tree.JCTree.JCVariableDecl; import com.sun.tools.javac.util.List; +import com.sun.tools.javac.util.ListBuffer; /** * Handles the {@code ToString} annotation for javac. @@ -130,12 +131,12 @@ public class HandleToString implements JavacAnnotationHandler { return false; } - List nodesForToString = List.nil(); + ListBuffer nodesForToString = 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())) nodesForToString = nodesForToString.append(child); + if (includes.contains(fieldDecl.name.toString())) nodesForToString.append(child); } } else { for (JavacNode child : typeNode.down()) { @@ -147,13 +148,13 @@ public class HandleToString implements JavacAnnotationHandler { if (excludes != null && excludes.contains(fieldDecl.name.toString())) continue; //Skip fields that start with $. if (fieldDecl.name.toString().startsWith("$")) continue; - nodesForToString = nodesForToString.append(child); + nodesForToString.append(child); } } switch (methodExists("toString", typeNode)) { case NOT_EXISTS: - JCMethodDecl method = createToString(typeNode, nodesForToString, includeFieldNames, callSuper, fieldAccess); + JCMethodDecl method = createToString(typeNode, nodesForToString.toList(), includeFieldNames, callSuper, fieldAccess); injectMethod(typeNode, method); return true; case EXISTS_BY_LOMBOK: diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java index d1884e5c..3f869410 100644 --- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java +++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java @@ -54,6 +54,7 @@ import com.sun.tools.javac.tree.JCTree.JCNewArray; import com.sun.tools.javac.tree.JCTree.JCStatement; 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; /** @@ -109,7 +110,7 @@ public class JavacHandlerUtil { public static void deleteImportFromCompilationUnit(JavacNode node, String name) { if (!node.shouldDeleteLombokAnnotations()) return; - List newDefs = List.nil(); + ListBuffer newDefs = ListBuffer.lb(); JCCompilationUnit unit = (JCCompilationUnit) node.top().get(); @@ -119,17 +120,17 @@ public class JavacHandlerUtil { JCImport imp0rt = (JCImport)def; delete = (!imp0rt.staticImport && imp0rt.qualid.toString().equals(name)); } - if (!delete) newDefs = newDefs.append(def); + if (!delete) newDefs.append(def); } - unit.defs = newDefs; + unit.defs = newDefs.toList(); } private static List filterList(List annotations, JCTree jcTree) { - List newAnnotations = List.nil(); + ListBuffer newAnnotations = ListBuffer.lb(); for (JCAnnotation ann : annotations) { - if (jcTree != ann) newAnnotations = newAnnotations.append(ann); + if (jcTree != ann) newAnnotations.append(ann); } - return newAnnotations; + return newAnnotations.toList(); } /** @@ -486,12 +487,12 @@ public class JavacHandlerUtil { } private static List addAllButOne(List defs, int idx) { - List out = List.nil(); + ListBuffer out = ListBuffer.lb(); int i = 0; for (JCTree def : defs) { - if (i++ != idx) out = out.append(def); + if (i++ != idx) out.append(def); } - return out; + return out.toList(); } /** @@ -537,7 +538,7 @@ public class JavacHandlerUtil { * Only the simple name is checked - the package and any containing class are ignored. */ public static List findAnnotations(JavacNode fieldNode, Pattern namePattern) { - List result = List.nil(); + ListBuffer result = ListBuffer.lb(); for (JavacNode child : fieldNode.down()) { if (child.getKind() == Kind.ANNOTATION) { JCAnnotation annotation = (JCAnnotation) child.get(); @@ -545,11 +546,11 @@ public class JavacHandlerUtil { int idx = name.lastIndexOf("."); String suspect = idx == -1 ? name : name.substring(idx + 1); if (namePattern.matcher(suspect).matches()) { - result = result.append(annotation); + result.append(annotation); } } } - return result; + return result.toList(); } /** @@ -586,16 +587,16 @@ public class JavacHandlerUtil { if (idx > -1) matched[idx] = true; } - List problematic = List.nil(); + ListBuffer problematic = ListBuffer.lb(); for (int i = 0 ; i < list.size() ; i++) { - if (!matched[i]) problematic = problematic.append(i); + if (!matched[i]) problematic.append(i); } - return problematic; + return problematic.toList(); } static List getAndRemoveAnnotationParameter(JCAnnotation ast, String parameterName) { - List params = List.nil(); + ListBuffer params = ListBuffer.lb(); List result = List.nil(); for (JCExpression param : ast.args) { @@ -614,18 +615,18 @@ public class JavacHandlerUtil { } } - params = params.append(param); + params.append(param); } - ast.args = params; + ast.args = params.toList(); return result; } static List copyAnnotations(List in) { - List out = List.nil(); + ListBuffer out = ListBuffer.lb(); for (JCExpression expr : in) { if (!(expr instanceof JCAnnotation)) continue; - out = out.append((JCAnnotation) expr.clone()); + out.append((JCAnnotation) expr.clone()); } - return out; + return out.toList(); } } diff --git a/src/delombok/lombok/delombok/Delombok.java b/src/delombok/lombok/delombok/Delombok.java index 6fc77c59..f3069c25 100644 --- a/src/delombok/lombok/delombok/Delombok.java +++ b/src/delombok/lombok/delombok/Delombok.java @@ -389,7 +389,7 @@ public class Delombok { JavaCompiler delegate = compiler.processAnnotations(compiler.enterTrees(toJavacList(roots))); for (JCCompilationUnit unit : roots) { - DelombokResult result = new DelombokResult(commentsMap.get(unit).comments, unit, force || tca.changed.contains(unit)); + DelombokResult result = new DelombokResult(commentsMap.get(unit).comments.toList(), unit, force || tca.changed.contains(unit)); if (verbose) feedback.printf("File: %s [%s]\n", unit.sourcefile.getName(), result.isChanged() ? "delomboked" : "unchanged"); Writer rawWriter; if (presetWriter != null) rawWriter = presetWriter; @@ -408,10 +408,10 @@ public class Delombok { } public static class Comments { - public com.sun.tools.javac.util.List comments = com.sun.tools.javac.util.List.nil(); + public com.sun.tools.javac.util.ListBuffer comments = com.sun.tools.javac.util.ListBuffer.lb(); void add(Comment comment) { - comments = comments.append(comment); + comments.append(comment); } } -- cgit