Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » how to augment the user model before generation?
how to augment the user model before generation? [message #1721081] Sat, 23 January 2016 13:51 Go to next message
Rafael Chaves is currently offline Rafael ChavesFriend
Messages: 10
Registered: August 2015
Junior Member
I would like to define implicit elements, elements that are present even if the user did not explicitly define them. Similar to how default constructors are generated in Java when the user does not specify one.

Is there a recommended way to implicitly augment the user model that is given to the generator?

Our DSL for SOA provides the ability for users to model services and their endpoints (commands and events).

There are some endpoints that every service has to contain (for instance, every service must include a serviceStarted event, in addition to whatever events the user defines herself).

I'd like to implicitly augment the user models so, before generation starts, every service always has a serviceStarted event.

A secondary (optional) requirement is that tools loading the model would also see the implicit elements. But a solution that only allowed to augment models before code generation would be sufficient.

As a workaround, I can do that in the validator, or in the generator. The former feels very wrong - it seems validators should be read-only. In the generator, it feels less wacky, however I am unsure whether it is safe to make changes to the model there - for instance:

* is the in-memory model exclusive to the generator (and hence safe to modify)?
* is the in-memory model reloaded after every generation pass (and hence I don't have to worry that I may be creating the same elements twice)?
Re: how to augment the user model before generation? [message #1721084 is a reply to message #1721081] Sat, 23 January 2016 14:11 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Have a look at iderivedstatecomputer

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: how to augment the user model before generation? [message #1721087 is a reply to message #1721084] Sat, 23 January 2016 15:31 Go to previous messageGo to next message
Rafael Chaves is currently offline Rafael ChavesFriend
Messages: 10
Registered: August 2015
Junior Member
Thanks for the quick reply, Christian, never heard of it before.

	/**
	 * is called when the resource is updated. Clients should revert all the changes they did during
	 * {@link #installDerivedState(DerivedStateAwareResource, boolean)}
	 */
	void discardDerivedState(DerivedStateAwareResource resource);


Is implementing discardDerivedState a mandatory requirement? What are the implicaitons of implementing it as a no-op?
Re: how to augment the user model before generation? [message #1721090 is a reply to message #1721087] Sat, 23 January 2016 15:56 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
http://xtextcasts.org/episodes/18-model-optimization

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: how to augment the user model before generation? [message #1721091 is a reply to message #1721090] Sat, 23 January 2016 15:56 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
And yes you should implement it

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: how to augment the user model before generation? [message #1721092 is a reply to message #1721091] Sat, 23 January 2016 16:07 Go to previous messageGo to next message
Rafael Chaves is currently offline Rafael ChavesFriend
Messages: 10
Registered: August 2015
Junior Member
Thanks for confirming it is a requirement. Could you expand on why? I'd rather not worry about removing the derived elements if for my use case (generation) there would be no unintended consequences (say, if the resulting model is not expected to be used for anything else afterwards, leaving the derived elements in might be safe).

Right now, I am adding the elements as the first thing I do in the doGenerate method of my language generator. Maybe in this specific use case (i.e. affecting only code generation) doing that is a safer approach (and less onerous) than implementing IDerivedStateComputer?

[Updated on: Sat, 23 January 2016 16:09]

Report message to a moderator

Re: how to augment the user model before generation? [message #1721093 is a reply to message #1721092] Sat, 23 January 2016 16:11 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
imagine your user add the implicit stuff explicitely. or a clean build is done etc.
if you do it in the derivedstatecomputer it will be there in validator etc.
you could even cross ref to a implicit element.

but the decision highly depends on your requirements.
maybe you dont need it at all and move the logic to runtime api


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: how to augment the user model before generation? [message #1721095 is a reply to message #1721093] Sat, 23 January 2016 16:54 Go to previous message
Rafael Chaves is currently offline Rafael ChavesFriend
Messages: 10
Registered: August 2015
Junior Member
Thanks, Christian, that was very helpful. I do not expect users to define the implicit elements or refer to them, so I guess I am going to take the ad-hoc approach and augment the model as the first step in the generator.

Cheers,

Rafael
Previous Topic:Extending the XBase compiler
Next Topic:Mixing simple and qualified names in cross references
Goto Forum:
  


Current Time: Thu Mar 28 18:28:57 GMT 2024

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

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

Back to the top