Create a new method to select an existing code block, Eclipse

I am using Eclipse 3.something and would like to know if it is possible to create a new method to select a block of code? Obviously, the signature of the method will contain the necessary existing references, and we will not be able to return more than one variable from the method.

I have various methods when the code associated with a view is mixed with code related to logic. Ty

+7
methods eclipse refactoring
source share
2 answers

Source :

Refactoring is the extraction method ( Alt - Shift - m ) and extract the local Variable ( Alt - Shift - l ).

But I get error messages:

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

or

The beginning of the selection contains characters that are not related to the expression.

Thus, repeated refactoring is required, as indicated in the original question.

+8
source share

Note: in the upcoming helios (eclipse3.6), the extract ("is" method has been expanded since it has been available since September 2009, in the M1 release):

Extract method refactoring now processes selections containing continue statements. To preserve the semantics of existing code, the selection must include the last loop statement. In the extracted method, continue statements are modified to return:

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

For a selection that requires 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

+2
source share

All Articles