In a referent set handler the 'referenceNode' has no parent, and no model as expected. Why?

I have a referent set handler, which has three parameters:

  • referentNode:  the node that contains the reference
  • oldReferentNode:  the old reference value
  • newReferentNode: the new reference value

This handler is called when I change the reference in the editor. SO far, so good.

Now I need to find an ancestor of the referentNode. To my surprise I cannot find the ancestor because the referentNode does not have a parent,  it isn't even in a model.

As the referentNode exists in my editor, I know that it definitely has a parent and is inside a model. Is this a bug? Or are there special circumstances where the referentNode can be null?


After a lot of additional experimentation,  I found that the referentNode has a parent and is inside a model when it has children. Doesn't help in my case,  but maybe this is a pointer of what is going on.


Concepts that have a single reference and no children are treated as "smart references" in MPS and in this case the concept is probably being created outside of a model, then its reference is set, and only then it's added to the parent.


One mistake from my side,  what I called the referentNode  is actually the referenceNode.

In this case the referenceNode itself is not a smart reference,  the link that is being is a smart reference (the newReferentNode).  However I don't have a problem with the link not being part of the model,  but with the referenceNode, which is the parent in which the reference is being set. This referenceNode is already part of the model even before the reference is being set.


This is the constraint that I am referring to. This prints "null" for both referenceNode.parent as well as referenceNode.model.


"In this case the referenceNode itself is not a smart reference,  the link that is being is a smart reference (the newReferentNode)."

Does the concept of referenceNode have any other children/references besides "type"? If not, it makes that concept a smart reference.


The referenceNode has properties, children  in addition to the reference.  As said earlier,  when there is an actual child, things are ok.  Only when the actual list of children is empty,  the parent and model is null.


I have been able to reproduce this is a small example project. Ican see that the node I am editing changes its ID (a new node is being created)  and the value of the "name" field disappears as soon as I set the reference. It seems the node is handled (incorrectly) as a smart reference.

I can work around it by changing the editor to have some constant text before the reference.


Sadly the workaround causes the INSERT action to add new nodes at the wrong place in the collection. So it's not really a workaround.


I'd be curious to see what you're trying to achieve, I might be able to suggest an alternative design. 

Short of that, I'd guess that you'd have to do some Transformation Menu/Substitution Menu magic to make this work.


Please sign in to leave a comment.