diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2018-09-11 01:41:22 +0200 |
---|---|---|
committer | Reinier Zwitserloot <reinier@zwitserloot.com> | 2018-09-11 01:59:19 +0200 |
commit | d7873f2d21564e8e7f22409fe03681d7dd4c8c1e (patch) | |
tree | 582ac7cf6ef36c69e93503a04b8391950df25f24 /src/core/lombok/javac/handlers/JavacHandlerUtil.java | |
parent | cc8370ab2d7b3ca15023364c99e53735e62e13d7 (diff) | |
download | lombok-d7873f2d21564e8e7f22409fe03681d7dd4c8c1e.tar.gz lombok-d7873f2d21564e8e7f22409fe03681d7dd4c8c1e.tar.bz2 lombok-d7873f2d21564e8e7f22409fe03681d7dd4c8c1e.zip |
Replaced the notion of ‘nullable’ and ‘nonnull’ get copied to ‘any ‘copyable’ annotations get copied’, with ‘copyable’ defined as a specific FQN-style list of well-known nullity-indicating annotations, plus whatever you configured in lombok.config.
Also some work on the notion of TYPE_USE annotations.
Diffstat (limited to 'src/core/lombok/javac/handlers/JavacHandlerUtil.java')
-rw-r--r-- | src/core/lombok/javac/handlers/JavacHandlerUtil.java | 53 |
1 files changed, 48 insertions, 5 deletions
diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java index 1cc28072..b1557533 100644 --- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java +++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java @@ -49,6 +49,7 @@ import lombok.core.LombokImmutableList; import lombok.core.AnnotationValues.AnnotationValue; import lombok.core.TypeResolver; import lombok.core.configuration.NullCheckExceptionType; +import lombok.core.configuration.TypeName; import lombok.core.handlers.HandlerUtil; import lombok.delombok.LombokOptionsFactory; import lombok.experimental.Accessors; @@ -1335,16 +1336,58 @@ public class JavacHandlerUtil { return result.toList(); } + public static boolean hasNonNullAnnotations(JavacNode node) { + for (JavacNode child : node.down()) { + if (child.getKind() == Kind.ANNOTATION) { + JCAnnotation annotation = (JCAnnotation) child.get(); + for (String nn : NONNULL_ANNOTATIONS) if (typeMatches(nn, node, annotation.annotationType)) return true; + } + } + + return false; + } + /** - * Searches the given field node for annotations and returns each one that matches the provided list of names. + * Searches the given field node for annotations and returns each one that is 'copyable' (either via configuration or from the base list). */ - public static List<JCAnnotation> findExactAnnotations(JavacNode fieldNode, java.util.List<String> names) { + public static List<JCAnnotation> findCopyableAnnotations(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(); + + java.util.List<TypeName> configuredCopyable = node.getAst().readConfiguration(ConfigurationKeys.COPYABLE_ANNOTATIONS); + + if (!annoName.isEmpty()) { + for (TypeName cn : configuredCopyable) if (typeMatches(cn.toString(), node, anno.annotationType)) return List.of(anno); + for (String bn : BASE_COPYABLE_ANNOTATIONS) if (typeMatches(bn, node, anno.annotationType)) return List.of(anno); + } + ListBuffer<JCAnnotation> result = new ListBuffer<JCAnnotation>(); - for (JavacNode child : fieldNode.down()) { + for (JavacNode child : node.down()) { if (child.getKind() == Kind.ANNOTATION) { JCAnnotation annotation = (JCAnnotation) child.get(); - String annoName = annotation.annotationType.toString(); - if (names.contains(annoName)) result.append(annotation); + boolean match = false; + for (TypeName cn : configuredCopyable) if (typeMatches(cn.toString(), node, annotation.annotationType)) { + result.append(annotation); + match = true; + break; + } + if (!match) for (String bn : BASE_COPYABLE_ANNOTATIONS) if (typeMatches(bn, node, annotation.annotationType)) { + result.append(annotation); + break; + } } } return result.toList(); |