Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Manipulating the model in Xtext
Manipulating the model in Xtext [message #663743] Wed, 06 April 2011 07:33 Go to next message
Eclipse UserFriend
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 09:14 Go to previous messageGo to next message
Eclipse UserFriend
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 13:02 Go to previous messageGo to next message
Eclipse UserFriend
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 14:37 Go to previous messageGo to next message
Eclipse UserFriend
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 14:38] by Moderator

Re: Manipulating the model in Xtext [message #663910 is a reply to message #663900] Wed, 06 April 2011 15:08 Go to previous message
Eclipse UserFriend
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: Fri Jul 04 20:29:38 EDT 2025

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

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

Back to the top