More (powerful) Code Templates in 6.9
In NetBeans there are some useful Code Templates, like “sout” which, when you type it in the editor and hit “Tab” will be expanded to “System.out.println();”. But you’re not limited to the predefined ones, you can also create your own templates. I’ve been playing around with Code Templates recently and was a bit disappointed, because the avaiable set of default parameters is quite limited. E.g. I tried to add some nice templates for logging, and I was missing a way to get hold of the class name of the current file. As a workaround I did something like:
java.util.logging.Logger.getLogger(getClass()”getName()).log(java.util.logging.Level.INFO}, “${cursor}”);
Today I asked on the list if there is no other way, and I received an answer by Michel Graciano that there are a couple of Templates related to Logging that add the class name. I replied that I had looked at every single Template and none of them is related to Logging, when he said he uses 6.9 M1. And there it is, shortcut “log”:
${loggerType type=”java.util.logging.Logger” default=”Logger” editable=”false”}.getLogger(${classVar editable=”false” currClassName default=”getClass()”}.class.getName()).log(${levelType type=”java.util.logging.Level” editable=”false” default=”Level”}.${logLevel default=”INFO” completionInvoke}, “${message}”);
“currClassname” adds the functionality I’ve been missing. ( Actually I think default=”getClass()” doesn’t make much sense, because it would be expanded to “…getClass().class.getName()..” (?) ). There’s also “loge” for logging errors and “logp” for logging with parameters… Thanks Michel!



Wow, you are welcome! The code template feature is really powerful but a reference with which parameters are available still is necessary. BTW, thanks to share you experience.
Comment by Michel Graciano
— 24. March 2010 @ 20:41
I agree, there’s a lack of documentation, but I heard documentatin team is aware of it. I also played around with the macro language and didn’t find a good reference. The keyboard-shortcuts page has some (hidden) information, and there’s an outdated inofficial list with commands. I’ve started putting together a table with macro commands. It’s fun, because you can simply guess many of them :-). When I’m ready I’ll create a ref-card to post it here.
Comment by Toni
— 25. March 2010 @ 07:44
Really GREAT news! I’ve been missing this kind of “shortcuts” since we moved, from JBuilder, to Netbeans a couple of years back.
Comment by RGV
— 26. March 2010 @ 12:34