Eclipse templates for auto code generation

Working with an IDE tends to make life quiet simple. However we still do not leverage the full potential of using an IDE like Eclipse. During development, i have found creating a few templates really helps to speed up things. Here are the few most common ones i use which are not part of the standard templates.
1) Log4J Logging
a) Create Logger

${:import(org.apache.log4j.Logger)}
private static final Logger logger = Logger.getLogger(${enclosing_type}.class);

b) LogInfo

logger.info(${word_selection}${});${cursor}

c) LogError

logger.error(${errorMessage}, ${e});

d) LogDebug

if(logger.isDebugEnabled())
logger.debug(${word_selection}${});${cursor}

2) Constants
a) Const

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

3) Map Iteration
a) MapIter

for(Map.Entry entry :
${map:var(java.util.Map)}.entrySet()) {
${key} key = entry.getKey();
${value} value = entry.getValue();
${cursor}
}

4) JUnit
a) Test Creation

public void test${name}() throws Exception {
${cursor}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: