Open API
This page not only considers the language repository, project modules, languages, and models, which can be accessed through Open API but also other parts of MPS that can be accessed programmatically.
In general, there are interfaces such as the ones from org.jetbrains.mps.openapi that you can use to programmatically access classes. The implementing classes can be in the same or a different package. For example, jetbrains.mps.openapi.editor.EditorComponent ⧉ is the interface, jetbrains.mps.nodeEditor.EditorComponent ⧉ one of the implementing classes. Especially implementing IntelliJ classes often have the suffix Impl, for example, DataManagerImpl is an implementation of DataManager ⧉.
How do you get an icon for a concept?
How can you copy a language without the new one having duplicate model IDs?
How can you change the default project directory?
Put the following code in an application plugin:
How can you execute an MPS action programmatically?
Use ActionUtils ⧉ to create an event and to run the action:
Since this code is based on IDEA components, we need to get the getNodeEditorComponent
, which is not part of the Open API. That's why we need to downcast it to the EditorComponent class.
Note: action<…>
comes from the jetbrains.mps.lang.plugin language.
How to shut down MPS programmatically?
In normal conditions, one can use ApplicationManager.getApplication().exit()
. If this doesn't work, throw an exception
on purpose.
How can you react to the opening and closing of projects?
Register a ProjectManagerListener ⧉ in a plugin via the class ProjectManager ⧉.
How do you change a model without creating an undo entry?
Example: Setting a property (=flag) via a button.
How do you work with temporary models?
How can you react to selection changes in the editor?
How can I delete a model in a module programmatically?
Get the model-to-be-deleted as SModel (interface) and use new ModelDeleteHelper(model).delete();
For more context see: DeleteModeHelper ⧉
How can you programmatically add a language to the Used Languages settings of a model?
- Module level:
((AbstractModule) moduleA).addDependency(moduleB.getModuleReference(), false)
- Model level:
new ModelImports(model).addUsedLanguage(language)
To get the language from a reference, you can call: MetaAdapterFactory.getLanguage(moduleRef)
.
How can you create an MPS Language programmatically and add it to the current project?
How do I save my project(s)?
Use SRepository.saveAll()
.
For a single project, for example, ProjectHelper.getProjectRepository(project).saveAll();
For all opened projects, e.g.
contributed by: @AlexeiQ
How can you convert a quotation to an expression?