Accepting class type for simple (qualifier) annotations in APIs?

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Accepting class type for simple (qualifier) annotations in APIs?

arjan tijms
Hi,

Wouldn't it be convenient as the CDI API that now requires an Annotation instance in various APIs, would also accept the class type of that Annotation?

E.g. in BeanManager there's this method:

Set<Bean<?>> getBeans(Type beanType, Annotation... qualifiers)

This not rarely requires one to create an AnnotationLiteral, which is not specifically difficult but a tad verbose. For qualifiers that have no (binding) attributes, a simple Class would be much easier to use.

Thoughts?

Kind regards,
Arjan Tijms

_______________________________________________
cdi-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/cdi-dev

Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
Reply | Threaded
Open this post in threaded view
|

Re: Accepting class type for simple (qualifier) annotations in APIs?

Romain Manni-Bucau
Think it is maybe saner to have AnnotationProvider.of(type, params) (like in deltaspike) since it doesnt leave the parameterized annotations (which are not rare) next the road.


2016-09-12 12:28 GMT+02:00 arjan tijms <[hidden email]>:
Hi,

Wouldn't it be convenient as the CDI API that now requires an Annotation instance in various APIs, would also accept the class type of that Annotation?

E.g. in BeanManager there's this method:

Set<Bean<?>> getBeans(Type beanType, Annotation... qualifiers)

This not rarely requires one to create an AnnotationLiteral, which is not specifically difficult but a tad verbose. For qualifiers that have no (binding) attributes, a simple Class would be much easier to use.

Thoughts?

Kind regards,
Arjan Tijms

_______________________________________________
cdi-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/cdi-dev

Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.


_______________________________________________
cdi-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/cdi-dev

Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
Reply | Threaded
Open this post in threaded view
|

Re: Accepting class type for simple (qualifier) annotations in APIs?

Martin Kouba
Type safety is not guaranteed in the current version of
AnnotationInstanceProvider (deltaspike). We should at least check the
provided map of member values against the set of declared methods.
Otherwise, I like the idea of standardizing a similar "annotation
instance builder".

Martin

Dne 12.9.2016 v 12:34 Romain Manni-Bucau napsal(a):

