Tutorial: how to add an Action to the Jetbrains MetaProgramming-System

The Jetbrains MetaProgrammin-System (MPS)

The MetaProgramming-System is a Language Workbench based on projectional editing and it is the most advanced publicly available tool of this kind.

If you have not yet took a look at it you should, really. It makes possible (and easy!) to evolve and mix programming languages and modelling languages providing specific tool support.

Have you ever dreamed to improve a little bit your favourite language (e.g., Java). Well, with MPS it is just some clicks away. To get familiar with it take a look at the basic tutorials at http://www.jetbrains.com/mps/documentation/index.html.

In this tutorial we will see how to add an action to the IDE.

How to write an action for MPS

The tutorial was tested using MPS 2.0.6

We want to add an action that we can invoke from the “Tools” menu.

The first step is create a new Project (File -> New Project).

Then we should add the plugin aspect to the language.

Now we have to create a Group.

This group will contain our Action. Set its name (ExportGroup) and add an element list where the editor indicates an error. Under the modifications section specify that the editor should go under the Tools group.

Then we should add an action.

Set the name and the caption. To test that our action get invoked we will show a Message using JOptionPane. To do that we should add the stub to our language. Select our language and from the context menu select “Module properties”. In the common tab add under Accessory models the javax.swing stub.

We can now add the code to show a message.

Add the Action to the group.

Now build the language (from the context menu of the Language select “Make Language ‘name of your language’ “). In the Tools menu it is now present our action.

If we invoke it a message appears.

In the next tutorial we will add some code into the action to export the models as XML.

Download the guide with 68 resources on Creating Programming Languages

68resources

Receive the guide to your inbox to read it on all your devices when you have time

Powered by ConvertKit
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply