Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,39 @@ Note you can replace the #master by another branch such as #development or a tag

Check out the [Moose wiki](https://modularmoose.org/beginners/install-moose/).

### Metamodel generation

Define entities and relations with the existing generator DSL, then run:

```Smalltalk
MyMetamodelGenerator generate
```

Generation first builds a Fame `FMMetaModel`, then materializes Pharo code and
installs that same description on the generated Moose model class. Changes are
filtered and ordered before application; obsolete generated code is removed and
handwritten code is preserved.

To inspect the description before installing code:

```Smalltalk
metamodel := MyMetamodelGenerator buildMetamodel
```

This does not install classes or methods. The description includes dependencies,
handwritten property annotations, and metamodel extensions included by default.
Famix support methods and helper classes are retained as generation metadata.

An inspected or modified description can be materialized explicitly:

```Smalltalk
FamixFameMaterializer new materialize: metamodel.
MyModel metamodel: metamodel
```

Use the generator's `generate` entry point when applying its configured cleaning
strategy and updating existing model instances.

## Version management

This project use semantic versioning to define the releases. This means that each stable release of the project will be assigned a version number of the form `vX.Y.Z`.
Expand Down
90 changes: 90 additions & 0 deletions src/Famix-MetamodelBuilder-Core/FM3Property.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
Extension { #name : 'FM3Property' }

{ #category : '*Famix-MetamodelBuilder-Core' }
FM3Property >> famixIsGenerated [

^ ((self metamodel additionalPropertiesFor: self) at: #famixHandwrittenProperty ifAbsent: [ false ]) not
]

{ #category : '*Famix-MetamodelBuilder-Core' }
FM3Property >> famixOpposite [

self opposite ifNotNil: [ :opposite | ^ opposite ].
^ (self metamodel additionalPropertiesFor: self) at: #famixDeclaredOpposite ifAbsent: [ nil ]
]

{ #category : '*Famix-MetamodelBuilder-Core' }
FM3Property >> isMany [

^ self isMultivalued
]

{ #category : '*Famix-MetamodelBuilder-Core' }
FM3Property >> isOne [

^ self isMultivalued not
]

{ #category : '*Famix-MetamodelBuilder-Core' }
FM3Property >> isRemote [

^ self package isNotNil and: [ self package ~= self owner package ]
]

{ #category : '*Famix-MetamodelBuilder-Core' }
FM3Property >> oppositeName [

^ self famixOpposite name
]

{ #category : '*Famix-MetamodelBuilder-Core' }
FM3Property >> oppositeSide [

^ self famixOpposite
]

{ #category : '*Famix-MetamodelBuilder-Core' }
FM3Property >> oppositeType [

^ self type famixImplementationName
]

{ #category : '*Famix-MetamodelBuilder-Core' }
FM3Property >> producesSlot [

^ self isRemote not and: [ self famixOpposite isNil or: [ self famixOpposite isRemote not ] ]
]

{ #category : '*Famix-MetamodelBuilder-Core' }
FM3Property >> propertyType [

^ self type famixImplementationName
]

{ #category : '*Famix-MetamodelBuilder-Core' }
FM3Property >> remotePackageDo: aBlock [

self package ifNotNil: [ :package | aBlock value: package name ]
]

{ #category : '*Famix-MetamodelBuilder-Core' }
FM3Property >> slotDefinition [

^ '#' , self name , ' => ' , self slotExpression
]

{ #category : '*Famix-MetamodelBuilder-Core' }
FM3Property >> slotExpression [

self famixOpposite ifNil: [
^ self defaultValue ifNil: [ 'FMProperty' ] ifNotNil: [ :value | 'FMProperty defaultValue: ' , value printString ] ].
^ (self isMultivalued
ifTrue: [ 'FMMany' ]
ifFalse: [ 'FMOne' ]) , ' type: #' , self type famixImplementationName , ' opposite: #' , self famixOpposite name
]

{ #category : '*Famix-MetamodelBuilder-Core' }
FM3Property >> validate [

self type ifNil: [ FmxMBIncompletePropertyDefiniton signal ]
]
21 changes: 21 additions & 0 deletions src/Famix-MetamodelBuilder-Core/FM3Type.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Extension { #name : 'FM3Type' }

{ #category : '*Famix-MetamodelBuilder-Core' }
FM3Type >> famixImplementationName [

self metamodel ifNil: [ ^ self name ].
^ (self metamodel additionalPropertiesFor: self) at: #famixImplementationName ifAbsent: [ self name ]
]

{ #category : '*Famix-MetamodelBuilder-Core' }
FM3Type >> famixTraitDefinitions [

| exclusions |
exclusions := (self metamodel additionalPropertiesFor: self) at: #famixTraitExclusions ifAbsent: [ Dictionary new ].
^ (self traits sorted: #famixImplementationName ascending) collect: [ :trait |
exclusions
at: trait famixImplementationName
ifPresent: [ :selectors |
'(' , trait famixImplementationName , ' - {' , ('. ' join: (selectors collect: #printString)) , '})' ]
ifAbsent: [ trait famixImplementationName ] ]
]
32 changes: 32 additions & 0 deletions src/Famix-MetamodelBuilder-Core/FamixFameMaterializer.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"
I materialize Famix Fame descriptions using the existing change filtering, ordering and handwritten-code preservation. I bind the same descriptions to the installed Pharo classes.
"
Class {
#name : 'FamixFameMaterializer',
#superclass : 'FMMaterializer',
#category : 'Famix-MetamodelBuilder-Core-Generation',
#package : 'Famix-MetamodelBuilder-Core',
#tag : 'Generation'
}

{ #category : 'api' }
FamixFameMaterializer >> changesFor: aMetamodel [

^ FmxMBFameChangesBuilderVisitor new
buildChangesFor: aMetamodel;
filterRedoundantChanges;
changesToApply
]

{ #category : 'api' }
FamixFameMaterializer >> materialize: aMetamodel [

FmxMBFameChangesBuilderVisitor new
buildChangesFor: aMetamodel;
filterRedoundantChanges;
applyChanges.
aMetamodel classes , aMetamodel traits do: [ :type |
type implementingClass: (self class environment at: type famixImplementationName) ].
aMetamodel updateCache.
^ aMetamodel
]
Loading
Loading