acceleo code generation

Post on 13-Jul-2015

3.399 Views

Category:

Documents

5 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Gaël Blondellegael.blondelle@obeo.fr

AcceleoCode Generation

From the modelto the Android app

Stéphane Bégaudeaustephane.begaudeau@obeo.fr

Goals of the tutorial

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

I 'm I 'm notnot

an Android an Android development expertdevelopment expert

1.

Acceleo:A new code generator

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

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

Acceleo 2

Acceleo 3

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

9

Acceleo Runtime (Compiler + Engine)

Acceleo Development Tools

+=

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

OSGi, Eclipse...)

The Acceleo SDK

2.

Prototype based

approach

Let's have a look at the Android prototype

12

Unlock the power of your models

Java UI Java DB

XML Properties

Different kinds of source

artifacts to be generated

13

One kind of file to be

generated...

...one MTL file to be created

Good Practice

Manifest, database adapter,

properties file, edition page,

edition page layout...

15

A little bit of syntax

Header

16

Body

A little bit of syntax

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.

18

The workflow file

The MTL file calling the other

ones

@main annotation

19

Initialize the generation project

1. Create new Acceleo project

2. Use the wizard(update file paths)

3. Create a workflow file

20

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

Launch configuration

Anything that can

launch Java...

Generated Java Main

Standalone

Same VM as Eclipse

Standalone Standalone

21

Ignition

1. Launch the generator

(launch config as Eclipse plugin)

From a static generator...

… to a onedynamic

3.

23

Quick replacement

Select a text section in the

template, then hit "Content

Assist" hotkeys

24

Hierarchy Tree

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

"Source > As For/If"

25

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

...use template

Good Practice

polymorphism instead!!

26

Generation patterns

Use the Generation

Patterns View

27

Extract as

template

Select a text section in the

template, then right click

"Refactor > Extract as template"

28

Refactoring

Alt + Shift + R

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

Have a look at the Result view

30

4.

Make the Android App run

31

Debug your templates

Thanks to Acceleo

debugger

32

Configure the Android Development Kit

Create a new Android Virtual Device - AVD

Set the path to the

SDK location

33

Turn on the phone

34

5.

A generic Android App generator

Create a fresh new model

36

Android Apps

Generate new

37

6.

A new App in a few

clicks

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

39

Packaging settings

Filename pattern of the model

Target folder of the generation

Warning Eclipse specific

40

Workout

1. Create new Acceleo UI project

2. Use the wizard

3. Launch a 2nd Eclipse Runtime and test

41

7.

Override specific behavior

42

Static overriding

Dynamic overriding

Overriding existing generators

Eclipse-only

43

Module B

Template MT

Module A

Template MT

Extendsoverr

ides

Module CImports

C invokes MT, B.MT

will be executed

Overriding behavior

44

A common problem with code generators...

if you change the generated code...

your modifications are lost during the next generation.

Lost code

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

@Generated

Acceleo also uses JMerge

You can protect a whole block with a simple comment

47

© C

opyri

gh

t 20

10

Ob

eo

8.

The next step: Acceleo 3.1

48

© C

opyri

gh

t 20

10

Ob

eo

Documentation

49

© C

opyri

gh

t 20

10

Ob

eo

UI Improvements

Thank you for your attention!

Questions?

top related