acceleo code generation

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

Upload: stephane-begaudeau

Post on 13-Jul-2015

3.399 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: Acceleo Code Generation

Gaël [email protected]

AcceleoCode Generation

From the modelto the Android app

Stéphane Bé[email protected]

Page 2: Acceleo Code Generation

Goals of the tutorial

Page 3: Acceleo Code Generation

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

Page 4: Acceleo Code Generation

I 'm I 'm notnot

an Android an Android development expertdevelopment expert

Page 5: Acceleo Code Generation

1.

Acceleo:A new code generator

Page 6: Acceleo Code Generation

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

Page 7: Acceleo Code Generation

A long history...A long history...

Acceleo 2

Acceleo 3

Page 8: Acceleo Code Generation

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

Page 9: Acceleo Code Generation

9

Acceleo Runtime (Compiler + Engine)

Acceleo Development Tools

+=

Eclipse independant: can be run anywhere (plain old Jar,

OSGi, Eclipse...)

The Acceleo SDK

Page 10: Acceleo Code Generation

2.

Prototype based

approach

Page 11: Acceleo Code Generation

Let's have a look at the Android prototype

Page 12: Acceleo Code Generation

12

Unlock the power of your models

Java UI Java DB

XML Properties

Different kinds of source

artifacts to be generated

Page 13: Acceleo Code Generation

13

One kind of file to be

generated...

...one MTL file to be created

Good Practice

Page 14: Acceleo Code Generation

Manifest, database adapter,

properties file, edition page,

edition page layout...

Page 15: Acceleo Code Generation

15

A little bit of syntax

Header

Page 16: Acceleo Code Generation

16

Body

A little bit of syntax

Page 17: Acceleo Code Generation

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.

Page 18: Acceleo Code Generation

18

The workflow file

The MTL file calling the other

ones

@main annotation

Page 19: Acceleo Code Generation

19

Initialize the generation project

1. Create new Acceleo project

2. Use the wizard(update file paths)

3. Create a workflow file

Page 20: Acceleo Code Generation

20

3... 2... 1...

Launch configuration

Anything that can

launch Java...

Generated Java Main

Standalone

Same VM as Eclipse

Standalone Standalone

Page 21: Acceleo Code Generation

21

Ignition

1. Launch the generator

(launch config as Eclipse plugin)

Page 22: Acceleo Code Generation

From a static generator...

… to a onedynamic

3.

Page 23: Acceleo Code Generation

23

Quick replacement

Select a text section in the

template, then hit "Content

Assist" hotkeys

Page 24: Acceleo Code Generation

24

Hierarchy Tree

Select a text section in the template, then right-click

"Source > As For/If"

Page 25: Acceleo Code Generation

25

"As For/If" is quick but dirty...

...use template

Good Practice

polymorphism instead!!

Page 26: Acceleo Code Generation

26

Generation patterns

Use the Generation

Patterns View

Page 27: Acceleo Code Generation

27

Extract as

template

Select a text section in the

template, then right click

"Refactor > Extract as template"

Page 28: Acceleo Code Generation

28

Refactoring

Alt + Shift + R

Page 29: Acceleo Code Generation

Launch the generator- open the Result view- launch config as Eclipse plugin- activate the Traceability

Have a look at the Result view

Page 30: Acceleo Code Generation

30

4.

Make the Android App run

Page 31: Acceleo Code Generation

31

Debug your templates

Thanks to Acceleo

debugger

Page 32: Acceleo Code Generation

32

Configure the Android Development Kit

Create a new Android Virtual Device - AVD

Set the path to the

SDK location

Page 33: Acceleo Code Generation

33

Turn on the phone

Page 34: Acceleo Code Generation

34

5.

A generic Android App generator

Page 35: Acceleo Code Generation

Create a fresh new model

Page 36: Acceleo Code Generation

36

Android Apps

Generate new

Page 37: Acceleo Code Generation

37

6.

A new App in a few

clicks

Page 38: Acceleo Code Generation

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

Page 39: Acceleo Code Generation

39

Packaging settings

Filename pattern of the model

Target folder of the generation

Warning Eclipse specific

Page 40: Acceleo Code Generation

40

Workout

1. Create new Acceleo UI project

2. Use the wizard

3. Launch a 2nd Eclipse Runtime and test

Page 41: Acceleo Code Generation

41

7.

Override specific behavior

Page 42: Acceleo Code Generation

42

Static overriding

Dynamic overriding

Overriding existing generators

Eclipse-only

Page 43: Acceleo Code Generation

43

Module B

Template MT

Module A

Template MT

Extendsoverr

ides

Module CImports

C invokes MT, B.MT

will be executed

Overriding behavior

Page 44: Acceleo Code Generation

44

A common problem with code generators...

if you change the generated code...

your modifications are lost during the next generation.

Lost code

Page 45: Acceleo Code Generation

45

© C

opyri

gh

t 20

10

Ob

eo

Protected area

Will not be erased after re-generation

Dont forget the

comments marks...... and the ID

Page 46: Acceleo Code Generation

@Generated

Acceleo also uses JMerge

You can protect a whole block with a simple comment

Page 47: Acceleo Code Generation

47

© C

opyri

gh

t 20

10

Ob

eo

8.

The next step: Acceleo 3.1

Page 48: Acceleo Code Generation

48

© C

opyri

gh

t 20

10

Ob

eo

Documentation

Page 49: Acceleo Code Generation

49

© C

opyri

gh

t 20

10

Ob

eo

UI Improvements

Page 50: Acceleo Code Generation

Thank you for your attention!

Questions?