Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Spoon doesn't support generating local classes within methods #786

Closed
lukemerrick opened this issue Aug 15, 2016 · 4 comments
Closed

Spoon doesn't support generating local classes within methods #786

lukemerrick opened this issue Aug 15, 2016 · 4 comments

Comments

@lukemerrick
Copy link
Contributor

Although it's not usually best practice to do so, it is legal in Java to declare a class InnerClass as such:

class MainClass {
    public foo () {
        class InnerClass {}
        // method body that initializes and uses objects of type InnerClass
    }
}

However, when generating a CtClass object via the Core() factory, the type seems to default to MainClass.InnerClass which is incorrect if InnerClass is inserted into the method foo. The create method of the Class() factory (meant to create inner classes) also requires a declaring class and thus also only seems to support code of the structure:

class MainClass {
    class InnerClass {}
    public foo () {
        // method body
    }
}
@tdurieux
Copy link
Collaborator

It's related to #776.
Unfortunatelly, we don't yet a valid solution for this issue

@monperrus
Copy link
Collaborator

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

@monperrus
Copy link
Collaborator

by the way, should you find a fix for this problem, a pull request would be welcome

@monperrus
Copy link
Collaborator

closing this one, #776 is the reference issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants