How to create new SContainmentLink for non-existent role?

Good afternoon.

I want to create a util method to be able to create invalid data inside already created nodes. For example, I would like to create a child node with role that is not defined in the concept.

The reason is to check migration scripts on real data that migration is working. Yes, we have migration script tests but they not allowed to create incorrect data (for example, if child was moved from one concept to another).

I know that there is exists deprecated method for this: ownerNode/.addChild(roleName, newChildNode);

But I would like to use not deprecated method with SContainmentLink attribute instead of roleName. But I don't understand how to create a new one.

Util method example:

I will be very thankful for the help.

2 comments
Comment actions Permalink

SContainmentLink can be created through MetaAdapterFactory (https://github.com/JetBrains/MPS/blob/25c9de8c91c5f466e497d47d134f92b7024d9a78/core/kernel/source/jetbrains/mps/smodel/adapter/structure/MetaAdapterFactory.java#L278 and the other methods). I am not sure whether the `concept` parameter should be your `owner.getConcept()` or `childConcept`. The `long link` looks like the part which will make your node invalid, so maybe just put a 0 there?

EDIT: After some reverse engineering I found out the `concept` parameter should be the owner concept of the containment link (your `owner.getConcept()`).

 

You should also check out the following links, maybe you need some of them.

Other MetaAdapters which you will maybe use:

https://github.com/JetBrains/MPS/blob/25c9de8c91c5f466e497d47d134f92b7024d9a78/core/kernel/source/jetbrains/mps/smodel/adapter/MetaAdapterByDeclaration.java#L87 

https://github.com/JetBrains/MPS/blob/25c9de8c91c5f466e497d47d134f92b7024d9a78/core/kernel/source/jetbrains/mps/smodel/adapter/structure/MetaAdapterFactoryByName.java#L84 (note: deprecated)

ContainmentLinkAdapters:

https://github.com/JetBrains/MPS/blob/25c9de8c91c5f466e497d47d134f92b7024d9a78/core/kernel/source/jetbrains/mps/smodel/adapter/structure/link/InvalidContainmentLink.java#L30 

https://github.com/JetBrains/MPS/blob/25c9de8c91c5f466e497d47d134f92b7024d9a78/core/kernel/source/jetbrains/mps/smodel/adapter/structure/link/SContainmentLinkAdapterById.java#L35 

https://github.com/JetBrains/MPS/blob/25c9de8c91c5f466e497d47d134f92b7024d9a78/core/smodel/source/jetbrains/mps/smodel/adapter/ids/MetaIdFactory.java#L29 

1
Comment actions Permalink

Adrian Szegedi, thanks a lot for your help.

MetaAdapterFactory works like a charm )

0

Please sign in to leave a comment.