Created a JIRA to improve Intellij IDEA support : https://youtrack.jetbrains.com/issue/IDEA-131745

Vote on it if you want ;o)

Antonio

On Tue, Oct 21, 2014 at 6:47 PM, Antonio Goncalves <antonio.goncalves@gmail.com> wrote:
BTW, if I take the @Alternative producer out (so there is no more @Alternative) but leave the <alternative> element, the Weld error message is :

WELD-001422: Enabled alternative <class>org.agoncal.cdi.PrefixProducer</class> in file:/beans.xml@7 is not an alternative

Again, the error message is very "bean" oriented, don't you think ?

Antonio

On Tue, Oct 21, 2014 at 4:10 PM, Antonio Goncalves <antonio.goncalves@gmail.com> wrote:
Hi all,

I often use code such as the one below: one bean, two producers and one producer is an alternative (not the bean) :

public class PrefixProducer
{

  
@Produces
  
public String prefixNonAlt = "non-alternative";

  
@Produces
   @Alternative
  
public String prefixAlt = "alternative"
;
}


I enable the alternative, as usual, by declaring the bean in the beans.xml :

<alternatives>
 
<class>org.agoncal.cdi.PrefixProducer</class>
</alternatives>


This works fine, no problem. But I just realized that Intellij IDEA displays the warning "Alternative class expected here". I've looked around, read the spec, the Weld documentation, and didn't find any example of the code above. I think people are unware of this. The only reference of alternative producers I found is in the spec : 

5.1.1.2
An alternative is selected for the bean archive if either:
* the alternative is a producer method, field or resource, and the bean class that declares the method or field is listed

I think for such easy use cases (i.e PrefixProducer) there is no need to multiply beans, so the code is fine and easy to read. But the code you see around, tend to multiply beans (people think that Alternatives are *only* for beans, not for producers).

Shouldn't the spec/Weld documentation mention this case a bit more often, by giving an example ? 

WDYT ? 

Antonio








 

_______________________________________________
cdi-dev mailing list
cdi-dev@lists.jboss.org
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.



--
Antonio Goncalves
Software architect, Java Champion and Pluralsight author

Web site | TwitterLinkedIn | Pluralsight | Paris JUG | Devoxx France



--
Antonio Goncalves
Software architect, Java Champion and Pluralsight author

Web site | TwitterLinkedIn | Pluralsight | Paris JUG | Devoxx France