Bug 15374 - Surround with try/finally action [refactoring]
Summary: Surround with try/finally action [refactoring]
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 2.0   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: investigate
: 64677 (view as bug list)
Depends on:
Blocks:
 
Reported: 2002-05-06 17:15 EDT by Scott Rutledge CLA
Modified: 2004-05-31 14:28 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Scott Rutledge CLA 2002-05-06 17:15:41 EDT
It would be handy to have an action that takes a block of code and wraps it in a try/finally 
clause.

This could be implemented by defining a new template var (say ${code}) that equals 
the block of code that's selected when the template is invoked. This would involve a new way of 
invoking templates: when a block of code is selected and code assist is activated, it shows a list 
of 'wrapping templates' (those with ${code} in it). This would allow for a simple form of user 
definable formatting rules. So a try/finally template would be defined thus:

try {
   
${code}
} finally {
}

Note that the formatter would have to apply the indent before 
${code} to all lines in the code block.

Just an idea. In any case, a try/finally tool would be 
handy.
Comment 1 Erich Gamma CLA 2002-05-07 16:45:33 EDT
to be considered after 2.0
Comment 2 Dirk Baeumer CLA 2002-07-23 13:25:11 EDT
[refactoring]

As an alternative we can provide an action similar to Surround with try/catch.

Consider for 2.1

Comment 3 Scott Rutledge CLA 2002-07-23 13:32:20 EDT
On reflection, that would probably be the best way to go from a UI perspective. However I still like 
my 'wrapping template' idea, but I'll raise a seperate FR for it.
Comment 4 Martin Aeschlimann CLA 2003-04-01 05:45:01 EST
in 2.1 select lines to surround, ctrl + 1 and you will see all templates that
contain the variables ${line_selection}
do, while, try are defined by default , but you can also define your own
surrounding templates.
Comment 5 Dirk Baeumer CLA 2004-05-30 09:12:43 EDT
*** Bug 64677 has been marked as a duplicate of this bug. ***
Comment 6 Wendell Beckwith CLA 2004-05-31 14:28:06 EDT
While this does work (and thanks, since I never used the templates before),
nonetheless there are 2 ways of creating a try/catch block, templates and the
context menu, and since a try/finally block is analogous to a try/catch, I think
this issue warrants similar handling.  Besides not all users are ex/current
vi/emacs users and enjoy the cryptic key bindings.  Some are propbably like me
and use the context menu more than anything else.  This issue should be reopend
and menu item added.