Getting to node <SomeConceptType> from SNode


When I have an instance of SNode, is it possible to get to the nicer "node <SomeConceptType>" way of working with concept instances?

That way being able to elegantly access the contents of concept instances:

Code based on node<>
   node <SomeConceptType> myNode = ...;
    w.write(myNode.myField); // note the convenient and safe access to myField
prettyPrint(); instead of:

Code based on SNode
   SNode myNode = ...;
    foreach f in myNode.getChildren("myField") {
prettyPrint(); My use case is writing a custom build facet.
So, there I resort to doing things like below, needing to specify identifiers via String-s and other boilerplate (like foreach needed even if a field has arity 1), which is not too nice:

Build facet target code
(progressMonitor, input)->void
    ModelAccess.instance().runReadAction({ =>
        input.forEach({~inpt => 
            input.models().forEach({~curModel =>
 foreach rootNode in curModel.getRootNodes() { 
     foreach fieldNode in rootNode.getChildren("myField") { 
         // do something with fieldNode
     foreach inheritFrom in rootNode.getChildren("inheritFrom") { 
         w.write("// inheritFrom: " + inheritFrom + "\n"); 
         SReference iInheritable = inheritFrom.getReference("iInheritable"); 
         SNode targetNode = iInheritable.getTargetNode(); 
         // BTW, is it a good way of using SModel references?
         w.write("// iInheritable ... TargetNode " + targetNode + "\n"); 
    // ...
prettyPrint(); Any help appreciated :-).

Comment actions Permalink
In NYoSh, we do it like this:

for (SNode rootNode : tres.modelDescriptor.getRootNodes()) {
  ifInstanceOf (rootNode is PluginScript pluginScript) {
    if (pluginScript.pluginSystem.path.isNotEmpty) {
      destinationPath = pluginScript.pluginSystem.path + "/plugins/" + pluginScript.pluginKind + "/" + pluginScript.pluginId;
    } else {
      info "Cannot copy, destination not specified for " + rootNode;

You may have to import smodel and/or smodel.resources.
Comment actions Permalink
Hi Fabien.
Thanks a lot!
I've converted all my SNode-based code to use isInstanceOf as you pointed out.
Actually I have tried it some days ago, but there was some error, so I thought that maybe it was too naive to try isInstanceOf in this way.

But now it works :-). That improvement has made my day :).

Btw, NYoSh seems quite interesting - what's the current status - is it deployed? Good to see more MPS projects out there.

Thanks again.
Wishing you success,
Comment actions Permalink
Glad that helped.

At this stage NYoSh is still a research project. We try out different ideas to see how we can improve interactivity when building computational analysis pipelines. We published about our experience building a first prototype last year, and we are now working on the second iteration of the project. Hope to be able to share more details in the Fall when the second version is more advanced and polished.
Comment actions Permalink
That last statement gave me an idea: why not have a "tradition" that people would post updates and MPS-usage success stories (not only questions, like is currently the case) ?
So maybe you can drop us an update via an MPS forum post in the Fall?
Comment actions Permalink
Sounds like a great idea. I would also be very interested to hear what others are doing with MPS.

Please sign in to leave a comment.