Skip to content

Commit

Permalink
Fix #99
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Laborde committed Sep 22, 2023
1 parent 489ac2a commit 4ba9dd1
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 22 deletions.
10 changes: 10 additions & 0 deletions Molecule-Tests/MolDirtyComponentTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,15 @@ MolDirtyComponentTest >> testDirtyTypeWithInstanceVariableInsteadOfComponentTrai
MolComponentFactory createComponentForType: MolDirtyType named: self generatedDirtyTypeImplementationSymbol in: self generationTag.
component := self class environment at: self generatedDirtyTypeImplementationSymbol.

self deny: (component methodDictionary includesKey: #getnilSubscriber).
self deny: (component methodDictionary includesKey: #getnilNotifier).
self deny: (component methodDictionary includesKey: #getnilProvider).

self assert: component allConsumedEvents isEmpty.
self assert: component allProducedEvents isEmpty.
self assert: component allProvidedServices isEmpty.
self assert: component allUsedServices isEmpty.
self assert: component allProvidedParameters isEmpty.
self assert: component allUsedParameters isEmpty.

]
30 changes: 30 additions & 0 deletions Molecule-Tests/MolDirtyType.trait.st
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,33 @@ MolDirtyType classSide >> consumedComponentEvents [
<componentContract>
^ { anInstanceVariable }
]

{ #category : #'accessing - events' }
MolDirtyType classSide >> producedComponentEvents [
<componentContract>
^ {anInstanceVariable}
]

{ #category : #'accessing - parameters' }
MolDirtyType classSide >> providedComponentParameters [
<componentContract>
^ {anInstanceVariable}
]

{ #category : #'accessing - services' }
MolDirtyType classSide >> providedComponentServices [
<componentContract>
^ {anInstanceVariable}
]

{ #category : #'accessing - parameters' }
MolDirtyType classSide >> usedComponentParameters [
<componentContract>
^ {anInstanceVariable}
]

{ #category : #'accessing - services' }
MolDirtyType classSide >> usedComponentServices [
<componentContract>
^ {anInstanceVariable}
]
39 changes: 23 additions & 16 deletions Molecule/MolComponentFactory.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -575,26 +575,33 @@ MolComponentFactory >> dirtyComponents [
MolComponentFactory >> generateComponentAccessorsFor: aSymbol withList: aCollection in: aComponent suffix: suffix [
| selector sourceCode sourceMethod method |

aCollection copy do: [ :trait |
aCollection copy do: [ :e | | trait |

selector := ('get' , trait printString , suffix) asSymbol.
sourceCode := self getSourceCodeFor: aSymbol trait: trait selector: selector.
(aComponent allSelectors includes: selector) ifFalse: [
aComponent compile: sourceCode contents classified: self class protocolForComponentAccess
] ifTrue: [
"if the method exist inspect this source code for search any difference between the existing required services and the requested required services"
"the selector must not be a parent"
(aComponent selectors includes: selector) ifTrue: [
method := aComponent >> selector.
sourceMethod := method sourceCode.
sourceMethod ifNotNil: [
sourceMethod ~= sourceCode contents ifTrue: [
"rewrite the method"
aComponent compile: sourceCode contents classified: self class protocolForComponentAccess
"e can be another thing that a Trait, need to check nature of e before generate"
( e notNil and:[ e isTrait and:[( e isComponentServices or:[ e isComponentParameters or:[ e isComponentEvents ]])]]) ifTrue:[

trait := e.

selector := ('get' , trait printString , suffix) asSymbol.
sourceCode := self getSourceCodeFor: aSymbol trait: trait selector: selector.
(aComponent allSelectors includes: selector) ifFalse: [
aComponent compile: sourceCode contents classified: self class protocolForComponentAccess
] ifTrue: [
"if the method exist inspect this source code for search any difference between the existing required services and the requested required services"
"the selector must not be a parent"
(aComponent selectors includes: selector) ifTrue: [
method := aComponent >> selector.
sourceMethod := method sourceCode.
sourceMethod ifNotNil: [
sourceMethod ~= sourceCode contents ifTrue: [
"rewrite the method"
aComponent compile: sourceCode contents classified: self class protocolForComponentAccess
].
].
].
].
].

].
]
]

Expand Down
30 changes: 24 additions & 6 deletions Molecule/MolComponentType.trait.st
Original file line number Diff line number Diff line change
Expand Up @@ -21,66 +21,84 @@ Trait {
{ #category : #actions }
MolComponentType classSide >> allConsumedEvents [
| collection |
collection := Set withAll: self consumedComponentEvents.

collection := (self consumedComponentEvents select:[ :e | e notNil and:[ e isTrait and:[ e isComponentEvents ]]]) asSet.

self allSuperclassesDo: [ :s |
(s allTraits includes: MolComponentType) ifTrue: [
collection addAll: s consumedComponentEvents
] ].

^ collection asOrderedCollection
]

{ #category : #actions }
MolComponentType classSide >> allProducedEvents [
| collection |
collection := Set withAll: self producedComponentEvents.

collection := (self producedComponentEvents select:[ :e | e notNil and:[ e isTrait and:[ e isComponentEvents ]]]) asSet.

self allSuperclassesDo: [ :s |
(s allTraits includes: MolComponentType) ifTrue: [
collection addAll: s producedComponentEvents
] ].

^ collection asOrderedCollection
]

{ #category : #actions }
MolComponentType classSide >> allProvidedParameters [
| collection |
collection := Set withAll: self providedComponentParameters.

collection := (self providedComponentParameters select:[ :e | e notNil and:[ e isTrait and:[ e isComponentParameters ]]]) asSet.

self allSuperclassesDo: [ :s |
(s allTraits includes: MolComponentType) ifTrue: [
collection addAll: s providedComponentParameters
] ].

^ collection asOrderedCollection
]

{ #category : #actions }
MolComponentType classSide >> allProvidedServices [
| collection |
collection := Set withAll: self providedComponentServices.

collection := (self providedComponentServices select:[ :e | e notNil and:[ e isTrait and:[ e isComponentServices ]]]) asSet.

self allSuperclassesDo: [ :s |
(s allTraits includes: MolComponentType) ifTrue: [
collection addAll: s providedComponentServices
] ].

^ collection asOrderedCollection
]

{ #category : #actions }
MolComponentType classSide >> allUsedParameters [
| collection |
collection := Set withAll: self usedComponentParameters.

collection := (self usedComponentParameters select:[ :e | e notNil and:[ e isTrait and:[ e isComponentParameters ]]]) asSet.

self allSuperclassesDo: [ :s |
(s allTraits includes: MolComponentType) ifTrue: [
collection addAll: s usedComponentParameters
] ].

^ collection asOrderedCollection
]

{ #category : #actions }
MolComponentType classSide >> allUsedServices [
| collection |
collection := Set withAll: self usedComponentServices.

collection := (self usedComponentServices select:[ :e | e notNil and:[ e isTrait and:[ e isComponentServices ]]]) asSet.

self allSuperclassesDo: [ :s |
(s allTraits includes: MolComponentType) ifTrue: [
collection addAll: s usedComponentServices
] ].

^ collection asOrderedCollection
]

Expand Down

0 comments on commit 4ba9dd1

Please sign in to comment.