Eclipse modeling with Acceleo code generator
Jump to navigation
Jump to search
Vademecum
Get Eclipse Modeling Tools
Download 'Eclipse Modeling Tools' from http://www.eclipse.org/downloads/ (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 Identifier: org.eclipse.acceleo.feature.group Version: 3.4.0.201306101458 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 'http://www.eclipse.org/emf/2002/Ecore' 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('http://www.eclipse.org/emf/2002/Ecore')]
[template public generateElement(anEClass : EClass) { anEClassName: String = anEClass.name.toUpperFirst(); } ]
[comment @main/]
[file (anEClassName.concat('.h'), false, 'UTF-8')]
#ifndef [anEClassName/]_H_
#define [anEClassName/]_H_
class [anEClassName/]
{
public:
explicit [anEClassName/]();
virtual ~[anEClassName/]();
[for (a: EAttribute | anEClass.eAllAttributes) separator('\n')]
[a.eAttributeType.name/] get[a.name.toUpperFirst()/]();
[/for]
private:
[for (a: EAttribute | anEClass.eAllAttributes) separator('\n')]
[a.eAttributeType.name/] [a.name/];
[/for]
};
#endif
[/file]
[file (anEClassName.concat('.cpp'), false, 'UTF-8')]
#include "[anEClassName/].h"
[anEClassName/]::[anEClassName/]()
{
}
[anEClassName/]::~[anEClassName/]()
{
}
[/file]
[/template]
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'
resources
links
- http://wiki.eclipse.org/Acceleo
- http://download.eclipse.org/modeling/emf/emf/javadoc/2.4.2/org/eclipse/emf/ecore/package-summary.html
- http://help.eclipse.org/helios/index.jsp?topic=%2Forg.eclipse.acceleo.doc%2Fdoc%2Fhtml%2Facceleo_equivalence.html
- http://www.omg.org/spec/OCL/2.2/
- http://www.obeonetwork.com/group/acceleo/page/acceleo-3-1-0-user-guide