Skip to content

Commit 4c484c8

Browse files
Merge pull request #218 from OpenSmock/dev-217
fix #217
2 parents 818f09d + 214db12 commit 4c484c8

File tree

2 files changed

+60
-50
lines changed

2 files changed

+60
-50
lines changed

src/Molecule-Tests/MolComponentFactoryTest.class.st

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,18 @@ MolComponentFactoryTest >> testCollectComponentConnectionTraits [
264264
self assert: (traits includes: MolUsedParameters).
265265
]
266266

267+
{ #category : #tests }
268+
MolComponentFactoryTest >> testCollectComponentConnectionTraitsOrder [
269+
"This test check the order of the traits collect: events, services and parameters. This is necessary to control the order to not change generated code in existing components"
270+
271+
| traits |
272+
traits := MolComponentFactory default collectComponentConnectionTraits: MolCompleteComponentImpl.
273+
self assert: traits size equals: 3.
274+
self assert: (traits at: 1) equals: MolUsedEvents.
275+
self assert: (traits at: 2) equals: MolUsedServices.
276+
self assert: (traits at: 3) equals: MolUsedParameters
277+
]
278+
267279
{ #category : #tests }
268280
MolComponentFactoryTest >> testComponentChangedOnComponentCreationWithoutType [
269281
"Create a class, edit this class from different ways and check if the factory define the component or not"
@@ -1338,90 +1350,78 @@ MolComponentFactoryTest >> testRebuildComponentAccessorsFor [
13381350
MolComponentFactoryTest >> testRemoveOverloadedConsumedEvents [
13391351
"Testing issue #210 fix"
13401352

1341-
| exception |
1342-
exception := nil.
13431353
"Remove the method which overload the services contract: no error should appears"
1344-
[ MolCompleteComponentOverloadImpl class removeSelector: #consumedComponentEvents ]
1354+
1355+
[
1356+
MolCompleteComponentOverloadImpl class removeSelector:
1357+
#consumedComponentEvents ]
13451358
on: Exception
1346-
do: [ :e | exception := e ].
1347-
1348-
exception ifNotNil: [ exception signal ].
1349-
self assert: exception isNil.
1359+
do: [ :e | e signal ]
13501360
]
13511361

13521362
{ #category : #'test - overload' }
13531363
MolComponentFactoryTest >> testRemoveOverloadedProducedEvents [
13541364
"Testing issue #210 fix"
13551365

1356-
| exception |
1357-
exception := nil.
13581366
"Remove the method which overload the services contract: no error should appears"
1359-
[ MolCompleteComponentOverloadImpl class removeSelector: #producedComponentEvents ]
1367+
1368+
[
1369+
MolCompleteComponentOverloadImpl class removeSelector:
1370+
#producedComponentEvents ]
13601371
on: Exception
1361-
do: [ :e | exception := e ].
1362-
1363-
exception ifNotNil: [ exception signal ].
1364-
self assert: exception isNil.
1372+
do: [ :e | e signal ]
13651373
]
13661374

13671375
{ #category : #'test - overload' }
13681376
MolComponentFactoryTest >> testRemoveOverloadedProvidedParameters [
13691377
"Testing issue #210 fix"
13701378

1371-
| exception |
1372-
exception := nil.
13731379
"Remove the method which overload the services contract: no error should appears"
1374-
[ MolCompleteComponentOverloadImpl class removeSelector: #providedComponentParameters ]
1375-
on: Exception
1376-
do: [ :e | exception := e ].
13771380

1378-
exception ifNotNil: [ exception signal ].
1379-
self assert: exception isNil.
1381+
[
1382+
MolCompleteComponentOverloadImpl class removeSelector:
1383+
#providedComponentParameters ]
1384+
on: Exception
1385+
do: [ :e | e signal ]
13801386
]
13811387

13821388
{ #category : #'test - overload' }
13831389
MolComponentFactoryTest >> testRemoveOverloadedProvidedServices [
13841390
"Testing issue #210 fix"
13851391

1386-
| exception |
1387-
exception := nil.
13881392
"Remove the method which overload the services contract: no error should appears"
1389-
[ MolCompleteComponentOverloadImpl class removeSelector: #providedComponentServices ]
1390-
on: Exception
1391-
do: [ :e | exception := e ].
13921393

1393-
exception ifNotNil: [ exception signal ].
1394-
self assert: exception isNil.
1394+
[
1395+
MolCompleteComponentOverloadImpl class removeSelector:
1396+
#providedComponentServices ]
1397+
on: Exception
1398+
do: [ :e | e signal ]
13951399
]
13961400

13971401
{ #category : #'test - overload' }
13981402
MolComponentFactoryTest >> testRemoveOverloadedUsedParameters [
13991403
"Testing issue #210 fix"
14001404

1401-
| exception |
1402-
exception := nil.
14031405
"Remove the method which overload the services contract: no error should appears"
1404-
[ MolCompleteComponentOverloadImpl class removeSelector: #usedComponentParameters ]
1405-
on: Exception
1406-
do: [ :e | exception := e ].
14071406

1408-
exception ifNotNil: [ exception signal ].
1409-
self assert: exception isNil.
1407+
[
1408+
MolCompleteComponentOverloadImpl class removeSelector:
1409+
#usedComponentParameters ]
1410+
on: Exception
1411+
do: [ :e | e signal ]
14101412
]
14111413

14121414
{ #category : #'test - overload' }
14131415
MolComponentFactoryTest >> testRemoveOverloadedUsedServices [
14141416
"Testing issue #210 fix"
14151417

1416-
| exception |
1417-
exception := nil.
14181418
"Remove the method which overload the services contract: no error should appears"
1419-
[ MolCompleteComponentOverloadImpl class removeSelector: #usedComponentServices ]
1419+
1420+
[
1421+
MolCompleteComponentOverloadImpl class removeSelector:
1422+
#usedComponentServices ]
14201423
on: Exception
1421-
do: [ :e | exception := e ].
1422-
1423-
exception ifNotNil: [ exception signal ].
1424-
self assert: exception isNil
1424+
do: [ :e | e signal ]
14251425
]
14261426

14271427
{ #category : #'test - overload' }

src/Molecule/MolComponentFactory.class.st

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -426,17 +426,17 @@ MolComponentFactory >> activateDynamicContractUpdate: isInform [
426426
MolComponentFactory >> checkAndRebuildUsedTraitList: aTraitList inComponentClass: aComponentClass [
427427
"Check if a Component Class uses a list of Trait Class and do uses"
428428
| traitList toAddTraits toRemoveTraits |
429-
429+
430430
traitList := self collectComponentConnectionTraits: aComponentClass.
431431

432432
"added traits"
433-
toAddTraits := aTraitList reject: [ :e | (traitList includes: e) or:[ e isObsolete ] ].
433+
toAddTraits := self sortTraits: (aTraitList reject: [ :e | (traitList includes: e) or:[ e isObsolete ] ]).
434434
toAddTraits ifNotEmpty:[
435435
self rebuildComponent: aComponentClass traitsAdding: toAddTraits.
436436
].
437437

438438
"removed traits"
439-
toRemoveTraits := traitList reject: [ :e | aTraitList includes: e ].
439+
toRemoveTraits := self sortTraits: (traitList reject: [ :e | aTraitList includes: e ]).
440440
toRemoveTraits ifNotEmpty:[
441441
self rebuildComponent: aComponentClass traitsRemoving: toRemoveTraits.
442442
].
@@ -446,13 +446,12 @@ MolComponentFactory >> checkAndRebuildUsedTraitList: aTraitList inComponentClass
446446
MolComponentFactory >> collectComponentConnectionTraits: aComponentOrAComponentClass [
447447
"Collect a Component Traits : Services, Events and Parameters"
448448
| componentClass |
449-
aComponentOrAComponentClass ifNil:[^OrderedCollection new].
449+
aComponentOrAComponentClass ifNil:[ ^ OrderedCollection new ].
450+
450451
componentClass := aComponentOrAComponentClass isClass ifTrue:[aComponentOrAComponentClass] ifFalse:[aComponentOrAComponentClass class].
451-
componentClass isComponentClass ifFalse:[^OrderedCollection new].
452+
componentClass isComponentClass ifFalse:[ ^ OrderedCollection new ].
452453

453-
^ componentClass traitComposition allTraits select: [ :e |
454-
e isComponentServices or:[e isComponentEvents or:[e isComponentParameters]]
455-
]
454+
^ self sortTraits: (componentClass traitComposition allTraits)
456455
]
457456

458457
{ #category : #announcements }
@@ -1064,3 +1063,14 @@ MolComponentFactory >> removeOldUsedParametersAndServicesComponentAccessorsFor:
10641063

10651064
toBeRemoveProviderSelectors do: [ :s | aComponent removeSelector: s ]
10661065
]
1066+
1067+
{ #category : #private }
1068+
MolComponentFactory >> sortTraits: aTraitsList [
1069+
1070+
| events services parameters |
1071+
events := aTraitsList select: [ :e | e isComponentEvents ].
1072+
services := aTraitsList select: [ :e | e isComponentServices ].
1073+
parameters := aTraitsList select: [ :e | e isComponentParameters ].
1074+
1075+
^ (OrderedCollection withAll: events) addAll: services; addAll: parameters; removeDuplicates; yourself
1076+
]

0 commit comments

Comments
 (0)