Slide 1

Slide 1 text

Gaël Blondelle [email protected] Acceleo Code Generation From the model to the Android app Stéphane Bégaudeau [email protected]

Slide 2

Slide 2 text

Goals of the tutorial

Slide 3

Slide 3 text

Goals of the tutorial Beginners See a simple concrete case study Acceleo addicts Discover new killing features Android experts Learn enough to build a full fledged generator

Slide 4

Slide 4 text

I 'm I 'm not not an Android an Android development expert development expert

Slide 5

Slide 5 text

1. Acceleo: A new code generator

Slide 6

Slide 6 text

A long history... A long history... Version 3.0 is part of the Eclipse Helios release train From Acceleo.org in 2006... ...to Eclipse.org in 2009

Slide 7

Slide 7 text

A long history... A long history... Acceleo 2 Acceleo 3

Slide 8

Slide 8 text

8 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 A new code generation language

Slide 9

Slide 9 text

9 Acceleo Runtime (Compiler + Engine) Acceleo Development Tools + = Eclipse independant: can be run anywhere (plain old Jar, OSGi, Eclipse...) The Acceleo SDK

Slide 10

Slide 10 text

2. Prototype based approach

Slide 11

Slide 11 text

Let's have a look at the Android prototype

Slide 12

Slide 12 text

12 Unlock the power of your models Java UI Java DB XML Properties Different kinds of source artifacts to be generated

Slide 13

Slide 13 text

13 One kind of file to be generated... ...one MTL file to be created Good Practice

Slide 14

Slide 14 text

Manifest, database adapter, properties file, edition page, edition page layout...

Slide 15

Slide 15 text

15 A little bit of syntax Header

Slide 16

Slide 16 text

16 Body A little bit of syntax

Slide 17

Slide 17 text

17 A little bit of syntax Queries can return any kind of objects Templates are better for generating text and return a string You can call Java services from a template or a query The result of a query is stored in a cache.

Slide 18

Slide 18 text

18 The workflow file The MTL file calling the other ones @main annotation

Slide 19

Slide 19 text

19 Initialize the generation project 1. Create new Acceleo project 2. Use the wizard (update file paths) 3. Create a workflow file

Slide 20

Slide 20 text

20 3... 2... 1... Launch configuration Anything that can launch Java... Generated Java Main Stand alone Same VM as Eclipse Standalone Standalone

Slide 21

Slide 21 text

21 Ignition 1. Launch the generator (launch config as Eclipse plugin)

Slide 22

Slide 22 text

From a static generator... … to a one dynamic 3.

Slide 23

Slide 23 text

23 Quick replacement Select a text section in the template, then hit "Content Assist" hotkeys

Slide 24

Slide 24 text

24 Hierarchy Tree Select a text section in the template, then right-click "Source > As For/If"

Slide 25

Slide 25 text

25 "As For/If" is quick but dirty... ...use template Good Practice polymorphism instead!!

Slide 26

Slide 26 text

26 Generation patterns Use the Generation Patterns View

Slide 27

Slide 27 text

27 Extract as template Select a text section in the template, then right click "Refactor > Extract as template"

Slide 28

Slide 28 text

28 Refactoring Alt + Shift + R

Slide 29

Slide 29 text

Launch the generator - open the Result view - launch config as Eclipse plugin - activate the Traceability Have a look at the Result view

Slide 30

Slide 30 text

30 4. Make the Android App run

Slide 31

Slide 31 text

31 Debug your templates Thanks to Acceleo debugger

Slide 32

Slide 32 text

32 Configure the Android Development Kit Create a new Android Virtual Device - AVD Set the path to the SDK location

Slide 33

Slide 33 text

33 Turn on the phone

Slide 34

Slide 34 text

34 5. A generic Android App generator

Slide 35

Slide 35 text

Create a fresh new model

Slide 36

Slide 36 text

36 Android Apps Generate new

Slide 37

Slide 37 text

37 6. A new App in a few clicks

Slide 38

Slide 38 text

38 Packaging and deploying Generate an Eclipse UI plugin Add an action on right-click on models Create a builder Synchronize your code and your model

Slide 39

Slide 39 text

39 Packaging settings Filename pattern of the model Target folder of the generation Warning Eclipse specific

Slide 40

Slide 40 text

40 Workout 1. Create new Acceleo UI project 2. Use the wizard 3. Launch a 2n d Eclipse Runtime and test

Slide 41

Slide 41 text

41 7. Override specific behavior

Slide 42

Slide 42 text

42 Static overriding Dynamic overriding Overriding existing generators Eclipse-only

Slide 43

Slide 43 text

43 Module B Template MT Module A Template MT Extends overrides Module C Imports C invokes MT, B.MT will be executed Overriding behavior

Slide 44

Slide 44 text

44 A common problem with code generators... if you change the generated code... your modifications are lost during the next generation. Lost code

Slide 45

Slide 45 text

45 © Copyright 2010 Obeo Protected area Will not be erased after re-generation Dont forget the comments marks... ... and the ID

Slide 46

Slide 46 text

@Generated Acceleo also uses JMerge You can protect a whole block with a simple comment

Slide 47

Slide 47 text

47 © Copyright 2010 Obeo 8. The next step: Acceleo 3.1

Slide 48

Slide 48 text

48 © Copyright 2010 Obeo Documentation

Slide 49

Slide 49 text

49 © Copyright 2010 Obeo UI Improvements

Slide 50

Slide 50 text

Thank you for your attention! Questions?