I am fairly new to Xtext, and am trying to write a unit test to assert that an error occurs in deliberately bad syntax. I'm not exactly sure how to pass the second (EClass) argument to the function call. Can anyone post an example and explain how to specify a value for this argument?
Jan Koehnlein Messages: 733 Registered: July 2009 Location: Hamburg
In Xtext, an EClass is the type of an element in your AST. The 'E' stands for Ecore, which offers a bit higher-level description of types than Java.
If you use a generated Ecore model (that's the default), the EClasses are defined by the rules in your grammar, e.g.
generate myEcore "http:..." // will result in an EPackage 'myEcore'
Foo: // will result in an EClass 'Foo'
'foo' name=ID; // will result in an EAttribute 'name'
Will result in an EClass 'Foo' with and EAttribute 'name' of type 'EString'.
Once you run the workflow, the code generator will derive an Ecore model with the EClasses from your grammar. Then it will run the EMF code generator to generate Java classes from the Ecore model.
If you need to access an EClass, e.g. to pass it to the ValidationTestHelper, you find it as a singleton in the generated EPackage class. In our case
If you have an element of the AST in your hands, use