Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enum Value as annotation type value not possible #750

Closed
red-hood opened this issue Jul 15, 2016 · 3 comments
Closed

Enum Value as annotation type value not possible #750

red-hood opened this issue Jul 15, 2016 · 3 comments
Assignees

Comments

@red-hood
Copy link

red-hood commented Jul 15, 2016

I am trying to annotate a field via the annotation factory, and would like to set the value of an annotation element to an enum value, e.g.

annoFactory.annotate(field, BoundNumber.class, "byteOrder", ByteOrder.LittleEndian);

where ByteOrder.LittleEndian is the enum value. Running the annoation processor, I get the error message

"Please, submit a valid value."

In CtAnnotationImpl.java, starting at line 88, the annotation values passed in are converted to CtExpression values, but I can not find any clause that would match en enum value. What is the proper way to convert an enum value as shown above to the according CtExpression instance?

@monperrus
Copy link
Collaborator

monperrus commented Jul 21, 2016

in method annotate, there is some magic to transform an object into an CtExpression, but not unfortunately not for enum values.

In this case, a workaround is to transform the last element and manually create a CtFieldRead that corresponds to ByteOrder.LittleEndian. It's cumbersome, I agree.

We have to improve convertValueToExpression to handle enum values.

@red-hood
Copy link
Author

Thank you, I tried a CtVariableRead, but that did not work for me. It would be good to have an overview, which elements in the Java language actually correspond to which Ct element wrappers, I think.

@red-hood
Copy link
Author

Thank you for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants