8

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

2 Answers 2

9

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.