Eclipse how to refactor variable names?

40,096

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:

  1. Go to Search->File...
  2. Enter the name of the variable in Containing text:
  3. Click Replace... which is located at the bottom of the dialog box.
  4. A new dialog box opens. There, put the variable name you want to replace with in With... labelled text box.
  5. To preview, where the changes will be reflected, click on Preview >
  6. 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

Share:
40,096
Ben
Author by

Ben

Updated on July 15, 2022

Comments

  • Ben
    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 :)