Skip to content

Commit 95b8e3a

Browse files
committed
Fix annotation value parsing.
Signed-off-by: Manoel Campos <manoelcampos@gmail.com>
1 parent c54f1f5 commit 95b8e3a

File tree

1 file changed

+15
-10
lines changed
  • src/main/java/com/github/markusbernhardt/xmldoclet

1 file changed

+15
-10
lines changed

src/main/java/com/github/markusbernhardt/xmldoclet/Parser.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -221,19 +221,24 @@ protected AnnotationInstance parseAnnotationDesc(final AnnotationMirror annotati
221221

222222
final Object objValue = elementValuesPair.getValue();
223223
switch (objValue) {
224-
case AnnotationValue[] annotationValues -> {
225-
for (final AnnotationValue annotationValue : annotationValues) {
226-
if (annotationValue.getValue() instanceof AnnotationMirror annoDesc) {
227-
annotationArgumentNode.getAnnotation().add(parseAnnotationDesc(annoDesc, programElement));
228-
} else {
229-
annotationArgumentNode.getValue().add(annotationValue.getValue().toString());
224+
case AnnotationValue annotationValue -> {
225+
if (annotationValue.getValue() instanceof List<?> valueList) {
226+
for (final Object value : valueList) {
227+
if (annotationValue.getValue() instanceof AnnotationMirror annoDesc) {
228+
annotationArgumentNode.getAnnotation().add(parseAnnotationDesc(annoDesc, programElement));
229+
} else {
230+
/*
231+
Consider the annotation @Annotation1("A") or @Annotation1({"A", "B"}}).
232+
The annotation value is an AnnototionValue object with value attribute.
233+
This attribute is a List (even if there is a single value).
234+
But each value is not the actual value, but another AnnotationValue object with a value attribute.
235+
*/
236+
annotationArgumentNode.getValue().add(((AnnotationValue)value).getValue().toString());
237+
}
230238
}
231239
}
232240
}
233-
case VariableElement fieldDoc -> annotationArgumentNode.getValue().add(getSimpleName(fieldDoc));
234-
case TypeElement classDoc -> annotationArgumentNode.getValue().add(getQualifiedName(classDoc));
235-
case null -> {
236-
}
241+
case null -> {}
237242
default -> annotationArgumentNode.getValue().add(objValue.toString());
238243
}
239244

0 commit comments

Comments
 (0)