diff options
Diffstat (limited to 'src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java')
-rw-r--r-- | src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java index 1e29764a..5d582aad 100644 --- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java +++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java @@ -48,6 +48,7 @@ import lombok.core.AnnotationValues; import lombok.core.AnnotationValues.AnnotationValue; import lombok.core.TypeResolver; import lombok.core.configuration.NullCheckExceptionType; +import lombok.core.configuration.TypeName; import lombok.core.debug.ProblemReporter; import lombok.core.handlers.HandlerUtil; import lombok.eclipse.Eclipse; @@ -448,6 +449,24 @@ public class EclipseHandlerUtil { return out; } + public static Annotation[] getTypeUseAnnotations(TypeReference from) { + Annotation[][] a; + try { + a = (Annotation[][]) reflect(TYPE_REFERENCE__ANNOTATIONS, from); + } catch (Exception e) { + return null; + } + if (a == null) return null; + Annotation[] b = a[a.length - 1]; + return b.length == 0 ? null : b; + } + + public static void removeTypeUseAnnotations(TypeReference from) { + try { + reflectSet(TYPE_REFERENCE__ANNOTATIONS, from, null); + } catch (Exception ignore) {} + } + public static TypeReference namePlusTypeParamsToTypeReference(char[] typeName, TypeParameter[] params, long p) { if (params != null && params.length > 0) { TypeReference[] refs = new TypeReference[params.length]; @@ -672,6 +691,47 @@ public class EclipseHandlerUtil { } } + public static boolean hasNonNullAnnotations(EclipseNode node) { + AbstractVariableDeclaration avd = (AbstractVariableDeclaration) node.get(); + if (avd.annotations == null) return false; + for (Annotation annotation : avd.annotations) { + TypeReference typeRef = annotation.type; + if (typeRef != null && typeRef.getTypeName() != null) { + for (String bn : NONNULL_ANNOTATIONS) if (typeMatches(bn, node, typeRef)) return true; + } + } + return false; + } + + private static final Annotation[] EMPTY_ANNOTATIONS_ARRAY = new Annotation[0]; + + /** + * Searches the given field node for annotations and returns each one that is 'copyable' (either via configuration or from the base list). + */ + public static Annotation[] findCopyableAnnotations(EclipseNode node) { + AbstractVariableDeclaration avd = (AbstractVariableDeclaration) node.get(); + if (avd.annotations == null) return EMPTY_ANNOTATIONS_ARRAY; + List<Annotation> result = new ArrayList<Annotation>(); + List<TypeName> configuredCopyable = node.getAst().readConfiguration(ConfigurationKeys.COPYABLE_ANNOTATIONS); + + for (Annotation annotation : avd.annotations) { + TypeReference typeRef = annotation.type; + boolean match = false; + if (typeRef != null && typeRef.getTypeName() != null) { + for (TypeName cn : configuredCopyable) if (typeMatches(cn.toString(), node, typeRef)) { + result.add(annotation); + match = true; + break; + } + if (!match) for (String bn : BASE_COPYABLE_ANNOTATIONS) if (typeMatches(bn, node, typeRef)) { + result.add(annotation); + break; + } + } + } + return result.toArray(EMPTY_ANNOTATIONS_ARRAY); + } + /** * Checks if the provided annotation type is likely to be the intended type for the given annotation node. * |