Rapster
Rapster

Reputation: 524

How to duplicate a class with Spoon?

My requirement is as such: I have a class (a.b.C1) contained in 3rd party library which I want to duplicate so I can make modifications and result into x.y.C2. In a few words, I need to make x.y.C2 inherits a.b.C1 and strip down few methods, and change visibilities.

As I stumbled on lot of "issues" (certainly due to my lack of knowleges on this topic). What I do is: create class x.y.C2 and copy one by one fields/methods/nested types. The problem doing that, is when I copy a method having statements containing a nested type, the statement will contain references to the nested type I'm copying the nested from (a.b.C1.N) instead of (x.y.C1.N)

First, is there a way to make this more straightforward? Ideally, I'd like to duplicate the class into new package (x.y) and make sure nested types will references this new class

Upvotes: 1

Views: 42

Answers (1)

Martin Monperrus
Martin Monperrus

Reputation: 2051

Use the clone() method.

aCtClass.clone()

Upvotes: 0

Related Questions