MPS 2020.1 Help

Using model & module dependencies FAQ

// Entry point
// accessing model of the node
model m = node.model;
/* "Down-"casting it to the interface from MPS open API. Similarly this will work on node<> -> SNode, enumeration -> SEnumeration, concept -> SConcept */
SModel sModel = m;
/* "Up-"casting an interface from MPS open API to an smodel language type. Similarly this will work on SNode -> node<>, SEnumeration -> enumeration, SConcept -> concept */
model m2 = sModel;
// non-open API interface for MPS model
SModelInternal internalSModel = (SModelInternal) sModel;
// accessing the module owning the model
SModule sModule = sModel.getModule();

//    Repository or modules
// accessing repository of modules
SRepository sRepository = sModel.getRepository();
// accessing modules from the repository
Iterable<SModule> modules = sRepository.getModules();
SModule module = sRepository.getModule(sModule.getModuleId());
SModule closuresRuntimeModule = sRepository.getModule( module reference /closures.runtime/.getModuleId());

// Languages are represented as a special module type
if (module instanceof Language) {
   Language language = (Language) module;
}

// Getting language by "direct" reference:
// Note: no repository is mentioned here. In the MPS we actually have single repository now,
// so you can use this expression to get module from the single repository
Language mpsBaseLanguage = (Language) module /jetbrains.mps.baseLanguage/;

//    Module dependencies

// accessing module dependencies
sequence <SDependency> dependencies = mmodule.getDeclaredDependencies()

// adding used language to a module
AbstractModule internalModule = (AbstractModule) sModule;
internalModule.getModuleDescriptor().getUsedLanguages().add( module reference /jetbrains.mps.baseLanguage/);

// modify module dependencies
sequence <Dependency> internalDependencies = internalModule.getModuleDescriptor().getDependencies();
sequence <SModuleReference> usedModuleReferences = internalDependencies.select({~it => it.getModuleRef(); });
internalModule.getModuleDescriptor().getDependencies().add( new Dependency( module reference /closures.runtime/, SDependencyScope. DEFAULT false ));

// working with DevKits:
internalModule.getModuleDescriptor().getUsedDevkits().add( module reference /jetbrains.mps.devkit.general-purpose/);

//    Models
// accessing models from the module
Iterable<SModel> models = sModule.getModels();
sModule.getModel(sModel.getModelId());

// working with imported models:
internalSModel.importedModels();
internalSModel.addModelImport(sModel.getReference(), false );
internalSModel.deleteModelImport(sModel.getReference());

// working with imported languages:
internalSModel.importedLanguages();
internalSModel.addLanguage(mpsBaseLanguage.getModuleReference());
internalSModel.addLanguage( module reference /jetbrains.mps.baseLanguage/);

// working with imported DevKits
internalSModel.importedDevkits();
internalSModel.addDevKit( module reference /jetbrains.mps.devkit.general-purpose/);
internalSModel.deleteDevKit( module reference /jetbrains.mps.devkit.general-purpose/);

Last modified: 18 June 2020