jaxb-codemodel icon indicating copy to clipboard operation
jaxb-codemodel copied to clipboard

error: an enum switch case label must be the unqualified name of an enumeration constant

Open glassfishrobot opened this issue 11 years ago • 4 comments

the code generator uses qualified enum constant refs in switch-case constructs. I'll add a test case.

error: an enum switch case label must be the unqualified name of an enumeration constant case MyEnumWithValuesButWithoutConstructor._50 :

Affected Versions

[2.6]

glassfishrobot avatar Oct 26 '14 16:10 glassfishrobot

Reported by unrh265h

glassfishrobot avatar Oct 26 '14 16:10 glassfishrobot

unrh265h said:

@Test
    public void testEnumSwitch() throws Exception {
        JCodeModel cm = new JCodeModel();
        JDefinedClass cls = cm.rootPackage()._class(JMod.PUBLIC, "EnumSwitch", ClassType.ENUM);

        JMethod toStringMethod = cls.method(JMod.PUBLIC, String.class, "toString");
        toStringMethod.annotate(Override.class);
        JSwitch sw = toStringMethod.body()._switch(JExpr._this());

        String enumConstName = "AA";
        JEnumConstant enumConst = cls.enumConstant(enumConstName);
        JCase cse = sw._case(enumConst);

        ByteArrayOutputStream baos = new AccessibleByteArrayOutputStream();
        cm.build(new SingleStreamCodeWriter(baos));

        assertTrue(baos.toString().contains("case AA:"));
    }

glassfishrobot avatar Oct 26 '14 16:10 glassfishrobot

phax said: This was fixed by https://github.com/phax/jcodemodel/issues/41

glassfishrobot avatar Apr 21 '16 09:04 glassfishrobot

This issue was imported from java.net JIRA CODEMODEL-25

glassfishrobot avatar Apr 24 '17 07:04 glassfishrobot