Skip to content
Merged
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
19 changes: 12 additions & 7 deletions src/Fame-Core/FM3Class.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,6 @@ FM3Class >> accept: aVisitor [
^ aVisitor visitClass: self
]

{ #category : 'enumerating' }
FM3Class >> allPropertiesDo: block [
properties do: block.
self superclass ifNotNil: [ :class | class allPropertiesDo: block ].
self traits do: [ :trait | trait allPropertiesDo: block ]
]

{ #category : 'accessing' }
FM3Class >> allSubclasses [
| all |
Expand Down Expand Up @@ -111,6 +104,18 @@ FM3Class >> createInstance [
ifNotNil: [ implementingClass new ]
]

{ #category : 'accessing-query' }
FM3Class >> fillPropertiesDictionary: nameDict [
"this method is used to avoid code duplication when filling dictionnary"

super fillPropertiesDictionary: nameDict.

"adding superclasses"
self superclass ifNotNil: [ :class |
class allProperties do: [ :each |
nameDict at: each name ifAbsentPut: [ each ] ] ]
]

{ #category : 'testing' }
FM3Class >> hasPackage [
^ package isNotNil
Expand Down
29 changes: 22 additions & 7 deletions src/Fame-Core/FM3Type.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Class {
#instVars : [
'package',
'properties',
'traits'
'traits',
'cachedAllProperties'
],
#category : 'Fame-Core-Model',
#package : 'Fame-Core',
Expand Down Expand Up @@ -46,19 +47,21 @@ FM3Type >> allPrimitiveProperties [

{ #category : 'accessing-query' }
FM3Type >> allProperties [

<FMProperty: #allProperties type: 'FM3.Property'>
<multivalued>
<derived>
| nameDict |
nameDict := Dictionary new: 60. "estimated initial size."
self allPropertiesDo: [ :each | nameDict at: each name ifAbsentPut: [ each ] ].
^ nameDict values asArray
^ cachedAllProperties ifNil: [
| nameDict |
nameDict := Dictionary new: 60. "estimated initial size."
self fillPropertiesDictionary: nameDict.
cachedAllProperties := nameDict values asArray ]
]

{ #category : 'enumerating' }
FM3Type >> allPropertiesDo: block [
self properties do: block.
self traits do: [ :trait | trait allPropertiesDo: block ]

self allProperties do: block
]

{ #category : 'accessing-query' }
Expand All @@ -75,6 +78,18 @@ FM3Type >> classUsers [
^ { self }
]

{ #category : 'as yet unclassified' }
FM3Type >> fillPropertiesDictionary: nameDict [
"this method is used to avoid code duplication when filling dictionnary"

self properties do: [ :each |
nameDict at: each name ifAbsentPut: [ each ] ].

self traits do: [ :trait |
trait allPropertiesDo: [ :each |
nameDict at: each name ifAbsentPut: [ each ] ] ]
]

{ #category : 'initialization' }
FM3Type >> initialize [
super initialize.
Expand Down
53 changes: 53 additions & 0 deletions src/Fame-Tests/FM3ClassTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,59 @@ FM3ClassTest >> testAllProperties [
self denyEmpty: element allProperties
]

{ #category : 'tests' }
FM3ClassTest >> testAllPropertiesDoGiveSameElementsAsAllProperties [

| superclass class listWithPropDo listWithoutPropDo |
superclass := self actualClass named: 'Superclass'.
class := self actualClass named: 'Class'.
class superclass: superclass.

superclass properties: {
(FM3Property named: #isDead).
(FM3Property named: #numberOfLinesOfCode) }.
class properties: {
(FM3Property named: #isDead).
(FM3Property named: #cc) }.

"collecting with allPropertiesDo:"
listWithPropDo := OrderedCollection new.
class allPropertiesDo: [ :prop | listWithPropDo add: prop name ].

"collecting with allProperties"
listWithoutPropDo := class allProperties collect: [ :prop |
prop name ].

"the two lists should be equals"
self
assert: listWithPropDo asArray sorted equals: listWithoutPropDo asArray sorted
]

{ #category : 'tests' }
FM3ClassTest >> testAllPropertiesHasNoDuplication [

| superclass class numberOfProperties expectedNumberOfProperties |
superclass := self actualClass named: 'Superclass'.
class := self actualClass named: 'Class'.
class superclass: superclass.

superclass properties: {
(FM3Property named: #isDead).
(FM3Property named: #numberOfLinesOfCode) }.
class properties: {
(FM3Property named: #isDead).
(FM3Property named: #cc) }.

numberOfProperties := 0.
class allPropertiesDo: [ :each |
numberOfProperties := numberOfProperties + 1 ].

expectedNumberOfProperties := class allProperties size.

self assert: numberOfProperties equals: expectedNumberOfProperties.
self assert: numberOfProperties equals: 3
]

{ #category : 'tests' }
FM3ClassTest >> testAllPropertiesMoreThanProperties [
element := metaMetamodel elementNamed: 'FM3.Class'.
Expand Down