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
Last modified: Sep 21, 2016. Refactoring is the process of modifying code without altering its behavior and meaning. We do refactoring to make code more understandable, easier to maintain or modify, or to bring it into conformance with our coding organizations standards.
In Eclipse, go to Windows -> Preference -> Java -> Formatter. In Active Profile drop down box, select any profile, click Edit on right of it.
To rename all uses of this msg variable, highlight the variable and select Refactor→ Rename, or right-click the variable and select Refactor→ Rename, opening the dialog shown in Figure 4-1.
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.
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:
For a selection that would need multiple return values in the extracted method, Eclipse now lists the conflicting variables in the error message:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With