aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/javac
diff options
context:
space:
mode:
authorWerner Dietl <wdietl@gmail.com>2018-08-27 18:36:13 -0400
committerReinier Zwitserloot <reinier@zwitserloot.com>2018-09-11 01:59:19 +0200
commit79bfcc4f7ae4bcd61f7f942bfefb940c77927b71 (patch)
tree382b77e1806bd3513dc8f49b009e1aa23cc4dd2d /src/core/lombok/javac
parent7a575e1e5d1c78fa5be1deca7fc308bd9eb390dd (diff)
downloadlombok-79bfcc4f7ae4bcd61f7f942bfefb940c77927b71.tar.gz
lombok-79bfcc4f7ae4bcd61f7f942bfefb940c77927b71.tar.bz2
lombok-79bfcc4f7ae4bcd61f7f942bfefb940c77927b71.zip
Add configuration key, handle whereever NULLABLE is handled, support Eclipse.
Diffstat (limited to 'src/core/lombok/javac')
-rw-r--r--src/core/lombok/javac/handlers/HandleBuilder.java7
-rw-r--r--src/core/lombok/javac/handlers/HandleConstructor.java3
-rw-r--r--src/core/lombok/javac/handlers/HandleGetter.java3
-rw-r--r--src/core/lombok/javac/handlers/HandleSetter.java3
-rw-r--r--src/core/lombok/javac/handlers/HandleWither.java3
-rw-r--r--src/core/lombok/javac/handlers/JavacHandlerUtil.java17
6 files changed, 31 insertions, 5 deletions
diff --git a/src/core/lombok/javac/handlers/HandleBuilder.java b/src/core/lombok/javac/handlers/HandleBuilder.java
index 335dee1a..75bfb01c 100644
--- a/src/core/lombok/javac/handlers/HandleBuilder.java
+++ b/src/core/lombok/javac/handlers/HandleBuilder.java
@@ -149,10 +149,15 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> {
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<JCAnnotation> nonNulls = findAnnotations(fieldNode, NON_NULL_PATTERN);
+ List<JCAnnotation> nullables = findAnnotations(fieldNode, NULLABLE_PATTERN);
+ List<JCAnnotation> copyAnnotations = findExactAnnotations(fieldNode, copyAnnotationNames(fieldNode.getAst()));
+
BuilderFieldData bfd = new BuilderFieldData();
bfd.rawName = fd.name;
bfd.name = removePrefixFromField(fieldNode);
- bfd.annotations = fd.mods.annotations;
+ bfd.annotations = nonNulls.appendList(nullables).appendList(copyAnnotations);
bfd.type = fd.vartype;
bfd.singularData = getSingularData(fieldNode);
bfd.originalFieldNode = fieldNode;
diff --git a/src/core/lombok/javac/handlers/HandleConstructor.java b/src/core/lombok/javac/handlers/HandleConstructor.java
index 76caaffe..b0fa3d29 100644
--- a/src/core/lombok/javac/handlers/HandleConstructor.java
+++ b/src/core/lombok/javac/handlers/HandleConstructor.java
@@ -331,8 +331,9 @@ public class HandleConstructor {
Name rawName = field.name;
List<JCAnnotation> nonNulls = findAnnotations(fieldNode, NON_NULL_PATTERN);
List<JCAnnotation> nullables = findAnnotations(fieldNode, NULLABLE_PATTERN);
+ List<JCAnnotation> copyAnnotations = findExactAnnotations(fieldNode, copyAnnotationNames(fieldNode.getAst()));
long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, typeNode.getContext());
- JCVariableDecl param = maker.VarDef(maker.Modifiers(flags, nonNulls.appendList(nullables)), fieldName, field.vartype, null);
+ JCVariableDecl param = maker.VarDef(maker.Modifiers(flags, nonNulls.appendList(nullables).appendList(copyAnnotations)), 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 4fc6155c..6e4b2685 100644
--- a/src/core/lombok/javac/handlers/HandleGetter.java
+++ b/src/core/lombok/javac/handlers/HandleGetter.java
@@ -245,10 +245,11 @@ public class HandleGetter extends JavacAnnotationHandler<Getter> {
List<JCAnnotation> nonNulls = findAnnotations(field, NON_NULL_PATTERN);
List<JCAnnotation> nullables = findAnnotations(field, NULLABLE_PATTERN);
+ List<JCAnnotation> copyAnnotations = findExactAnnotations(field, copyAnnotationNames(field.getAst()));
List<JCAnnotation> delegates = findDelegatesAndRemoveFromField(field);
- List<JCAnnotation> annsOnMethod = copyAnnotations(onMethod).appendList(nonNulls).appendList(nullables);
+ List<JCAnnotation> annsOnMethod = copyAnnotations(onMethod).appendList(nonNulls).appendList(nullables).appendList(copyAnnotations);
if (isFieldDeprecated(field)) {
annsOnMethod = annsOnMethod.prepend(treeMaker.Annotation(genJavaLangTypeRef(field, "Deprecated"), List.<JCExpression>nil()));
}
diff --git a/src/core/lombok/javac/handlers/HandleSetter.java b/src/core/lombok/javac/handlers/HandleSetter.java
index 0ddaa7d7..631ea193 100644
--- a/src/core/lombok/javac/handlers/HandleSetter.java
+++ b/src/core/lombok/javac/handlers/HandleSetter.java
@@ -228,9 +228,10 @@ public class HandleSetter extends JavacAnnotationHandler<Setter> {
ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();
List<JCAnnotation> nonNulls = findAnnotations(field, NON_NULL_PATTERN);
List<JCAnnotation> nullables = findAnnotations(field, NULLABLE_PATTERN);
+ List<JCAnnotation> copyAnnotations = findExactAnnotations(field, copyAnnotationNames(field.getAst()));
Name methodName = field.toName(setterName);
- List<JCAnnotation> annsOnParam = copyAnnotations(onParam).appendList(nonNulls).appendList(nullables);
+ List<JCAnnotation> annsOnParam = copyAnnotations(onParam).appendList(nonNulls).appendList(nullables).appendList(copyAnnotations);
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 87f3c16a..e6fc2d02 100644
--- a/src/core/lombok/javac/handlers/HandleWither.java
+++ b/src/core/lombok/javac/handlers/HandleWither.java
@@ -224,6 +224,7 @@ public class HandleWither extends JavacAnnotationHandler<Wither> {
List<JCAnnotation> nonNulls = findAnnotations(field, NON_NULL_PATTERN);
List<JCAnnotation> nullables = findAnnotations(field, NULLABLE_PATTERN);
+ List<JCAnnotation> copyAnnotations = findExactAnnotations(field, copyAnnotationNames(field.getAst()));
Name methodName = field.toName(witherName);
@@ -231,7 +232,7 @@ public class HandleWither extends JavacAnnotationHandler<Wither> {
JCBlock methodBody = null;
long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, field.getContext());
- List<JCAnnotation> annsOnParam = copyAnnotations(onParam).appendList(nonNulls).appendList(nullables);
+ List<JCAnnotation> annsOnParam = copyAnnotations(onParam).appendList(nonNulls).appendList(nullables).appendList(copyAnnotations);
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 92c642d4..cb729183 100644
--- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java
+++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java
@@ -1336,6 +1336,23 @@ public class JavacHandlerUtil {
}
/**
+ * Searches the given field node for annotations and returns each one that matches the provided list of names.
+ */
+ public static List<JCAnnotation> findExactAnnotations(JavacNode fieldNode, java.util.List<String> names) {
+ ListBuffer<JCAnnotation> result = new ListBuffer<JCAnnotation>();
+ 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);
+ }
+ }
+ }
+ 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.
*/