Eclipse modeling with Acceleo code generator

Jump to navigation Jump to search


Get Eclipse Modeling Tools

Download 'Eclipse Modeling Tools' from (this tutorial use 'Kepler' version)

Extract and run ./eclipse

Install Acceleo:

Help->Install New Software
Work with: '--All Available Sites--'
search for "Acceleo"
select 'Acceleo' // or 'Acceleo SDK' for the complete kit
click 'Next', 'Next', accept and 'Finish'

This tutorial use this version of acceleo:

Name: Acceleo
Provider: Eclipse Modeling Project

Create a new project:

'File' -> 'New->Project'
select 'Acceleo Model to Text' -> 'Acceleo Project'
'Project name:' "TestAcceleoProject"
click 'Next >'
'Module Name:' "generate"
'Metamodel URIs:' click '+'
select 'Runtime Version'
select ''
click 'OK'
'Template Name:' "generateElement"
'Type:' 'EClass'
select 'Template'
select 'Generate file'
select 'Main Template'
click 'Finish'

Edit the generate.mtl template:

there is a 'generate.mtl' file in 'src/TestAcceleoProject.main'

sobstitute the content with the follow:

[comment encoding = UTF-8 /]
[module generate('')]

[template public generateElement(anEClass : EClass)  { anEClassName: String =; } ]
[comment @main/]

[file (anEClassName.concat('.h'), false, 'UTF-8')]
#ifndef [anEClassName/]_H_
#define [anEClassName/]_H_

class [anEClassName/]
    explicit [anEClassName/]();
    virtual ~[anEClassName/]();

[for (a: EAttribute | anEClass.eAllAttributes) separator('\n')]
    [] get[]();

[for (a: EAttribute | anEClass.eAllAttributes) separator('\n')]
    [] [];



[file (anEClassName.concat('.cpp'), false, 'UTF-8')]
#include "[anEClassName/].h"





Create the model:

on 'Package Explorer' right click on "TestAcceleoProject" project

'New' -> 'Other...'
select 'Ecore Tools' -> 'Ecore Diagram'
'Directory:' "/TestAcceleoProject"
'Domain file name:' model.ecore
click 'Finish'

Now create your class diagram

Generate the code:

on 'Package Explorer' right click on 'generate.mtl' file

'Run As' -> 'Run Configurations'
select 'Acceleo Application' and click 'New launch configuration'
Name: "TestAcceleoProject generate.mtl"
Project: "TestAcceleoProject"
Main class: "TestAcceleoProject.main.Generate"
Model: "/TestAcceleoProject/model.ecore"
Target: "/TestAcceleoProject/generated"
click 'Run'