Oh No Vector!
By Geertjan-Oracle on Oct 04, 2011
The superest hidden feature of NetBeans IDE 7.1 is about to be revealed. Check it out:
Above, you see a piece of code in the JFugue Music NotePad. It's an old piece of code from several years ago, hence you see a Vector being used. In NetBeans IDE, Vectors are recognized by the hint infrastructure and you are given a tip that you have an "Obsolete Collection".
However, that's not the only thing I see when I click on the lightbulb next to the Vector declaration above (i.e., the 2nd lightbulb above, the first is there because an @Override could be added):
Wow... NetBeans IDE offers to rewrite my Vector to a List. So, I press Enter and the conversion is done for me. Then I click the next lightbulb, i.e., because "addElement" applies to a Vector, but not to a List, and I see this:
OK. Thanks for the suggestion NetBeans IDE and so I press Enter again. And now the changes are as follows:
Nice, right? And how is this done? Because I created the folder/file structure that you see below, i.e., look at META-INF.upgrade, with its content, i.e., a plain file ending in ".hint":
In that file, I have provided a piece of NetBeans Inspection Syntax. It tells the IDE what kind of code structures to look for and how to transform them.
The above syntax is definitely suboptimal, I don't understand it all yet, but it works. I learnt the basics this afternoon from NetBeans engineer Jan Lahoda at the NetBeans booth at JavaOne. The above is similar to or based on Jackpot Rules. It is not intended to be used in the way shown above, since there is a special GUI for the above in the "Inspect & Transform" dialog, hence you're able to apply the above rule to a scope of your choosing, i.e., I'm able to find all the above Vector structures throughout the music application and transform them, which is something that the related NetBeans standard hint doesn't let me do. But, though it's not the way you will optimally provide these rules, it's interesting to see this underlying functionality and how effective it can be.