how to augment the user model before generation? [message #1721081] |
Sat, 23 January 2016 13:51 |
Rafael Chaves 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 #1721092 is a reply to message #1721091] |
Sat, 23 January 2016 16:07 |
Rafael Chaves 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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02807 seconds