Model Access in Post Process Scripts of Generator Aspect

Hello everyone,

I have a post-process script in the generator aspect of my language and I want to iterate on all the related nodes in the model.
For this purpose I am trying to use the following code however I cannot get any node:
for (node<NodeType> nd: model.roots(NodeType)) { 
   //implementation
}
prettyPrint();
If I use something like this:

for (node<NodeType> nd: model/myLanguage.sandbox/.roots(NodeType)) { 
   //implementation
}
prettyPrint();
It actually gets the nodes that I want to iterate however it is not a generic solution.

How could I get the nodes from models in a generic way for post-process script?

Thanks in advance,

Özlem
5 comments
Are you sure that the NodeType you use in above example is "rootable"? Try mode.nodes(NodeType) instead, if the NodeType is not a root concept.
0
Yes the concept is rootable. Actually I can get the NodeType nodes from the model when I specify the model name by using

model/myLanguage.sandbox/.roots(NodeType) 
prettyPrint(); I also try your suggestion however it's not working either.
0
I noticed something. Since I am using post-process script, in the model parameter there are no NodeType roots anymore. By using the model parameter now I have access to the classes that I am generating via the generator aspect for each NodeType. I wasn't aware of that.

How could I get the NodeType roots under the sandbox model in post-process script?
0
You can use genContext.originalModel, but in in general you shouldn't use that, because it breaks the extendability of your language.
0
To get the input model in the post-process script, I used SModelRepository and get the model by fqName from it.

Here is the code:

model inputModel = SModelRepository.getInstance().getModelDescriptor(model.name);
prettyPrint();
It seems to work for me however I don't know wheter it will cause any complications in the language afterwards.
0

Please sign in to leave a comment.