Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Extend EMF classes generated by xText(Extend EMF generated interfaces+classes with an external ECore interface)
Extend EMF classes generated by xText [message #629022] Sun, 26 September 2010 09:23 Go to next message
Jucovschi Constantin is currently offline Jucovschi ConstantinFriend
Messages: 2
Registered: September 2010
Junior Member
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
Re: Extend EMF classes generated by xText [message #629032 is a reply to message #629022] Sun, 26 September 2010 15:09 Go to previous messageGo to next message
Jucovschi Constantin is currently offline Jucovschi ConstantinFriend
Messages: 2
Registered: September 2010
Junior Member
replacing referencedGenModels = "../SemxText/model/semxtext.genmodel" with referencedGenModels = "," Smile gets rid of the "The generated EPackage references ..." error but still generates the Model files Sad how come?.

Re: Extend EMF classes generated by xText [message #629077 is a reply to message #629022] Mon, 27 September 2010 06:39 Go to previous message
Sven Efftinge is currently offline Sven EfftingeFriend
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
Previous Topic:Does XText support opening files outside of workspace?
Next Topic:Updatesite is missing 0.7.2
Goto Forum:
  


Current Time: Thu Apr 18 13:55:50 GMT 2024

Powered by FUDForum. Page generated in 0.02356 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top