Andrey Tarantsov's Wiki / eclipse / templates
-->  

My JDT templates

These are from Eclipse's Preferences > Java > Editor > Templates.

color

Often needed when debugging SWT layouts.

Display.getDefault().getSystemColor(SWT.${color:link(COLOR_RED,COLOR_GREEN,COLOR_BLUE)})

npe

Bound to npe, allows easy checking of input parameters.

if (${arg:localVar} == null)
    throw new ${exception:link(NullPointerException,IllegalArgumentException)}("${arg:localVar} is null");

toString

@Override
public abstract String toString();

unsup

Again, a great debugging aid (instead of leaving the method empty).

throw new UnsupportedOperationException();

listeners

private transient Listeners<${ListenerType:link}> ${listeners:link} = newListenersByIdentity();

public synchronized void addListener(${ListenerType}  listener) {
    ${listeners}.add(listener);
}${imp2:importStatic(com.yoursway.utils.Listeners.newListenersByIdentity)}

public synchronized void removeListener(${ListenerType} listener) {
    ${listeners}.remove(listener);
}${imp:import(com.yoursway.utils.Listeners)}
${cursor}

fire

for(${ListenerType:elemType(listeners)} ${listener:link} : ${listeners:field(com.yoursway.utils.Listeners)}) ${listener}.${method:link}; ${cursor}

lookup

${return_type} ${result:link} = ${map:field(java.util.Map)}.get(${key:var});
if (${result} == null) {
    ${result} = ${create:link}(${key});
    ${map}.put(${key}, ${result});
}
return ${result};