Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert a method's local variable or expression to a method parameter using Eclipse?

How do I convert a method's local variable or expression into a method parameter using Eclipse's built-in refactoring tools?

like image 877
zachary Avatar asked May 23 '10 19:05

zachary


People also ask

How do I refactor a method in Eclipse?

Changing a Method Signature Select the method or place the cursor somewhere inside. Right-click and choose Refactor > Change Method Signature.

What does refactor do in Eclipse?

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.

How do I change all references in Eclipse?

Eclipse makes this absurdly easy to do. Right-click on almost anything and choose Refactor > Rename. Type in a new name for whatever it is, and make sure that the Update References checkbox is checked. This will ensure that all references in all of your code will be updated.

How do I use refractor in Eclipse?

Refactoring using EclipseRight clicking on a Java element in the Package Explorer view and selecting Refactor menu item. Right clicking on a Java element in the Java editor and selecting Refactor menu item. Selecting a Java element in either the Package Explorer view or Java Editor and clicking Shift + Alt + T.


2 Answers

You can use the "Introduce Parameter" option on the Refactor.. submenu when you right-click.

You'll need to select an expression, such as the expression used to initialise the local variable, for this to work.

like image 72
chrisbunney Avatar answered Oct 06 '22 17:10

chrisbunney


If you remove the declaration of your local variable, the places you used that variable will no longer compile. You can then choose "Add parameter" from the quick fix menu (Ctrl-1 I think, don't have Eclipse open now).

like image 36
Jorn Avatar answered Oct 06 '22 17:10

Jorn