Hi everyone, can I find the parent name of a child concept? or should I add a reference to it parent? For example, Concept A Children: concept B In textGen I will add the concept B with its propert...
This is an auto-generated question from the MPS Slack community: Hi everyone,
can I find the parent name of a child concept? or should I add a reference to it parent?
For example,
Concept A
Children: concept B
In textGen I will add the concept B with its properties + the name of its parent.
6 comments
Sort by
Date
Votes
Hi Slack user:U030HG137TJ>, each node in MPS has a parent except for the root nodes. With the `.parent` operation you will access the parent node. For accessing its attributes you would need to cast to the concept of it… because it is generic ( `node.parent:MyParentConcept.someAttribute` )
Is there a specific reason for using the TextGen instead of a generator template?
Slack user:U6K7KNMHB> thanks.
I generate sql code. That's why I use TextGen instead of generator.
Slack user:U030HG137TJ> we did this in our project also a long time ago, for us the indentation was an issue… migration project …
after moving to com.dsl.foundry.PlainTextGen the indentation problem was gone.
thank you Slack user:U6K7KNMHB> , i will try it.
If you know the type of the parent you might also use `node.ancestor<ParentType>` . This is slightly more robust, as this will keep working even if you put a concept between A and B, because `ancestor` will go up multiple parents to find the one matching the parent type.
This is auto-generated question from the MPS Community Slack Workspace. If you want to comment on the question, do it from the Slack workspace
Post is closed for comments.