Open Source Modeling MDSD with Eclipse and o

  • Slides: 43
Download presentation
Open Source Modeling MDSD with Eclipse and o. AW Markus Voelter voelter@acm. org www.

Open Source Modeling MDSD with Eclipse and o. AW Markus Voelter voelter@acm. org www. voelter. de Bernd Kolb b. kolb@kolbware. de www. kolbware. de Peter Friese peter. friese@itemis. de oaw. itemis. eu

Overview Open Source MDSD with Eclipse and o. AW

Overview Open Source MDSD with Eclipse and o. AW

Eclipse Modeling in a Nutshell Eclipse Modeling is the umbrella project for all things

Eclipse Modeling in a Nutshell Eclipse Modeling is the umbrella project for all things modeling that happen on the Eclipse platform: The Eclipse Modeling Project focuses on the evolution and promotion of model-based development technologies within the Eclipse community by providing a unified set of modeling frameworks, tooling, and standards implementations. Eclipse Modeling is not formally related to OMG, but implements several of their standards. It is fair to say that many leading edge modeling tools are hosted/developed at Eclipse Modeling. Everything Open Source under the Eclipse Public License © Bernd Kolb, Markus Voelter, Peter Friese 2008

EMP Core: EMF The Eclipse Modeling Framework (EMF) serves as the foundation: It provides

EMP Core: EMF The Eclipse Modeling Framework (EMF) serves as the foundation: It provides the Ecore Metamodel and frameworks and tools around it for tasks such as Editing Transactions Validation Query Distribution/Persistence (CDO, Net 4 j, Teneo) © Bernd Kolb, Markus Voelter, Peter Friese 2008

EMP Concrete Syntax: GMF and TMF The Graphical Modeling Framework (GMF) is used for

EMP Concrete Syntax: GMF and TMF The Graphical Modeling Framework (GMF) is used for building custom graphical editors based on meta models defined via EMF. It is currently in version 2. x Proven technology, used in many industrial-strength systems Based on Eclipse GEF The Textual Modeling Framework is used for building custom textual editors. Project is currently being set up Will be populated initially from o. AW Xtext and INRIA TCS. © Bernd Kolb, Markus Voelter, Peter Friese 2008

EMP Concrete Syntax: Model Development Tools UML 2. x: An implementation of the UML

EMP Concrete Syntax: Model Development Tools UML 2. x: An implementation of the UML 2 meta model based on EMF UML 2 Tools: GMF editors for the UML 2 models OCL: APIs for OCL expression syntax for implementing queries and contraints. XSD Infoset: reference library that provides an API for use with any code that examines, creates or modifies W 3 C XML Schema. © Bernd Kolb, Markus Voelter, Peter Friese 2008

EMP Concrete Syntax: Model Transformation Tools M 2 M (Model-to-Model) : delivers an extensible

EMP Concrete Syntax: Model Transformation Tools M 2 M (Model-to-Model) : delivers an extensible framework for model-to-model transformation languages. ATL: M 2 M language from INRIA QVT implementations M 2 T (Model-to-Text) : focuses on technologies for transforming models into text (code generation) JET : provides code generation framework & facilities that are used by EMF. Xpand: o. AW’s code generation engine, to be part of M 2 T in the Ganymede release © Bernd Kolb, Markus Voelter, Peter Friese 2008

open. Architecture. Ware: An integrated toolkit for MDSD An integrated, tested, one-stop toolkit for

open. Architecture. Ware: An integrated toolkit for MDSD An integrated, tested, one-stop toolkit for MDSD Version 4. 3 is current (4. 3. 1 being built) Proven track record in various domains & project contexts Stable, productive and helpful developer, support and user communities www. openarchitectureware. org and eclipse. org/gmt/oaw Integration with Eclipse: Uses EMF as a basis Graphical editors based on GMF All editors and tooling based on Eclipse © Bernd Kolb, Markus Voelter, Peter Friese 2008

open. Architecture. Ware 5 Version 5 currently under development: Migration of o. AW Components

open. Architecture. Ware 5 Version 5 currently under development: Migration of o. AW Components to Eclipse Modeling proper: Xpand, Xtend, Check Model-to-Text (M 2 T) Xtext Textual Modeling Framework (TMF) Workflow Modeling Workflow Engine (MWE) More features New backend: a VM for M 2 T (and maybe more languages) Mixing Languages: Xpand, Xtend, Check in one file Xtext: Grammar Fragments and the stuff from the 4. 3 beta Generic Tree/Form Editor, mixing editors Wizard Framework © Bernd Kolb, Markus Voelter, Peter Friese 2008

EMP GMT open. Architecture. Ware II: Overview on a Slide © Bernd Kolb, Markus

EMP GMT open. Architecture. Ware II: Overview on a Slide © Bernd Kolb, Markus Voelter, Peter Friese 2008

Abstract Syntax/ Metamodeling Open Source MDSD with Eclipse and o. AW

Abstract Syntax/ Metamodeling Open Source MDSD with Eclipse and o. AW

Creating the metamodel EMF EMOF implementation Roughly similar to the capabilities of UML Class

