I've been working on a processor that injects an inner class inside a method, and I'm having a lot of trouble figuring out just how to generate the class and accompanying object initialization without incurring auto-generation of an incorrect fully-qualified name.
For example, I've been processing stuff like: I've been making a new class:
CtClass internal = getFactory().Core().createClass();
and then inserting it before an element within a method
element.insertBefore(internal);
but when I make an initialization statement:
CtConstructorCall call = getFactory().Core().createConstructorCall();
call.setType(internal);
internal.insertAfter(call);
I get a call that looks like:
Main.internal initializedInternalObject = new Main.internal();
Where Main
is the name of the overall class that everything is inside, even though internal
is declared only inside a specific method. I've tried using getFactory().Class().create() method for internal classes, but that method only seems to be targeted toward classes nested within classes, as opposed to classes delcared within methods.
Am I doing something wrong with the class declaration? Am I just running into a limitation of spoon's ability to generate internal classes? Any suggestions?
Thanks everyone!