MPS 2019.1ヘルプ




Let's alter the 図形 sample project created as part of the introductory 図形チュートリアル and bundled with MPS distributions as a sample project. The project allows the language users to define various colorful shapes and put them on a canvas. The colors of each shape are defined as references to one of the StaticFieldDeclarations defined in the class.

Accessories models allow us to define our own color constants instead of referencing directly the class and thus impose a dependency on BaseLanguage from the user solutions. You'll get finer control over what colors will be available and how they will get generated.

Define the concept to represent colors

First we need to define the concept that we will then use to define individual colors:


Update ColorReference

The カラーリファレンス concept should now point to nodes of the MyColor concept:


Define a method to obtain the real Color

During generation we will need to replace nodes of MyColor with nodes of StaticFieldDeclaration representing the corresponding color constants defined in the class:


Change the generator templates for circle and square

These templates hold a reference macro that inserts a reference to the particular desired static field in the class. We need to change the macro so that it uses the findColor() behavior method that we defined above:


Define colors in the Accessories model

Now the colors can be safely defined:


After rebuilding the language the color constants will be available in the completion menu in your キャンバス nodes and the generated code will hold correct references to Java colors.

最終更新日: 2019年6月7日