问题
Is there any way to automatically rename accessor/mutator when a variable they get/set gets refactored -> renamed (Eclipse 3.4)?
回答1:
1 - When you select Refactor->Rename on a variable, Eclipse prompts you to enter the new name in an "in-line" box. Directly below it, there is a help message and next to it a small icon (an arrow going down).Click on that arrow and then select "Open Rename Dialog". A new pop-up appears with the checkboxes you need.
2 - Alternatively, select the variable you want to change and press twice Alt+Shift+R. Again check the getter/setter checkboxes.
回答2:
By default eclipse will not rename getters and setters when using 'inline' renaming of a variable. However you can change this behaviour by using the 'Rename Field' dialog for a rename once, and selecting 'Rename getter' and 'Rename setter'. (see the answer by idrosid for details only how to open this window).
After this the 'inline' renames will also update the getter and setter for that field (but not the parameter in the setter).
Note, I have tested this with Eclipse 4.5
来源:https://stackoverflow.com/questions/197123/renaming-accessor-mutator-methods-in-eclipse