Generate clone() plugin for Eclipse
This plugin consists of two parts:
- An Eclipse builder that detects four different code smells w.r.t.
cloning:
- Returning null from
clone()
- Never calling super.clone().
- Implementing clone() but not Clooneable or vice versa.
- In a Java 5 project, not using the covariant return type for
clone().
- A code generator very similar in style to "generate
hashCode()/equals()" that allows to generate correct clone methods with
selective deep copy of fields that have as declared type a reference
type that also implements Cloneable.
Documentation
Two kinds of informal documentation exist:
- Project report, commenting on design
decisions and a case study which this plugin was applied to. (This
plugin was developed as acourse project for COMP
762.)
- Presentation slides with similar
content.
(PPT)
Installation via update site
Point Eclipse to this URL: http://www.sable.mcgill.ca/~ebodde/genclone/
Usage
To use the plugin, install it as usual and then simply right click on
any Java project and click on Enable/disable
checking of clone(). The builder will then check for wrong
implementations of clone() during the next build process. Generated
warnings can be fixed via quick fixes. Alternatively, you can also
right-click on any type and have a clone() method generated for you.
Integration into JDT
I am currently
discussion integration of this plugin into the main Eclipse build
stream. If you support this idea, you might want to vote for
it here.
Screen shots
Builder

Code generation dialog
