Bug 21156 - [move method] Move methed from inner to outer class
Summary: [move method] Move methed from inner to outer class
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 2.0   Edit
Hardware: All All
: P3 enhancement with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-07-01 03:16 EDT by Konstantin Scheglov CLA
Modified: 2008-12-01 10:12 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Konstantin Scheglov CLA 2002-07-01 03:16:19 EDT
I have entered some code inside anonymouse class for event handling.
  Now decide extract all code from method to main class, but because it 
contains returns, refactoring fails. Can you change this behavior so that if I 
extract ALL code from method it should not check this?
Comment 1 Dirk Baeumer CLA 2002-07-29 06:43:12 EDT
I am not sure if I understand your request correctly. You want to move code 
from an anonymous class to an outer class. If so, this can't be done by extract 
method. Extract method always places the method into the same class. And I 
can't think of a case where you try to extract all code from a method body that 
this can't be done due to return statements. This can only happen if your code 
isn't correct (e.g contains compile errors).

Can you please provide more info.
Comment 2 Konstantin Scheglov CLA 2002-07-29 07:01:25 EDT
  I really wont to extract method outside of inner class, and I understand that 
this is currently not possible. However I think, that it would be usefull to 
have such feature, because this assists in SWT programming style. ;-)
  But problem of course is not in this.
  Look in code.
  When I select code
				if (e.time > 100)
					return;
				System.out.println("test");
and try to extract methods it complains about "returns" and flow. But if I 
add "return" directly after stdo it works.

package ru.nlmk.test.extract_method_with_returns;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.widgets.Text;
public class Test {
	public void run() {
		Text text = new Text(null, SWT.NONE);
		text.addControlListener(new ControlAdapter() {
			public void controlResized(ControlEvent e) {
				if (e.time > 100)
					return;
				System.out.println("test");
			}
		});
	}
	public static void main(String[] args) {
		(new Test()).run();
	}
}
Comment 3 Dirk Baeumer CLA 2002-07-29 13:21:04 EDT
You are correct and there is already a bug for it bug 15442. The other request 
is more Move method to outer class. I adapted the title accordingly.
Comment 4 Dirk Baeumer CLA 2003-02-06 12:14:14 EST
The issue with the return statement got addressed for M5.

Now that we have move method for some cases we should think about supporting 
this case as well.