for IntelliJ IDEA

Compatible with:  IntelliJ IDEA Android Studio
9 010

Adds an option to generate a copy constructor to the generate menu (alt + ins).

The action will generate a copy constructor taking an instance of the same class and copying over every field. If there is a copy constructor available in the superclass it will be called as well.

Also adds a number of inspections that generate warnings if a copy constructor might be faulty (e.g. not all fields copied or superclass constructor not invoked).

Download plugin

Johann, any reason why you decided to approach this problem using direct attribute access instead of getters and setters? Getters and setters would better apply to a deep copy scenario, as well as be better protected for use as DAO's and EJB. I am nearly finished implementing something similar for a single class inspection using groovy for live templates, but it would probably serve you better to approach this using accessors, rather than direct attribute access.
Great, but give false "Suspicioud assingment" warnings (which I'd like to turn off in some settings [not by annotations]), for lists or using new Constructor(other.objectToCloneByConstructor). Great works with immutables strings, integers etc. But poorly with other elements/collections (need some polishing), but saved me some time anyway. Thanks.
Copies over private static final fields as well. This is an issue.
Please  sign in  to leave a comment.