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.

Advertisements
This entry was posted in Uncategorized by Manuel. Bookmark the permalink.

One thought on “Eclipse JDT Templates

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