Eclipse how to refactor variable names?
Solution 1
If you are on windows/ubuntu platform use alt+shift+R
or on mac use command+option+r
. It will refactor all the occurences where that variable is used.
To get the list of shortcuts available in eclipse, use ctrl+shift+L
in windows/ubuntu and command+shift+l
in mac.
Solution 2
You can Also Press Alt+Shift+R in Eclipse to refactor on variable.
Solution 3
No plugins needed, rightclick on the variable name, then "refactor" -> "rename". However, never tried before, I don't know how reliable it is among the whole project.
Solution 4
In Eclipse Neon, I do the following to rename a variable across the project:
- Go to
Search->File...
- Enter the name of the variable in
Containing text:
- Click
Replace...
which is located at the bottom of the dialog box. - A new dialog box opens. There, put the variable name you want to replace with in
With...
labelled text box. - To preview, where the changes will be reflected, click on
Preview >
- Once, you are sure, click
OK
.
Hope this helps!
Solution 5
Refactor within a file: Use Alt+Shift+R
Refactor within multiple files: Use Alt+Shift+R two times (To make it simple, hold Alt+Shift and press R two times).
This behaviour works with Eclipse Oxygen, Windows.
Version: Oxygen.3a Release (4.7.3a)
Build id: 20180405-1200
Ben
Updated on July 15, 2022Comments
-
Ben almost 2 years
In my 15 years old java project, Standard Java Conventions are not respected, and first letter of variable names is often capitalized.
I would like to refactor my project to lower case first letter of variables names, especially in method signatures :
public void creerProfil(String CodeProfil, Profil ProfilACreer) throws Exception { ... }
should be :
public void creerProfil(String codeProfil, Profil profilACreer) throws Exception { ... }
If you have any idea of plugin which could do that, I would be glad to hear it :)