Refactoring to add and remove new fields

Answered

Stupid question time as I'm starting to wonder if I just dreamed doing this in the past. Is there a way to add a new property to a given class and automatically have the getter & setters created and any equals() and hascode() methods updated? Probally a similar set of changes in reverse for property removal.

PS. Just out of interest has anybody been able to template the creation of PropertyChangeListener bound beans? or for that matter any other binding framework beans.

-      Richard

1
6 comments

I wondered this today as well.

We have a big feature toggle class where removing a field or adding one it could be helpful to have a more automatic way.

0
Hi, perhaps Lombok may help? https://projectlombok.org/features/GetterSetter
With plugin "Lombok" enabled, it should be much easier to control getter and setter.
0

Jerome Guan  Thank you for your advice. But this is a No Go library for me. As it adds complexity add a different level.

0
Understood, thanks for rasing this request. currently there is no available option for automatic way of implementing getter and setter, another way for most of code languages is to use the Generate menu by pressing `Alt`+`Insert` or by navigating to Code → Generate in the menu.
0

For me the most interesting part is rather the removal of related getter/setter as a refactoring option. As generating as you point out is fairly easy with the alt insert method.

0
Yeah removing is not that convenient at current stage. The shortcut `Alt Del` can be used when cursor is placed in the getter and setter method.
0

Please sign in to leave a comment.