Eclipse Modeling

Open Source Modeling
Markus Voelter
[email protected]
www.voelter.de
Bernd Kolb
[email protected]
www.kolbware.de
Peter Friese
[email protected]
oaw.itemis.eu
Open Source MDSD

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

The Eclipse Modeling Framework (EMF) serves as the
foundation: It provides the Ecore Metametamodel and
frameworks and tools around it for tasks such as
 Editing
 Transactions
 Validation
 Query
 Distribution/Persistence (CDO, Net4j, Teneo)
© Bernd Kolb, Markus Voelter, Peter Friese 2008

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 oAW Xtext and INRIA TCS.
© Bernd Kolb, Markus Voelter, Peter Friese 2008

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 W3C XML
Schema.
© Bernd Kolb, Markus Voelter, Peter Friese 2008

M2M (Model-to-Model) : delivers an extensible framework
for model-to-model transformation languages.
 ATL: M2M language from INRIA
 QVT implementations

M2T (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: oAW’s code generation engine, to be part of M2T in the
Ganymede release
© Bernd Kolb, Markus Voelter, Peter Friese 2008

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

Version 5 currently under development:

Migration of oAW Components to Eclipse Modeling proper:
 Xpand, Xtend, Check  Model-to-Text (M2T)
 Xtext  Textual Modeling Framework (TMF)
 Workflow  Modeling Workflow Engine (MWE)

More features
 New backend: a VM for M2T (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
© Bernd Kolb, Markus Voelter, Peter Friese 2008
Open Source MDSD

EMF
 EMOF implementation
 Roughly similar to the capabilities of UML Class Diagram
 No bidirectional associations, only unidir. references

UML2
▪ Reference implementation of the OMG’s UML2 spec
▪ UML2 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

One approach is to use a
UML tool (one which
supports Eclipse UML2
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…!)
oAW uml2ecore
•
•
•
Ecore File
Name Management
(qualified, namespaces)
Various constraints
© Bernd Kolb, Markus Voelter, Peter Friese 2008
Open Source MDSD

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 – 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
© Bernd Kolb, Markus Voelter, Peter Friese 2008

Xtext makes this much more feasible.

Based on an EBNF grammar it generates
 ANTLR3-based parser
 EMF-based metamodel
 Eclipse editor with
▪ syntax highlighting
▪ code completion
▪ customizable outline
▪ code folding
▪ real-time constraint checking

Xtext is part of openArchitectureWare / Eclipse Modeling
© Bernd Kolb, Markus Voelter, Peter Friese 2008
© Bernd Kolb, Markus Voelter, Peter Friese 2008
© Bernd Kolb, Markus Voelter, Peter Friese 2008

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. Rules start with
their name followed by
: and ending with ;
© Bernd Kolb, Markus Voelter, Peter Friese 2008

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
template later
© Bernd Kolb, Markus Voelter, Peter Friese 2008
Open Source MDSD

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 M2T’s Xpand
 OCL like with some useful extensions
© Bernd Kolb, Markus Voelter, Peter Friese 2008

Uses the oAW 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

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

OCL-like expression language used throughout oAW
 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
Open Source MDSD

oAW’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

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
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

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

oAW comes with a set
of utility extensions.
They can be found in
the stdlib
© Bernd Kolb, Markus Voelter, Peter Friese 2008

OCL-like expression language used throughout oAW
 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

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
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.

Connected by Patterns, etc.
Application
Model
Generator
Complete
System
Manually
Written
Source
Generated
Source
Compiler/
Build Tool
© Bernd Kolb, Markus Voelter, Peter Friese 2008





A) Generated code can call
non-generated 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)
a)
b)
c)
d)
generated code
e)
non-generated code
© Bernd Kolb, Markus Voelter, Peter Friese 2008
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
Adding the extends
clause makes all of them
green
© Bernd Kolb, Markus Voelter, Peter Friese 2008
Open Source MDSD
Model M
Model M
Model
Modfication
Model M
Model K
Model M
Model
Transformation
© Bernd Kolb, Markus Voelter, Peter Friese 2008

Xtend has some special support for M2M 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
© Bernd Kolb, Markus Voelter, Peter Friese 2008
Open Source MDSD