Question

I'm using Eclipse 3.something and would like to know if it is possible to create a new method from selecting a block of code? Obviously the method's signature would contain the necessary existing references and we can't return more than one variable from a method.

I have various methods where code related to presentation is mixed with code related to the logic. TY

Was it helpful?

Solution

Source:

The refactorings are Extract Method (Alt-Shift-m) and Extract Local Variable(Alt-Shift-l).

But I'm getting the error messages:

Not all selected statements are enclosed by the same parent statement.

or

The beginning of the selection contains characters that do not belong to a statement.

So some further refactoring is required as mentioned in the original question.

OTHER TIPS

Note: in the upcoming Helios (eclipse3.6), the extract method is enhanced ("is", because it is available since September 2009, in the M1 release):

The Extract Method refactoring now handles selections that contain continue statements. To preserve the semantics of the existing code, the selection needs to include the last statement of the loop. In the extracted method, continue statements are changed to return:

http://archive.eclipse.org/eclipse/downloads/drops/R-3.6-201006080911/images/extract-method-continue.png

For a selection that would need multiple return values in the extracted method, Eclipse now lists the conflicting variables in the error message:

http://archive.eclipse.org/eclipse/downloads/drops/R-3.6-201006080911/images/extract-method-multiple-return-values.png

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top