Creating a Code Generator
OCCIware Studio » Creating a Code Generator
The following steps allow to create an Acceleo generator based on the OCCI meta-model.
Click File » New » Acceleo Project.
Give your project a name and click Next.
In the next window, set the generator options.
Click Finish. This will open the Acceleo perspective.
Modify the *.mtl file with whatever you want to put in the file.
Then execute the generator by following these steps.
-
In the new project, open the generate.mtl file from the navigator view (left panel).
This file is located under the src directory, in the project’s.main package. -
Set the generated file name.
This can be a dynamic expression.
# Dynamic one
file (extension.name, false, 'UTF-8')
# Static one
file ('configuration.xml', false, 'UTF-8')
The static example is on purpose.
Indeed, a configuration does not have any attribute usable to generate a distinct name.
3. Inside the “file” mark-ups, write the generator: static text, dynamic text using ocl generation, templates calls, etc. Please refer to Acceleo’s documentation for more informations on how to write a generator. The extension that generates documentation can be used as an inspiration.
To test the generator, right-click on the generate.mtl file and select Run as » Launch Acceleo application.
Add the OCCI meta-model URI: click on the +
button and select http://schemas.ogf.org/occi
.
Then, select the input model to use (delete the “xmi” filter in the dialog in order to display all files).
The input model is the root type of the generator (so, either an extension or a configuration, depending on whether you
want to generate from an occie or occic extension).
Select the Target (project) directory where the generated files are going to be stored.
Eventually…
- Check the Main template and Generate file options.
- Configuration: Runner => Java Application
- Click Run.
- Open the generated file in the target directory to check the result.
To ease the generator’s development, you can open both the generator and resulting file and drag one of them.
This way, you will view both of them at the same time (some sort of WYSIWYG).
To relaunch a generation, hitCTRL + F11
when the focus is on the generate.mtl file.