-
1. Re: Qualifiers with Members
nickarls Jan 4, 2010 2:42 PM (in response to meetoblivion)Doesn't work == the member isn't taken into account?
Strange that it doesn't work since I think meta-annotations go through the same isEquivalent that uses reflection for access (at a quick glance)...
-
2. Re: Qualifiers with Members
meetoblivion Jan 4, 2010 3:08 PM (in response to meetoblivion)Doesn't work in the sense that Weld seems to ignore it as a qualifier. InjectionPoint.getAnnotated().getAnnotation(RepositorySession.class) returns null. No errors or anything, just something really bizarre and I noticed that it wasn't public, switched it to public and it worked fine.
My annotation in question looks like this:
@Qualifier @Retention(RUNTIME) @Target({METHOD, FIELD, PARAMETER, TYPE}) public @interface RepositorySession { @Nonbinding String value(); }
I changed it to
@Qualifier @Retention(RUNTIME) @Target({METHOD, FIELD, PARAMETER, TYPE}) public @interface RepositorySession { @Nonbinding public String value(); }
and it worked correctly.
-
3. Re: Qualifiers with Members
nickarls Jan 5, 2010 8:29 AM (in response to meetoblivion)I tried fiddling with @Random in the numberguess-example.
- Added a nonbinding String value() and injected with @Random(
foo
), worked - Removed the @Nonbinding, worked
Can you try your findings in numberguess?
- Added a nonbinding String value() and injected with @Random(
-
4. Re: Qualifiers with Members
meetoblivion Jan 5, 2010 11:32 AM (in response to meetoblivion)Well that's the trick, I guess.
You need to give it a try with
@Random("foo") int random1; @Random("bar") int random2;
I'll number guess a try.
-
5. Re: Qualifiers with Members
nickarls Jan 5, 2010 12:00 PM (in response to meetoblivion)Annotation members can only be public so no qualifier probably equals to public.
If you can reproduce it, file a JIRA, in that case it must be a bug in the qualifier comparision algorithm -
6. Re: Qualifiers with Members
nickarls Jan 5, 2010 12:08 PM (in response to meetoblivion)I have
@Target( { TYPE, METHOD, PARAMETER, FIELD }) @Retention(RUNTIME) @Documented @Qualifier public @interface Stuff { String value(); }
and
@Produces @Stuff("good") public String getGood() { return "good"; } @Produces @Stuff("bad") public String getBad() { return "bad"; }
and
@Inject @Stuff("good") String good; @Inject @Stuff("bad") String bad;
works for me
-
7. Re: Qualifiers with Members
nickarls Jan 5, 2010 12:16 PM (in response to meetoblivion)Adding @Nonbinding gives ambiguous, OK
I can also do
@Produces @Stuff public String getUgly() { return "ugly"; }
and
@Inject @Stuff String ugly;
if I default @Stuff value to
ugly
-
8. Re: Qualifiers with Members
meetoblivion Jan 5, 2010 1:29 PM (in response to meetoblivion)
Nicklas Karlsson wrote on Jan 05, 2010 12:16:
Adding @Nonbinding gives ambiguous, OKI'm still trying to figure out what the purpose is of @Nonbinding.
The producer I was using was something like this:
@Produces @RepositorySession("") public Session produceRepositorySession(InjectionPoint ip) { RepositorySession rs = ip.getAnnotated().getAnnotation(RepositorySession.class); return someMember.get(rs.value()); }
I'm more inclined to say the issue's with using @Nonbinding in my annotation. Is it necessary? Every annotation example I've seen uses it, but it seems to result in some odd behavior.
-
9. Re: Qualifiers with Members
nickarls Jan 5, 2010 2:00 PM (in response to meetoblivion)Simple case is qualifier with no members
To keep number of qualifiers down, members can be added (as in our examples above)
If you don't want to consider some member when resolving (but it might provide info for factories etc, use @Nonbinding)
-
10. Re: Qualifiers with Members
meetoblivion Jan 5, 2010 2:04 PM (in response to meetoblivion)So then by the spec, both versions of my qualifier should be valid, right? E.g. this looks like a bug.
-
11. Re: Qualifiers with Members
nickarls Jan 5, 2010 2:11 PM (in response to meetoblivion)Post a reproducible JIRA