[cdi-dev] CDI-471 and repeatable annotations

John Ament john.ament at spartasystems.com
Mon Nov 21 21:26:42 EST 2016


I looked at your implementation.  While its not perfect, it does work.  It does have one critical flaw.  You're assuming how the JDK does repeatable annotations.  I did come up with a way that doesn't make this assumption and is less cumbersome.


The problem is that the recommended implementation is a compile-time thing.  So in theory, other JDKs can do it differently.


I've raised a PR.  I figure we'll have some back and forth on it.


John


________________________________
From: Martin Kouba <mkouba at redhat.com>
Sent: Monday, November 21, 2016 9:00 AM
To: John Ament; cdi-dev
Subject: Re: [cdi-dev] CDI-471 and repeatable annotations

Hi John,

No problem, #4 was optional ;-)

By the way, this is the default implementation from Weld experimental API:
https://github.com/weld/api/blob/master/weld/src/main/java/org/jboss/weld/experimental/ExperimentalAnnotated.java


It's not perfect. E.g. Class.getMethod() should be used with privileges
enabled if a SecurityManager is used. But it could be a good base to
start with.

Thanks,

Martin

Dne 21.11.2016 v 14:47 John Ament napsal(a):
> Martin,
>
>
> I'll make these changes for #1-#3.  I'm not in favor of #4.  Its not
> consistent with our existing method.  (I'd prefer consistency of our API
> over consistency with the Java lang's spec)
>
>
> I may get to them this evening.
>
>
> John
>
>
>
> ------------------------------------------------------------------------
> *From:* cdi-dev-bounces at lists.jboss.org
> <cdi-dev-bounces at lists.jboss.org> on behalf of Martin Kouba
> <mkouba at redhat.com>
> *Sent:* Monday, November 21, 2016 8:25 AM
> *To:* cdi-dev
> *Subject:* [cdi-dev] CDI-471 and repeatable annotations
>
> Dear EG,
>
> during the review of CDI API 2.0.Alpha5 with modified Annotated SPI [1]
> I came across few questionable parts:
>
> 1. We should be more clear that the original methods like
> Annotated.getAnnotations() or Annotated.isAnnotationPresent() DO NOT
> support repeatable annotations - this is what Reflection API does to
> remain backward compatible - see also AnnotatedElement javadoc [2]
> 2. Thus AnnotatedElement.getAnnotation(Class<T>) should not be
> deprecated - for the same reasons as
> AnnotatedElement.getAnnotation(Class<T>) is not
> 3. We should provide a default implementation of
> Annotated.getAnnotations(Class<T>), otherwise a lot of extensions
> providing their own Annotated implementations would be broken
> 4. We should consider renaming the method to "getAnnotationsByType()" to
> keep it simple for users used to Reflection API
>
> Thanks,
>
> Martin
>
> [1]
> https://github.com/cdi-spec/cdi/pull/330
[https://avatars3.githubusercontent.com/u/108167?v=3&s=400]<https://github.com/cdi-spec/cdi/pull/330>

CDI-471 Introduce SPI for retrieving multiple annotations of the same… by johnament · Pull Request #330 · cdi-spec/cdi<https://github.com/cdi-spec/cdi/pull/330>
github.com
… type, deprecating the old one. Updated spec docs for qualifiers to reflect repeatability and spec docs for annotated for new method.



> <https://github.com/cdi-spec/cdi/pull/330>
[https://avatars3.githubusercontent.com/u/108167?v=3&s=400]<https://github.com/cdi-spec/cdi/pull/330>

CDI-471 Introduce SPI for retrieving multiple annotations of the same… by johnament · Pull Request #330 · cdi-spec/cdi<https://github.com/cdi-spec/cdi/pull/330>
github.com
… type, deprecating the old one. Updated spec docs for qualifiers to reflect repeatability and spec docs for annotated for new method.



>
> CDI-471 Introduce SPI for retrieving multiple annotations of the same…
> by johnament · Pull Request #330 · cdi-spec/cdi
> <https://github.com/cdi-spec/cdi/pull/330>
[https://avatars3.githubusercontent.com/u/108167?v=3&s=400]<https://github.com/cdi-spec/cdi/pull/330>

CDI-471 Introduce SPI for retrieving multiple annotations of the same… by johnament · Pull Request #330 · cdi-spec/cdi<https://github.com/cdi-spec/cdi/pull/330>
github.com
… type, deprecating the old one. Updated spec docs for qualifiers to reflect repeatability and spec docs for annotated for new method.



> github.com
> … type, deprecating the old one. Updated spec docs for qualifiers to
> reflect repeatability and spec docs for annotated for new method.
>
>
>
>
> [2]
> https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/AnnotatedElement.html
AnnotatedElement (Java Platform SE 8 ) - Oracle<https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/AnnotatedElement.html>
docs.oracle.com
Represents an annotated element of the program currently running in this VM. This interface allows annotations to be read reflectively. All annotations returned by ...



>
> AnnotatedElement (Java Platform SE 8 ) - Oracle
> <https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/AnnotatedElement.html>
AnnotatedElement (Java Platform SE 8 ) - Oracle<https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/AnnotatedElement.html>
docs.oracle.com
Represents an annotated element of the program currently running in this VM. This interface allows annotations to be read reflectively. All annotations returned by ...



> docs.oracle.com
> Represents an annotated element of the program currently running in this
> VM. This interface allows annotations to be read reflectively. All
> annotations returned by ...
>
>
>
> _______________________________________________
> cdi-dev mailing list
> cdi-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/cdi-dev
cdi-dev Info Page - JBoss Developer<https://lists.jboss.org/mailman/listinfo/cdi-dev>
lists.jboss.org
List to discuss the development of CDI (the specification) To see the collection of prior postings to the list, visit the cdi-dev Archives.



> cdi-dev Info Page - JBoss Developer
> <https://lists.jboss.org/mailman/listinfo/cdi-dev>
cdi-dev Info Page - JBoss Developer<https://lists.jboss.org/mailman/listinfo/cdi-dev>
lists.jboss.org
List to discuss the development of CDI (the specification) To see the collection of prior postings to the list, visit the cdi-dev Archives.



> lists.jboss.org
> List to discuss the development of CDI (the specification) To see the
> collection of prior postings to the list, visit the cdi-dev Archives.
>
________________________________
NOTICE: This e-mail message and any attachments may contain confidential, proprietary, and/or privileged information which should be treated accordingly. If you are not the intended recipient, please notify the sender immediately by return e-mail, delete this message, and destroy all physical and electronic copies. Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/cdi-dev/attachments/20161122/07c4a7a5/attachment-0001.html 


More information about the cdi-dev mailing list