I need to generate Java enums via DSL, using xtend 2.5. My grammar looks something like this:
grammar de.mytest.xtext.enumdsl.EnumDsl with org.eclipse.xtext.xbase.annotations.XbaseWithAnnotations
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
import "http://www.eclipse.org/xtext/xbase/Xbase" as xbase
EnumModel:
pckg=EnumPackage;
EnumPackage:
{EnumPackage}
importSection=XImportSection?
'package' name=QualifiedName '{'
(enums+=MyEnum)*
'}';
MyEnum:
'enum' name=ValidID '{' (items+=ValidID)* '}';
With this grammar the DSL could look like this:
package de.mytest.enumpackage {
enum MyEnumTest {
YES
NO
MAYBE
}
}
The resulting Java enum expected would be:
package de.mytest.enumpackage;
public enum MyEnumTest {
YES,
NO,
MAYBE
}
I tried to use implement the xtend method infer() using toEnumerateType(), but without success. Also I couldn't find any examples for that! My google-fu doesn't seem to be good enough!
Using toEnumerateLiteral(), which also works inside toClass(), but it generates a class obviously...
Do you have any ideas?
Thanks in advance, Michael