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
Proposal: annotation support in reflection wrapper #2215
Conversation
…tring[] member types only.
…primitive" types before. Fixed a few compile warnings.
…icy.RUNTIME annotations.
Sorry, I haven't had time to look into this. I'll try to make a point of it soon. Any idea how much bloat is added by the addition of annotations to the ReflectionCache on GWT? |
There is one new type declaration per annotation interface, but this overhead should be pretty negligible. Classes "Field" and "Type" have a new member annotations[], which is null if unused. Each time a field or class annotation is used, annotations[] will gain one more entry, which gets a unique implementation of the annotation interface. The actual overhead depends on how many and what type of parameters the annotation exposes. At this point some caching mechanism might be an idea to reduce overhead. An example: @retention(RetentionPolicy.RUNTIME) used in: @DeclareSerializeField(name = "translate") is generated as: new my.company.project.serialization.annotations.DeclareSerializeField() { |
@@ -673,6 +681,107 @@ else if (typeArg.isParameterized() != null) | |||
return "null"; | |||
} | |||
|
|||
private String getAnnotations (Annotation[] annotations) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The formatting on this is a bit funky, can you apply the gdx formatter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought I did. I'm running IntelliJ 12 with the Eclipse Code Formatter plugin enabled. What's wrong with the format of this part?
This looks pretty good to me (haven't tested it). Actually, could you add a tiny little test just so we can check if the basic functionality is the same on all platforms? Great stuff! |
Proposal: annotation support in reflection wrapper
Hey ho,
with this PR it is possible to query annotation information at runtime via the reflection wrapper. It supports class and field annotations. The annotation interfaces themselves must be annotated with RetentionPolicy.RUNTIME to become available.
I've already finished adding wrapper functions to the non-GWT versions before I discovered the insanity that lies behind IReflectionCache...
Anyway, it seems to work now, so some of you might be interested in skim through the changes.
The ReflectionCacheSourceCreator for GWT now basically embeds and returns anonymous implementations of the annotation interfaces, fetching the values from source during compilation. I recommend to just try an example and peek at the generated code.