Community
Participate
Working Groups
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?
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.
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(); } }
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.
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.