Creating the metamodel EMF EMOF implementation Roughly similar to the capabilities of UML Class Diagram No bidirectional associations, only unidir. references UML 2 ▪ Reference implementation of the OMG’s UML 2 spec ▪ UML 2 Class Models can be transformed into an EMF meta model Default EMF tree editor GMF Ecore demo editor / Ecore Tools Xtext Grammar © Bernd Kolb, Markus Voelter, Peter Friese 2008

Creating the metamodel II One approach is to use a UML tool (one which

Creating the metamodel II One approach is to use a UML tool (one which supports Eclipse UML 2 export) and transform the model into an Ecore meta model. An alternative is to use a suitable textual notation (make sure you can distribute the model over several files…!) o. AW uml 2 ecore • • • Ecore File Name Management (qualified, namespaces) Various constraints © Bernd Kolb, Markus Voelter, Peter Friese 2008

Concrete Syntax Open Source MDSD with Eclipse and o. AW

Concrete Syntax Open Source MDSD with Eclipse and o. AW

Default EMF Editor EMF’s default reflective editor can be used out of the box

Default EMF Editor EMF’s default reflective editor can be used out of the box to create instances of any meta model Generic, But not very usable or scalable © Bernd Kolb, Markus Voelter, Peter Friese 2008

GMF – Graphical Editors GMF – The Graphical Modeling Framework Define custom graphical editors

GMF – Graphical Editors GMF – The Graphical Modeling Framework Define custom graphical editors for your meta model Use the editor to “draw” instances of the meta model © Bernd Kolb, Markus Voelter, Peter Friese 2008

GMF – Graphical Editors (II) © Bernd Kolb, Markus Voelter, Peter Friese 2008

GMF – Graphical Editors (II) © Bernd Kolb, Markus Voelter, Peter Friese 2008

TMF / Xtext makes this much more feasible. Based on an EBNF grammar it

TMF / Xtext makes this much more feasible. Based on an EBNF grammar it generates ANTLR 3 -based parser EMF-based metamodel Eclipse editor with ▪ syntax highlighting ▪ code completion ▪ customizable outline ▪ code folding ▪ real-time constraint checking Xtext is part of open. Architecture. Ware / Eclipse Modeling © Bernd Kolb, Markus Voelter, Peter Friese 2008

TMF / Xtext (II) © Bernd Kolb, Markus Voelter, Peter Friese 2008

TMF / Xtext (II) © Bernd Kolb, Markus Voelter, Peter Friese 2008

TMF / Xtext (III) © Bernd Kolb, Markus Voelter, Peter Friese 2008

TMF / Xtext (III) © Bernd Kolb, Markus Voelter, Peter Friese 2008

Defining The Grammar is defined in an EBNF-like format in the Xtext editor. The

Defining The Grammar is defined in an EBNF-like format in the Xtext editor. The editor provides code completion and constraint checking for the grammars themselves Grammar is a collection of Rules start with their name followed by : and ending with ; © Bernd Kolb, Markus Voelter, Peter Friese 2008

The derived EMF meta model The Xtext generator builds an EMF meta model from

The derived EMF meta model The Xtext generator builds an EMF meta model from the grammar. The generated parser then instantiates the meta model from a model. Processing Xtext models is based on this meta model: all existing EMF tooling is suitable for processing. We’ll show a code gen templater © Bernd Kolb, Markus Voelter, Peter Friese 2008

Validation Open Source MDSD with Eclipse and o. AW

Validation Open Source MDSD with Eclipse and o. AW

Validation is very important! Constrain the models over what Ecore can express directly Fail

Validation is very important! Constrain the models over what Ecore can express directly Fail early in the development process – more semantics! Report errors and warnings to the user Only run transformations and generators on a valid model OCL Implementation for OMG’s spec No nice editor yet Check Part of M 2 T’s Xpand OCL like with some useful extensions © Bernd Kolb, Markus Voelter, Peter Friese 2008

Constraint Checks Uses the o. AW Check language, based on Xtend Used to validate

Constraint Checks Uses the o. AW Check language, based on Xtend Used to validate the static semantics of the models Report Warnings and Errors Based completely on the generated meta model, no concrete syntax hassles Tool support (syntax highlighting, code completion, …) © Bernd Kolb, Markus Voelter, Peter Friese 2008

Real Time Constraint Validation The constraints defined for the language are evaluated in the

Real Time Constraint Validation The constraints defined for the language are evaluated in the editor on the fly. Xtext/TMF GMF Constraints can also be checked as part of a workflow that processes the models. © Bernd Kolb, Markus Voelter, Peter Friese 2008

Sidebar: Xtend OCL-like expression language used throughout o. AW Can be used in constraint

Sidebar: Xtend OCL-like expression language used throughout o. AW Can be used in constraint checks, model transformations and generators Add “methods” to meta types (Java calls are possible if necessary) path expressions, set operations, (some) higher order functions Polymorphism (multiple dispatch) Tool support (syntax highlighting, code completion, debugger) © Bernd Kolb, Markus Voelter, Peter Friese 2008

Code Generation Open Source MDSD with Eclipse and o. AW

Code Generation Open Source MDSD with Eclipse and o. AW

Xpand Template Language o. AW’s Xpand template language is a powerful and well established

Xpand Template Language o. AW’s Xpand template language is a powerful and well established code generation facility with nice tooling. You can easily traverse the model/meta model using the Xtend language (à la OCL) © Bernd Kolb, Markus Voelter, Peter Friese 2008

Xpand (II) Designed specifically for code (actually, text) generation OO template engine supporting template

Xpand (II) Designed specifically for code (actually, text) generation OO template engine supporting template polymorphism French quotation marks as escape characters Embedded Expressions based on Xtend (OCL-like) Support for Recursion Support for Template Varibility using AOP Metamodel-aware Editor with Code Completion and Syntax Highlighting Debugger © Bernd Kolb, Markus Voelter, Peter Friese 2008

Xpand (III) Import: make meta models visible to template file Define: define a new

Xpand (III) Import: make meta models visible to template file Define: define a new template File: open a file into which output is written Expand: Call another template for one or several elements Foreach: iterate over coll. , generate code for each element If: conditional template code Extension: import an extension file for use in the templates Error: report an error Let: define a temporary variable Proteced regions: well, you should not use this… Rem: define comments Around: advice other templates (AO) © Bernd Kolb, Markus Voelter, Peter Friese 2008

Extensions It is good practice to keep a generator simple Complex (and/or reused) expression

Extensions It is good practice to keep a generator simple Complex (and/or reused) expression should not be put into templates Xpand can delegate these parts to another language Xtend is used for this purpose You have to import the extension files you’d like to use o. AW comes with a set of utility extensions. They can be found in the stdlib © Bernd Kolb, Markus Voelter, Peter Friese 2008

Sidebar: Xtend OCL-like expression language used throughout o. AW Can be used in constraint

Sidebar: Xtend OCL-like expression language used throughout o. AW Can be used in constraint checks, model transformations and generators Add “methods” to meta types (Java calls are possible if necessary) path expressions, set operations, (some) higher order functions Polymorphism (multiple dispatch) Tool support (syntax highlighting, code completion, debugger) © Bernd Kolb, Markus Voelter, Peter Friese 2008

Aspect-Orientation (AOP) AOP is an important mechanism to adapt existing transformations and generators by

Aspect-Orientation (AOP) AOP is an important mechanism to adapt existing transformations and generators by “advising” before/after/around existing templates non-invasively Define variants of generators in the context of PLE. Aspects can be added to Xtend functions and Xpand templates © Bernd Kolb, Markus Voelter, Peter Friese 2008

Separate Generated and Non. Generated Code Keep generated and non-generated code in separate files.

Separate Generated and Non. Generated Code Keep generated and non-generated code in separate files. Never modify generated code. Design an architecture that clearly defines which artifacts are generated, and which are not. Use suitable design approaches to “join” generated and nongenerated code. Interfaces as well as design patterns such as factory, strategy, bridge, or template method are good starting points. © Bernd Kolb, Markus Voelter, Peter Friese 2008

Separate Generated and Non. Generated Code II A) Generated code can call nongenerated code

