Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

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

Open
glassfishrobot opened this issue Oct 26, 2014 · 4 comments

Comments

@glassfishrobot
Copy link
Contributor

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
Copy link
Contributor Author

Reported by unrh265h

@glassfishrobot
Copy link
Contributor Author

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
Copy link
Contributor Author

phax said:
This was fixed by phax/jcodemodel#41

@glassfishrobot
Copy link
Contributor Author

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant