|
|
Re: Extend EMF classes generated by xText [message #629077 is a reply to message #629022] |
Mon, 27 September 2010 06:39 |
Sven Efftinge Messages: 1823 Registered: July 2009 |
Senior Member |
|
|
You could have a synthetic (i.e. never called) parser rule, to declare
the inheritance relationship:
MyFoo returns my::SemxTextCore :
Model | Command;
In that case you also need to add an import statement at the top of the
grammar and add the genmodel location to the mwe2 file (see documentation).
Sven
Am 9/26/10 11:24 AM, schrieb Jucovschi Constantin:
> Hi,
>
> I have a xText grammar and I would like to make some of the grammar
> elements which generate an EMF interface+implementation class to inherit
> (and generate implementation) to an interface which is defined in
> another project. For example, I have the grammar:
>
> Model :
> (units+=Unit)*;
> Unit : Command | Options | Words ;
> Words : wordName = ( ID | ANY_OTHER ) ;
> Command : SLASH commandName=(ID | ANY_OTHER | '{' | '}' | '[' | ']' |
> SLASH);
> Options : optionType='{' model=Model '}' | optionType='[' model=Model ']';
> This generates the classes Model, Unit, Words and so on. I would like
> that the Model and Command interfaces extend an interface defined in
> another dependency project (SemxTextCore) ex:
>
> public interface IProps extends EObject {
> EList<String> getProps();
> }
>
> I did the following:
> 1) Created a Xtend Post Processor which contains the function:
> addPropsInterface(EPackage pack, List[String] classesList) :
> let propsClass =
> SemxTextCore::SemxTextCorePackage::eINSTANCE.getEClassifier( "IProps"):
> (
> pack.eClassifiers.typeSelect(EClass).collect(class|
> classesList.contains(class.name) ?
> class.eSuperTypes.add(propsClass) : false
> )
> )
> ;
>
> i.e. it adds the
> SemxTextCore::SemxTextCorePackage::eINSTANCE.getEClassifier( "IProps")
> class to the superclass of the classes I specify.
>
> If I run the generator - it says:
> The generated EPackage references an external EPackage, but
> 'referencedGenModels' hasn't been registered.
>
> the I add:
> referencedGenModels = "../SemxText/model/semxtext.genmodel"
>
> in the MWE2 file and it works fine but generates the model code in the
> current project instead of just referencing the implementation in the
> SemxText project.
> Any idea how to make it generate references instead of creating the
> implementation?
>
> Thanks in advance,
> Constantin
--
Need professional support for Xtext or other Eclipse Modeling technologies?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : http://blog.efftinge.de
|
|
|
Powered by
FUDForum. Page generated in 0.02356 seconds