aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/javac/handlers
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2010-11-15 20:05:04 +0100
committerReinier Zwitserloot <reinier@zwitserloot.com>2010-11-15 20:05:04 +0100
commit415bc490dcaaa46cac4c6958e3058049ec100a9a (patch)
tree4181b9597da1109f62ca2485454187a899610285 /src/core/lombok/javac/handlers
parent80982cc9d6f22de35d9db23d547d580800976794 (diff)
parent1c2556b1f7b26ea0b70d356d9eeefb638560a46f (diff)
downloadlombok-415bc490dcaaa46cac4c6958e3058049ec100a9a.tar.gz
lombok-415bc490dcaaa46cac4c6958e3058049ec100a9a.tar.bz2
lombok-415bc490dcaaa46cac4c6958e3058049ec100a9a.zip
Merge branch 'master' of github.com:rzwitserloot/lombok
Diffstat (limited to 'src/core/lombok/javac/handlers')
-rw-r--r--src/core/lombok/javac/handlers/HandleCleanup.java20
-rw-r--r--src/core/lombok/javac/handlers/HandleConstructor.java67
-rw-r--r--src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java83
-rw-r--r--src/core/lombok/javac/handlers/HandleGetter.java27
-rw-r--r--src/core/lombok/javac/handlers/HandleToString.java9
-rw-r--r--src/core/lombok/javac/handlers/JavacHandlerUtil.java43
6 files changed, 127 insertions, 122 deletions
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<Cleanup> {
}
boolean seenDeclaration = false;
- List<JCStatement> tryBlock = List.nil();
- List<JCStatement> newStatements = List.nil();
+ ListBuffer<JCStatement> newStatements = ListBuffer.lb();
+ ListBuffer<JCStatement> 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<Cleanup> {
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<Cleanup> {
JCBlock finalizer = maker.Block(0, List.<JCStatement>of(ifNotNullCleanup));
- newStatements = newStatements.append(maker.Try(maker.Block(0, tryBlock), List.<JCCatch>nil(), finalizer));
+ newStatements.append(maker.Try(maker.Block(0, tryBlock.toList()), List.<JCCatch>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<JavacNode> findRequiredFields(JavacNode typeNode) {
- List<JavacNode> fields = List.nil();
+ ListBuffer<JavacNode> 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<JavacNode> fields = List.nil();
+ ListBuffer<JavacNode> 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<JCExpression> fieldNames = List.nil();
+ ListBuffer<JCExpression> 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.<JCExpression>nil(), fieldNames);
+ JCExpression fieldNamesArray = maker.NewArray(null, List.<JCExpression>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<JavacNode> fields, boolean suppressConstructorProperties) {
TreeMaker maker = typeNode.getTreeMaker();
- List<JCStatement> nullChecks = List.nil();
- List<JCStatement> assigns = List.nil();
- List<JCVariableDecl> params = List.nil();
+ ListBuffer<JCStatement> nullChecks = ListBuffer.lb();
+ ListBuffer<JCStatement> assigns = ListBuffer.lb();
+ ListBuffer<JCVariableDecl> params = ListBuffer.lb();
for (JavacNode fieldNode : fields) {
JCVariableDecl field = (JCVariableDecl) fieldNode.get();
List<JCAnnotation> nonNulls = findAnnotations(fieldNode, TransformationsUtil.NON_NULL_PATTERN);
List<JCAnnotation> 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("<init>"),
- null, List.<JCTypeParameter>nil(), params, List.<JCExpression>nil(), maker.Block(0L, nullChecks.appendList(assigns)), null);
+ null, List.<JCTypeParameter>nil(), params.toList(), List.<JCExpression>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<JCTypeParameter> typeParams = List.nil();
- List<JCVariableDecl> params = List.nil();
- List<JCExpression> typeArgs1 = List.nil();
- List<JCExpression> typeArgs2 = List.nil();
- List<JCExpression> args = List.nil();
+ ListBuffer<JCTypeParameter> typeParams = ListBuffer.lb();
+ ListBuffer<JCVariableDecl> params = ListBuffer.lb();
+ ListBuffer<JCExpression> typeArgs1 = ListBuffer.lb();
+ ListBuffer<JCExpression> typeArgs2 = ListBuffer.lb();
+ ListBuffer<JCExpression> 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<JCExpression> tArgs = List.nil();
- for (JCExpression arg : typeApply.arguments) tArgs = tArgs.append(arg);
- pType = maker.TypeApply(typeApply.clazz, tArgs);
+ ListBuffer<JCExpression> tArgs = ListBuffer.lb();
+ for (JCExpression arg : typeApply.arguments) tArgs.append(arg);
+ pType = maker.TypeApply(typeApply.clazz, tArgs.toList());
} else {
pType = field.vartype;
}
List<JCAnnotation> nonNulls = findAnnotations(fieldNode, TransformationsUtil.NON_NULL_PATTERN);
List<JCAnnotation> 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.<JCExpression>nil(), constructorType, args, null));
+ JCReturn returnStatement = maker.Return(maker.NewClass(null, List.<JCExpression>nil(), constructorType, args.toList(), null));
JCBlock body = maker.Block(0, List.<JCStatement>of(returnStatement));
- return maker.MethodDef(mods, typeNode.toName(name), returnType, typeParams, params, List.<JCExpression>nil(), body, null);
+ return maker.MethodDef(mods, typeNode.toName(name), returnType, typeParams.toList(), params.toList(), List.<JCExpression>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<EqualsAnd
errorNode.addWarning("Generating equals/hashCode implementation but without a call to superclass, even though this class does not extend java.lang.Object. If this is intentional, add '@EqualsAndHashCode(callSuper=false)' to your type.");
}
- List<JavacNode> nodesForEquality = List.nil();
+ ListBuffer<JavacNode> 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 JavacAnnotationHandler<EqualsAnd
if (excludes != null && excludes.contains(fieldDecl.name.toString())) continue;
//Skip fields that start with $
if (fieldDecl.name.toString().startsWith("$")) continue;
- nodesForEquality = nodesForEquality.append(child);
+ nodesForEquality.append(child);
}
}
@@ -175,7 +176,7 @@ public class HandleEqualsAndHashCode implements JavacAnnotationHandler<EqualsAnd
boolean isFinal = (((JCClassDecl)typeNode.get()).mods.flags & Flags.FINAL) != 0;
needsCanEqual = !isFinal || !isDirectDescendantOfObject;
- JCMethodDecl method = createEquals(typeNode, nodesForEquality, callSuper, fieldAccess, needsCanEqual);
+ JCMethodDecl method = createEquals(typeNode, nodesForEquality.toList(), callSuper, fieldAccess, needsCanEqual);
injectMethod(typeNode, method);
break;
case EXISTS_BY_LOMBOK:
@@ -202,7 +203,7 @@ public class HandleEqualsAndHashCode implements JavacAnnotationHandler<EqualsAnd
}
switch (methodExists("hashCode", typeNode)) {
case NOT_EXISTS:
- JCMethodDecl method = createHashCode(typeNode, nodesForEquality, callSuper, fieldAccess);
+ JCMethodDecl method = createHashCode(typeNode, nodesForEquality.toList(), callSuper, fieldAccess);
injectMethod(typeNode, method);
break;
case EXISTS_BY_LOMBOK:
@@ -223,28 +224,28 @@ public class HandleEqualsAndHashCode implements JavacAnnotationHandler<EqualsAnd
JCAnnotation overrideAnnotation = maker.Annotation(chainDots(maker, typeNode, "java", "lang", "Override"), List.<JCExpression>nil());
JCModifiers mods = maker.Modifiers(Flags.PUBLIC, List.of(overrideAnnotation));
JCExpression returnType = maker.TypeIdent(TypeTags.INT);
- List<JCStatement> statements = List.nil();
+ ListBuffer<JCStatement> 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<JCExpression> intoResult = List.nil();
+ 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 = intoResult.append(callToSuper);
+ intoResult.append(callToSuper);
}
int tempCounter = 0;
@@ -255,14 +256,14 @@ public class HandleEqualsAndHashCode implements JavacAnnotationHandler<EqualsAnd
switch (((JCPrimitiveTypeTree)fType).getPrimitiveTypeKind()) {
case BOOLEAN:
/* this.fieldName ? 1231 : 1237 */
- intoResult = intoResult.append(maker.Conditional(fieldAccessor, maker.Literal(1231), maker.Literal(1237)));
+ intoResult.append(maker.Conditional(fieldAccessor, maker.Literal(1231), maker.Literal(1237)));
break;
case LONG:
- intoResult = intoResult.append(longToIntForHashCode(maker, fieldAccessor, createFieldAccessor(maker, fieldNode, fieldAccess)));
+ intoResult.append(longToIntForHashCode(maker, fieldAccessor, createFieldAccessor(maker, fieldNode, fieldAccess)));
break;
case FLOAT:
/* Float.floatToIntBits(this.fieldName) */
- intoResult = intoResult.append(maker.Apply(
+ intoResult.append(maker.Apply(
List.<JCExpression>nil(),
chainDots(maker, typeNode, "java", "lang", "Float", "floatToIntBits"),
List.of(fieldAccessor)));
@@ -274,9 +275,9 @@ public class HandleEqualsAndHashCode implements JavacAnnotationHandler<EqualsAnd
List.<JCExpression>nil(),
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 JavacAnnotationHandler<EqualsAnd
case INT:
case CHAR:
/* just the field */
- intoResult = intoResult.append(fieldAccessor);
+ intoResult.append(fieldAccessor);
break;
}
} else if (fType instanceof JCArrayTypeTree) {
@@ -294,14 +295,14 @@ public class HandleEqualsAndHashCode implements JavacAnnotationHandler<EqualsAnd
boolean useDeepHC = multiDim || !primitiveArray;
JCExpression hcMethod = chainDots(maker, typeNode, "java", "util", "Arrays", useDeepHC ? "deepHashCode" : "hashCode");
- intoResult = intoResult.append(
+ intoResult.append(
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")),
List.<JCExpression>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 JavacAnnotationHandler<EqualsAnd
for (JCExpression expr : intoResult) {
JCExpression mult = maker.Binary(JCTree.MUL, maker.Ident(resultName), maker.Ident(primeName));
JCExpression add = maker.Binary(JCTree.PLUS, mult, expr);
- statements = statements.append(maker.Exec(maker.Assign(maker.Ident(resultName), add)));
+ statements.append(maker.Exec(maker.Assign(maker.Ident(resultName), add)));
}
/* return result; */ {
- statements = statements.append(maker.Return(maker.Ident(resultName)));
+ statements.append(maker.Return(maker.Ident(resultName)));
}
- JCBlock body = maker.Block(0, statements);
+ JCBlock body = maker.Block(0, statements.toList());
return maker.MethodDef(mods, typeNode.toName("hashCode"), returnType,
List.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), body, null);
}
@@ -344,38 +345,38 @@ public class HandleEqualsAndHashCode implements JavacAnnotationHandler<EqualsAnd
JCExpression objectType = chainDots(maker, typeNode, "java", "lang", "Object");
JCExpression returnType = maker.TypeIdent(TypeTags.BOOLEAN);
- List<JCStatement> statements = List.nil();
- List<JCVariableDecl> params = List.of(maker.VarDef(maker.Modifiers(Flags.FINAL), oName, objectType, null));
+ 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 = 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<JCExpression> wildcards1 = List.nil();
- List<JCExpression> wildcards2 = List.nil();
+ ListBuffer<JCExpression> wildcards1 = ListBuffer.lb();
+ ListBuffer<JCExpression> 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 JavacAnnotationHandler<EqualsAnd
JCExpression equalityCheck = maker.Apply(exprNil,
maker.Select(maker.Ident(otherName), typeNode.toName("canEqual")),
List.<JCExpression>of(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 JavacAnnotationHandler<EqualsAnd
maker.Select(maker.Ident(typeNode.toName("super")), typeNode.toName("equals")),
List.<JCExpression>of(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<EqualsAnd
switch (((JCPrimitiveTypeTree)fType).getPrimitiveTypeKind()) {
case FLOAT:
/* if (Float.compare(this.fieldName, other.fieldName) != 0) return false; */
- statements = statements.append(generateCompareFloatOrDouble(thisFieldAccessor, otherFieldAccessor, maker, typeNode, false));
+ statements.append(generateCompareFloatOrDouble(thisFieldAccessor, otherFieldAccessor, maker, typeNode, false));
break;
case DOUBLE:
/* if (Double(this.fieldName, other.fieldName) != 0) return false; */
- statements = statements.append(generateCompareFloatOrDouble(thisFieldAccessor, otherFieldAccessor, maker, typeNode, true));
+ statements.append(generateCompareFloatOrDouble(thisFieldAccessor, otherFieldAccessor, maker, typeNode, true));
break;
default:
/* if (this.fieldName != other.fieldName) return false; */
- statements = statements.append(
+ statements.append(
maker.If(maker.Binary(JCTree.NE, thisFieldAccessor, otherFieldAccessor), returnBool(maker, false), null));
break;
}
@@ -427,7 +428,7 @@ public class HandleEqualsAndHashCode implements JavacAnnotationHandler<EqualsAnd
JCExpression eqMethod = chainDots(maker, typeNode, "java", "util", "Arrays", useDeepEquals ? "deepEquals" : "equals");
List<JCExpression> 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.<JCExpression>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 JavacAnnotationHandler<EqualsAnd
maker.Select(createFieldAccessor(maker, fieldNode, fieldAccess), typeNode.toName("equals")),
List.of(createFieldAccessor(maker, fieldNode, fieldAccess, maker.Ident(otherName))));
JCExpression fieldsAreNotEqual = maker.Conditional(thisEqualsNull, otherNotEqualsNull, maker.Unary(JCTree.NOT, thisEqualsThat));
- statements = statements.append(maker.If(fieldsAreNotEqual, returnBool(maker, false), null));
+ statements.append(maker.If(fieldsAreNotEqual, returnBool(maker, false), null));
}
}
/* return true; */ {
- statements = statements.append(returnBool(maker, true));
+ statements.append(returnBool(maker, true));
}
- JCBlock body = maker.Block(0, statements);
+ JCBlock body = maker.Block(0, statements.toList());
return maker.MethodDef(mods, typeNode.toName("equals"), returnType, List.<JCTypeParameter>nil(), params, List.<JCExpression>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<Getter> {
return value.get();
*/
- List<JCStatement> statements = List.nil();
+ ListBuffer<JCStatement> statements = ListBuffer.lb();
JCVariableDecl field = (JCVariableDecl) fieldNode.get();
field.type = null;
@@ -302,46 +303,46 @@ public class HandleGetter implements JavacAnnotationHandler<Getter> {
/* java.util.concurrent.atomic.AtomicReference<ValueType> 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<JCStatement> synchronizedStatements = List.nil();
+ ListBuffer<JCStatement> 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<JCStatement> innerIfStatements = List.nil();
+ ListBuffer<JCStatement> innerIfStatements = ListBuffer.lb();
/* value = new java.util.concurrent.atomic.AtomicReference<ValueType>(new ValueType());*/ {
JCTypeApply valueVarType = maker.TypeApply(chainDotsString(maker, fieldNode, AR), List.of(copyType(maker, field)));
JCNewClass newInstance = maker.NewClass(null, NIL_EXPRESSION, valueVarType, List.<JCExpression>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.<JCStatement>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<Getter> {
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<ToString> {
return false;
}
- List<JavacNode> nodesForToString = List.nil();
+ ListBuffer<JavacNode> 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<ToString> {
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<JCTree> newDefs = List.nil();
+ ListBuffer<JCTree> 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<JCAnnotation> filterList(List<JCAnnotation> annotations, JCTree jcTree) {
- List<JCAnnotation> newAnnotations = List.nil();
+ ListBuffer<JCAnnotation> 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<JCTree> addAllButOne(List<JCTree> defs, int idx) {
- List<JCTree> out = List.nil();
+ ListBuffer<JCTree> 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<JCAnnotation> findAnnotations(JavacNode fieldNode, Pattern namePattern) {
- List<JCAnnotation> result = List.nil();
+ ListBuffer<JCAnnotation> 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<Integer> problematic = List.nil();
+ ListBuffer<Integer> 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<JCExpression> getAndRemoveAnnotationParameter(JCAnnotation ast, String parameterName) {
- List<JCExpression> params = List.nil();
+ ListBuffer<JCExpression> params = ListBuffer.lb();
List<JCExpression> 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<JCAnnotation> copyAnnotations(List<JCExpression> in) {
- List<JCAnnotation> out = List.nil();
+ ListBuffer<JCAnnotation> 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();
}
}