How to copy languages (and dependencies) from one Model to another Model programmatically?
Do I have to cast SModel to SModelInternal? What model should I import to have access to SModelInternal? Ctrl R does not give anything ...
Kind Regards,
Arjan Kok.
Please sign in to leave a comment.
Hi Arjan,
I am working on something similar and came across CloneUtil (jetbrains.mps.generator.impl.CloneUtil). I asked a question in the slack channel if it is okay to use this utility to clone models which are not transient models (since CloneUtil seems to be used only for that purpose by MPS internally) awaiting an answer.
Anyway, programmatically, it works to use this utility like so:
If you want to do it manually, try something like this:
Best,
Robert
Hi, Robert!
Actually, CloneUtil class used in few more places in MPS except the Generator. ;-)
I think, it's ok to use this class if you'd like to copy content of the model completely.
You may find j.m.smodel.ModelImports(openapi.SModel) class handy, as it hides the knowledge about particular SModelInternal/SModelBase implementations and is intended to deal with model dependencies.
Do not know what went wrong, but Ctrl +R works fine, and returns the model I need to import. The SModelInternal interface contains indeed the necessary methods to add languages and imports to the output model.