Geertjan's Blog

  • June 27, 2007

Code Template Registration

Geertjan Wielenga
Product Manager
In the last day or so, Girish Patil, the engineer responsible for the (brand new!) JAXB tooling in NetBeans IDE 6.0, integrated some handy code templates. If you type 'jaxbm' in the editor, and you then press Tab to expand the abbreviation, a snippet of JAXB marshalling code is generated, with some of the variables automatically filled in, based on the code available around the invocation of the template. Similarly, when you type 'jaxbu', you'll get a snippet of JAXB unmarshalling code.

So, apart from playing with that a bit and adding it to a (brand new!) tutorial that will describe all of this, I asked him how he registered these code templates. That's something I've never done. It turns out that you simply need to create an XML file that conforms to the EditorCodeTemplates-1_0.dtd. Then, drop that in the MIME type's layer folder in Editors/MIME-type/CodeTemplates. And then you're done! Here you see Girish's XML file and also where he put it in the Java MIME type's CodeTemplates folder:

Wow, that's easy. Now I can create others, stick them in a module, and distribute them to whoever wants them. In particular, registering code templates is a small yet powerful thing in support of some other larger feature, such as the JAXB tooling that Girish is working on. So... let's now all go out there and create some cool new code templates!

Join the discussion

Comments ( 2 )
  • Tor Norbye Thursday, June 28, 2007
    Another (in my opinion easier) approach is to use the Code Template editing functionality in the Options dialog (see Code Templates there). You get syntax highlighting etc. as you're editing your code snippet. When you're done save, and you can then grab the XML file from within your userdir (look under config/Editors/\*\*) and paste the relevant XML into your own module for distribution.
    (I then do some manual transformations to change the abbreviation description from an inlined element to a bundle lookup)
  • raveman Thursday, June 28, 2007
    nice :)
    as far as templates goes, is it still impossible to write template like
    foreach($method_parameter) do
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.