MPS 2019.1ヘルプ

付属品

アクセサーリーモデルは、言語の側面として(推奨)、またはソリューションにある通常のモデルとして、2か所に保管できます。どちらの場合も、モデルを使用できるように言語ランタイム言語設定に追加する必要があります。典型的なユースケースは、その言語が使用されている任意の場所で利用可能になるConceptインスタンスのデフォルトライブラリーです。

サンプル

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:

Ac1

Update ColorReference

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

Ac2

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:

Ac4

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:

Ac3

Define colors in the Accessories model

Now the colors can be safely defined:

Ac5

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日