This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 220693 - Autodiscover all possible/ @produces annotated methods for a given @Inject
Summary: Autodiscover all possible/ @produces annotated methods for a given @Inject
Status: RESOLVED WONTFIX
Alias: None
Product: javaee
Classification: Unclassified
Component: CDI (show other bugs)
Version: 7.3
Hardware: PC Linux
: P3 normal (vote)
Assignee: Sergey Petrov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-10-23 20:36 UTC by viggonavarsete
Modified: 2016-07-07 08:53 UTC (History)
1 user (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description viggonavarsete 2012-10-23 20:36:57 UTC
With CDI it is possible to use @Inject to inject something that is produced with @produces somewhere else in the source code. It can be seen as "black magic" for many new to CDI, and it can also be hard to discover even for experienced CDI users where things are produced. I would therefor like to propose an enhancement that Netbeans gives a list of possible producers for a given @Inject (if it is possible to do technically though...).
Comment 1 viggonavarsete 2012-10-24 06:10:34 UTC
Input from Michael Nascimento (NetCAT mailing list): 

Not only things from @Produces can be injected, so maybe something
like this with a see all? CDI extensions would have to be manually
handled though, i.e., NetBeans would have to provide a SPI for
extension developers to code an implementation for their own
extension.
Comment 2 viggonavarsete 2012-10-24 06:13:52 UTC
I think such a feature belong to either the Navigate or Edit (with a new "Find CDI beans" feature) menu, or maybe by right-clicking on a field being annotated with @Inject and Netbeans can give a list of possible things that could be injected (I assume this would be the "black magic" to be implemented;) ).

I foresee the usage of CDI to maybe become the same issue as people have with interceptors..they don't see where things are applied...or as with using Spring when declared in XML files...don't see directly in code where  the link to other files are. I hope Netbeans can be proactive here and give the user some help before CDI become painful and hard :)
Comment 3 viggonavarsete 2012-10-24 06:15:21 UTC
Input to the discussion is also if Netbeans should/must scan external dependencies on the classpath to find other possible CDI beans that can be injected
Comment 4 Denis Anisimov 2012-10-24 08:20:20 UTC
(In reply to comment #0)
> With CDI it is possible to use @Inject to inject something that is produced
> with @produces somewhere else in the source code. It can be seen as "black
> magic" for many new to CDI, and it can also be hard to discover even for
> experienced CDI users where things are produced. I would therefor like to
> propose an enhancement that Netbeans gives a list of possible producers for a
> given @Inject (if it is possible to do technically though...).

This is ALREADY implemented.
You are able to use injection point ( f.e. field, method parameter,......) as 
a context for number of CDI related actions.
F.e. you may choose injection point in the editor and invoke popup menu action :
Navigate->Go To Injectable/Go To Decorator/Inspect CDI.
The last action ( Inspect CDI ) allows to you see ALL available eligible for 
injection elements. This list includes Java Types, producers (methods and fields)
resolved by typesafe resolution specification. It even contains disabled beans
(they are looks like disabled in the UI).
So I suppose there is already all functionality that you requested here.
There is also editor glyph gutter actions with special icons on the left side 
bar of the editor pane. They duplicate the mentioned actions ( no need to invoke
popup menu actions ). They are context dependent. 

See also http://wiki.netbeans.org/CDIFeatures71
and
http://wiki.netbeans.org/NewAndNoteworthyNB71#CDI
Comment 5 Denis Anisimov 2012-10-24 08:23:34 UTC
(In reply to comment #3)
> Input to the discussion is also if Netbeans should/must scan external
> dependencies on the classpath to find other possible CDI beans that can be
> injected

All project's classpath is scanned.
There is only one issue which is limitation of Java infrastructure performance:
search methods with specified annotation is very time consuming task for binary 
classpath.
So producers from binary classpath is not available in the final result.
Comment 6 Denis Anisimov 2012-10-25 07:53:51 UTC
(In reply to comment #1)
> Input from Michael Nascimento (NetCAT mailing list): 
> 
> Not only things from @Produces can be injected, so maybe something
> like this with a see all? CDI extensions would have to be manually
> handled though, i.e., NetBeans would have to provide a SPI for
> extension developers to code an implementation for their own
> extension.

This is the only thing in the issue which is not implemented.
But it seems this feature would be rarely used.
Comment 7 Martin Balin 2016-07-07 08:53:58 UTC
This old bug may not be relevant anymore. If you can still reproduce it in 8.2 development builds please reopen this issue.

Thanks for your cooperation,
NetBeans IDE 8.2 Release Boss