Renaming accessor/mutator methods in Eclipse?

倾然丶 夕夏残阳落幕 提交于 2019-12-19 05:33:59

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!