I am using the code model API to generate java source files. I have an enum defined through codemodel API and I want to use that in a switch block. In a switch statement, the enum constants should be used as unqualified. I have trouble in accessing the unqualified name of the enum constants, as cod开发者_StackOverflow社区e model API qualifies the constants with the enum class name.
In short, I want to generate the following code fragment using codemodel APIs.
enum MyEnum {A,B};
MyEnum m = MyEnum.A;
switch (m){
case A:
//do something
case B:
//d0 something else
}
but codemodel generates like this
enum MyEnum {A,B};
MyEnum m = MyEnum.A;
switch (m){
case MyEnum.A:
//do something
case MyEnum.B:
//d0 something else
}
Appreciate your help.
JExpr.ref("A")
gives a direct reference to the enum constant.
精彩评论