If you are used to heavily editing XML files in NetBeans, you would have wished for the code completion assistance to be a bit smarter. As an example, let us take the case of editing a Spring Framework Beans Configuration file. I want to add an <alias> tag to the XML configuration file. This tag has two required attributes: name and alias. It all starts by invoking the code completion assistance by typing in '<'. The following dialog shows up:
When I select the alias tag and hit Enter, the completion assistance just puts in the tag name:
To insert the attributes I have to again press CTRL + SPACE:
If the code completion were a bit smarter, it would insert the required attributes as well. I mean, why will anyone use a tag without using the required attributes? Anyway, NetBeans doesn't offer this feature, so I decided to do some hacking.
I downloaded the NetBeans sources and opened up the module project for the Schema based code completion in NetBeans (NB_SRC_ROOT/xml/schema/completion)
The items displayed in the completion assistance popup are implemented in ElementResultItem.java and AttributeResultItem.java. Since I want additional text to be added when the user wants to add a new XML tag (element), I will modify the ElementResultItem.java. I modified the constructors of the class to add the additional text:
I needed to override a method to return the new text to the completion infrastructure.
That's it. Now I built NetBeans, and run the same scenario for code completion, and here's what I see:
Notice the required attributes appearing alongwith the end tag (another nifty thing which the current XML code completion misses). Now pressing Enter gives me the tag complete with it's required attributes and end tag.
The hack still needs some work, but you can see the point. If there is something you want in NetBeans, just dig through the sources and modify it and contribute it back to the community. This in my mind is the single most advantage of using an Open Source tool.