Skip to content
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

Depedency Injection: Diagnostic for handling more than one @Qualifier #165

Closed
2 tasks
KidoVin01 opened this issue Sep 28, 2021 · 3 comments
Closed
2 tasks
Labels
diagnostic Diagnostic item

Comments

@KidoVin01
Copy link
Contributor

KidoVin01 commented Sep 28, 2021

Spec

Unchecked Errors:

  • When more than one @Qualifier annotation is provided

Potential Solution:

  • Remove the last @Qualifier

Related to #153

@KidoVin01 KidoVin01 changed the title Adding support for handling more than one qualifiers Adding support for handling more than one @Qualifier Sep 28, 2021
@kathrynkodama
Copy link
Contributor

Is this diagnostic to warn users when they have a field/method with @Inject and more than one qualifier annotation?

According to https://jakarta.ee/specifications/dependency-injection/2.0/apidocs/jakarta/inject/inject:

A qualifier may annotate an injectable field or parameter and, combined with the type, identify the implementation to inject. Qualifiers are optional, and when used with @Inject in injector-independent classes, no more than one qualifier should annotate a single field or parameter. The qualifiers are bold in the following example:

public class Car {
@Inject private @leather Provider seatProvider;

 @Inject void install(@Tinted Windshield windshield,
     @Big Trunk trunk) { ... }

}
If one injectable method overrides another, the overriding method's parameters do not automatically inherit qualifiers from the overridden method's parameters.

In the example above, how would we determine that @Leather and @Tinted are qualifier annotations if they are in separate classes. We may not have knowledge of those classes.

Also see https://jakarta.ee/specifications/dependency-injection/2.0/apidocs/jakarta/inject/qualifier

@kathrynkodama kathrynkodama added the diagnostic Diagnostic item label Sep 29, 2021
@KidoVin01
Copy link
Contributor Author

KidoVin01 commented Sep 30, 2021

Is this diagnostic to warn users

The diagnostic should show an error since it would not compile properly when annotated

when they have a field/method with @Inject and more than one qualifier annotation?

Yes, that is correct.

In the example above, how would we determine that @leather and @TINTED are qualifier annotations if they are in separate classes. We may not have knowledge of those classes.

I guess that does pose a problem.

Maybe if the annotations appear in front of a type or alongside with an @Inject, we can infer it is a @Qualifier? Or we could internally keep track of the declared @Qualifiers (not sure whether that is possible).

@KidoVin01 KidoVin01 changed the title Adding support for handling more than one @Qualifier Depedency Injection: Diagnostic for handling more than one @Qualifier Oct 1, 2021
@KidoVin01 KidoVin01 changed the title Depedency Injection: Diagnostic for handling more than one @Qualifier Depedency Injection: Diagnostic for handling more than one @Qualifier Oct 1, 2021
@KidoVin01
Copy link
Contributor Author

According to spec

Any bean may declare multiple qualifier types

Closing this issue until more detailed error can be specified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
diagnostic Diagnostic item
Projects
None yet
Development

No branches or pull requests

2 participants