Eclipse Code Template

Eclipse's Java editor allows you to define code templates. You can use them to code complete things that you type all the time, such as get logger, logger.debug, etc.

Go to Windows->Preferences->Java->Editor->Templates , and put in the following templates


private static final Log logger =
LogFactory.getLog( ${enclosing_type}.class );


if (logger.isDebugEnabled()) {
logger.debug(${Message}, ${exception});


logger.error(${Message}, ${exception});

name:info${Message}, ${exception});


logger.warn(${Message}, ${exception});


private static final ${type} ${name} = new ${type} ${cursor};

After you have these templates setup, type the first few characters of the template name and hit ctrl-space, the editor will code complete the template. For example, type getlog, ctrl-space, and enter will declare a logger variable named logger