From cc8370ab2d7b3ca15023364c99e53735e62e13d7 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Tue, 4 Sep 2018 01:47:59 +0200 Subject: code review and fixes for the ‘copyable annotations’ setting concept. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/lombok/javac/handlers/HandleBuilder.java | 15 ++++++++++----- src/core/lombok/javac/handlers/HandleConstructor.java | 4 ++-- src/core/lombok/javac/handlers/HandleGetter.java | 4 ++-- src/core/lombok/javac/handlers/HandleSetter.java | 4 ++-- src/core/lombok/javac/handlers/HandleWither.java | 4 ++-- src/core/lombok/javac/handlers/JavacHandlerUtil.java | 8 +++----- 6 files changed, 21 insertions(+), 18 deletions(-) (limited to 'src/core/lombok/javac') diff --git a/src/core/lombok/javac/handlers/HandleBuilder.java b/src/core/lombok/javac/handlers/HandleBuilder.java index 75bfb01c..7577eeb2 100644 --- a/src/core/lombok/javac/handlers/HandleBuilder.java +++ b/src/core/lombok/javac/handlers/HandleBuilder.java @@ -149,15 +149,15 @@ public class HandleBuilder extends JavacAnnotationHandler { JCVariableDecl fd = (JCVariableDecl) fieldNode.get(); JavacNode isDefault = findAnnotation(Builder.Default.class, fieldNode, false); boolean isFinal = (fd.mods.flags & Flags.FINAL) != 0 || (valuePresent && !hasAnnotation(NonFinal.class, fieldNode)); - + List nonNulls = findAnnotations(fieldNode, NON_NULL_PATTERN); List nullables = findAnnotations(fieldNode, NULLABLE_PATTERN); - List copyAnnotations = findExactAnnotations(fieldNode, copyAnnotationNames(fieldNode.getAst())); - + List copyableAnnotations = findExactAnnotations(fieldNode, getCopyableAnnotationNames(fieldNode.getAst())); + BuilderFieldData bfd = new BuilderFieldData(); bfd.rawName = fd.name; bfd.name = removePrefixFromField(fieldNode); - bfd.annotations = nonNulls.appendList(nullables).appendList(copyAnnotations); + bfd.annotations = nonNulls.appendList(nullables).appendList(copyableAnnotations); bfd.type = fd.vartype; bfd.singularData = getSingularData(fieldNode); bfd.originalFieldNode = fieldNode; @@ -333,10 +333,15 @@ public class HandleBuilder extends JavacAnnotationHandler { for (JavacNode param : fillParametersFrom.down()) { if (param.getKind() != Kind.ARGUMENT) continue; BuilderFieldData bfd = new BuilderFieldData(); + + List nonNulls = findAnnotations(param, NON_NULL_PATTERN); + List nullables = findAnnotations(param, NULLABLE_PATTERN); + List copyableAnnotations = findExactAnnotations(param, getCopyableAnnotationNames(param.getAst())); + JCVariableDecl raw = (JCVariableDecl) param.get(); bfd.name = raw.name; bfd.rawName = raw.name; - bfd.annotations = raw.mods.annotations; + bfd.annotations = nonNulls.appendList(nullables).appendList(copyableAnnotations); bfd.type = raw.vartype; bfd.singularData = getSingularData(param); bfd.originalFieldNode = param; diff --git a/src/core/lombok/javac/handlers/HandleConstructor.java b/src/core/lombok/javac/handlers/HandleConstructor.java index b0fa3d29..1e45d73f 100644 --- a/src/core/lombok/javac/handlers/HandleConstructor.java +++ b/src/core/lombok/javac/handlers/HandleConstructor.java @@ -331,9 +331,9 @@ public class HandleConstructor { Name rawName = field.name; List nonNulls = findAnnotations(fieldNode, NON_NULL_PATTERN); List nullables = findAnnotations(fieldNode, NULLABLE_PATTERN); - List copyAnnotations = findExactAnnotations(fieldNode, copyAnnotationNames(fieldNode.getAst())); + List copyableAnnotations = findExactAnnotations(fieldNode, getCopyableAnnotationNames(fieldNode.getAst())); long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, typeNode.getContext()); - JCVariableDecl param = maker.VarDef(maker.Modifiers(flags, nonNulls.appendList(nullables).appendList(copyAnnotations)), fieldName, field.vartype, null); + JCVariableDecl param = maker.VarDef(maker.Modifiers(flags, nonNulls.appendList(nullables).appendList(copyableAnnotations)), fieldName, field.vartype, null); params.append(param); if (!nonNulls.isEmpty()) { JCStatement nullCheck = generateNullCheck(maker, fieldNode, param, source); diff --git a/src/core/lombok/javac/handlers/HandleGetter.java b/src/core/lombok/javac/handlers/HandleGetter.java index 6e4b2685..04b300a8 100644 --- a/src/core/lombok/javac/handlers/HandleGetter.java +++ b/src/core/lombok/javac/handlers/HandleGetter.java @@ -245,11 +245,11 @@ public class HandleGetter extends JavacAnnotationHandler { List nonNulls = findAnnotations(field, NON_NULL_PATTERN); List nullables = findAnnotations(field, NULLABLE_PATTERN); - List copyAnnotations = findExactAnnotations(field, copyAnnotationNames(field.getAst())); + List copyableAnnotations = findExactAnnotations(field, getCopyableAnnotationNames(field.getAst())); List delegates = findDelegatesAndRemoveFromField(field); - List annsOnMethod = copyAnnotations(onMethod).appendList(nonNulls).appendList(nullables).appendList(copyAnnotations); + List annsOnMethod = copyAnnotations(onMethod).appendList(nonNulls).appendList(nullables).appendList(copyableAnnotations); if (isFieldDeprecated(field)) { annsOnMethod = annsOnMethod.prepend(treeMaker.Annotation(genJavaLangTypeRef(field, "Deprecated"), List.nil())); } diff --git a/src/core/lombok/javac/handlers/HandleSetter.java b/src/core/lombok/javac/handlers/HandleSetter.java index 631ea193..e5e9481d 100644 --- a/src/core/lombok/javac/handlers/HandleSetter.java +++ b/src/core/lombok/javac/handlers/HandleSetter.java @@ -228,10 +228,10 @@ public class HandleSetter extends JavacAnnotationHandler { ListBuffer statements = new ListBuffer(); List nonNulls = findAnnotations(field, NON_NULL_PATTERN); List nullables = findAnnotations(field, NULLABLE_PATTERN); - List copyAnnotations = findExactAnnotations(field, copyAnnotationNames(field.getAst())); + List copyableAnnotations = findExactAnnotations(field, getCopyableAnnotationNames(field.getAst())); Name methodName = field.toName(setterName); - List annsOnParam = copyAnnotations(onParam).appendList(nonNulls).appendList(nullables).appendList(copyAnnotations); + List annsOnParam = copyAnnotations(onParam).appendList(nonNulls).appendList(nullables).appendList(copyableAnnotations); long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, field.getContext()); JCVariableDecl param = treeMaker.VarDef(treeMaker.Modifiers(flags, annsOnParam), fieldDecl.name, fieldDecl.vartype, null); diff --git a/src/core/lombok/javac/handlers/HandleWither.java b/src/core/lombok/javac/handlers/HandleWither.java index e6fc2d02..b0e32d61 100644 --- a/src/core/lombok/javac/handlers/HandleWither.java +++ b/src/core/lombok/javac/handlers/HandleWither.java @@ -224,7 +224,7 @@ public class HandleWither extends JavacAnnotationHandler { List nonNulls = findAnnotations(field, NON_NULL_PATTERN); List nullables = findAnnotations(field, NULLABLE_PATTERN); - List copyAnnotations = findExactAnnotations(field, copyAnnotationNames(field.getAst())); + List copyableAnnotations = findExactAnnotations(field, getCopyableAnnotationNames(field.getAst())); Name methodName = field.toName(witherName); @@ -232,7 +232,7 @@ public class HandleWither extends JavacAnnotationHandler { JCBlock methodBody = null; long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, field.getContext()); - List annsOnParam = copyAnnotations(onParam).appendList(nonNulls).appendList(nullables).appendList(copyAnnotations); + List annsOnParam = copyAnnotations(onParam).appendList(nonNulls).appendList(nullables).appendList(copyableAnnotations); JCVariableDecl param = maker.VarDef(maker.Modifiers(flags, annsOnParam), fieldDecl.name, fieldDecl.vartype, null); diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java index cb729183..1cc28072 100644 --- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java +++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java @@ -1343,15 +1343,13 @@ public class JavacHandlerUtil { for (JavacNode child : fieldNode.down()) { if (child.getKind() == Kind.ANNOTATION) { JCAnnotation annotation = (JCAnnotation) child.get(); - String annoname = annotation.annotationType.toString(); - if (names.contains(annoname)) { - result.append(annotation); - } + String annoName = annotation.annotationType.toString(); + if (names.contains(annoName)) result.append(annotation); } } return result.toList(); } - + /** * Generates a new statement that checks if the given variable is null, and if so, throws a configured exception with the * variable name as message. -- cgit