Famix Next-Generation
Julien Deplanque
julien.deplanque@inria.fr
Introduction
Objectives
Understand Famix Next Generation (NG)
Get familiar with the DSL
Resources
https://github.com/SquareBracketAssociates/Booklet-
FamixNG (in progress)
How it works
Describe your meta-model using the DSL
Generator
Class
Trait
Trait
Class
Class
Class
Differences with previous version
(Old) Famix Famix NG
Implement MM as Pharo classes. Implement MM using the
DSL
Huge usage of inheritance. Huge usage of traits.
Single MM. Multiple MM.
Verifications on the MM once
created.
Verifications on the MM
from its specification
written using the DSL.
Take a step back
Presentation
Slide
Slide
Take a step back
Slide
Slide
Uniform Resource Identifier
(URI)
A simple meta-model for presentations
Uri
+ uri: String
Presentation
Slide
0..*
0..*
0..*
presentation
slides
referencedBy
referencing
FamixNG-ified meta-model for presentations
Uri
+ uri: String
Presentation
Slide
0..*
0..*
1
presentation
slides
UriReference
0..*
1
source
outgoingReferences
target
incomingReferences
The DSL - Entities
Selector Meaning
#newClassNamed:comment: Creates a new class for the MM
#newTraitNamed:comment: Creates a new stateful trait for the MM
Question: How to choose?
Classes must be used for entities that will be instantiated.
Traits can not be instantiated.
Can only inherit from one class.
Can “inherit” from multiple traits.
Example
presentation := builder newClassNamed: #Presentation.
slide := builder newClassNamed: #Slide.
uri := builder newClassNamed: #Uri.
uriReference := builder newClassNamed: #UriReference.
The DSL - Inheritance
Selector Short version Meaning
generalization: --|> Inheritance relation
Remark: Can be written the other way around (<|- -).
Example (1)
Uri
+ uri: String
Presentation
Slide
0..*
0..*
1
presentation
slides
UriReference
0..*
1
source
outgoingReferences
target
incomingReferences
NamedEntity
+ name: String
Association
Entity
presentation --|> namedEntity.
slide --|> namedEntity. uriReference --|> association.
uri --|> entity.
Example (2)
Uri
+ uri: String
Presentation
Slide
0..*
0..*
1
presentation
slides
UriReference
0..*
1
source
outgoingReferences
target
incomingReferences
NamedEntity
+ name: String
Association
Entity
TWithReferences TReference
TReferenceable
0..*
1target
incomingReferences
0..*
1 outgoingReferences
source
slide --|> #TWithReferences.
uriReference --|> #TReference.
uri --|> #TReferenceable
The DSL - Relations
Selector Short version Meaning
oneBelongsTo: -<> Composition with 1 child
manyBelongTo: *-<> Composition with 0..* children
containsOne: <>- Composition with 1 child
containsMany: <>-* Composition with 0..* children
oneToOne: - Association 0..1 to 0..1
oneToMany: -* Association 0..1 to 0..*
manyToOne: *- Association 0..* to 0..1
manyToMany: *-* Association 0..* to 0..*
Remark: As in the old Famix, Famix NG relations ensure
that if one side of the relation is modified, the other side
is updated accordingly.
Example
Uri
+ uri: String
Presentation
Slide
0..*
0..*
1
presentation
slides
UriReference
0..*
1
source
outgoingReferences
target
incomingReferences
(presentation property: #slides)
    <>-* (slide property: #presentation)
The DSL - Properties
Selector Meaning
#property:type: Creates a property for the class/trait.
Example
Uri
+ uri: String
Presentation
Slide
0..*
0..*
1
presentation
slides
UriReference
0..*
1
source
outgoingReferences
target
incomingReferences
uri property: #uri type: #String.
Summary (part 1)
defineClasses
super defineClasses.
presentation := builder newClassNamed: #Presentation.
slide := builder newClassNamed: #Slide.
uri := builder newClassNamed: #Uri.
uriReference := builder newClassNamed: #UriReference.
defineHierarchy
super defineHierarchy.
presentation --|> namedEntity.
slide --|> namedEntity.
slide --|> #TWithReferences.
uriReference --|> association.
uriReference --|> #TReference.
uri --|> entity.
uri --|> #TReferenceable.
Summary (part 2)
defineRelations
super defineRelations.
(presentation property: #slides)
<>-* (slide property: #presentation)
defineProperties
super defineProperties.
uri property: #uri type: #String
Basic infrastructure traits catalog
Famix-Traits package provides a set of traits implementing
generic concepts reusable accross meta-models.
FamixTReference, FamixTReferenceable and
FamixTWithReferences
FamixTAccess, FamixTAccessible and
FamixTWithAccesses
FamixTClass and FamixTWithClasses
. . .
To use one of these traits in your meta-model builder, reference
it via a symbol (without Famix prefix).
"Here you make Uri class use FamixTReferenceable"
uri --|> #TReferenceable.
In practice: Step 1
Create a subclass of one of
FamixMetamodelGenerator
FamixBasicInfrastructureGenerator
FamixFileBasedLanguageGenerator
In practice: Step 2
Implement class-side methods #packageName (name of the package
in which the MM will be generated) and prefix (prefix for your
generated classes)
In practice: Step 3
Override the following instance-side methods depending on what
part of the MM you describe:
#defineClasses for classes definitions
#defineHierarchy for classes inheritance definitions
#defineRelations for classes relations definitions
#defineProperties to define classes properties
#defineTraits for traits definitions
In practice (summary)
1. Create a subclass of one of
FamixMetamodelGenerator
FamixBasicInfrastructureGenerator
FamixFileBasedLanguageGenerator
2. Implement class-side methods #packageName (name of the
package in which the MM will be generated) and prefix
(prefix for your generated classes)
3. Override the following instance-side methods depending on
what part of the MM you describe:
#defineClasses for classes definitions
#defineHierarchy for classes inheritance definitions
#defineRelations for classes relations definitions
#defineProperties to define classes properties
#defineTraits for traits definitions
Tutorial time: Presentation
Load a fresh Moose 7 image from the CI and implement the
previous meta-model.
Metacello new
repository:
'github://juliendelplanque/FamixNG-Slides/src';
baseline: 'FamixNGSlides';
load: 'Tutorial'.
Hint: the meta-model
Uri
+ uri: String
Presentation
Slide
0..*
0..*
1
presentation
slides
UriReference
0..*
1
source
outgoingReferences
target
incomingReferences
Tutorial time: Fortran
https://github.com/juliendelplanque/FamixNGFortran
Metacello new repository:
'github://juliendelplanque/FamixNGFortran/src';
baseline: 'FamixNGFortran'; load: 'Tutorial'.
Tutorial time: Fortran

Famix Next-Generation

  • 1.
  • 2.
    Introduction Objectives Understand Famix NextGeneration (NG) Get familiar with the DSL Resources https://github.com/SquareBracketAssociates/Booklet- FamixNG (in progress)
  • 3.
    How it works Describeyour meta-model using the DSL Generator Class Trait Trait Class Class Class
  • 4.
    Differences with previousversion (Old) Famix Famix NG Implement MM as Pharo classes. Implement MM using the DSL Huge usage of inheritance. Huge usage of traits. Single MM. Multiple MM. Verifications on the MM once created. Verifications on the MM from its specification written using the DSL.
  • 5.
    Take a stepback Presentation Slide Slide
  • 6.
    Take a stepback Slide Slide Uniform Resource Identifier (URI)
  • 7.
    A simple meta-modelfor presentations Uri + uri: String Presentation Slide 0..* 0..* 0..* presentation slides referencedBy referencing
  • 8.
    FamixNG-ified meta-model forpresentations Uri + uri: String Presentation Slide 0..* 0..* 1 presentation slides UriReference 0..* 1 source outgoingReferences target incomingReferences
  • 9.
    The DSL -Entities Selector Meaning #newClassNamed:comment: Creates a new class for the MM #newTraitNamed:comment: Creates a new stateful trait for the MM Question: How to choose? Classes must be used for entities that will be instantiated. Traits can not be instantiated. Can only inherit from one class. Can “inherit” from multiple traits.
  • 10.
    Example presentation := buildernewClassNamed: #Presentation. slide := builder newClassNamed: #Slide. uri := builder newClassNamed: #Uri. uriReference := builder newClassNamed: #UriReference.
  • 11.
    The DSL -Inheritance Selector Short version Meaning generalization: --|> Inheritance relation Remark: Can be written the other way around (<|- -).
  • 12.
    Example (1) Uri + uri:String Presentation Slide 0..* 0..* 1 presentation slides UriReference 0..* 1 source outgoingReferences target incomingReferences NamedEntity + name: String Association Entity presentation --|> namedEntity. slide --|> namedEntity. uriReference --|> association. uri --|> entity.
  • 13.
    Example (2) Uri + uri:String Presentation Slide 0..* 0..* 1 presentation slides UriReference 0..* 1 source outgoingReferences target incomingReferences NamedEntity + name: String Association Entity TWithReferences TReference TReferenceable 0..* 1target incomingReferences 0..* 1 outgoingReferences source slide --|> #TWithReferences. uriReference --|> #TReference. uri --|> #TReferenceable
  • 14.
    The DSL -Relations Selector Short version Meaning oneBelongsTo: -<> Composition with 1 child manyBelongTo: *-<> Composition with 0..* children containsOne: <>- Composition with 1 child containsMany: <>-* Composition with 0..* children oneToOne: - Association 0..1 to 0..1 oneToMany: -* Association 0..1 to 0..* manyToOne: *- Association 0..* to 0..1 manyToMany: *-* Association 0..* to 0..* Remark: As in the old Famix, Famix NG relations ensure that if one side of the relation is modified, the other side is updated accordingly.
  • 15.
  • 16.
    The DSL -Properties Selector Meaning #property:type: Creates a property for the class/trait.
  • 17.
  • 18.
    Summary (part 1) defineClasses superdefineClasses. presentation := builder newClassNamed: #Presentation. slide := builder newClassNamed: #Slide. uri := builder newClassNamed: #Uri. uriReference := builder newClassNamed: #UriReference. defineHierarchy super defineHierarchy. presentation --|> namedEntity. slide --|> namedEntity. slide --|> #TWithReferences. uriReference --|> association. uriReference --|> #TReference. uri --|> entity. uri --|> #TReferenceable.
  • 19.
    Summary (part 2) defineRelations superdefineRelations. (presentation property: #slides) <>-* (slide property: #presentation) defineProperties super defineProperties. uri property: #uri type: #String
  • 20.
    Basic infrastructure traitscatalog Famix-Traits package provides a set of traits implementing generic concepts reusable accross meta-models. FamixTReference, FamixTReferenceable and FamixTWithReferences FamixTAccess, FamixTAccessible and FamixTWithAccesses FamixTClass and FamixTWithClasses . . . To use one of these traits in your meta-model builder, reference it via a symbol (without Famix prefix). "Here you make Uri class use FamixTReferenceable" uri --|> #TReferenceable.
  • 21.
    In practice: Step1 Create a subclass of one of FamixMetamodelGenerator FamixBasicInfrastructureGenerator FamixFileBasedLanguageGenerator
  • 22.
    In practice: Step2 Implement class-side methods #packageName (name of the package in which the MM will be generated) and prefix (prefix for your generated classes)
  • 23.
    In practice: Step3 Override the following instance-side methods depending on what part of the MM you describe: #defineClasses for classes definitions #defineHierarchy for classes inheritance definitions #defineRelations for classes relations definitions #defineProperties to define classes properties #defineTraits for traits definitions
  • 24.
    In practice (summary) 1.Create a subclass of one of FamixMetamodelGenerator FamixBasicInfrastructureGenerator FamixFileBasedLanguageGenerator 2. Implement class-side methods #packageName (name of the package in which the MM will be generated) and prefix (prefix for your generated classes) 3. Override the following instance-side methods depending on what part of the MM you describe: #defineClasses for classes definitions #defineHierarchy for classes inheritance definitions #defineRelations for classes relations definitions #defineProperties to define classes properties #defineTraits for traits definitions
  • 25.
    Tutorial time: Presentation Loada fresh Moose 7 image from the CI and implement the previous meta-model. Metacello new repository: 'github://juliendelplanque/FamixNG-Slides/src'; baseline: 'FamixNGSlides'; load: 'Tutorial'.
  • 26.
    Hint: the meta-model Uri +uri: String Presentation Slide 0..* 0..* 1 presentation slides UriReference 0..* 1 source outgoingReferences target incomingReferences
  • 27.
    Tutorial time: Fortran https://github.com/juliendelplanque/FamixNGFortran Metacellonew repository: 'github://juliendelplanque/FamixNGFortran/src'; baseline: 'FamixNGFortran'; load: 'Tutorial'.
  • 28.