Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Consistent renaming of fields in eclipse

When refactoring a field, the default behaviour in eclipse is to rename just the field, leaving accessor methods with inconsistent names.

Pressing Alt+Shift+R twice shows a "Renaming dialog" where I can select if accessors should be renamed as well (as two separate options). This eases the pain of manually renaming the accessors, but is still quite suboptimal, involving pressing 3 more shortcuts than with the in-place renaming, plus my usual forgetfulness... :)

I cannot think of a reason why I would NOT like my refactoring to be consistent, so is there a way to make accessor renaming the default behaviour? I'm OK with tweaking cryptic settings and setting obscure flags as long as it works.

Thank you

like image 359
kostja Avatar asked May 31 '12 09:05

kostja


People also ask

How can I change variable name in all places in Eclipse?

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.

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.

How do I rename a method in Eclipse?

We can rename variables and methods by following these simple steps: Select the element. Right-click the element. Click the Refactor > Rename option.

Can you rename files in Eclipse?

Right click file -> Refactor -> Rename. Show activity on this post. You can rename classes or any file by hitting F2 on the filename in Eclipse. It will ask you if you want to update references.


1 Answers

Just tried that in Eclipse 3.6 Helios (but I remember it works in Eclipse 3.4 and 3.5 and probably even earlier)

A single Alt-Shift-R rename in the editor, once ENTER is pressed, will change the method name of corresponding getter and setter. The prerequisite is probably you should have once open the Rename Field dialog by pressing Alt-Shift-R twice, and select options in Rename getter and Rename setter. Subsequent rename actions will remember your choice on this.

like image 111
Adrian Shum Avatar answered Oct 01 '22 17:10

Adrian Shum