Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

proper support for creating internal classes (within methods) with the intercession API #776

Closed
monperrus opened this issue Aug 8, 2016 · 2 comments

Comments

@monperrus
Copy link
Collaborator

possible bug reported on stackoverflow

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.

@monperrus
Copy link
Collaborator Author

One possible solution is to prefix the internal class name by a digit. Does this work?

@monperrus
Copy link
Collaborator Author

  • internal CtClass getQualifiedName.getDeclaration() OK
  • internal CtClass getReference.getDeclaration() OK
  • internal CtClass getReference().getDeclaration() OK
  • constructor to internal CtClass OK

@monperrus monperrus changed the title fully qualified name with internal classes proper support for creating internal classes (within methods) with the intercession API Aug 25, 2016
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant