views:

72

answers:

1

I have begun using Eclipse code templates and am loving 'em! But for existing code they are a bit hard to use. This is easiest with an example.

I have a pre-existing bit of code and I want to wrap it in a try-catch block. Currently I create the try-catch block from the template and then cut-paste the code I want inside the try block.

What I want is a way to cut the code and have it insert inside the try template automatically, i.e. using something like a {clipboard} tag inside the template code. Is there a way to accomplish this in Eclipse?

A: 

You can use a variable of type "Selection". Create the template code then go to the Variables tab and change your variable's type.

To use, select the code that will be the body of the try-block. Hit ctrl-enter. Select template.

The template code would look something like:

try
  $sel$
catch (exception e) {
  // TODO blah
}
GinoA