Model driven software engineering in practice book - Chapter 9 - Model to text transformations and code generation

Marco Brambilla
Marco BrambillaFull Professor of Computer Science and Engineering at Politecnico di Milano
Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Model-Driven Software Engineering In Practice. Morgan & Claypool 2012.
Teaching material for the book
Model-Driven Software Engineering in Practice
by Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Morgan & Claypool, USA, 2012.
Copyright © 2012 Brambilla, Cabot, Wimmer.
www.mdse-book.com
MODEL-TO-TEXT
TRANSFORMATIONS
CHAPTER 9
Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Model-Driven Software Engineering In Practice. Morgan & Claypool 2012.
Content
§ Introduction
§ Programming Languages based Code Generation
§ M2T Transformation based Code Generation
§ Mastering Code Generation
Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Model-Driven Software Engineering In Practice. Morgan & Claypool 2012.
www.mdse-book.com
INTRODUCTION
Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Model-Driven Software Engineering In Practice. Morgan & Claypool 2012.
Introduction
Terminology
§  Code generation
§  Wikipedia:
„Code generation is the process by which a compiler‘s code generator
converts a syntactically-correct program into a series of instructions that can
be executed by a machine.“
§  Code Generation in Action (Herrington 2003):
„Code generation is the technique of using or writing programs that write
source code.“
§  Code generation (http://en.wikipedia.org)
§  Compiler Engineering: component of the synthesis phase
§  Software Engineering: program to generate source code
§  Résumé: Term Code Generation is overloaded!
Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Model-Driven Software Engineering In Practice. Morgan & Claypool 2012.
Introduction
Code Generation - Basic Questions
§  How much is generated?
§  Which parts can be automatically generated from models?
§  Full or partial code generation?
§  What is generated?
§  Which kind of source code to generate?
§  The less code to generate, the better!
§  How to generate?
§  Which languages and tools to use for developing code generators?
§  GPLs vs. DSLs
Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Model-Driven Software Engineering In Practice. Morgan & Claypool 2012.
Introduction
Code Generation in MDA (just an example)
Requirements
Analysis
Design
Implementation
Test&Deployment
CIM
PIM
PSM
Code
Feedback
CIM
PIM
Web
Model
DAO
Model
SQL
Model
JSP
Code
DAO
Code
SQL
Code
Manual
Development
+
Model2Model
Transformation
Model2Model
Transformation
Model2Text
Transformation
Rational Unified Process MDA Artifacts
Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Model-Driven Software Engineering In Practice. Morgan & Claypool 2012.
Introduction
What kind of code is generated?
§  Model-to-Text, whereas text may be distinguished in
§  Program code
§  Documentation
§  Test cases
§  Model serialization (XMI)
§  Direct translation to machine code possible, but inconvenient, error-
prone and hard to optimize
§  Reuse existing code generators
§  Using existing functionality (frameworks, APIs, components)
§  Motto: The less code to generate, the better!
Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Model-Driven Software Engineering In Practice. Morgan & Claypool 2012.
Introduction
Example: Platform for Web application development
§  Example: developing a code generator for Web applications
§  What options exist for the to be generated code?
§  Dimensions of Web applications: Content, Hypertext, Presentation
§  Programming languages: Java, C#, Ruby, PHP, …
§  Architectures: 2-layer, 3-layer, MVC, ActiveRecords, …
§  Frameworks: JSF, Spring, Struts, Hibernate, Ruby on Rails, ASP, …
§  Products: MySQL, Tomcat, WebLogic, …
§  Which combinations are appropriate?
§  Experience gained in earlier projects
§  What has proven useful?
§  Reference architectures
Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Model-Driven Software Engineering In Practice. Morgan & Claypool 2012.
Introduction
What kind of code is generated?
Production code Test code
Class
diagrams
State charts
OCL
Object
diagrams
Sequence
diagrams
A B
C
1..*
1
1 *
1
0..1
z1 z2
z3
z4
e e‘
e‘
a:A b:B c:C
m1
m2
m3
b1:B
c1:C
c2:C
b2:B
Picture based on Berhard Rumpe: Agile Modellierung mit UML. Springer, 2012.
Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Model-Driven Software Engineering In Practice. Morgan & Claypool 2012.
Introduction
Overview of generation techniques
Model Source Code
Object Code
or
Byte Code
Running
Program
Model
Transformation
Source Code
Generation
Code
Transformation
Byte Code
Rewriting
Reflection
C++
Templates
Java, .
Net
Java,
.Net
AspectJ
ATL
QVT
Code Generation in MDE
Acceleo XPand MofScript
Compilation
Java, .
Net
Based on Markus Völter. A catalog of patterns for program generation. In Proceedings of the 8th
European Conference on Pattern Languages of Programs (EuroPLoP’03), pages 285–320, 2003.
Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Model-Driven Software Engineering In Practice. Morgan & Claypool 2012.
Introduction
Why code generation?
§  Code generation enables
§  Separation of application modeling and technical code
§  Increasing maintainability, extensibility, portability to new hardware,
operating systems, and platforms
§  Rapid prototyping
§  Early and fast feedback due to demonstrations and test runs
§  Code generation enables to combine redundant code fragments in
one source
§  Example: DDL, Hibernate, and Java Beans
à may be specified in one UML Class Diagram
Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Model-Driven Software Engineering In Practice. Morgan & Claypool 2012.
Introduction
Why code generation? – in contradiction to MDE? (1/2)
§  Often no “real” model simulation possible
§  UML environments mostly do not provide simulation features
§  However, they provide transparent transformation to C, C#, Java, …
§  UML Virtual Machines
§  Interpreter approach – spare code generation for certain platforms
§  Gets a new twist with fUML!
§  Semantics of modeling languages, especially DSMLs, often
defined by code generation
class Car {
public String color;
public int door;
public int engine;
}
Car
Color : String
Door : Integer
Engine : Integer
DSL
Code Generator
Java
Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Model-Driven Software Engineering In Practice. Morgan & Claypool 2012.
Introduction
Why code generation? – in contradiction to MDE? (2/2)
§  Runtime environments are designed for programming languages
§  Established frameworks available (Struts, Spring, Hibernate, …)
§  Systems depend on existing software (Web Services, DB)
§  Extensions for code level often required (Logging)
§  Disadvantage: using models and code in parallel
§  No single source of information – OUCH!
§  Having the same information in two places may lead to inconsistences, e.g.,
consider maintainability of systems
Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Model-Driven Software Engineering In Practice. Morgan & Claypool 2012.
Introduction
Example: MiniUML_2_MiniJava
MiniUML Metamodel
MiniUML Model
class	
  Student	
  extends	
  Person{	
  
	
  
	
  	
  private	
  String	
  regNo;	
  
	
  
	
  	
  public	
  void	
  setRegNo(…){…}	
  
	
  
	
  	
  public	
  String	
  getRegNo(){…}	
  
	
  
}	
  
MiniJava Code
MiniJava Grammar
Model2Text
NamedElement
type : Type
type 0..1
Relationship
0..1
superClass
minCard : Integer
maxCard : Integer
*
*
–  String
–  Boolean
–  …
«enumeration»
Type
ClassDec	
  :=	
  Modifier	
  “class”	
  Identifier	
  [“extends”	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  Identifier]	
  ClassBody;	
  
	
  
AttributeDec	
  :=	
  Modifier	
  Type	
  Identifier“;”;	
  
	
  
MethodDec	
  :=	
  Modifier	
  ReturnType	
  Identifier	
  “(”	
  	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  ParamList	
  “)”	
  “{”	
  MethodBody	
  “}”;	
  
	
  
Identifier	
  :=	
  {“a”-­‐”z”	
  |	
  “A”-­‐”Z”	
  |	
  “0”-­‐”9”};	
  
Class
Attribute
name: String
Person
Student
regNo : String
Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Model-Driven Software Engineering In Practice. Morgan & Claypool 2012.
www.mdse-book.com
PROGRAMMING LANGUAGES
BASED CODE GENERATION
Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Model-Driven Software Engineering In Practice. Morgan & Claypool 2012.
Programming languages
Introduction – Code generation with Java based on EMF
§  Code generation may be realized using a traditional general purpose
programming language, e.g., Java, C#, …
§  Models are de-serialized to an in-memory object graph
§  Pre-defined XMI de-serialzer provided by meta-modeling frameworks
§  Out-of-the-box support in EMF
§  Model API eases processing of models
§  Generated automatically from metamodels
§  In EMF: .ecore -> .genmodel -> Java code
§  If metamodel not available, you may use reflection
Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Model-Driven Software Engineering In Practice. Morgan & Claypool 2012.
Programming languages
Model APIs for processing models
§  Example: Ecore-based metamodel and automatically generated
Java code (shown as UML Class Diagram)
Attribute
atts0..*
Class
name : String
name : String
type : Type
Operation
ops0..*
name : String
returnType : Type
Ecore2Java
Attribute
Class
Operation
getName() : String
setName(String) : void
getAtts() : EList<Attribute>
getOps() : EList<Operation>
getName() : String
setName(String) : void
…
getName() : String
setName(String) : void
…
MM in Ecore Model API
Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Model-Driven Software Engineering In Practice. Morgan & Claypool 2012.
Programming languages
Code generation with Java: phases of code generation
1.  Load models
§  Load XMI file into memory
2.  Process models and produce code
§  Process models by traversing the model structure
§  Use model information to produce code
§  Save code into String variable
3.  Write code
§  Persist String variable to a file using streams
Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Model-Driven Software Engineering In Practice. Morgan & Claypool 2012.
Programming languages
Code generation with Java: Process and Architecture
Model
Code Generator
XMI Parser FileStream API
Code
String code;
Model API
e.g., UML e.g., JavaJava
Object Graph
M2T
(1) Load (2) Produce (3) Write
Process
Architecture
EMF
Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Model-Driven Software Engineering In Practice. Morgan & Claypool 2012.
Programming languages
Running Example solved in Java
ResourceSet	
  resourceSet	
  =	
  new	
  ResourceSetImpl();	
  
Resource	
  resource	
  =	
  resourceSet.getResource(URI.create("model.miniUML"));	
  
TreeIterator	
  treeIter	
  =	
  resource.getAllContents();	
  
	
  
while	
  (treeIter.hasNext())	
  {	
  
	
  	
  	
  Object	
  object	
  =	
  treeIt.next();	
  
	
  	
  	
  if	
  (!object	
  instanceof	
  Class)	
  continue;	
  
	
  
	
  	
  	
  Class	
  cl	
  =	
  (Class)	
  object;	
  
	
  	
  	
  String	
  code	
  =	
  "class	
  „	
  +	
  cl.getName()	
  +	
  "{";	
  
	
  	
  	
  //	
  generate	
  Constructor:	
  code	
  +=	
  …	
  
	
  	
  	
  //	
  generate	
  Attributs:	
  code	
  +=	
  …	
  
	
  	
  	
  //	
  generate	
  Methods:	
  code	
  +=	
  …	
  
	
  	
  	
  code	
  +=	
  "}";	
  
	
  	
  	
  	
  
	
  	
  try	
  {	
  
	
  	
  	
  	
  FileOutputStream	
  fos	
  =	
  new	
  FileOutputStream(cl.getName()	
  +".java“);	
  
	
  	
  	
  	
  fos.write(code.getBytes());	
  
	
  	
  	
  	
  fos.close();	
  
	
  	
  }	
  catch	
  (Exception	
  e)	
  {…}	
  
}	
  
Query values via
model API
Create a file for
each class
Get all model
elements
(1) Load
(2) Produce
(3) Write
Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Model-Driven Software Engineering In Practice. Morgan & Claypool 2012.
Programming languages
Summary
§  Advantages
§  No new languages have to be learned
§  No additional tool dependencies
§  Disadvantages
§  Intermingled static/dynamic code
§  Non-graspable output structure
§  Lack of declarative query language
§  Lack of reusable base functionality
Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Model-Driven Software Engineering In Practice. Morgan & Claypool 2012.
www.mdse-book.com
M2T TRANSFORMATION
BASED CODE GENERATION
Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Model-Driven Software Engineering In Practice. Morgan & Claypool 2012.
M2T Transformation Languages…
…are Template based
§  Templates are a well-established technique in software
engineering
§  Application domains: Text processing, Web engineering, …
§  Example:
§  Components of a template-based approach
§  Templates
§  Text fragments and embedded meta-markers
§  Meta-markers query an additional data source
§  Have to be interpreted and evaluated in contrast to text fragments
§  Declarative model query: query languages (OCL, XPath, SQL)
§  Imperative model query: programming languages (Java, C#)
§  Template engine
§  Replaces meta-markers with data at runtime and produces output files
Dear Homer Simpson,
Congratulations! You have won …
E-Mail Text
Dear «firstName» «lastName»,
Congratulations! You have won …
Template Text
Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Model-Driven Software Engineering In Practice. Morgan & Claypool 2012.
M2T Transformation Languages
Core Architecture
§  Template-based approach at a glance
«context class»
public class «name» { String id, … }
Template
Engine
Query
Result
Input
public class Person { String id, …}
Template
Text fragment
Meta-marker
Output1 Output2
…public class Customer { String id, …}
Person
Customer
…
Source
Model
Produced Text
Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Model-Driven Software Engineering In Practice. Morgan & Claypool 2012.
M2T Transformation Languages
Benefits
§  Separated static/dynamic code
§  Templates separate static code, i.e., normal text, from dynamic code that is
described by meta-markers
§  Explicit output structure
§  Primary structure of the template is the output structure
§  Computation logic is embedded in this structure
§  Declarative query language
§  OCL is employed to query the input models
§  Reusable base functionality
§  Support for reading in models, serialize text to files, …
Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Model-Driven Software Engineering In Practice. Morgan & Claypool 2012.
M2T Transformation Languages
Approaches
§ A bunch of template languages for M2T transformation
available
§ JET, JET2
§ Xpand, Xtend
§ MOFScript
§ Acceleo
§ XSLT
§ …
Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Model-Driven Software Engineering In Practice. Morgan & Claypool 2012.
Acceleo
Introduction
§  Acceleo is a mature implementation of the OMG M2T
transformation standard
§  Acceleo website: http://www.eclipse.org/acceleo/
§  M2T Transformation standard: http://www.omg.org/spec/MOFM2T
§  Template-based language
§  Several meta-markers for useful for code generation available
§  Powerful API supporting
§  OCL
§  String manipulation functions
§  …
§  Powerful tooling supporting
§  Editor, debugger, profiler, traceability between model and code, …
Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Model-Driven Software Engineering In Practice. Morgan & Claypool 2012.
Acceleo
Language Concepts
§ Module concept is provided
§ Imports the metamodels for the input models
§ Act as container for templates
§ A template is always defined for a particular meta-class
§ Plus an optional pre-condition to filter instances
§ Templates may call each other
§ Templates may extended each other
§ Templates contain text and provided meta-markers
Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Model-Driven Software Engineering In Practice. Morgan & Claypool 2012.
Acceleo
Language Concepts
§  Several meta-markers (called tags) are supported
§  File Tag: To open and close files in which code is generated
§  For/If Tag: Control constructs for defining loops and conditions
§  Query Tag: Reusable helper functions
§  Expression Tag: Compute values that are embedded in the
output
§  Protected Tag: Define areas that are not overridden by future
generation runs
Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Model-Driven Software Engineering In Practice. Morgan & Claypool 2012.
Acceleo
Example
[module generateJavaClass('http://smvcml/1.0')]
[query public getter(att : Attribute) : String = 'get'+att.name.toUpperFirst() /]
[query public returnStatement(type: String) : String = if type = 'Boolean'
then 'return true;' else '...' endif /]
[template public javaClass(aClass : Class)]
[file (aClass.name.toUpperFirst()+'.java', false, 'UTF-8')]
package entities;
import java.io.Serializable;
public class [aClass.name/] implements Serializable {
[for (att : Attribute | aClass.atts) separator ('n')]
[javaAttribute(att)/]
[/for]
[for (op : Operation | aClass.ops) separator ('n')]
[javaMethod(op)/]
[/for]
}
[/file]
[/template]
…
…
[template public javaAttribute(att : Attribute)]
private [att.type/] [att.name/];
public [att.type/] [att.getter()/]() {
return [att.name/];
}
...
[/template]
[template public javaMethod(op : Operation)]
public [op.type/] [op.name/]() {
// [protected (op.name)]
// Fill in the operation implementation here!
[returnStatement(op.type)/]
// [/protected]
}
[/template]
Import metamodel
(root package)
Template definition
Open output file
Close output file
Expression
Meta class
Loop
Static Text
Protected
Area
Query
Template
Call
Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Model-Driven Software Engineering In Practice. Morgan & Claypool 2012.
Acceleo
Protected Areas
§  Protected areas are not overriden by the next generator run
§  They are marked by comments
§  Their content is merged with the newly produced code
§  If the right place cannot be found, warning is given!
§  Example
public boolean checkAvailability(){
// Start of user code checkAvailability
// Fill in the operation implementation here!
return true;
// End of user code
}
Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Model-Driven Software Engineering In Practice. Morgan & Claypool 2012.
www.mdse-book.com
MASTERING
CODE GENERATION
Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Model-Driven Software Engineering In Practice. Morgan & Claypool 2012.
Abstracting Templates
§  To ensure that generated code is accepted by developers (cf. Turing
test for code-generation), familiar code should be generated
§  Especially when only a partial code generation is possible!
§  Abstract code generation templates from reference code to have
known structure and coding guidelines considered
§  Acceleo supports dedicated refactorings to transform code into
templates
§  E.g., substitute String with Expression Tag
Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Model-Driven Software Engineering In Practice. Morgan & Claypool 2012.
Generating step-by-step
§  Divide code generation process into several steps
§  Same applies as for M2M transformations!
§  Transformation chains may use a mixture of M2M and M2T
transformations
§  To keep the gap between the models and the code short
§  If code generators exists, try to produce their required input format with
simpler M2M or M2T transformations
§  E.g., code generator for flat state machines, transform composite state
machines to flat ones and run existing code generator
Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Model-Driven Software Engineering In Practice. Morgan & Claypool 2012.
Separating transformation logic from text
§  Separete complex transformation logic from text fragements
§  Use queries or libraries that are imported to the M2T transformation
§  By this, templates get more readable and maintainable
§  Queries may be reused
Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Model-Driven Software Engineering In Practice. Morgan & Claypool 2012.
Mastering code layout
§  Code layout is determined by the template layout
§  Challenging to produce code layout when several control structures
such as loops and conditionals are used in the template
§  Special escape characters for line breaks used for enhancing the reabability
of the template are provided
§  Alternative
§  Use code beautifiers in a post-processing step
§  Supported by Xpand for Java/XML out-of-the-box
Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Model-Driven Software Engineering In Practice. Morgan & Claypool 2012.
Model/code synchronization issues
§  Protected areas help saving manually added code in succeeding
generator runs
§  Code contained in protected areas is not always automatically
integrated in the newly generated code
§  Assume a method is renamed on model level
§  Where to place the code of the method implementation?
§  Which identifier to use for identifying a protected area?
§  Natural or artificial identifiers?
§  Model refactorings may be replayed on the code level before the next
generator run is started
§  Code in protected areas may also reflect the refactorings!
Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Model-Driven Software Engineering In Practice. Morgan & Claypool 2012.
Code Generation = M2M + TCS?
§  Code Generation achievable through applying a M2M transformations
to a programming language metamodel
§  If a TCS is available for the programming language metamodel, the
resulting model may be directly serialized into text
§  Only recommended when
§  programming language metamodel + TCS are already available
§  full code generation is possible
Model
Metamodel
(ModLang)
Model
Metamodel
(ProgLang)
M2M Spec
M2M Exec
TCS Spec
(ProgLang)
TCS
Serialization
«conformsTo» «conformsTo» «conformsTo»
visualizes
symbolizes
Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Model-Driven Software Engineering In Practice. Morgan & Claypool 2012.
Teaching material for the book
Model-Driven Software Engineering in Practice
by Marco Brambilla, Jordi Cabot, Manuel Wimmer.
Morgan & Claypool, USA, 2012.
Copyright © 2012 Brambilla, Cabot, Wimmer.
www.mdse-book.com
MODEL-DRIVEN SOFTWARE
ENGINEERING IN PRACTICE
Marco Brambilla,
Jordi Cabot,
Manuel Wimmer.
Morgan & Claypool, USA, 2012.
www.mdse-book.com
www.morganclaypool.com
1 of 39

Recommended

Model-Driven Software Engineering in Practice - Chapter 2 - MDSE Principles by
Model-Driven Software Engineering in Practice - Chapter 2 - MDSE PrinciplesModel-Driven Software Engineering in Practice - Chapter 2 - MDSE Principles
Model-Driven Software Engineering in Practice - Chapter 2 - MDSE PrinciplesMarco Brambilla
12.1K views41 slides
Model-Driven Software Engineering in Practice - Chapter 5 - Integration of Mo... by
Model-Driven Software Engineering in Practice - Chapter 5 - Integration of Mo...Model-Driven Software Engineering in Practice - Chapter 5 - Integration of Mo...
Model-Driven Software Engineering in Practice - Chapter 5 - Integration of Mo...Marco Brambilla
8.7K views23 slides
Model-driven Software Engineering in practice: Chapter 3 - MDSE Use cases by
Model-driven Software Engineering in practice: Chapter 3 - MDSE Use casesModel-driven Software Engineering in practice: Chapter 3 - MDSE Use cases
Model-driven Software Engineering in practice: Chapter 3 - MDSE Use casesJordi Cabot
12K views27 slides
Model-Driven Software Engineering in Practice - Chapter 1 - Introduction by
Model-Driven Software Engineering in Practice - Chapter 1 - IntroductionModel-Driven Software Engineering in Practice - Chapter 1 - Introduction
Model-Driven Software Engineering in Practice - Chapter 1 - IntroductionMarco Brambilla
23.1K views19 slides
Model-Driven Software Engineering in Practice - Chapter 8 - Model-to-model tr... by
Model-Driven Software Engineering in Practice - Chapter 8 - Model-to-model tr...Model-Driven Software Engineering in Practice - Chapter 8 - Model-to-model tr...
Model-Driven Software Engineering in Practice - Chapter 8 - Model-to-model tr...Jordi Cabot
8.8K views91 slides
Model driven software engineering in practice book - chapter 7 - Developing y... by
Model driven software engineering in practice book - chapter 7 - Developing y...Model driven software engineering in practice book - chapter 7 - Developing y...
Model driven software engineering in practice book - chapter 7 - Developing y...Marco Brambilla
9.2K views123 slides

More Related Content

What's hot

Mutation Testing: Testing your tests by
Mutation Testing: Testing your testsMutation Testing: Testing your tests
Mutation Testing: Testing your testsStephen Leigh
387 views14 slides
Web technologies: Model Driven Engineering by
Web technologies: Model Driven EngineeringWeb technologies: Model Driven Engineering
Web technologies: Model Driven EngineeringPiero Fraternali
5.7K views45 slides
INTRODUCTION TO SOFTWARE ENGINEERING by
INTRODUCTION TO SOFTWARE ENGINEERINGINTRODUCTION TO SOFTWARE ENGINEERING
INTRODUCTION TO SOFTWARE ENGINEERINGProf Ansari
1.9K views32 slides
software testing strategies by
software testing strategiessoftware testing strategies
software testing strategiesHemanth Gajula
37.9K views7 slides
Software evolution and maintenance by
Software evolution and maintenanceSoftware evolution and maintenance
Software evolution and maintenanceFeliciano Colella
1.1K views18 slides
software characteristics by
software characteristicssoftware characteristics
software characteristicsMuhammad Sikandar Mustafa
3K views13 slides

What's hot(20)

Mutation Testing: Testing your tests by Stephen Leigh
Mutation Testing: Testing your testsMutation Testing: Testing your tests
Mutation Testing: Testing your tests
Stephen Leigh387 views
Web technologies: Model Driven Engineering by Piero Fraternali
Web technologies: Model Driven EngineeringWeb technologies: Model Driven Engineering
Web technologies: Model Driven Engineering
Piero Fraternali5.7K views
INTRODUCTION TO SOFTWARE ENGINEERING by Prof Ansari
INTRODUCTION TO SOFTWARE ENGINEERINGINTRODUCTION TO SOFTWARE ENGINEERING
INTRODUCTION TO SOFTWARE ENGINEERING
Prof Ansari1.9K views
software testing strategies by Hemanth Gajula
software testing strategiessoftware testing strategies
software testing strategies
Hemanth Gajula37.9K views
Model-driven architecture (MDA) by Alia Hamwi
Model-driven architecture (MDA) Model-driven architecture (MDA)
Model-driven architecture (MDA)
Alia Hamwi192 views
Pressman ch-1-software by AlenaDion
Pressman ch-1-softwarePressman ch-1-software
Pressman ch-1-software
AlenaDion1.1K views
Lecture 7: Hidden Markov Models (HMMs) by Marina Santini
Lecture 7: Hidden Markov Models (HMMs)Lecture 7: Hidden Markov Models (HMMs)
Lecture 7: Hidden Markov Models (HMMs)
Marina Santini22.9K views
MATS stack (MLFlow, Airflow, Tensorflow, Spark) for Cross-system Orchestratio... by Databricks
MATS stack (MLFlow, Airflow, Tensorflow, Spark) for Cross-system Orchestratio...MATS stack (MLFlow, Airflow, Tensorflow, Spark) for Cross-system Orchestratio...
MATS stack (MLFlow, Airflow, Tensorflow, Spark) for Cross-system Orchestratio...
Databricks702 views
SE CHAPTER 2 PROCESS MODELS by Abrar ali
SE CHAPTER 2 PROCESS MODELSSE CHAPTER 2 PROCESS MODELS
SE CHAPTER 2 PROCESS MODELS
Abrar ali1.2K views
Recurrent Neural Networks for Text Analysis by odsc
Recurrent Neural Networks for Text AnalysisRecurrent Neural Networks for Text Analysis
Recurrent Neural Networks for Text Analysis
odsc6.6K views
Chapter 1 - Software Design - Introduction.pptx by HaifaMohd3
Chapter 1 - Software Design - Introduction.pptxChapter 1 - Software Design - Introduction.pptx
Chapter 1 - Software Design - Introduction.pptx
HaifaMohd389 views
LLaMA Open and Efficient Foundation Language Models - 230528.pdf by taeseon ryu
LLaMA Open and Efficient Foundation Language Models - 230528.pdfLLaMA Open and Efficient Foundation Language Models - 230528.pdf
LLaMA Open and Efficient Foundation Language Models - 230528.pdf
taeseon ryu207 views

Similar to Model driven software engineering in practice book - Chapter 9 - Model to text transformations and code generation

Model-Driven Software Engineering in Practice - Chapter 10 - Managing models by
Model-Driven Software Engineering in Practice - Chapter 10 - Managing modelsModel-Driven Software Engineering in Practice - Chapter 10 - Managing models
Model-Driven Software Engineering in Practice - Chapter 10 - Managing modelsJordi Cabot
8.4K views42 slides
Model-Driven Software Engineering in Practice - Chapter 4 - Model-Driven Arch... by
Model-Driven Software Engineering in Practice - Chapter 4 - Model-Driven Arch...Model-Driven Software Engineering in Practice - Chapter 4 - Model-Driven Arch...
Model-Driven Software Engineering in Practice - Chapter 4 - Model-Driven Arch...Jordi Cabot
10.2K views74 slides
Model-To-Text Transformation Language chapter 9 – J Cabot model driven engine... by
Model-To-Text Transformation Language chapter 9 – J Cabot model driven engine...Model-To-Text Transformation Language chapter 9 – J Cabot model driven engine...
Model-To-Text Transformation Language chapter 9 – J Cabot model driven engine...majid lotfinia
814 views43 slides
2013 Good Design Is Good Business MDD Embedded Systems by
2013 Good Design Is Good Business MDD Embedded Systems2013 Good Design Is Good Business MDD Embedded Systems
2013 Good Design Is Good Business MDD Embedded SystemsRoger Snook
730 views32 slides
Future Trends on Software and Systems Modeling by
Future Trends on Software and Systems ModelingFuture Trends on Software and Systems Modeling
Future Trends on Software and Systems ModelingJordi Cabot
2.5K views51 slides
Lightweight Model-Driven Engineering by
Lightweight Model-Driven EngineeringLightweight Model-Driven Engineering
Lightweight Model-Driven EngineeringJordi Cabot
3.4K views122 slides

Similar to Model driven software engineering in practice book - Chapter 9 - Model to text transformations and code generation(20)

Model-Driven Software Engineering in Practice - Chapter 10 - Managing models by Jordi Cabot
Model-Driven Software Engineering in Practice - Chapter 10 - Managing modelsModel-Driven Software Engineering in Practice - Chapter 10 - Managing models
Model-Driven Software Engineering in Practice - Chapter 10 - Managing models
Jordi Cabot8.4K views
Model-Driven Software Engineering in Practice - Chapter 4 - Model-Driven Arch... by Jordi Cabot
Model-Driven Software Engineering in Practice - Chapter 4 - Model-Driven Arch...Model-Driven Software Engineering in Practice - Chapter 4 - Model-Driven Arch...
Model-Driven Software Engineering in Practice - Chapter 4 - Model-Driven Arch...
Jordi Cabot10.2K views
Model-To-Text Transformation Language chapter 9 – J Cabot model driven engine... by majid lotfinia
Model-To-Text Transformation Language chapter 9 – J Cabot model driven engine...Model-To-Text Transformation Language chapter 9 – J Cabot model driven engine...
Model-To-Text Transformation Language chapter 9 – J Cabot model driven engine...
majid lotfinia814 views
2013 Good Design Is Good Business MDD Embedded Systems by Roger Snook
2013 Good Design Is Good Business MDD Embedded Systems2013 Good Design Is Good Business MDD Embedded Systems
2013 Good Design Is Good Business MDD Embedded Systems
Roger Snook730 views
Future Trends on Software and Systems Modeling by Jordi Cabot
Future Trends on Software and Systems ModelingFuture Trends on Software and Systems Modeling
Future Trends on Software and Systems Modeling
Jordi Cabot2.5K views
Lightweight Model-Driven Engineering by Jordi Cabot
Lightweight Model-Driven EngineeringLightweight Model-Driven Engineering
Lightweight Model-Driven Engineering
Jordi Cabot3.4K views
acomprehensivereviewoflargelanguagemodelsfor-230515063139-1fc27b64.pdf by YaserAli40
acomprehensivereviewoflargelanguagemodelsfor-230515063139-1fc27b64.pdfacomprehensivereviewoflargelanguagemodelsfor-230515063139-1fc27b64.pdf
acomprehensivereviewoflargelanguagemodelsfor-230515063139-1fc27b64.pdf
YaserAli401 view
A Comprehensive Review of Large Language Models for.pptx by SaiPragnaKancheti
A Comprehensive Review of Large Language Models for.pptxA Comprehensive Review of Large Language Models for.pptx
A Comprehensive Review of Large Language Models for.pptx
SaiPragnaKancheti2.3K views
1 get started with c# by Tuan Ngo
1   get started with c#1   get started with c#
1 get started with c#
Tuan Ngo458 views
MoDisco Eclipse-OMG Symp 2010 by fmadiot
MoDisco Eclipse-OMG Symp 2010MoDisco Eclipse-OMG Symp 2010
MoDisco Eclipse-OMG Symp 2010
fmadiot926 views
Acceleo Day - Orange by sliard
Acceleo Day - OrangeAcceleo Day - Orange
Acceleo Day - Orange
sliard863 views
Clean Infrastructure as Code by QAware GmbH
Clean Infrastructure as CodeClean Infrastructure as Code
Clean Infrastructure as Code
QAware GmbH311 views
Operationalizing AI at scale using MADlib Flow - Greenplum Summit 2019 by VMware Tanzu
Operationalizing AI at scale using MADlib Flow - Greenplum Summit 2019Operationalizing AI at scale using MADlib Flow - Greenplum Summit 2019
Operationalizing AI at scale using MADlib Flow - Greenplum Summit 2019
VMware Tanzu929 views
Model driven engineering for big data management systems by Marcos Almeida
Model driven engineering for big data management systemsModel driven engineering for big data management systems
Model driven engineering for big data management systems
Marcos Almeida378 views
MDD and modeling tools research by Roger Xia
MDD and modeling tools researchMDD and modeling tools research
MDD and modeling tools research
Roger Xia1.2K views

More from Marco Brambilla

Hierarchical Transformers for User Semantic Similarity - ICWE 2023 by
Hierarchical Transformers for User Semantic Similarity - ICWE 2023Hierarchical Transformers for User Semantic Similarity - ICWE 2023
Hierarchical Transformers for User Semantic Similarity - ICWE 2023Marco Brambilla
159 views31 slides
Exploring the Bi-verse. A trip across the digital and physical ecospheres by
Exploring the Bi-verse.A trip across the digital and physical ecospheresExploring the Bi-verse.A trip across the digital and physical ecospheres
Exploring the Bi-verse. A trip across the digital and physical ecospheresMarco Brambilla
373 views61 slides
Conversation graphs in Online Social Media by
Conversation graphs in Online Social MediaConversation graphs in Online Social Media
Conversation graphs in Online Social MediaMarco Brambilla
389 views30 slides
Trigger.eu: Cocteau game for policy making - introduction and demo by
Trigger.eu: Cocteau game for policy making - introduction and demoTrigger.eu: Cocteau game for policy making - introduction and demo
Trigger.eu: Cocteau game for policy making - introduction and demoMarco Brambilla
315 views26 slides
Generation of Realistic Navigation Paths for Web Site Testing using RNNs and ... by
Generation of Realistic Navigation Paths for Web Site Testing using RNNs and ...Generation of Realistic Navigation Paths for Web Site Testing using RNNs and ...
Generation of Realistic Navigation Paths for Web Site Testing using RNNs and ...Marco Brambilla
1.3K views14 slides
Analyzing rich club behavior in open source projects by
Analyzing rich club behavior in open source projectsAnalyzing rich club behavior in open source projects
Analyzing rich club behavior in open source projectsMarco Brambilla
2K views22 slides

More from Marco Brambilla(20)

Hierarchical Transformers for User Semantic Similarity - ICWE 2023 by Marco Brambilla
Hierarchical Transformers for User Semantic Similarity - ICWE 2023Hierarchical Transformers for User Semantic Similarity - ICWE 2023
Hierarchical Transformers for User Semantic Similarity - ICWE 2023
Marco Brambilla159 views
Exploring the Bi-verse. A trip across the digital and physical ecospheres by Marco Brambilla
Exploring the Bi-verse.A trip across the digital and physical ecospheresExploring the Bi-verse.A trip across the digital and physical ecospheres
Exploring the Bi-verse. A trip across the digital and physical ecospheres
Marco Brambilla373 views
Conversation graphs in Online Social Media by Marco Brambilla
Conversation graphs in Online Social MediaConversation graphs in Online Social Media
Conversation graphs in Online Social Media
Marco Brambilla389 views
Trigger.eu: Cocteau game for policy making - introduction and demo by Marco Brambilla
Trigger.eu: Cocteau game for policy making - introduction and demoTrigger.eu: Cocteau game for policy making - introduction and demo
Trigger.eu: Cocteau game for policy making - introduction and demo
Marco Brambilla315 views
Generation of Realistic Navigation Paths for Web Site Testing using RNNs and ... by Marco Brambilla
Generation of Realistic Navigation Paths for Web Site Testing using RNNs and ...Generation of Realistic Navigation Paths for Web Site Testing using RNNs and ...
Generation of Realistic Navigation Paths for Web Site Testing using RNNs and ...
Marco Brambilla1.3K views
Analyzing rich club behavior in open source projects by Marco Brambilla
Analyzing rich club behavior in open source projectsAnalyzing rich club behavior in open source projects
Analyzing rich club behavior in open source projects
Marco Brambilla2K views
Analysis of On-line Debate on Long-Running Political Phenomena. The Brexit C... by Marco Brambilla
Analysis of On-line Debate on Long-Running Political Phenomena.The Brexit C...Analysis of On-line Debate on Long-Running Political Phenomena.The Brexit C...
Analysis of On-line Debate on Long-Running Political Phenomena. The Brexit C...
Marco Brambilla445 views
Community analysis using graph representation learning on social networks by Marco Brambilla
Community analysis using graph representation learning on social networksCommunity analysis using graph representation learning on social networks
Community analysis using graph representation learning on social networks
Marco Brambilla1.6K views
Available Data Science M.Sc. Thesis Proposals by Marco Brambilla
Available Data Science M.Sc. Thesis Proposals Available Data Science M.Sc. Thesis Proposals
Available Data Science M.Sc. Thesis Proposals
Marco Brambilla1.5K views
Data Cleaning for social media knowledge extraction by Marco Brambilla
Data Cleaning for social media knowledge extractionData Cleaning for social media knowledge extraction
Data Cleaning for social media knowledge extraction
Marco Brambilla1.6K views
Iterative knowledge extraction from social networks. The Web Conference 2018 by Marco Brambilla
Iterative knowledge extraction from social networks. The Web Conference 2018Iterative knowledge extraction from social networks. The Web Conference 2018
Iterative knowledge extraction from social networks. The Web Conference 2018
Marco Brambilla1.1K views
Driving Style and Behavior Analysis based on Trip Segmentation over GPS Info... by Marco Brambilla
Driving Style and Behavior Analysis based on Trip Segmentation over GPS  Info...Driving Style and Behavior Analysis based on Trip Segmentation over GPS  Info...
Driving Style and Behavior Analysis based on Trip Segmentation over GPS Info...
Marco Brambilla2.3K views
Myths and challenges in knowledge extraction and analysis from human-generate... by Marco Brambilla
Myths and challenges in knowledge extraction and analysis from human-generate...Myths and challenges in knowledge extraction and analysis from human-generate...
Myths and challenges in knowledge extraction and analysis from human-generate...
Marco Brambilla2K views
Harvesting Knowledge from Social Networks: Extracting Typed Relationships amo... by Marco Brambilla
Harvesting Knowledge from Social Networks: Extracting Typed Relationships amo...Harvesting Knowledge from Social Networks: Extracting Typed Relationships amo...
Harvesting Knowledge from Social Networks: Extracting Typed Relationships amo...
Marco Brambilla634 views
Model-driven Development of User Interfaces for IoT via Domain-specific Comp... by Marco Brambilla
Model-driven Development of  User Interfaces for IoT via Domain-specific Comp...Model-driven Development of  User Interfaces for IoT via Domain-specific Comp...
Model-driven Development of User Interfaces for IoT via Domain-specific Comp...
Marco Brambilla1.4K views
A Model-Based Method for Seamless Web and Mobile Experience. Splash 2016 conf. by Marco Brambilla
A Model-Based Method for  Seamless Web and Mobile Experience. Splash 2016 conf.A Model-Based Method for  Seamless Web and Mobile Experience. Splash 2016 conf.
A Model-Based Method for Seamless Web and Mobile Experience. Splash 2016 conf.
Marco Brambilla783 views
Big Data and Stream Data Analysis at Politecnico di Milano by Marco Brambilla
Big Data and Stream Data Analysis at Politecnico di MilanoBig Data and Stream Data Analysis at Politecnico di Milano
Big Data and Stream Data Analysis at Politecnico di Milano
Marco Brambilla701 views
On the Quest for Changing Knowledge. Capturing emerging entities from social ... by Marco Brambilla
On the Quest for Changing Knowledge. Capturing emerging entities from social ...On the Quest for Changing Knowledge. Capturing emerging entities from social ...
On the Quest for Changing Knowledge. Capturing emerging entities from social ...
Marco Brambilla1.6K views
Studying Multicultural Diversity of Cities and Neighborhoods through Social M... by Marco Brambilla
Studying Multicultural Diversity of Cities and Neighborhoods through Social M...Studying Multicultural Diversity of Cities and Neighborhoods through Social M...
Studying Multicultural Diversity of Cities and Neighborhoods through Social M...
Marco Brambilla3.2K views

Recently uploaded

DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko... by
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...Deltares
14 views23 slides
FIMA 2023 Neo4j & FS - Entity Resolution.pptx by
FIMA 2023 Neo4j & FS - Entity Resolution.pptxFIMA 2023 Neo4j & FS - Entity Resolution.pptx
FIMA 2023 Neo4j & FS - Entity Resolution.pptxNeo4j
7 views26 slides
Copilot Prompting Toolkit_All Resources.pdf by
Copilot Prompting Toolkit_All Resources.pdfCopilot Prompting Toolkit_All Resources.pdf
Copilot Prompting Toolkit_All Resources.pdfRiccardo Zamana
8 views4 slides
EV Charging App Case by
EV Charging App Case EV Charging App Case
EV Charging App Case iCoderz Solutions
5 views1 slide
DSD-INT 2023 Leveraging the results of a 3D hydrodynamic model to improve the... by
DSD-INT 2023 Leveraging the results of a 3D hydrodynamic model to improve the...DSD-INT 2023 Leveraging the results of a 3D hydrodynamic model to improve the...
DSD-INT 2023 Leveraging the results of a 3D hydrodynamic model to improve the...Deltares
6 views22 slides
Unleash The Monkeys by
Unleash The MonkeysUnleash The Monkeys
Unleash The MonkeysJacob Duijzer
7 views28 slides

Recently uploaded(20)

DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko... by Deltares
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...
Deltares14 views
FIMA 2023 Neo4j & FS - Entity Resolution.pptx by Neo4j
FIMA 2023 Neo4j & FS - Entity Resolution.pptxFIMA 2023 Neo4j & FS - Entity Resolution.pptx
FIMA 2023 Neo4j & FS - Entity Resolution.pptx
Neo4j7 views
Copilot Prompting Toolkit_All Resources.pdf by Riccardo Zamana
Copilot Prompting Toolkit_All Resources.pdfCopilot Prompting Toolkit_All Resources.pdf
Copilot Prompting Toolkit_All Resources.pdf
Riccardo Zamana8 views
DSD-INT 2023 Leveraging the results of a 3D hydrodynamic model to improve the... by Deltares
DSD-INT 2023 Leveraging the results of a 3D hydrodynamic model to improve the...DSD-INT 2023 Leveraging the results of a 3D hydrodynamic model to improve the...
DSD-INT 2023 Leveraging the results of a 3D hydrodynamic model to improve the...
Deltares6 views
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx by animuscrm
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx
animuscrm14 views
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t... by Deltares
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...
Deltares9 views
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J... by Deltares
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...
Deltares9 views
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ... by Donato Onofri
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...
Donato Onofri825 views
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ... by Deltares
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...
Deltares11 views
Navigating container technology for enhanced security by Niklas Saari by Metosin Oy
Navigating container technology for enhanced security by Niklas SaariNavigating container technology for enhanced security by Niklas Saari
Navigating container technology for enhanced security by Niklas Saari
Metosin Oy14 views
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra... by Marc Müller
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra....NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra...
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra...
Marc Müller38 views
Myths and Facts About Hospice Care: Busting Common Misconceptions by Care Coordinations
Myths and Facts About Hospice Care: Busting Common MisconceptionsMyths and Facts About Hospice Care: Busting Common Misconceptions
Myths and Facts About Hospice Care: Busting Common Misconceptions
DSD-INT 2023 Machine learning in hydraulic engineering - Exploring unseen fut... by Deltares
DSD-INT 2023 Machine learning in hydraulic engineering - Exploring unseen fut...DSD-INT 2023 Machine learning in hydraulic engineering - Exploring unseen fut...
DSD-INT 2023 Machine learning in hydraulic engineering - Exploring unseen fut...
Deltares7 views
Fleet Management Software in India by Fleetable
Fleet Management Software in India Fleet Management Software in India
Fleet Management Software in India
Fleetable11 views
Software evolution understanding: Automatic extraction of software identifier... by Ra'Fat Al-Msie'deen
Software evolution understanding: Automatic extraction of software identifier...Software evolution understanding: Automatic extraction of software identifier...
Software evolution understanding: Automatic extraction of software identifier...
Quality Engineer: A Day in the Life by John Valentino
Quality Engineer: A Day in the LifeQuality Engineer: A Day in the Life
Quality Engineer: A Day in the Life
John Valentino6 views

Model driven software engineering in practice book - Chapter 9 - Model to text transformations and code generation

  • 1. Marco Brambilla, Jordi Cabot, Manuel Wimmer. Model-Driven Software Engineering In Practice. Morgan & Claypool 2012. Teaching material for the book Model-Driven Software Engineering in Practice by Marco Brambilla, Jordi Cabot, Manuel Wimmer. Morgan & Claypool, USA, 2012. Copyright © 2012 Brambilla, Cabot, Wimmer. www.mdse-book.com MODEL-TO-TEXT TRANSFORMATIONS CHAPTER 9
  • 2. Marco Brambilla, Jordi Cabot, Manuel Wimmer. Model-Driven Software Engineering In Practice. Morgan & Claypool 2012. Content § Introduction § Programming Languages based Code Generation § M2T Transformation based Code Generation § Mastering Code Generation
  • 3. Marco Brambilla, Jordi Cabot, Manuel Wimmer. Model-Driven Software Engineering In Practice. Morgan & Claypool 2012. www.mdse-book.com INTRODUCTION
  • 4. Marco Brambilla, Jordi Cabot, Manuel Wimmer. Model-Driven Software Engineering In Practice. Morgan & Claypool 2012. Introduction Terminology §  Code generation §  Wikipedia: „Code generation is the process by which a compiler‘s code generator converts a syntactically-correct program into a series of instructions that can be executed by a machine.“ §  Code Generation in Action (Herrington 2003): „Code generation is the technique of using or writing programs that write source code.“ §  Code generation (http://en.wikipedia.org) §  Compiler Engineering: component of the synthesis phase §  Software Engineering: program to generate source code §  Résumé: Term Code Generation is overloaded!
  • 5. Marco Brambilla, Jordi Cabot, Manuel Wimmer. Model-Driven Software Engineering In Practice. Morgan & Claypool 2012. Introduction Code Generation - Basic Questions §  How much is generated? §  Which parts can be automatically generated from models? §  Full or partial code generation? §  What is generated? §  Which kind of source code to generate? §  The less code to generate, the better! §  How to generate? §  Which languages and tools to use for developing code generators? §  GPLs vs. DSLs
  • 6. Marco Brambilla, Jordi Cabot, Manuel Wimmer. Model-Driven Software Engineering In Practice. Morgan & Claypool 2012. Introduction Code Generation in MDA (just an example) Requirements Analysis Design Implementation Test&Deployment CIM PIM PSM Code Feedback CIM PIM Web Model DAO Model SQL Model JSP Code DAO Code SQL Code Manual Development + Model2Model Transformation Model2Model Transformation Model2Text Transformation Rational Unified Process MDA Artifacts
  • 7. Marco Brambilla, Jordi Cabot, Manuel Wimmer. Model-Driven Software Engineering In Practice. Morgan & Claypool 2012. Introduction What kind of code is generated? §  Model-to-Text, whereas text may be distinguished in §  Program code §  Documentation §  Test cases §  Model serialization (XMI) §  Direct translation to machine code possible, but inconvenient, error- prone and hard to optimize §  Reuse existing code generators §  Using existing functionality (frameworks, APIs, components) §  Motto: The less code to generate, the better!
  • 8. Marco Brambilla, Jordi Cabot, Manuel Wimmer. Model-Driven Software Engineering In Practice. Morgan & Claypool 2012. Introduction Example: Platform for Web application development §  Example: developing a code generator for Web applications §  What options exist for the to be generated code? §  Dimensions of Web applications: Content, Hypertext, Presentation §  Programming languages: Java, C#, Ruby, PHP, … §  Architectures: 2-layer, 3-layer, MVC, ActiveRecords, … §  Frameworks: JSF, Spring, Struts, Hibernate, Ruby on Rails, ASP, … §  Products: MySQL, Tomcat, WebLogic, … §  Which combinations are appropriate? §  Experience gained in earlier projects §  What has proven useful? §  Reference architectures
  • 9. Marco Brambilla, Jordi Cabot, Manuel Wimmer. Model-Driven Software Engineering In Practice. Morgan & Claypool 2012. Introduction What kind of code is generated? Production code Test code Class diagrams State charts OCL Object diagrams Sequence diagrams A B C 1..* 1 1 * 1 0..1 z1 z2 z3 z4 e e‘ e‘ a:A b:B c:C m1 m2 m3 b1:B c1:C c2:C b2:B Picture based on Berhard Rumpe: Agile Modellierung mit UML. Springer, 2012.
  • 10. Marco Brambilla, Jordi Cabot, Manuel Wimmer. Model-Driven Software Engineering In Practice. Morgan & Claypool 2012. Introduction Overview of generation techniques Model Source Code Object Code or Byte Code Running Program Model Transformation Source Code Generation Code Transformation Byte Code Rewriting Reflection C++ Templates Java, . Net Java, .Net AspectJ ATL QVT Code Generation in MDE Acceleo XPand MofScript Compilation Java, . Net Based on Markus Völter. A catalog of patterns for program generation. In Proceedings of the 8th European Conference on Pattern Languages of Programs (EuroPLoP’03), pages 285–320, 2003.
  • 11. Marco Brambilla, Jordi Cabot, Manuel Wimmer. Model-Driven Software Engineering In Practice. Morgan & Claypool 2012. Introduction Why code generation? §  Code generation enables §  Separation of application modeling and technical code §  Increasing maintainability, extensibility, portability to new hardware, operating systems, and platforms §  Rapid prototyping §  Early and fast feedback due to demonstrations and test runs §  Code generation enables to combine redundant code fragments in one source §  Example: DDL, Hibernate, and Java Beans à may be specified in one UML Class Diagram
  • 12. Marco Brambilla, Jordi Cabot, Manuel Wimmer. Model-Driven Software Engineering In Practice. Morgan & Claypool 2012. Introduction Why code generation? – in contradiction to MDE? (1/2) §  Often no “real” model simulation possible §  UML environments mostly do not provide simulation features §  However, they provide transparent transformation to C, C#, Java, … §  UML Virtual Machines §  Interpreter approach – spare code generation for certain platforms §  Gets a new twist with fUML! §  Semantics of modeling languages, especially DSMLs, often defined by code generation class Car { public String color; public int door; public int engine; } Car Color : String Door : Integer Engine : Integer DSL Code Generator Java
  • 13. Marco Brambilla, Jordi Cabot, Manuel Wimmer. Model-Driven Software Engineering In Practice. Morgan & Claypool 2012. Introduction Why code generation? – in contradiction to MDE? (2/2) §  Runtime environments are designed for programming languages §  Established frameworks available (Struts, Spring, Hibernate, …) §  Systems depend on existing software (Web Services, DB) §  Extensions for code level often required (Logging) §  Disadvantage: using models and code in parallel §  No single source of information – OUCH! §  Having the same information in two places may lead to inconsistences, e.g., consider maintainability of systems
  • 14. Marco Brambilla, Jordi Cabot, Manuel Wimmer. Model-Driven Software Engineering In Practice. Morgan & Claypool 2012. Introduction Example: MiniUML_2_MiniJava MiniUML Metamodel MiniUML Model class  Student  extends  Person{        private  String  regNo;        public  void  setRegNo(…){…}        public  String  getRegNo(){…}     }   MiniJava Code MiniJava Grammar Model2Text NamedElement type : Type type 0..1 Relationship 0..1 superClass minCard : Integer maxCard : Integer * * –  String –  Boolean –  … «enumeration» Type ClassDec  :=  Modifier  “class”  Identifier  [“extends”                            Identifier]  ClassBody;     AttributeDec  :=  Modifier  Type  Identifier“;”;     MethodDec  :=  Modifier  ReturnType  Identifier  “(”                                ParamList  “)”  “{”  MethodBody  “}”;     Identifier  :=  {“a”-­‐”z”  |  “A”-­‐”Z”  |  “0”-­‐”9”};   Class Attribute name: String Person Student regNo : String
  • 15. Marco Brambilla, Jordi Cabot, Manuel Wimmer. Model-Driven Software Engineering In Practice. Morgan & Claypool 2012. www.mdse-book.com PROGRAMMING LANGUAGES BASED CODE GENERATION
  • 16. Marco Brambilla, Jordi Cabot, Manuel Wimmer. Model-Driven Software Engineering In Practice. Morgan & Claypool 2012. Programming languages Introduction – Code generation with Java based on EMF §  Code generation may be realized using a traditional general purpose programming language, e.g., Java, C#, … §  Models are de-serialized to an in-memory object graph §  Pre-defined XMI de-serialzer provided by meta-modeling frameworks §  Out-of-the-box support in EMF §  Model API eases processing of models §  Generated automatically from metamodels §  In EMF: .ecore -> .genmodel -> Java code §  If metamodel not available, you may use reflection
  • 17. Marco Brambilla, Jordi Cabot, Manuel Wimmer. Model-Driven Software Engineering In Practice. Morgan & Claypool 2012. Programming languages Model APIs for processing models §  Example: Ecore-based metamodel and automatically generated Java code (shown as UML Class Diagram) Attribute atts0..* Class name : String name : String type : Type Operation ops0..* name : String returnType : Type Ecore2Java Attribute Class Operation getName() : String setName(String) : void getAtts() : EList<Attribute> getOps() : EList<Operation> getName() : String setName(String) : void … getName() : String setName(String) : void … MM in Ecore Model API
  • 18. Marco Brambilla, Jordi Cabot, Manuel Wimmer. Model-Driven Software Engineering In Practice. Morgan & Claypool 2012. Programming languages Code generation with Java: phases of code generation 1.  Load models §  Load XMI file into memory 2.  Process models and produce code §  Process models by traversing the model structure §  Use model information to produce code §  Save code into String variable 3.  Write code §  Persist String variable to a file using streams
  • 19. Marco Brambilla, Jordi Cabot, Manuel Wimmer. Model-Driven Software Engineering In Practice. Morgan & Claypool 2012. Programming languages Code generation with Java: Process and Architecture Model Code Generator XMI Parser FileStream API Code String code; Model API e.g., UML e.g., JavaJava Object Graph M2T (1) Load (2) Produce (3) Write Process Architecture EMF
  • 20. Marco Brambilla, Jordi Cabot, Manuel Wimmer. Model-Driven Software Engineering In Practice. Morgan & Claypool 2012. Programming languages Running Example solved in Java ResourceSet  resourceSet  =  new  ResourceSetImpl();   Resource  resource  =  resourceSet.getResource(URI.create("model.miniUML"));   TreeIterator  treeIter  =  resource.getAllContents();     while  (treeIter.hasNext())  {        Object  object  =  treeIt.next();        if  (!object  instanceof  Class)  continue;          Class  cl  =  (Class)  object;        String  code  =  "class  „  +  cl.getName()  +  "{";        //  generate  Constructor:  code  +=  …        //  generate  Attributs:  code  +=  …        //  generate  Methods:  code  +=  …        code  +=  "}";              try  {          FileOutputStream  fos  =  new  FileOutputStream(cl.getName()  +".java“);          fos.write(code.getBytes());          fos.close();      }  catch  (Exception  e)  {…}   }   Query values via model API Create a file for each class Get all model elements (1) Load (2) Produce (3) Write
  • 21. Marco Brambilla, Jordi Cabot, Manuel Wimmer. Model-Driven Software Engineering In Practice. Morgan & Claypool 2012. Programming languages Summary §  Advantages §  No new languages have to be learned §  No additional tool dependencies §  Disadvantages §  Intermingled static/dynamic code §  Non-graspable output structure §  Lack of declarative query language §  Lack of reusable base functionality
  • 22. Marco Brambilla, Jordi Cabot, Manuel Wimmer. Model-Driven Software Engineering In Practice. Morgan & Claypool 2012. www.mdse-book.com M2T TRANSFORMATION BASED CODE GENERATION
  • 23. Marco Brambilla, Jordi Cabot, Manuel Wimmer. Model-Driven Software Engineering In Practice. Morgan & Claypool 2012. M2T Transformation Languages… …are Template based §  Templates are a well-established technique in software engineering §  Application domains: Text processing, Web engineering, … §  Example: §  Components of a template-based approach §  Templates §  Text fragments and embedded meta-markers §  Meta-markers query an additional data source §  Have to be interpreted and evaluated in contrast to text fragments §  Declarative model query: query languages (OCL, XPath, SQL) §  Imperative model query: programming languages (Java, C#) §  Template engine §  Replaces meta-markers with data at runtime and produces output files Dear Homer Simpson, Congratulations! You have won … E-Mail Text Dear «firstName» «lastName», Congratulations! You have won … Template Text
  • 24. Marco Brambilla, Jordi Cabot, Manuel Wimmer. Model-Driven Software Engineering In Practice. Morgan & Claypool 2012. M2T Transformation Languages Core Architecture §  Template-based approach at a glance «context class» public class «name» { String id, … } Template Engine Query Result Input public class Person { String id, …} Template Text fragment Meta-marker Output1 Output2 …public class Customer { String id, …} Person Customer … Source Model Produced Text
  • 25. Marco Brambilla, Jordi Cabot, Manuel Wimmer. Model-Driven Software Engineering In Practice. Morgan & Claypool 2012. M2T Transformation Languages Benefits §  Separated static/dynamic code §  Templates separate static code, i.e., normal text, from dynamic code that is described by meta-markers §  Explicit output structure §  Primary structure of the template is the output structure §  Computation logic is embedded in this structure §  Declarative query language §  OCL is employed to query the input models §  Reusable base functionality §  Support for reading in models, serialize text to files, …
  • 26. Marco Brambilla, Jordi Cabot, Manuel Wimmer. Model-Driven Software Engineering In Practice. Morgan & Claypool 2012. M2T Transformation Languages Approaches § A bunch of template languages for M2T transformation available § JET, JET2 § Xpand, Xtend § MOFScript § Acceleo § XSLT § …
  • 27. Marco Brambilla, Jordi Cabot, Manuel Wimmer. Model-Driven Software Engineering In Practice. Morgan & Claypool 2012. Acceleo Introduction §  Acceleo is a mature implementation of the OMG M2T transformation standard §  Acceleo website: http://www.eclipse.org/acceleo/ §  M2T Transformation standard: http://www.omg.org/spec/MOFM2T §  Template-based language §  Several meta-markers for useful for code generation available §  Powerful API supporting §  OCL §  String manipulation functions §  … §  Powerful tooling supporting §  Editor, debugger, profiler, traceability between model and code, …
  • 28. Marco Brambilla, Jordi Cabot, Manuel Wimmer. Model-Driven Software Engineering In Practice. Morgan & Claypool 2012. Acceleo Language Concepts § Module concept is provided § Imports the metamodels for the input models § Act as container for templates § A template is always defined for a particular meta-class § Plus an optional pre-condition to filter instances § Templates may call each other § Templates may extended each other § Templates contain text and provided meta-markers
  • 29. Marco Brambilla, Jordi Cabot, Manuel Wimmer. Model-Driven Software Engineering In Practice. Morgan & Claypool 2012. Acceleo Language Concepts §  Several meta-markers (called tags) are supported §  File Tag: To open and close files in which code is generated §  For/If Tag: Control constructs for defining loops and conditions §  Query Tag: Reusable helper functions §  Expression Tag: Compute values that are embedded in the output §  Protected Tag: Define areas that are not overridden by future generation runs
  • 30. Marco Brambilla, Jordi Cabot, Manuel Wimmer. Model-Driven Software Engineering In Practice. Morgan & Claypool 2012. Acceleo Example [module generateJavaClass('http://smvcml/1.0')] [query public getter(att : Attribute) : String = 'get'+att.name.toUpperFirst() /] [query public returnStatement(type: String) : String = if type = 'Boolean' then 'return true;' else '...' endif /] [template public javaClass(aClass : Class)] [file (aClass.name.toUpperFirst()+'.java', false, 'UTF-8')] package entities; import java.io.Serializable; public class [aClass.name/] implements Serializable { [for (att : Attribute | aClass.atts) separator ('n')] [javaAttribute(att)/] [/for] [for (op : Operation | aClass.ops) separator ('n')] [javaMethod(op)/] [/for] } [/file] [/template] … … [template public javaAttribute(att : Attribute)] private [att.type/] [att.name/]; public [att.type/] [att.getter()/]() { return [att.name/]; } ... [/template] [template public javaMethod(op : Operation)] public [op.type/] [op.name/]() { // [protected (op.name)] // Fill in the operation implementation here! [returnStatement(op.type)/] // [/protected] } [/template] Import metamodel (root package) Template definition Open output file Close output file Expression Meta class Loop Static Text Protected Area Query Template Call
  • 31. Marco Brambilla, Jordi Cabot, Manuel Wimmer. Model-Driven Software Engineering In Practice. Morgan & Claypool 2012. Acceleo Protected Areas §  Protected areas are not overriden by the next generator run §  They are marked by comments §  Their content is merged with the newly produced code §  If the right place cannot be found, warning is given! §  Example public boolean checkAvailability(){ // Start of user code checkAvailability // Fill in the operation implementation here! return true; // End of user code }
  • 32. Marco Brambilla, Jordi Cabot, Manuel Wimmer. Model-Driven Software Engineering In Practice. Morgan & Claypool 2012. www.mdse-book.com MASTERING CODE GENERATION
  • 33. Marco Brambilla, Jordi Cabot, Manuel Wimmer. Model-Driven Software Engineering In Practice. Morgan & Claypool 2012. Abstracting Templates §  To ensure that generated code is accepted by developers (cf. Turing test for code-generation), familiar code should be generated §  Especially when only a partial code generation is possible! §  Abstract code generation templates from reference code to have known structure and coding guidelines considered §  Acceleo supports dedicated refactorings to transform code into templates §  E.g., substitute String with Expression Tag
  • 34. Marco Brambilla, Jordi Cabot, Manuel Wimmer. Model-Driven Software Engineering In Practice. Morgan & Claypool 2012. Generating step-by-step §  Divide code generation process into several steps §  Same applies as for M2M transformations! §  Transformation chains may use a mixture of M2M and M2T transformations §  To keep the gap between the models and the code short §  If code generators exists, try to produce their required input format with simpler M2M or M2T transformations §  E.g., code generator for flat state machines, transform composite state machines to flat ones and run existing code generator
  • 35. Marco Brambilla, Jordi Cabot, Manuel Wimmer. Model-Driven Software Engineering In Practice. Morgan & Claypool 2012. Separating transformation logic from text §  Separete complex transformation logic from text fragements §  Use queries or libraries that are imported to the M2T transformation §  By this, templates get more readable and maintainable §  Queries may be reused
  • 36. Marco Brambilla, Jordi Cabot, Manuel Wimmer. Model-Driven Software Engineering In Practice. Morgan & Claypool 2012. Mastering code layout §  Code layout is determined by the template layout §  Challenging to produce code layout when several control structures such as loops and conditionals are used in the template §  Special escape characters for line breaks used for enhancing the reabability of the template are provided §  Alternative §  Use code beautifiers in a post-processing step §  Supported by Xpand for Java/XML out-of-the-box
  • 37. Marco Brambilla, Jordi Cabot, Manuel Wimmer. Model-Driven Software Engineering In Practice. Morgan & Claypool 2012. Model/code synchronization issues §  Protected areas help saving manually added code in succeeding generator runs §  Code contained in protected areas is not always automatically integrated in the newly generated code §  Assume a method is renamed on model level §  Where to place the code of the method implementation? §  Which identifier to use for identifying a protected area? §  Natural or artificial identifiers? §  Model refactorings may be replayed on the code level before the next generator run is started §  Code in protected areas may also reflect the refactorings!
  • 38. Marco Brambilla, Jordi Cabot, Manuel Wimmer. Model-Driven Software Engineering In Practice. Morgan & Claypool 2012. Code Generation = M2M + TCS? §  Code Generation achievable through applying a M2M transformations to a programming language metamodel §  If a TCS is available for the programming language metamodel, the resulting model may be directly serialized into text §  Only recommended when §  programming language metamodel + TCS are already available §  full code generation is possible Model Metamodel (ModLang) Model Metamodel (ProgLang) M2M Spec M2M Exec TCS Spec (ProgLang) TCS Serialization «conformsTo» «conformsTo» «conformsTo» visualizes symbolizes
  • 39. Marco Brambilla, Jordi Cabot, Manuel Wimmer. Model-Driven Software Engineering In Practice. Morgan & Claypool 2012. Teaching material for the book Model-Driven Software Engineering in Practice by Marco Brambilla, Jordi Cabot, Manuel Wimmer. Morgan & Claypool, USA, 2012. Copyright © 2012 Brambilla, Cabot, Wimmer. www.mdse-book.com MODEL-DRIVEN SOFTWARE ENGINEERING IN PRACTICE Marco Brambilla, Jordi Cabot, Manuel Wimmer. Morgan & Claypool, USA, 2012. www.mdse-book.com www.morganclaypool.com