2.3.5. Code Templates

Many times the type of code written is repetitive. (If you don’t agree, you have not yet heard about design patterns.) Eclipse support many kinds of templates. Higher level templates for files/function. Lower level templates for loops and similar constructs. You can even have your own custom templates.

What makes these templates special, their own inherent intelligence.

e.g. The for loop template:

for (${var} = 0; ${var} < ${max}; ++${var}) {

When a for template is created, you need to enter the var only once. The other two entries (comparison and increment) are filled automatically. Sample — For Loop

Here is an example to introduce for loop over a selection of code.

  1. Select the code block

  2. Press Ctrl + Space. Eclipse would also show a preview of the changes

  3. Eclipse has now put in the template. Note that colored blocks and the cursor mark (Circled for reference)

  4. Type the value for the iterator. (In this case iTest and press TAB

  5. Now you can update value of the MAX limit.