quarkusio/gizmo

missing enum support in AnnotatedElement

Closed this issue · 4 comments

Hello,
I try to use jandex to add annotation like:
@XmlAccessorType(XmlAccessType.FIELD)

So I use the following code:
classCreator.addAnnotation(AnnotationInstance.create(
DotName.createSimple(XmlAccessorType.class.getName()), null,
new AnnotationValue[]{
AnnotationValue.createEnumValue("value",
DotName.createSimple(XmlAccessType.class.getName()),
String.valueOf(XmlAccessType.FIELD))}));

but I try a lot of different value for string value: "FIELD", String.valueOf(XmlAccessType.FIELD), XmlAccessType.FIELD.toString(), XmlAccessType.FIELD.toString(), XmlAccessType.FIELD.name() but it never work.
AnnotationValue.createStringValue work but impossible to have a string value for a regular enum.
generated class has the annotation but without value:
@XmlAccessorType
public class Reply {
instead of
@XmlAccessorType(XmlAccessType.FIELD)
public class Reply {

Indeed it seems that a code is missing in
https://github.com/quarkusio/gizmo/blob/0a6f1bd53288a76fbe6b28496833f644a96db710/src/main/java/io/quarkus/gizmo/AnnotatedElement.java
to handle Kind.Enum

I think something like
else if (member.kind() == AnnotationValue.Kind.ARRAY) {
Class enumType = (Class) Class.forName(member.asEnumType().toString()); Enum enumval = Enum.valueOf(enumType, member.asEnum());
ac.addValue(member.name(),enumval );
}

I try to bypass issue with
AnnotationCreator ac = classCreator.addAnnotation(XmlAccessorType.class.getName());
ac.addValue("value", javax.xml.bind.annotation.XmlAccessType.FIELD);
but AnnotationUtils.visitAnnotationValue must handle enum with
visitor.visitEnum(final String name, final String desc, final String value)

@stuartwdouglas @cescoffier I think you need to add something in AnnotatedElement else classCreator.addAnnotation(.... Will not worked no?

Anyway thanks for your quick fix 😊

I have send a MR for remaining part.