From e9b71f015628c181a625b62472b6354696d39700 Mon Sep 17 00:00:00 2001 From: Marcel Date: Mon, 27 Jul 2015 12:41:05 +0200 Subject: implemented support for annotation arrays as annotation attributes in javac --- src/core/lombok/core/AnnotationValues.java | 4 ++++ .../lombok/javac/handlers/JavacHandlerUtil.java | 23 ++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/core/lombok/core/AnnotationValues.java b/src/core/lombok/core/AnnotationValues.java index d04797cb..df426a65 100644 --- a/src/core/lombok/core/AnnotationValues.java +++ b/src/core/lombok/core/AnnotationValues.java @@ -298,6 +298,10 @@ public class AnnotationValues { } } + if (guess instanceof AnnotationValues) { + return ((AnnotationValues) guess).getInstance(); + } + throw new AnnotationValueDecodeFail(v, "Can't translate a " + guess.getClass() + " to the expected " + expected, pos); } diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java index 0db59da1..ea61a406 100644 --- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java +++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java @@ -239,8 +239,19 @@ public class JavacHandlerUtil { * @param node A Lombok AST node representing an annotation in source code. */ public static AnnotationValues createAnnotation(Class type, final JavacNode node) { + return createAnnotation(type, (JCAnnotation) node.get(), node); + } + + /** + * Creates an instance of {@code AnnotationValues} for the provided AST Node + * and Annotation expression. + * + * @param type An annotation class type, such as {@code lombok.Getter.class}. + * @param anno the annotation expression + * @param node A Lombok AST node representing an annotation in source code. + */ + public static AnnotationValues createAnnotation(Class type, JCAnnotation anno, final JavacNode node) { Map values = new HashMap(); - JCAnnotation anno = (JCAnnotation) node.get(); List arguments = anno.getArguments(); for (JCExpression arg : arguments) { @@ -265,7 +276,15 @@ public class JavacHandlerUtil { for (JCExpression inner : elems) { raws.add(inner.toString()); expressions.add(inner); - guesses.add(calculateGuess(inner)); + if (inner instanceof JCAnnotation) { + try { + guesses.add(createAnnotation((Class) Class.forName(inner.type.toString()), (JCAnnotation) inner, node)); + } catch (ClassNotFoundException ex) { + throw new IllegalStateException(ex); + } + } else { + guesses.add(calculateGuess(inner)); + } positions.add(inner.pos()); } } else { -- cgit