Need to refactor field names in eclipse which should change getters/setters as well
I need to do lot of refactoring (actually need to change field names) in eclipse. It is changing all occurrences, references of fields. But one thing is it is not changing getter/setter names which have been generate开发者_开发技巧d based on previous name.
Do we have any plugin to do this or any configuration change needed to be done?
Yes, in Galileo the "rename" dialog has an option for changing the setters and getters of a field - see here. (Alternatively, you can use ALT + SHIFT + R
twice after selecting the field)
Before Galileo, you'd have to do 3 actions instead of one (not that bad)
ALT+SHIFT+R is the default keyboard shortcut for renaming ... it's awesome!
There is no real necessity for 'getters' and 'setters' to have the same name as the internal field. In fact many would argue that linking the two together is a violation of the data hiding principles of object oriented programming. Part of the point of having getters and setters is to protect the rest of the code from changes that are internal to the class, like renaming.
Having said that, if you absolutely decide that you need to rename the methods as well as the fields, then Eclipse will do it for you. You have to do them separately, but the same 'rename' that you are using for renaming fields works for methods. Just select the method and do what you did before.
Step-1 Go to Package Explorer
Step-2 Move to the field name which is to be renamed
Step-3 Press F2. A rename dialog box will appear
Step-4 Tick mark checkboxes to rename getter and setter too. Click OK.
You're done.
精彩评论