Open KidoVin01 opened 2 years ago
Can you link/quote where in the spec this is mentioned and provide an example of how this might look?
@AlvinTan2000 Does this section of the CDI spec cover the ambiguous injection you are referring to?
If so, we need to come up with some concrete ways of checking whether it is an ambiguous injection
Provided some examples code demonstrating the errors.
What conditions would we check for when delivering the diagnostic?
We would check for the whether all the applicable sub-classes share the conflicting annotations, which would depend on #159
How to check for ambiguous injection (expanding on the error identification section above):
@Inject
on a field, method or constructor@Inject
private GreetingItf greeting;
public interface GreetingItf {
public String greet(String greeting);
}
Detecting if every implementation has the same bean attributes gets a bit tricky, the logic is if every implementation has:
@RequestScoped
, @SessionScoped
, @ApplicationScoped
, @Dependent
, @ConversationScoped
)
AND IF @Named
is present: the same name defined (value set by: @Named
)
AND IF a custom @Qualifier
annotation is present: the same qualifier defined (would involve checking for custom qualifiers)
AND IF@Alternative
is present: all are marked @Alternative
or ![all but one] are marked @Alternative
AND IF [add priority logic here]
AND IF [add type logic here] @AlvinTan2000 I am leaving these logic sections empty as I am not sure the rules associated. Please fill in with an additional comment. To start, we can cover the base case and iteratively build up support. The base case would be:
Search the java project for classes that implement the corresponding interface. If there is more than one class that implements the interface with the: same scope defined, (possible scopes are: @RequestScoped
, @SessionScoped
, @ApplicationScoped
, @Dependent
, @ConversationScoped
) and NO other annotations present on those classes then deliver a warning diagnostic.
ie. both the following classes implement GreetingItf
, have @ApplicationScoped
, and DO NOT have any other annotations.
@ApplicationScoped
public class GreetingA implements GreetingItf{
public String greet(String name) {
return "GreetingA, " + name;
}
}
```java
@ApplicationScoped
public class GreetingB implements GreetingItf{
public String greet(String name) {
return "GreetingB, " + name;
}
}
We can break this issue down into subsequent tasks and iteratively build:
@Named
support@Qualifier
support@Alternative
support@Priority
support@Type
supportDetecting if every implementation has the same bean attributes gets a bit tricky, the logic is if every implementation has:
- the same scope defined, (possible scopes are: @RequestScoped, @SessionScoped, @ApplicationScoped, @Dependent, @ConversationScoped) AND IF @Named is present: the same name defined (value set by: @Named ) AND IF a custom @Qualifier annotation is present: the same qualifier defined (would involve checking for custom qualifiers) AND IF@Alternative is present: all are marked @Alternative or ![all but one] are marked @Alternative AND IF [add priority logic here] AND IF [add type logic here] @AlvinTan2000 I am leaving these logic sections empty as I am not sure the rules associated. Please fill in with an additional comment.
AND IF @Priority(value)
is present: at least two shares the same highest value
Don't think it is possible to purposely create an ambiguous error with just a single @Type
annotation.
What is ambiguous dependency?
Dependency injection and lookup
Which Java classes are managed beans?
Beans and Attributes
Error Identification:
@Inject
and a set of default or user-specified bean attributes@Qualifiers
@Alternative
)@Priority
)@Named
@Type
(TODO)Note: if no classes match the set of bean attributes, it is an unsatisfied error, refer to #164
Potential Diagnostics:
@Inject
field/method/constructorExample error for
@Alternative
:Note: The diagnostics and error identification depends on #159 for reading class information across files.
Related to #153