Bug 115233 - [quick fix] offer to move declaration to visible scope
Summary: [quick fix] offer to move declaration to visible scope
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.2   Edit
Hardware: PC Linux-GTK
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-11-06 06:58 EST by Tom Hofmann CLA
Modified: 2009-01-23 11:34 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tom Hofmann CLA 2005-11-06 06:58:57 EST
3.2. M3

I often find myself in a situation similar to the following example (| caret
location):

	int foo() {
		try {
			int value= compute();
		} catch (Exception e) {
		}
		return value;|
	}

This is especially true after using the "surround with" template which does not
split the variable declaration like the "surround with try/catch" quick fix. But
even with the latter, if I add the return statement after adding the exception
handler, 'value' is out of scope.

Current flow:
- move to the declaration of the local var
- quick assist: split declaration
- move declaration to outer scope
- intialize the variable, either to a default value at the declaration, or to an
error value within the catch block

Enhancement: 
- quick fix "move variable declaration to outer scope" which does steps 1-3 from
above.
- for the initialization, I would suggest moving the caret to the declaration so
that I can add an initializer. Not sure though. Adding an initializer in the
catch block is probably not the right thing, also because there may be more than
one catch block etc.

Expected result (|== caret location, ¦ caret exit position):

	int foo() {
		int value|;
		try {
			value= compute();
		} catch (Exception e) {
		}
		return value;¦
	}