-
Couldn't load subscription status.
- Fork 82
remove Annotations and add AnnotationBuilder #508
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
Conversation
0f1c89f to
e17bb2f
Compare
api/src/main/java/jakarta/enterprise/inject/build/compatible/spi/AnnotationBuilderFactory.java
Show resolved
Hide resolved
api/src/main/java/jakarta/enterprise/inject/build/compatible/spi/AnnotationBuilderFactory.java
Show resolved
Hide resolved
| * @return a {@link ClassInfo} representing the enum type | ||
| * @throws IllegalStateException if this annotation member value is not an enum value | ||
| */ | ||
| ClassInfo<?> asEnumClass(); |
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 was wondering if this is necessary since in Micronaut we don't actually store the enum type and only the constant value so it would be complicate matters, given the user can already lookup types via the Types impl ?
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 noticed you dropped this method and I thought it's probably a mistake, so I added it back. What I didn't notice is that you added a parameter to <E extends Enum<E>> E asEnum(Class<E> enumType) :-) IMHO, that should just be <E extends Enum<E>> E asEnum(). The enum type is available on the declaration of the annotation member, isn't it? As in, you should always be able to find it even if you don't remember it?
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.
Looks like as of today we just store enum values as strings. See https://github.com/micronaut-projects/micronaut-core/blob/a949a27c69ff00fe50fa751adf0501540aee79b2/inject-java/src/main/java/io/micronaut/annotation/processing/JavaAnnotationMetadataBuilder.java#L637-L641
I guess we would have to rework that code to store the actual enum values, although I am not sure how possible that is, we would I guess need to store the underlying VariableElement from the annotation processing API
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.
Alright that sounds weird. I don't know how you [intend to] implement this, but if your implementation of AnnotationMemberValue retains a reference to whatever you use to implement AnnotationInfo, you should be able to lookup the declaration of the annotation member and from there, lookup the enum type. Am I missing something?
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.
yeah probably there is a way, will try work it out
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.
Yea I thought asEnum might be problematic, I originally had a TODO for that method: // TODO should this be present?
Does adding the Class parameter help with the classpath issues? If so, I'm fine with leaving it there (and indeed it also help with type inference).
OK, I'll submit another PR to change AnnotationInfo.members() to return Map<String, SomeAnnotationMemberValueType_ProbablyAnnotationMember> and remove AnnotationMember as it currently stands. I've have to figure out one other thing now, but I should get to it later today.
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.
Yes having the Class parameter is better as the API user knows they have to have the class before they can the enum. That is why I added it in the other PR
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.
Here, the API user is the extension author. That is typically not the same person as the extension user.
I'd rather remove asEnum completely than having it sometimes failing with classloading errors, to be honest :-)
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.
Right, my point was if the extension author has to supply a Class parameter, they know that they have to configure their classpath to make sure the Class they are requesting is on the same classpath as the extension.
FooEnum e = info.asEnum(FooEnum.class);
In the above case FooEnum will not be referencable if it is not on the classpath of the extension and the extension author would get a compilation error.
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.
OK, if you're fine with it, then I am :-) Let's keep asEnum as it is now, then. I'll remove the TODO comment.
api/src/main/java/jakarta/enterprise/inject/build/compatible/spi/AnnotationBuilder.java
Show resolved
Hide resolved
api/src/main/java/jakarta/enterprise/inject/build/compatible/spi/AnnotationBuilder.java
Show resolved
Hide resolved
47f5c76 to
6acd8f3
Compare
The `Annotations` API was a provisional solution for creating annotation instances. This commit replaces it with a simpler, more traditional builder API: `AnnotationBuilder`. Considering that `AnnotationInfo.target()` was dropped, the builder can simply produce `AnnotationInfo` instances, which allows simplification of other APIs that expect users to pass annotation instances (annotation transformation and synthetic component registration). Additionally, this commit tries to establish a convention for documenting `null` handling: - if the user is forbidden to pass `null`, we say "must not be null" and we don't have to document that a NPE will be thrown; - if the API guarantees that `null` will never be returned, we simply say "never null".
6acd8f3 to
5b4891d
Compare
The
AnnotationsAPI was a provisional solution for creatingannotation instances. This commit replaces it with a simpler,
more traditional builder API:
AnnotationBuilder. Consideringthat
AnnotationInfo.target()was dropped, the builder cansimply produce
AnnotationInfoinstances, which allowssimplification of other APIs that expect users to pass
annotation instances (annotation transformation and synthetic
component registration).
Additionally, this commit tries to establish a convention
for documenting
nullhandling:null, we say "must notbe null" and we don't have to document that a NPE will be
thrown;
nullwill never be returned,we simply say "never null".