Generate Magik code from Class diagram

MDT UML2 Modeler allows to generate Magik source code from a class model. Source code generation is based on Magik dedicated profile. To generate code class the model should be valid and contain elements with applied stereotypes.

Step 1

Before generating the code we need to make sure that our model is correct. To do this run Magik Model Validation from editor's context menu.

Magik Model Validation action

Step 2

To generate code we need to specify a new launch configuration. Use the drop-down Run menu in the toolbar and select Run Configurations...

Run Configuration action

Step 3

A launch configuration allows you to configure code generation preferences including source and destination path. Select MDT UML2 Modeler and add a new configuration..

Step 4

Go to code generation tab and change its name to cordinates generation

Step 5

Select Magik Generation module by clicking on Select Module button and selectiong Magik 4.2.x

Code generation module selection

Step 6

Set the source model to model.uml file in project.

Step 7

Set output folder for generation results. We recommend to use the source folder location.

Target folder selection

Step 5

Apply and Run configuration. This will generate point exemplar:

 #% text_encoding = iso8859_1

_pragma(classify_level=basic)
##
def_slotted_exemplar(:point, {   
    {:x, _unset} 
    ,{:y, _unset} 
    }, {})  
$
 
_pragma(classify_level=basic)
## x coordinate
point.define_slot_access(:x, :readable, :public)
$

_pragma(classify_level=basic)
## y coordinate
point.define_slot_access(:y, :readable, :public)
$

_pragma(classify_level=basic)
_method point.change_location(x_coordinate, y_coordinate)
    ## Changes coordinates to location specified by x_coordinate and y_coordinate

_endmethod
$

Note: For any problems see log file located in the output location.

For additional configuration options see Generation Options Tab

Related reference

Generation Options Tab
Code Generation Tab

Related tasks

Create new model
First steps
Create class diagram