mardi 4 août 2015

Code Model Import for Class with Embedded Enum

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!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire