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

Missing qualification for inner classes in generic parameters of anonymous classes #84

Closed
fbaro opened this issue Jan 30, 2020 · 4 comments
Assignees

Comments

@fbaro
Copy link
Contributor

fbaro commented Jan 30, 2020

I'm creating a class, called Outer, and an inner class inside it, called Inner.

I'm then using the inner class as a generic parameter of an anonymous class in another class in the same package.

The result is that in the generic parameter the inner class is written unqualified and not imported, resulting in a compile error.

Here is an example code

        JCodeModel cm = new JCodeModel();

        JDefinedClass outerClass = cm._class("test.Outer");
        JDefinedClass innerClass = outerClass._class("Inner");

        JDefinedClass testClass = cm._class("test.Test");
        JAnonymousClass anonymousClass = cm.anonymousClass(cm.ref(List.class).narrow(innerClass));
        testClass.field(0, cm.ref(List.class).narrow(innerClass), "field", JExpr._new(anonymousClass));

And this is the result

package test;

import java.util.List;

public class Test {
    List<Outer.Inner> field = new List<Inner>() {
    }
    ;
}

The declaration List<Outer.Inner> field is correct, but the instantiation new List<Inner> is not.

@phax phax self-assigned this Jan 30, 2020
@phax phax added the bug label Jan 30, 2020
@fbaro
Copy link
Contributor Author

fbaro commented Jan 30, 2020

I think I have a suggestion for a fix.
Inside JAnonymousClass the generate method should be

@Override
  public void generate (final IJFormatter f)
  {
    m_aBaseClass.generate(f);
  }

instead of f.type (m_aBaseClass);

@phax
Copy link
Owner

phax commented Jan 30, 2020

Thanks for the suggestion - will check later. Working on sthg else atm.

@stale
Copy link

stale bot commented Apr 29, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Apr 29, 2020
@phax phax added pinned and removed wontfix labels Apr 29, 2020
@phax phax closed this as completed in 78aa846 May 25, 2020
@phax
Copy link
Owner

phax commented May 25, 2020

Part of 3.4.0 release

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

No branches or pull requests

2 participants