Skip to content

Commit

Permalink
Merge pull request #25 from enwiro/24-Impossible-to-call-descriptionO…
Browse files Browse the repository at this point in the history
…f-on-an-FM3Trait

Possible to call FMMetaModel>>descriptionOf: on an FM3Trait
  • Loading branch information
badetitou authored May 28, 2021
2 parents 2fe80d3 + 056dc64 commit 6e8414d
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 13 deletions.
6 changes: 6 additions & 0 deletions src/Fame-Core/FM3Type.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,9 @@ FM3Type >> traits [
<multivalued>
^ traits
]

{ #category : #accessing }
FM3Type >> traits: anObject [

traits := anObject
]
16 changes: 10 additions & 6 deletions src/Fame-Core/FMMetaModel.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Class {
#name : #FMMetaModel,
#superclass : #FMModel,
#instVars : [
'classDict',
'typeDict',
'nameDict'
],
#category : #'Fame-Core-Models'
Expand Down Expand Up @@ -69,12 +69,12 @@ FMMetaModel >> descriptionOf: smalltalkClass [

{ #category : #accessing }
FMMetaModel >> descriptionOf: smalltalkClass ifAbsent: elseBlock [
^ classDict at: smalltalkClass ifAbsent: elseBlock
^ typeDict at: smalltalkClass ifAbsent: elseBlock
]

{ #category : #accessing }
FMMetaModel >> descriptionOf: smalltalkClass ifPresent: aBlock ifAbsent: elseBlock [
^ classDict at: smalltalkClass ifPresent: aBlock ifAbsent: elseBlock
^ typeDict at: smalltalkClass ifPresent: aBlock ifAbsent: elseBlock
]

{ #category : #accessing }
Expand Down Expand Up @@ -138,12 +138,16 @@ FMMetaModel >> traits [
{ #category : #private }
FMMetaModel >> updateCache [
nameDict := (FM3Constant constants collect: [ :const | const name asString -> const ]) asDictionary.
classDict := (FM3Constant constants collect: [ :const | const class -> const ]) asDictionary.
typeDict := (FM3Constant constants collect: [ :const | const class -> const ]) asDictionary.
self elements do: [ :each | self updateCacheWith: each ]
]

{ #category : #private }
FMMetaModel >> updateCacheWith: element [
element fullName ifNotNil: [ :fullName | nameDict at: fullName put: element ].
element isFM3Class ifTrue: [ element implementingClass ifNotNil: [ :class | classDict at: class put: element ] ]

element fullName ifNotNil: [ :fullName |
nameDict at: fullName put: element ].
(element isFM3Class or: [ element isFM3Trait ]) ifTrue: [
element implementingClass ifNotNil: [ :class |
typeDict at: class put: element ] ]
]
2 changes: 2 additions & 0 deletions src/Fame-Example/LIBBook.class.st
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Class {
#name : #LIBBook,
#superclass : #LIBRoot,
#traits : 'LIBTNamed',
#classTraits : 'LIBTNamed classTrait',
#instVars : [
'title',
'authors'
Expand Down
2 changes: 2 additions & 0 deletions src/Fame-Example/LIBLibrary.class.st
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Class {
#name : #LIBLibrary,
#superclass : #LIBRoot,
#traits : 'LIBTNamed',
#classTraits : 'LIBTNamed classTrait',
#instVars : [
'librarian',
'books'
Expand Down
2 changes: 2 additions & 0 deletions src/Fame-Example/LIBPerson.class.st
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Class {
#name : #LIBPerson,
#superclass : #LIBRoot,
#traits : 'LIBTNamed',
#classTraits : 'LIBTNamed classTrait',
#instVars : [
'books',
'name'
Expand Down
2 changes: 1 addition & 1 deletion src/Fame-Example/LIBRoot.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ LIBRoot class >> library [

{ #category : #examples }
LIBRoot class >> libraryMetaModel [
^ FMMetaModelBuilder metamodelFrom: {LIBLibrary . LIBBook . LIBPerson}
^ FMMetaModelBuilder metamodelFrom: {LIBLibrary . LIBBook . LIBPerson. LIBTNamed }
]

{ #category : #examples }
Expand Down
10 changes: 10 additions & 0 deletions src/Fame-Example/LIBTNamed.trait.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Trait {
#name : #LIBTNamed,
#category : #'Fame-Example'
}

{ #category : #meta }
LIBTNamed classSide >> annotation [
<FMClass: #TNamed super: #Object>
<package: #LIB>
]
10 changes: 5 additions & 5 deletions src/Fame-Tests/FMExporterTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Class {
FMExporterTest >> testExportAsJSon [
| printer metamodel lines |
printer := FMJSONPrinter onString.
metamodel := FMMetaModelBuilder metamodelFrom: {LIBLibrary . LIBBook . LIBPerson}.
metamodel := FMMetaModelBuilder metamodelFrom: {LIBLibrary . LIBBook . LIBPerson . LIBTNamed}.
metamodel exportWithPrinter: printer.
lines := printer stream contents lines.
self assert: (lines first beginsWith: '[') .
Expand All @@ -22,12 +22,12 @@ FMExporterTest >> testExportAsJSon [
FMExporterTest >> testExportAsMSE [
| printer metamodel lines |
printer := FMMSEPrinter onString.
metamodel := FMMetaModelBuilder metamodelFrom: {LIBLibrary . LIBBook . LIBPerson}.
metamodel := FMMetaModelBuilder metamodelFrom: {LIBLibrary . LIBBook . LIBPerson . LIBTNamed}.
metamodel exportWithPrinter: printer.
self assert: printer stream contents isString.
lines := printer stream contents lines.
self assert: lines first equals: '(' .
self assert: printer stream contents lines size equals: 66.
self assert: printer stream contents lines size equals: 72.
self assert: (lines allButFirst allSatisfy: [ :l | l beginsWith: ' '] ) .
self assert: (lines anySatisfy: [ :l | l includesSubstring: 'FM3.Package'] ) .
self assert: (lines anySatisfy: [ :l | l includesSubstring: 'FM3.Class'] ) .
Expand All @@ -39,7 +39,7 @@ FMExporterTest >> testExportAsMSE [
FMExporterTest >> testExportAsXML [
| printer metamodel lines |
printer := FMXMLPrinter onString.
metamodel := FMMetaModelBuilder metamodelFrom: {LIBLibrary . LIBBook . LIBPerson}.
metamodel := FMMetaModelBuilder metamodelFrom: {LIBLibrary . LIBBook . LIBPerson . LIBTNamed}.
metamodel exportWithPrinter: printer.
lines := printer stream contents lines.
self assert: (lines first beginsWith: '<') .
Expand All @@ -53,7 +53,7 @@ FMExporterTest >> testExportAsXML [
{ #category : #tests }
FMExporterTest >> testExportedModelIsTheSameAsBeforeExport [
| metamodel printer |
metamodel := FMMetaModelBuilder metamodelFrom: {LIBLibrary . LIBBook . LIBPerson}.
metamodel := FMMetaModelBuilder metamodelFrom: {LIBLibrary . LIBBook . LIBPerson . LIBTNamed}.

self assert: metamodel packages size equals: 1.
self assert: metamodel classes size equals: 3.
Expand Down
2 changes: 1 addition & 1 deletion src/Fame-Tests/FMLibraryExample.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ FMLibraryExample >> testMetamodelSmalltalkBinding [
FMLibraryExample >> testPragmaProcessing [
| pragmaProcessor |
pragmaProcessor := FMMetaModelBuilder new
queue: {LIBBook . LIBLibrary . LIBPerson};
queue: {LIBBook . LIBLibrary . LIBPerson . LIBTNamed};
run.
self denyEmpty: pragmaProcessor elements.
self denyEmpty: pragmaProcessor packages.
Expand Down
8 changes: 8 additions & 0 deletions src/Fame-Tests/FMMetaModelTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ FMMetaModelTest >> testDescriptionOfIfPresentIfAbsent [
self deny: (metamodel descriptionOf: FMMetaMetaModelTest ifPresent: [ true ] ifAbsent: [ false ])
]

{ #category : #tests }
FMMetaModelTest >> testDescriptionOfTrait [
| metamodel tNamed |
metamodel := LIBRoot libraryMetaModel.
tNamed := (metamodel packageNamed: 'LIB') classNamed: 'TNamed'.
self assert: (metamodel descriptionOf: LIBTNamed) identicalTo: tNamed.
]

{ #category : #tests }
FMMetaModelTest >> testElementNamed [
| metamodel |
Expand Down

0 comments on commit 6e8414d

Please sign in to comment.