Eclipse JDT Templates

Eclipse Java development tool provides default Java templates such as for, syserr, sysout etc … When typing these templates in the Java editor and then pressing ctrl + space JDT insert automatically for you a for loop, a System.err.println(”") or a System.out.println(”"). Nice !!!

These shortcuts are really cool but what about creating our own shortcuts ??

For example as SWT developer we often need to write Display.getCurrent.getSystemColor(SWT.COLOR_XXXX);

Here is (from the JDT online help ) the way to follow to add this template :

To create your own templates, go to the Java > Editor > Templates preference page and press the New button to create a template. For our example, the template would look like this: Display.getCurrent().getSystemColor(SWT.COLOR_${cursor})

Using this feature, you can create all the templates you need !!! The previous sample adds a basic template but you can create complex templates depending on a lot of parameters of the current edited text. There is a lot of default templates provided within the JDT showing how to create complex templates.

More informations are available here.

Leave a Reply