aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/javac/handlers/JavacHandlerUtil.java
diff options
context:
space:
mode:
authorBulgakov Alexander <buls@yandex.ru>2019-05-07 10:49:50 +0300
committerBulgakov Alexander <buls@yandex.ru>2019-05-07 10:49:50 +0300
commit8f8cbae631ff2e7091a2a9b70339b778177122cc (patch)
tree936824b3998eff0bde662655ec89e1175e6e4c0e /src/core/lombok/javac/handlers/JavacHandlerUtil.java
parent06fb1034eac690f5775e104c4bc82df3ad929cc9 (diff)
parent3496a3e9633cd6526745bcc390877653afad7f09 (diff)
downloadlombok-8f8cbae631ff2e7091a2a9b70339b778177122cc.tar.gz
lombok-8f8cbae631ff2e7091a2a9b70339b778177122cc.tar.bz2
lombok-8f8cbae631ff2e7091a2a9b70339b778177122cc.zip
Merge remote-tracking branch 'lombok/master' into feature/typeInferenceImprovements
Diffstat (limited to 'src/core/lombok/javac/handlers/JavacHandlerUtil.java')
-rw-r--r--src/core/lombok/javac/handlers/JavacHandlerUtil.java56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java
index 509a7397..ee012d2b 100644
--- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java
+++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java
@@ -1418,6 +1418,15 @@ public class JavacHandlerUtil {
return false;
}
+ public static boolean hasNonNullAnnotations(JavacNode node, List<JCAnnotation> anns) {
+ if (anns == null) return false;
+ for (JCAnnotation ann : anns) {
+ for (String nn : NONNULL_ANNOTATIONS) if (typeMatches(nn, node, ann)) return true;
+ }
+
+ return false;
+ }
+
/**
* Searches the given field node for annotations and returns each one that is 'copyable' (either via configuration or from the base list).
*/
@@ -1465,6 +1474,44 @@ public class JavacHandlerUtil {
}
/**
+ * Searches the given field node for annotations that are specifically intentioned to be copied to the setter.
+ */
+ public static List<JCAnnotation> findCopyableToSetterAnnotations(JavacNode node) {
+ JCAnnotation anno = null;
+ String annoName = null;
+ for (JavacNode child : node.down()) {
+ if (child.getKind() == Kind.ANNOTATION) {
+ if (anno != null) {
+ annoName = "";
+ break;
+ }
+ JCAnnotation annotation = (JCAnnotation) child.get();
+ annoName = annotation.annotationType.toString();
+ anno = annotation;
+ }
+ }
+
+ if (annoName == null) return List.nil();
+
+ if (!annoName.isEmpty()) {
+ for (String bn : COPY_TO_SETTER_ANNOTATIONS) if (typeMatches(bn, node, anno.annotationType)) return List.of(anno);
+ }
+
+ ListBuffer<JCAnnotation> result = new ListBuffer<JCAnnotation>();
+ for (JavacNode child : node.down()) {
+ if (child.getKind() == Kind.ANNOTATION) {
+ JCAnnotation annotation = (JCAnnotation) child.get();
+ boolean match = false;
+ if (!match) for (String bn : COPY_TO_SETTER_ANNOTATIONS) if (typeMatches(bn, node, annotation.annotationType)) {
+ result.append(annotation);
+ break;
+ }
+ }
+ }
+ 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.
*/
@@ -1704,6 +1751,15 @@ public class JavacHandlerUtil {
return out.toList();
}
+ static List<JCAnnotation> mergeAnnotations(List<JCAnnotation> a, List<JCAnnotation> b) {
+ if (a == null || a.isEmpty()) return b;
+ if (b == null || b.isEmpty()) return a;
+ ListBuffer<JCAnnotation> out = new ListBuffer<JCAnnotation>();
+ for (JCAnnotation ann : a) out.append(ann);
+ for (JCAnnotation ann : b) out.append(ann);
+ return out.toList();
+ }
+
static boolean isClass(JavacNode typeNode) {
return isClassAndDoesNotHaveFlags(typeNode, Flags.INTERFACE | Flags.ENUM | Flags.ANNOTATION);
}