MPS 2019.1ヘルプ

モデルとモジュールの依存関係を使うFAQ

// Entry point
// accessing model of the node
model model = node. model ;
// "down-"casting it to the interface from MPS open API
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 = m odule.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: デフォルト 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/);
最終更新日: 2019年7月5日