Add some magic to Eclipse

Templatus Expandum! The top feature of the eclipse IDE is the very impressive refactoring possibilities. It makes code feel like play-doh, allowing you to knead it in any shape way or form you think fits the current situation. A close second to that is the impressive templates and code assist. Yes, Java is verbose, but I think 80% of the characters which make up a Java program was never actually typed. All the readability without the labour, brought to you by eclipse's powerful templates.

What many people don't realize is that you can easily add to this magic by creating your own templates. One of the first templates I always add to the environment is the one which adds a private static final log4j logger. I thought it would be great example to share with you.

[sourcecode language="java" gutter="false"] ${imp:import(org.apache.log4j.Logger)} private static final Logger LOG = Logger.getLogger(${enclosing_type}.class); [/sourcecode]

You can add and change existing templates in Eclipse -> Preferences -> Java -> Editor -> Templates. There are other great examples when you scroll through the list, and you can export the templates to a file in your shared SpiderOak folder to have them available on all your machines.

Templates configuration in Eclipse Remember to give your templates an easy name so you can quickly invoke them by code completion. Great examples are the existing "sysout" and "foreach" templates. I called mine "llog" with a double-l because "log" collides with too many other code completion possibilities.

Experiment and enjoy your increased productivity.