aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
diff options
context:
space:
mode:
authorJan Rieke <rieke@subshell.com>2018-09-24 16:46:00 +0200
committerJan Rieke <rieke@subshell.com>2018-09-24 16:46:00 +0200
commitb5648976b6501bdf755814d8d8a096c33f6997ec (patch)
treeaafe939cdc6fdda41719deb42f03c77934cb5209 /src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
parentfd4c9d4bff6e75b30a3ee247edafaabc6888a691 (diff)
parentaee4e76d864e01b5d453409e703ad54852fa57bb (diff)
downloadlombok-b5648976b6501bdf755814d8d8a096c33f6997ec.tar.gz
lombok-b5648976b6501bdf755814d8d8a096c33f6997ec.tar.bz2
lombok-b5648976b6501bdf755814d8d8a096c33f6997ec.zip
Merge remote-tracking branch 'upstream/master' into superToBuilder
Diffstat (limited to 'src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java')
-rw-r--r--src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java60
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.
*