Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Renaming a lot of variables in many Java classes at once

Tags:

java

I work in a pretty large Java-project (2500+ classes) that uses an old code standard where all member variables are prefixed with "m_" (e.g m_temperature). There is really no reason for this any longer and I'd like to get rid of them but:

  1. In order to make the change I must do all variables at once.
  2. It must not generate any bugs.

The first naive approach of simply renaming all the "m_variable" to just "variable" will not be sufficient as that could produce name collisions between an already existing variable named "variable", and the newly renamed one.

So, to sum up: How do I rename all these pesky member variablest without getting into trouble and are there any more problems than the one mentioned above?

Yes, I'm aware of the refactoring/renaming features within IDEs, please bear in mind that I want to do the changes to all variables matching the criteria at once and not by right-clicking on variables and renaming them one-by-one.

like image 540
tommys Avatar asked Feb 16 '12 09:02

tommys


People also ask

How do I change the variable name at a time in eclipse?

Solution. Select the element in the JDT editor and then select Refactor→ Rename, or right-click the element and select Refactor→ Rename. Enter the new name you want to give the item, and you're set.

How do you change multiple variable names at once?

Place the cursor inside a variable you want to rename and press Ctrl + R . Then type other name and editor will change all occurrences of that variable.

How do I change multiple variable names in eclipse?

Highlight and right click on the variable you want to rename. Navigate to Refactor and select Rename.... Type in your new variable name and press Enter.


1 Answers

How about below from : mass renaming of java variables

by Simulant

click on the variable name.

1:press [alt] + [shift] + [R]

2:enter the new name.

3:press [enter] to confirm.

-->all instances of this variable will be renamed.

like image 189
smwikipedia Avatar answered Oct 01 '22 19:10

smwikipedia