Acceleo
Code Generation
From the model
to the Android app
Stéphane Bégaudeau
stephane.begaudeau@obeo.fr
Mikaël Barbero
mikael.barbero@obeo.fr
Goals of the tutorial
Goals of the tutorialGoals of the tutorial
Beginners
See a simple
concrete
case-study
Acceleo
addicts
Discover
new killing
features
Android
experts
Learn
enough to
build
full-fledged
generator
I 'mI 'm notnot
an Androidan Android
development expertdevelopment expert
1.
Acceleo:
A new code generator
A long history
From Acceleo.org in 2006...
...to Eclipse.org in 2009
Version 3.0 is part of the
Eclipse Helios release train
A new codeA new code generation languagegeneration language
Metamodel and
templates based
technology
Implementation
of the Model To
Text OMG
standard (MTL)
Eclipse Modeling
/ M2T Project
Tooling to help
starting a new
generator from
scratch
The Acceleo SDK
Acceleo Runtime
(Compiler + Engine)
Acceleo
Development Tools
+=
Eclipse independant: can be
run anywhere (plain old Jar,
OSGi, Eclipse...)
2.
Prototype
based
approach
Warm-up
1. Launch the Eclipse
runtime
2. Switch to the
Acceleo perspective
3. Import the
handcrafted Android
application
Warm-up
1. Launch the Eclipse
runtime
2. Switch to the
Acceleo perspective
3. Import the
handcrafted Android
application
Put your hands dirty
Unlock the power of your models
Java UI Java DB
XML Properties
Different kinds of source
artifacts to be generated
One file to be generated...
...one MTL file to be created
Good Practice
A little bit of syntax
Header
A little bit of syntax
Body
The workflow file
The MTL file calling
the other ones
@main annotation
Initialize the generation project
1. Create new
Acceleo project
2. Use the wizard
(update file paths)
3. Create a
workflow file
Initialize the generation project
1. Create new
Acceleo project
2. Use the wizard
(update file paths)
3. Create a
workflow file
Put your hands dirty
3... 2... 1...
Launch
configuration
Anything
that can
launch Java...
Generated
Java Main
Stand
alone
Same
VM as
Eclipse
Standalone Standalone
Ignition
1. Launch the
generator
(launch config as Eclipse plugin)
2. Look @ the
traceability view
Ignition
1. Launch the
generator
(launch config as Eclipse plugin)
2. Look @ the
traceability view
Put your hands dirty
Quick replacement
Select a text section in the
template, then hit "Content
Assist" hotkeys
Quick replacement
Select a text section in the
template, then hit "Content
Assist" hotkeys
Put your hands dirty
Hierarchy Tree
Select a text section in the
template, then right-click
"Source > As For/If"
Hierarchy Tree
Select a text section in the
template, then right-click
"Source > As For/If"
Put your hands dirty
"As For/If" is quick but dirty...
...use templates
Good Practice
polymorphism instead!!
Generation patterns
Use the Generation
Patterns View
Generation patterns
Use the Generation
Patterns View
Put your hands dirty
Extract as
template
Select a text section in the
template, then right click
"Refactor > Extract as template"
Extract as
template
Select a text section in the
template, then right click
"Refactor > Extract as template"
Put your hands dirty
Refactoring
Alt + Shift + R
Refactoring
Alt + Shift + R
Put your hands dirty
3.
Make the Android App
run
Debug your templates
Thanks to Acceleo
debugger
Configure the
Android Development Kit
Create a new Android
Virtual Device - AVD
Set the path to the
SDK location
Turn on the phone
Turn on the phone
Put your hands dirty
4.
An generic Android App
generator
Create a fresh new model
Run the generator again
With a new Android
project as target folder
Generate new
Android Apps
Generate new
Generate new
Android Apps
Generate new
Put your hands dirty
5.
A new App
in a few
clicks
Packaging and deploying
Generate an Eclipse
UI plugin
Add an action on
right-click on models
Packaging settings
Filename pattern
of the model
Target folder of
the generation
Warning: Eclipse specific
Workout
1. Create new
Acceleo UI project
2. Use the wizard
3. Launch a 2nd
Eclipse Runtime
and test
Workout
1. Create new
Acceleo UI project
2. Use the wizard
3. Launch a 2nd
Eclipse Runtime
and test
Put your hands dirty
6.
Override specific behavior
Static
overriding
Dynamic
overriding
Overriding existing generators
Eclipse-only
Module B
Template
MT
Module A
Template
MT
Extends
overrides
Module C
Imports
C invokes MT, B.MT
will be executed
Overriding behavior
Protected area
Will not be erased
after re-generation
Dont forget the
comments marks...
... and the ID
Hands on
1. Statically override
previously defined
generators
2. Add protected area
in the body of
DBAdapter#updateNote()
Hands on
1. Statically override
previously defined
generators
2. Add protected area
in the body of
DBAdapter#updateNote()
Put your hands dirty
7.
The next step: Acceleo 3.1
Documentation
UI Improvements
(1) Brief history of Acceleo
(2) From an existing App to an App generator
(3) An App in a few clicks
(4) Advanced Acceleo features
(5) The next release
Thank you for your attention!
Questions?
CREDITS:
(c) Copyright Obeo, 2010
Photos (Creative Commons):
1. flickr/photos/laihiu/4407979507
2. flickr/photos/zachbonnell/5043454271
3. flickr/photos/mobergeron/130537193
4. flickr/photos/pictureperfectpose/76138988
5. flickr/photos/twid/410697715
7. flickr/photos/e2/2244075454
8. flickr/photos/17258892@N05/2588347668
9. flickr/photos/paperpariah/2417220138
10. flickr/photos/st3f4n/3975004250
11. flickr/photos/subcircle/500995147
12. flickr/photos/thetruthabout/2842830409
13. flickr/photos/enter/11960491
14. flickr/photos/enter/11960491
15. flickr/photos/wongdood/3379046643
16. flickr/photos/st3f4n/4106193567
17. flickr/photos/nasahqphoto/4109708805
18. flickr/photos/pcw/247087091
19. flickr/photos/purplemattfish/3020016417
20. flickr/photos/grungetextures/4213233972
21. flickr/photos/cococait/5016130987
22. flickr/photos/kh-67/3339157498
23. flickr/photos/carbonnyc/2965625438
24 .flickr/photos/7606551@N03/4917584222
25. flickr/photos/alain_limoges/4593736342
26. flickr/photos/knowprose/101872870
27. flickr/photos/john_dyer_jr/4764666803
28. flickr/photos/st3f4n/4408582299
29. http://www.android.com/media/
30. http://www.blogger.com
http://twitter.com/
http://www.fifa.com
http://www.openclipart.org
flickr/photos/schoffer/144670634
31. flickr/photos/loozrboy/4887231336
32. flickr/photos/st3f4n/4372885123
33. flickr/photos/darwinbell/316668966/
34. flickr/photos/edwbaker/4268008033
35. flickr/photos/wessexarchaeology/215904318
36. flickr/photos/st3f4n/4297940349
37. flickr/photos/koichiwb/4323277195
38. flickr/photos/merelymel/230291050
39. flickr/photos/st3f4n/4322352483
40. flickr/photos/gernot/2554175292
41. flickr/photos/st3f4n/4291462682
42. flickr/photos/40386452@N05/4487564062
43. flickr/photos/loty/326761635
44. flickr/photos/slowburn/2986303105
45. flickr/photos/82862943@N00/367490867
46. flickr/photos/stu_p/2317403942
Trademarks of brands and associated logos:
Android and Blogger are trademarks of Google, Inc.
Twitter is trademark of Twitter, Inc.
FIFA is trademark of FIFA

Generating an Android App with Acceleo (Eclipse Summit Europe 2010)