Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Manipulating the model in Xtext
Manipulating the model in Xtext [message #663743] Wed, 06 April 2011 11:33 Go to next message
Cedric Moonen is currently offline Cedric MoonenFriend
Messages: 274
Registered: August 2009
Senior Member
Hello,

This is a rather generic question: I was wondering if you could manipulate in some way the model within the grammar definition.

Let's take a very easy example: suppose that in our metamodel we have an EClass called "Entity" which has a name and a data attributes (both EString).

In our Xtext grammar we have a rule like this for the Entity:

Entity:
   'Entity' name=ID;


Now suppose that I automatically want to assign the name of the Entity to the data attribute (so, in the model in memory we will have an entity with the name and data attribute being the same).

Is this possible to modify the grammar rule to do something like that ?

Of course, in the example here it doesn't have a lot of advantages but sometimes it could be useful to be able to manipulate the model in order to automatically fill some parts of it.
Re: Manipulating the model in Xtext [message #663773 is a reply to message #663743] Wed, 06 April 2011 13:14 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

not within the grammar. Usually you would use an imported meta model. Then you can either modify the setters there or hook into the model instantiation.

Alex
Re: Manipulating the model in Xtext [message #663893 is a reply to message #663773] Wed, 06 April 2011 17:02 Go to previous messageGo to next message
Henrik Rentz-Reichert is currently offline Henrik Rentz-ReichertFriend
Messages: 261
Registered: July 2009
Senior Member
Alex is right.

But if you choose to let Xtext derive the ecore meta model then you can modify the resulting meta model using the post process
hook provided by the framework (an Xtend file named <yourDSL>Postprocessor.ext).

You can find an example for setting default values and adding operations in
http://git.eclipse.org/c/etrice/org.eclipse.etrice.git/tree/ plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/ core/RoomPostprocessor.ext

Hope that helps,
Henrik

Am 06.04.2011 15:14, schrieb Alexander Nittka:
> Hi,
>
> not within the grammar. Usually you would use an imported meta model. Then you can either modify the setters there or hook into
> the model instantiation.
> Alex
Re: Manipulating the model in Xtext [message #663900 is a reply to message #663773] Wed, 06 April 2011 18:37 Go to previous messageGo to next message
Johannes Stelzer is currently offline Johannes StelzerFriend
Messages: 30
Registered: October 2009
Member
Alexander Nittka wrote on Wed, 06 April 2011 09:14

... hook into the model instantiation.



Do you mean to customize the PackageFactory or can u tell me how to affect the model creation?

[Updated on: Wed, 06 April 2011 18:38]

Report message to a moderator

Re: Manipulating the model in Xtext [message #663910 is a reply to message #663900] Wed, 06 April 2011 19:08 Go to previous message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

I think one of the recommended ways is to do simple changes during the linking phase (check the methods in AbstractCleaningLinker and the classes extending it).

Alex
Previous Topic:Re: [Xtext2] Extending Xbase expressions
Next Topic:Internationalisation of ecore plugin language variables
Goto Forum:
  


Current Time: Sat Apr 20 04:15:47 GMT 2024

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

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

Back to the top