Separate Generated and Non. Generated Code II A) Generated code can call nongenerated code contained in libraries B) A non-generated framework can call generated parts. C) Factories can be used to „plug-in“ the generated building blocks D) Generated classes can also subclass non-generated classes. E) The base class can also contain abstract methods that it calls, they are implemented by the generated subclasses (template method pattern) © Bernd Kolb, Markus Voelter, Peter Friese 2008

Recipe Framework Recipes can be arranged hierarchically This is a failed check „Green“ ones

Recipe Framework Recipes can be arranged hierarchically This is a failed check „Green“ ones can also be hidden Here you can see additional information about the selected recipe © Bernd Kolb, Markus Voelter, Peter Friese 2008

Recipe Framework (II) Adding the extends clause makes all of them green © Bernd

Recipe Framework (II) Adding the extends clause makes all of them green © Bernd Kolb, Markus Voelter, Peter Friese 2008

Model-2 -Model Open Source MDSD with Eclipse and o. AW

Model-2 -Model Open Source MDSD with Eclipse and o. AW

Transformations and Modifications © Bernd Kolb, Markus Voelter, Peter Friese 2008

Transformations and Modifications © Bernd Kolb, Markus Voelter, Peter Friese 2008

Xtend for M 2 M Xtend has some special support for M 2 M

Xtend for M 2 M Xtend has some special support for M 2 M transformations Create-Extensions are used to create a new instance ▪ A new element is created only once for the same set of parameters Cached Extension can be used for perfomence improvements ▪ The same value is returned each time the extension is called with the same set of parameters Several utility extensions for naming, tracing, debugging, cloning, … © Bernd Kolb, Markus Voelter, Peter Friese 2008

M 2 M Example © Bernd Kolb, Markus Voelter, Peter Friese 2008

M 2 M Example © Bernd Kolb, Markus Voelter, Peter Friese 2008

The End. Thanks. Open Source MDSD with Eclipse and o. AW

The End. Thanks. Open Source MDSD with Eclipse and o. AW