> Think it is maybe saner to have AnnotationProvider.of(type, params)
> (like in deltaspike) since it doesnt leave the parameterized annotations
> (which are not rare) next the road.
>
>
> Romain Manni-Bucau
> @rmannibucau <https://twitter.com/rmannibucau> |  Blog
> <https://blog-rmannibucau.rhcloud.com> | Old Wordpress Blog
> <http://rmannibucau.wordpress.com> | Github
> <https://github.com/rmannibucau> | LinkedIn
> <https://www.linkedin.com/in/rmannibucau> | Tomitriber
> <http://www.tomitribe.com> | JavaEE Factory
> <https://javaeefactory-rmannibucau.rhcloud.com>
>
> 2016-09-12 12:28 GMT+02:00 arjan tijms <[hidden email]
> <mailto:[hidden email]>>:
>
>     Hi,
>
>     Wouldn't it be convenient as the CDI API that now requires an
>     Annotation instance in various APIs, would also accept the class
>     type of that Annotation?
>
>     E.g. in BeanManager there's this method:
>
>     Set<Bean<?>> getBeans(Type beanType, Annotation... qualifiers)
>
>     This not rarely requires one to create an AnnotationLiteral, which
>     is not specifically difficult but a tad verbose. For qualifiers that
>     have no (binding) attributes, a simple Class would be much easier to
>     use.
>
>     Thoughts?
>
>     Kind regards,
>     Arjan Tijms
>
>     _______________________________________________
>     cdi-dev mailing list
>     [hidden email] <mailto:[hidden email]>
>     https://lists.jboss.org/mailman/listinfo/cdi-dev
>     <https://lists.jboss.org/mailman/listinfo/cdi-dev>
>
>     Note that for all code provided on this list, the provider licenses
>     the code under the Apache License, Version 2
>     (http://www.apache.org/licenses/LICENSE-2.0.html
>     <http://www.apache.org/licenses/LICENSE-2.0.html>). For all other
>     ideas provided on this list, the provider waives all patent and
>     other intellectual property rights inherent in such information.
>
>
>
>
> _______________________________________________
> cdi-dev mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/cdi-dev
>
> Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
>
_______________________________________________
cdi-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/cdi-dev

Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
Reply | Threaded
Open this post in threaded view
|

Re: Accepting class type for simple (qualifier) annotations in APIs?

arjan tijms
Hi,

Annotation builder would be +1. It's a tiny bit less convenient, but more universal. So better for the spec.

Convenience addition could theoretically still be:

Set<Bean<?>> getBeans(Type beanType, Class<?> annotationType, Object... annotation attributes);

But... I acknowledge that  this would again be for a more specific situation (namely, a bean with exactly 1 qualifier and 0 or more binding attributes).

While on the subject, it's currently not possible for an injected bean to get hold of the annotation instance that's used in CDI.current().select(), BeanManager.getBeans, etc, is it?

Kind regards,
Arjan Tijms









On Mon, Sep 12, 2016 at 1:44 PM, Martin Kouba <[hidden email]> wrote:
Type safety is not guaranteed in the current version of AnnotationInstanceProvider (deltaspike). We should at least check the provided map of member values against the set of declared methods. Otherwise, I like the idea of standardizing a similar "annotation instance builder".

Martin

Dne 12.9.2016 v 12:34 Romain Manni-Bucau napsal(a):
Think it is maybe saner to have AnnotationProvider.of(type, params)
(like in deltaspike) since it doesnt leave the parameterized annotations
(which are not rare) next the road.


Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<https://blog-rmannibucau.rhcloud.com> | Old Wordpress Blog
<http://rmannibucau.wordpress.com> | Github
<https://github.com/rmannibucau> | LinkedIn
<https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com> | JavaEE Factory
<https://javaeefactory-rmannibucau.rhcloud.com>

2016-09-12 12:28 GMT+02:00 arjan tijms <[hidden email]
<mailto:[hidden email]>>:

    Hi,

    Wouldn't it be convenient as the CDI API that now requires an
    Annotation instance in various APIs, would also accept the class
    type of that Annotation?

    E.g. in BeanManager there's this method:

    Set<Bean<?>> getBeans(Type beanType, Annotation... qualifiers)

    This not rarely requires one to create an AnnotationLiteral, which
    is not specifically difficult but a tad verbose. For qualifiers that
    have no (binding) attributes, a simple Class would be much easier to
    use.

    Thoughts?

    Kind regards,
    Arjan Tijms

    _______________________________________________
    cdi-dev mailing list
    [hidden email] <mailto:[hidden email]>
    https://lists.jboss.org/mailman/listinfo/cdi-dev
    <https://lists.jboss.org/mailman/listinfo/cdi-dev>

    Note that for all code provided on this list, the provider licenses
    the code under the Apache License, Version 2
    (http://www.apache.org/licenses/LICENSE-2.0.html
    <http://www.apache.org/licenses/LICENSE-2.0.html>). For all other
    ideas provided on this list, the provider waives all patent and
    other intellectual property rights inherent in such information.




_______________________________________________
cdi-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/cdi-dev

Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.



_______________________________________________
cdi-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/cdi-dev

Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
Reply | Threaded
Open this post in threaded view
|

Re: Accepting class type for simple (qualifier) annotations in APIs?

Martin Kouba
I've created https://issues.jboss.org/browse/CDI-629

Dne 12.9.2016 v 14:14 arjan tijms napsal(a):

> Hi,
>
> Annotation builder would be +1. It's a tiny bit less convenient, but
> more universal. So better for the spec.
>
> Convenience addition could theoretically still be:
>
> Set<Bean<?>> getBeans(Type beanType, Class<?> annotationType, Object...
> annotation attributes);
>
> But... I acknowledge that  this would again be for a more specific
> situation (namely, a bean with exactly 1 qualifier and 0 or more binding
> attributes).
>
> While on the subject, it's currently not possible for an injected bean
> to get hold of the annotation instance that's used in
> CDI.current().select(), BeanManager.getBeans, etc, is it?

No and I cannot imagine a way to do this.

>
> Kind regards,
> Arjan Tijms
>
>
>
>
>
>
>
>
>
> On Mon, Sep 12, 2016 at 1:44 PM, Martin Kouba <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Type safety is not guaranteed in the current version of
>     AnnotationInstanceProvider (deltaspike). We should at least check
>     the provided map of member values against the set of declared
>     methods. Otherwise, I like the idea of standardizing a similar
>     "annotation instance builder".
>
>     Martin
>
>     Dne 12.9.2016 v 12:34 Romain Manni-Bucau napsal(a):
>
>         Think it is maybe saner to have AnnotationProvider.of(type, params)
>         (like in deltaspike) since it doesnt leave the parameterized
>         annotations
>         (which are not rare) next the road.
>
>
>         Romain Manni-Bucau
>         @rmannibucau <https://twitter.com/rmannibucau
>         <https://twitter.com/rmannibucau>> |  Blog
>         <https://blog-rmannibucau.rhcloud.com
>         <https://blog-rmannibucau.rhcloud.com>> | Old Wordpress Blog
>         <http://rmannibucau.wordpress.com
>         <http://rmannibucau.wordpress.com>> | Github
>         <https://github.com/rmannibucau
>         <https://github.com/rmannibucau>> | LinkedIn
>         <https://www.linkedin.com/in/rmannibucau
>         <https://www.linkedin.com/in/rmannibucau>> | Tomitriber
>         <http://www.tomitribe.com> | JavaEE Factory
>         <https://javaeefactory-rmannibucau.rhcloud.com
>         <https://javaeefactory-rmannibucau.rhcloud.com>>
>
>         2016-09-12 12:28 GMT+02:00 arjan tijms <[hidden email]
>         <mailto:[hidden email]>
>         <mailto:[hidden email] <mailto:[hidden email]>>>:
>
>             Hi,
>
>             Wouldn't it be convenient as the CDI API that now requires an
>             Annotation instance in various APIs, would also accept the class
>             type of that Annotation?
>
>             E.g. in BeanManager there's this method:
>
>             Set<Bean<?>> getBeans(Type beanType, Annotation... qualifiers)
>
>             This not rarely requires one to create an AnnotationLiteral,
>         which
>             is not specifically difficult but a tad verbose. For
>         qualifiers that
>             have no (binding) attributes, a simple Class would be much
>         easier to
>             use.
>
>             Thoughts?
>
>             Kind regards,
>             Arjan Tijms
>
>             _______________________________________________
>             cdi-dev mailing list
>             [hidden email] <mailto:[hidden email]>
>         <mailto:[hidden email] <mailto:[hidden email]>>
>             https://lists.jboss.org/mailman/listinfo/cdi-dev
>         <https://lists.jboss.org/mailman/listinfo/cdi-dev>
>             <https://lists.jboss.org/mailman/listinfo/cdi-dev
>         <https://lists.jboss.org/mailman/listinfo/cdi-dev>>
>
>             Note that for all code provided on this list, the provider
>         licenses
>             the code under the Apache License, Version 2
>             (http://www.apache.org/licenses/LICENSE-2.0.html
>         <http://www.apache.org/licenses/LICENSE-2.0.html>
>             <http://www.apache.org/licenses/LICENSE-2.0.html
>         <http://www.apache.org/licenses/LICENSE-2.0.html>>). For all other
>             ideas provided on this list, the provider waives all patent and
>             other intellectual property rights inherent in such information.
>
>
>
>
>         _______________________________________________
>         cdi-dev mailing list
>         [hidden email] <mailto:[hidden email]>
>         https://lists.jboss.org/mailman/listinfo/cdi-dev
>         <https://lists.jboss.org/mailman/listinfo/cdi-dev>
>
>         Note that for all code provided on this list, the provider
>         licenses the code under the Apache License, Version 2
>         (http://www.apache.org/licenses/LICENSE-2.0.html
>         <http://www.apache.org/licenses/LICENSE-2.0.html>). For all
>         other ideas provided on this list, the provider waives all
>         patent and other intellectual property rights inherent in such
>         information.
>
>

--
Martin Kouba
Software Engineer
Red Hat, Czech Republic
_______________________________________________
cdi-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/cdi-dev

Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
Reply | Threaded
Open this post in threaded view
|

Re: Accepting class type for simple (qualifier) annotations in APIs?

Mark Struberg
In reply to this post by arjan tijms
Well, the DeltaSpike AnnotationInstanceProvider (or OWB 'DefaultAnnotation' as it used to be called) exist for a slightly different reason: With AnnotationLiteral you need to know the class you want an Annotation for already at compile time.
The DeltaSpike AnnotationInstanceProvider does the same but fully dynamic. That way you can create an empty Annotation instance just by having e.g. the classname as String.


I use it e.g. to create an interceptor binding Annotation from a configuration file:
https://github.com/struberg/InterDyn/blob/master/interdyn/src/main/java/at/struct/devtools/cdi/interdyn/InterDynExtension.java#L172

LieGrue,
strub






On Monday, 12 September 2016, 14:16, arjan tijms <[hidden email]> wrote:


>
>
>Hi,
>
>
>Annotation builder would be +1. It's a tiny bit less convenient, but more universal. So better for the spec.
>
>
>Convenience addition could theoretically still be:
>
>Set<Bean<?>> getBeans(Type beanType, Class<?> annotationType, Object... annotation attributes);
>
>
>
>But... I acknowledge that  this would again be for a more specific situation (namely, a bean with exactly 1 qualifier and 0 or more binding attributes).
>
>
>While on the subject, it's currently not possible for an injected bean to get hold of the annotation instance that's used in CDI.current().select(), BeanManager.getBeans, etc, is it?
>
>
>Kind regards,
>Arjan Tijms
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>On Mon, Sep 12, 2016 at 1:44 PM, Martin Kouba <[hidden email]> wrote:
>
>Type safety is not guaranteed in the current version of AnnotationInstanceProvider (deltaspike). We should at least check the provided map of member values against the set of declared methods. Otherwise, I like the idea of standardizing a similar "annotation instance builder".
>>
>>Martin
>>
>>Dne 12.9.2016 v 12:34 Romain Manni-Bucau napsal(a):
>>
>>Think it is maybe saner to have AnnotationProvider.of(type, params)
>>>(like in deltaspike) since it doesnt leave the parameterized annotations
>>>(which are not rare) next the road.
>>>
>>>
>>>Romain Manni-Bucau
>>> @rmannibucau <https://twitter.com/rmannibuc au> |  Blog
>>><https://blog-rmannibucau.rhcl oud.com> | Old Wordpress Blog
>>><http://rmannibucau.wordpress. com> | Github
>>><https://github.com/rmannibuca u> | LinkedIn
>>><https://www.linkedin.com/in/r mannibucau> | Tomitriber
>>><http://www.tomitribe.com> | JavaEE Factory
>>><https://javaeefactory-rmannib ucau.rhcloud.com>
>>>
>>>2016-09-12 12:28 GMT+02:00 arjan tijms <[hidden email]
>>> <mailto:[hidden email]> >:
>>>
>>>    Hi,
>>>
>>>    Wouldn't it be convenient as the CDI API that now requires an
>>>    Annotation instance in various APIs, would also accept the class
>>>    type of that Annotation?
>>>
>>>    E.g. in BeanManager there's this method:
>>>
>>>    Set<Bean<?>> getBeans(Type beanType, Annotation... qualifiers)
>>>
>>>    This not rarely requires one to create an AnnotationLiteral, which
>>>    is not specifically difficult but a tad verbose. For qualifiers that
>>>    have no (binding) attributes, a simple Class would be much easier to
>>>    use.
>>>
>>>    Thoughts?
>>>
>>>    Kind regards,
>>>    Arjan Tijms
>>>
>>>    ______________________________ _________________
>>>    cdi-dev mailing list
>>>     [hidden email] <mailto:[hidden email] g>
>>>    https://lists.jboss.org/mailma n/listinfo/cdi-dev
>>>    <https://lists.jboss.org/mailm an/listinfo/cdi-dev>
>>>
>>>    Note that for all code provided on this list, the provider licenses
>>>    the code under the Apache License, Version 2
>>>    (http://www.apache.org/license s/LICENSE-2.0.html
>>>     <http://www.apache.org/license s/LICENSE-2.0.html>). For all other
>>>    ideas provided on this list, the provider waives all patent and
>>>    other intellectual property rights inherent in such information.
>>>
>>>
>>>
>>>
>>>______________________________ _________________
>>>cdi-dev mailing list
>>>[hidden email]
>>>https://lists.jboss.org/mailma n/listinfo/cdi-dev
>>>
>>>Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/license s/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
>>>
>>>
>
>
>_______________________________________________
>cdi-dev mailing list
>[hidden email]
>https://lists.jboss.org/mailman/listinfo/cdi-dev
>
>Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
>
>
_______________________________________________
cdi-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/cdi-dev

Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
Reply | Threaded
Open this post in threaded view
|

Re: Accepting class type for simple (qualifier) annotations in APIs?

Antoine Sabot-Durand
Administrator
In reply to this post by arjan tijms
Just a naive remark regarding Instance of annotations without members. I already used a lambda to have such an instance:

BeanManager.getBeans(MyBean.class, () -> MyQualifier.class)

I’m not sure there are no problem by using this short cut, but it is quite convenient.

Antoine


> Le 12 sept. 2016 à 12:28, arjan tijms <[hidden email]> a écrit :
>
> Hi,
>
> Wouldn't it be convenient as the CDI API that now requires an Annotation instance in various APIs, would also accept the class type of that Annotation?
>
> E.g. in BeanManager there's this method:
>
> Set<Bean<?>> getBeans(Type beanType, Annotation... qualifiers)
>
> This not rarely requires one to create an AnnotationLiteral, which is not specifically difficult but a tad verbose. For qualifiers that have no (binding) attributes, a simple Class would be much easier to use.
>
> Thoughts?
>
> Kind regards,
> Arjan Tijms
> _______________________________________________
> cdi-dev mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/cdi-dev
>
> Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.


_______________________________________________
cdi-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/cdi-dev

Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
Reply | Threaded
Open this post in threaded view
|

Re: Accepting class type for simple (qualifier) annotations in APIs?

Martin Kouba
Dne 15.9.2016 v 10:15 Antoine Sabot-Durand napsal(a):
> Just a naive remark regarding Instance of annotations without members. I already used a lambda to have such an instance:
>
> BeanManager.getBeans(MyBean.class, () -> MyQualifier.class)

What is this cryptic unclear lambda thing doing actually? I know it
compiles but I don't understand...

>
> I’m not sure there are no problem by using this short cut, but it is quite convenient.
>
> Antoine
>
>
>> Le 12 sept. 2016 à 12:28, arjan tijms <[hidden email]> a écrit :
>>
>> Hi,
>>
>> Wouldn't it be convenient as the CDI API that now requires an Annotation instance in various APIs, would also accept the class type of that Annotation?
>>
>> E.g. in BeanManager there's this method:
>>
>> Set<Bean<?>> getBeans(Type beanType, Annotation... qualifiers)
>>
>> This not rarely requires one to create an AnnotationLiteral, which is not specifically difficult but a tad verbose. For qualifiers that have no (binding) attributes, a simple Class would be much easier to use.
>>
>> Thoughts?
>>
>> Kind regards,
>> Arjan Tijms
>> _______________________________________________
>> cdi-dev mailing list
>> [hidden email]
>> https://lists.jboss.org/mailman/listinfo/cdi-dev
>>
>> Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
>
>
> _______________________________________________
> cdi-dev mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/cdi-dev
>
> Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
>
_______________________________________________
cdi-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/cdi-dev

Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
Reply | Threaded
Open this post in threaded view
|

Re: Accepting class type for simple (qualifier) annotations in APIs?

Antoine Sabot-Durand
Administrator

> Le 15 sept. 2016 à 10:26, Martin Kouba <[hidden email]> a écrit :
>
> Dne 15.9.2016 v 10:15 Antoine Sabot-Durand napsal(a):
>> Just a naive remark regarding Instance of annotations without members. I already used a lambda to have such an instance:
>>
>> BeanManager.getBeans(MyBean.class, () -> MyQualifier.class)
>
> What is this cryptic unclear lambda thing doing actually? I know it compiles but I don't understand…

It compiles and works every the time I used it. From my understanding it’s a short cut for

BeanManager.getBeans(MyBean.class, new Annotation() {
    @Override
    public Class<? extends Annotation> annotationType() {
        return MyQualifier.class;
    }
})

Which by the way also works. From your answer I guess it’s a bad solution ;), but I’d be happy to know why and what is the side effect makes it work.

Thanks,

Antoine

>
>>
>> I’m not sure there are no problem by using this short cut, but it is quite convenient.
>>
>> Antoine
>>
>>
>>> Le 12 sept. 2016 à 12:28, arjan tijms <[hidden email]> a écrit :
>>>
>>> Hi,
>>>
>>> Wouldn't it be convenient as the CDI API that now requires an Annotation instance in various APIs, would also accept the class type of that Annotation?
>>>
>>> E.g. in BeanManager there's this method:
>>>
>>> Set<Bean<?>> getBeans(Type beanType, Annotation... qualifiers)
>>>
>>> This not rarely requires one to create an AnnotationLiteral, which is not specifically difficult but a tad verbose. For qualifiers that have no (binding) attributes, a simple Class would be much easier to use.
>>>
>>> Thoughts?
>>>
>>> Kind regards,
>>> Arjan Tijms
>>> _______________________________________________
>>> cdi-dev mailing list
>>> [hidden email]
>>> https://lists.jboss.org/mailman/listinfo/cdi-dev
>>>
>>> Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
>>
>>
>> _______________________________________________
>> cdi-dev mailing list
>> [hidden email]
>> https://lists.jboss.org/mailman/listinfo/cdi-dev
>>
>> Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
>>


_______________________________________________
cdi-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/cdi-dev

Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
Reply | Threaded
Open this post in threaded view
|

Re: Accepting class type for simple (qualifier) annotations in APIs?

Martin Kouba
Dne 15.9.2016 v 10:48 Antoine Sabot-Durand napsal(a):

>
>> Le 15 sept. 2016 à 10:26, Martin Kouba <[hidden email]> a écrit :
>>
>> Dne 15.9.2016 v 10:15 Antoine Sabot-Durand napsal(a):
>>> Just a naive remark regarding Instance of annotations without members. I already used a lambda to have such an instance:
>>>
>>> BeanManager.getBeans(MyBean.class, () -> MyQualifier.class)
>>
>> What is this cryptic unclear lambda thing doing actually? I know it compiles but I don't understand…
>
> It compiles and works every the time I used it. From my understanding it’s a short cut for
>
> BeanManager.getBeans(MyBean.class, new Annotation() {
>     @Override
>     public Class<? extends Annotation> annotationType() {
>         return MyQualifier.class;
>     }
> })
>
> Which by the way also works. From your answer I guess it’s a bad solution ;), but I’d be happy to know why and what is the side effect makes it work.

I don't say it's a bad solution, but it's not obvious and I consider
similar things a bad practice, especially if we don't understand why it
works ;-)

>
> Thanks,
>
> Antoine
>
>>
>>>
>>> I’m not sure there are no problem by using this short cut, but it is quite convenient.
>>>
>>> Antoine
>>>
>>>
>>>> Le 12 sept. 2016 à 12:28, arjan tijms <[hidden email]> a écrit :
>>>>
>>>> Hi,
>>>>
>>>> Wouldn't it be convenient as the CDI API that now requires an Annotation instance in various APIs, would also accept the class type of that Annotation?
>>>>
>>>> E.g. in BeanManager there's this method:
>>>>
>>>> Set<Bean<?>> getBeans(Type beanType, Annotation... qualifiers)
>>>>
>>>> This not rarely requires one to create an AnnotationLiteral, which is not specifically difficult but a tad verbose. For qualifiers that have no (binding) attributes, a simple Class would be much easier to use.
>>>>
>>>> Thoughts?
>>>>
>>>> Kind regards,
>>>> Arjan Tijms
>>>> _______________________________________________
>>>> cdi-dev mailing list
>>>> [hidden email]
>>>> https://lists.jboss.org/mailman/listinfo/cdi-dev
>>>>
>>>> Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
>>>
>>>
>>> _______________________________________________
>>> cdi-dev mailing list
>>> [hidden email]
>>> https://lists.jboss.org/mailman/listinfo/cdi-dev
>>>
>>> Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
>>>
>

--
Martin Kouba
Software Engineer
Red Hat, Czech Republic
_______________________________________________
cdi-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/cdi-dev

Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
Reply | Threaded
Open this post in threaded view
|

Re: Accepting class type for simple (qualifier) annotations in APIs?

Antoine Sabot-Durand
Administrator
After some test I can answer myself. It’s bad because equals() is broken (2 annotations created with this code won’t be equals). And it works probably because all the equals call done in Weld are made from the inner Annotation not from user instance…

Also Annotation is not a functional interface.

Antoine

Le 15 sept. 2016 à 11:03, Martin Kouba <[hidden email]> a écrit :

Dne 15.9.2016 v 10:48 Antoine Sabot-Durand napsal(a):

Le 15 sept. 2016 à 10:26, Martin Kouba <[hidden email]> a écrit :

Dne 15.9.2016 v 10:15 Antoine Sabot-Durand napsal(a):
Just a naive remark regarding Instance of annotations without members. I already used a lambda to have such an instance:

BeanManager.getBeans(MyBean.class, () -> MyQualifier.class)

What is this cryptic unclear lambda thing doing actually? I know it compiles but I don't understand…

It compiles and works every the time I used it. From my understanding it’s a short cut for

BeanManager.getBeans(MyBean.class, new Annotation() {
   @Override
   public Class<? extends Annotation> annotationType() {
       return MyQualifier.class;
   }
})

Which by the way also works. From your answer I guess it’s a bad solution ;), but I’d be happy to know why and what is the side effect makes it work.

I don't say it's a bad solution, but it's not obvious and I consider similar things a bad practice, especially if we don't understand why it works ;-)


Thanks,

Antoine



I’m not sure there are no problem by using this short cut, but it is quite convenient.

Antoine


Le 12 sept. 2016 à 12:28, arjan tijms <[hidden email]> a écrit :

Hi,

Wouldn't it be convenient as the CDI API that now requires an Annotation instance in various APIs, would also accept the class type of that Annotation?

E.g. in BeanManager there's this method:

Set<Bean<?>> getBeans(Type beanType, Annotation... qualifiers)

This not rarely requires one to create an AnnotationLiteral, which is not specifically difficult but a tad verbose. For qualifiers that have no (binding) attributes, a simple Class would be much easier to use.

Thoughts?

Kind regards,
Arjan Tijms
_______________________________________________
cdi-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/cdi-dev

Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.


_______________________________________________
cdi-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/cdi-dev

Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.



-- 
Martin Kouba
Software Engineer
Red Hat, Czech Republic


_______________________________________________
cdi-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/cdi-dev

Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.