Over a million developers have joined DZone.

More (Powerful) Code Templates in NetBeans IDE 6.9

· Java Zone

Microservices! They are everywhere, or at least, the term is. When should you use a microservice architecture? What factors should be considered when making that decision? Do the benefits outweigh the costs? Why is everyone so excited about them, anyway?  Brought to you in partnership with IBM.

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 available 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}”);

I asked on the maling 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!

Reposted from http://eppleton.sharedhost.de/blog.

Discover how the Watson team is further developing SDKs in Java, Node.js, Python, iOS, and Android to access these services and make programming easy. Brought to you in partnership with IBM.

Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}