Child pages
  • Using model & module dependencies FAQ
Skip to end of metadata
Go to start of metadata

//    Entry point
// accessing model of the node
model model = node.model;
// "down-"casting it to the interface from MPS open API

// Be careful with package names: j.m.smodel.SModel is an implementation class, which normally should not be used

// The 'open API' resides in org.jetbrains.mps.openapi.model, e.g. org.jetbrains.mps.openapi.model.SModel.

SModel sModel = model;
// non-open API interface for MPS model
SModelInternal internalSModel = (SModelInternal) sModel;
// accesing 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 = module.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 ={~it => it.getModuleRef(); });
internalModule.getModuleDescriptor().getDependencies().add(new Dependency(module reference/closures.runtime/, SDependencyScope.DEFAULTfalse));

// 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();

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

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

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

  • No labels


  1. Anonymous


    I am new with MPS and use the version 3.2.

    I try to "down-"cast a model to sModel in the constraints aspect, whitout succes.

    org.jetbrains.mps.openapi.module_at_java_stub and jetbrains.mps.smodel_at_java_stub are imported  in the constraints aspect as models dependencies.

    The Code:



    Unknown macro: {languageName}

      is valid:(propertyValue, node)->boolean {
        model model = node.model;     SModel smodel = model;
        return false;


    And the error:

    Error: type model is not subtype of jetbrains.mps.smodel.SModel

    What i forgot ?



  2. Anonymous

    I have the same problem.



    1. This is not the right place to ask questions, however, it's an indication the page goes with certain assumptions not obvious to everyone, and is worth updating.

      Don't use j.m.smodel.SModel, it's implementation class, 'open API' in the text refers to classes in org.jetbrains.mps.openapi.model.SModel.