Support and embrace TYPE_USE target for @Qualifier annotations
- Dominant language
- Java
- Stars
- 27
- Forks
- 19
- PR merge metrics
- No merged PRs in 30d
Description
**Is your feature request related to a problem? Please describe.**
Currently, jakarta-inject suggest the default annotation target for `@Qualifier` annotations: https://github.com/jakartaee/inject/blob/90a96f769acdbcbc59b9ce6b9938171b1b0d07a7/src/main/java/jakarta/inject/Qualifier.java#L45-L51
It results in `ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD` targets, so the code like `List<@Leather(color = Color.RED) String>` does not compile.
**Describe the solution you'd like**
I would like to use `TYPE_USE` only annotations for `@Qualifier`, so I suggest updating the spec and the sample as follows:
```java
/**
*
* @java.lang.annotation.Documented
* @java.lang.annotation.Retention(RUNTIME)
* @java.lang.annotation.Target({ElementType.TYPE, ElementType.TYPE_USE}) // <-- add this
* @jakarta.inject.Qualifier
* public @interface Leather {
* Color color() default Color.TAN;
* public enum Color { RED, BLACK, TAN }
* }
*
* @see jakarta.inject.Named @Named
*/
```
**Additional context**
See:
* https://github.com/google/guice/issues/1910
* https://github.com/google/dagger/issues/4794
* Spring Framework supports `TYPE_USE` for its `@Qualifier`. Note that it supports `FIELD`, `METHOD` and so on for backward compatibility, and I think newly-created qualifier annotations should not have `FIELD`, `METHOD`, and the rest targets. `TYPE_USE` should be the right target just like [jspecify's `@Nullable`](https://github.com/jspecify/jspecify/blob/d02f3871f386f3a3b87af6710a40afa44f617805/src/main/java/org/jspecify/annotations/Nullable.java#L139)
Contributor guide
Research direction
Start with src/main/java/jakarta/inject/Qualifier.java, especially the documented default annotation target, then review the specification and sample referenced in the issue. Confirm how adding TYPE_USE affects qualifier declarations and ensure the specification and sample consistently describe the intended target.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100