The very first version of Context Dependency Injection (CDI) Tools was introduced as a part of JBoss Tools 3.1.0. But now JBoss Tools 3.2 is moving to its first stable release. Let's have some review of main features of the improved and up coming CDI Tools in JBoss Tools 3.2.
Enabling CDI support
First at all we need to enable CDI support for the project. If you already have some CDI project and don't want to start from scratch then just go toProject Properties->CDI->CDI support to enable all the features.
If your project is Maven-based and the pom.xml references the CDI api jars CDI support will be enabled automatically. If you want to create a brand new WTP project with CDI support, just add a CDI facet to the list of installing facets.
See Max's blog Simple CDI Hello World with Eclipse and JBoss Tools for details.
Make sure you have CDI support enabled for all the related projects. For instance if you have a web project (is to deployed as WAR) which uses some Java project (JAR) then both projects should have CDI support enabled.
If you are interested in Weld examples (Weld is the reference implementation of CDI spec.) you can download it from JBoss Tools example site.Help->Project Examples->Weld 1.0.1
CDI Wizards
There are a set of CDI Wizards to help you to create basic CDI artifacts. The wizards are available in File->New->Other...->CDI
CDI validation
CDI validation covers most of the rules declared in the JSR-299 specification. There are 100+ validation rules including definition errors and deployment problems. You can see the full list in the CDI Preferences, where you can also control which rules you want to be Errors, Warnings or simply Ignored.
The CDI validator checks for problems in java source files, JSP, XHTML and beans.xml files.
Some of the validation problems can be fixed via Quick Fixes menu (Ctrl+1):
Code completion
Another useful feature is a code completion. CDI tools provides two types of code completion. Code completion for @Named beans and their members which are available in EL expressions:
And code completion for the relevant types/annotations in beans.xml:
Hyperlinks (OpenOns)
Hyperlinks help you to navigate between source files. For example Ctrl+Click or F3 on any EL will navigate you to the corresponding java source.
For Injection's it is a bit more tricky. The built-in Java hyperlink for its declared type will open the type. But for Injection there are additional relevant items to navigate to. CDI Tools offers you an alternative navigation to the actual bean which is to be injected.
If the injection has multiple eligible beans, you can see a full list of these beans. Btw. you can fix the multiple eligible beans via a quick-fix (Ctrl+1).
Also you can open the corresponding class/interface mentioned in beans.xml via the same Ctrl+Click on the type name.
Observers and Events can be navigated to via OpenOn too.
As well as Producer and Disposer methods:
At last we also have:
- EL refactoring. For example if your name the method/field or class name of some bean using Java refactoring dialogs CDI Tools will offer you to update all the EL expressions that use this method/field/type.
- Related CDI Beans are added in search result for field/method references search. See demo movie.
Feedback
This was a quick overview of the main features of up coming JBoss Tools 3.2 for CDI developers.
If you think CDI Tools misses some useful functionality then please create a feature request in JIRA! We are working to help you to enjoy this exciting world of CDI