I'm working on generating some Java classes using CodeModel and I'm having some trouble adding import statements for classes that have embedded static Enum
For example if I have a class and create an instance variable...
Class<?> clazz = getPackageClass();
cls.field(JMod.PRIVATE, codeModel._ref(sourceClass), "testUnderlying");
But this creates code like...
import com.test.platform.xxx.UnderlyingType;
....
private UnderlyingType testUnderlying;
However, if UnderlyingType had a enum field that I want to invoke a static method on (e.g. valueOf)...
private UnderlyingType.EnumType enum;
...
...
UnderlyingType.EnumType.valueOf(xxx);
it seems to confuse CodeModel and instead of having a seprate import and the instance variable I will get
private com.test.platform.xxx.UnderlyingType testUnderlying;
Is it possible invoke the static method without losing the import?
Thanks for your help!
There's a comment in the JCodeModel code that mentions why they don't import inner classes:
Not sure what 6431987 is referring to (possibly an internal SUN bug tracker) but here is the referenced jaxb issue:
https://java.net/jira/si/jira.issueviews:issue-html/JAXB-166/JAXB-166.html
Seems they were having trouble with imports from inner classes colliding.
Worth noting, this fork of JCodeModel fixes this issue: https://github.com/UnquietCode/JCodeModel