1

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 code 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.

skaffman
  • 398,947
  • 96
  • 818
  • 769
Saravanan M
  • 4,697
  • 5
  • 35
  • 37

1 Answers1

0

JExpr.ref("A") gives a direct reference to the enum constant.

Saravanan M
  • 4,697
  • 5
  • 35
  • 37