Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MolUtils: add required/offered types for a component contract interfa… #165

Merged
merged 3 commits into from
Feb 28, 2024
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
56 changes: 56 additions & 0 deletions src/Molecule-Tests/MolUtilsTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,34 @@ MolUtilsTest >> testLog2 [
MolUtils isLogActive: (activate).
]

{ #category : #tests }
MolUtilsTest >> testOfferedTypes [

"Not used services"
| types |
self assert: (MolUtils offeredTypes: nil) isEmpty. "test with nil"
self assert: (MolUtils offeredTypes: Trait) isEmpty. "test with no component interface object"
self assert: (MolUtils offeredTypes: MolUnusedServices) isEmpty. "test with unused interface"

"Type used services"
types := MolUtils offeredTypes: MolUsedServices.
self assert: types size equals: 2.
self assert: (types includes: MolCompleteComponent).
self assert: (types includes: MolCompleteComponent2).

"Type provide events"
types := MolUtils offeredTypes: MolUsedEvents.
self assert: types size equals: 2.
self assert: (types includes: MolCompleteComponent).
self assert: (types includes: MolCompleteComponent2).

"Type used parameters"
types := MolUtils offeredTypes: MolUsedParameters.
self assert: types size equals: 2.
self assert: (types includes: MolCompleteComponent).
self assert: (types includes: MolCompleteComponent2).
]

{ #category : #tests }
MolUtilsTest >> testPassivateComponentNamed [

Expand Down Expand Up @@ -395,6 +423,34 @@ MolUtilsTest >> testRemoveComponents [
equals: false
]

{ #category : #tests }
MolUtilsTest >> testRequiredTypes [

"Not used services"
| types |
self assert: (MolUtils requiredTypes: nil) isEmpty. "test with nil"
self assert: (MolUtils requiredTypes: Trait) isEmpty. "test with no component interface object"
self assert: (MolUtils requiredTypes: MolUnusedServices) isEmpty. "test with unused interface"

"Type used services"
types := MolUtils requiredTypes: MolUsedServices.
self assert: types size equals: 2.
self assert: (types includes: MolCompleteComponent).
self assert: (types includes: MolCompleteComponent2).

"Type provide events"
types := MolUtils requiredTypes: MolUsedEvents.
self assert: types size equals: 2.
self assert: (types includes: MolCompleteComponent).
self assert: (types includes: MolCompleteComponent2).

"Type used parameters"
types := MolUtils requiredTypes: MolUsedParameters.
self assert: types size equals: 2.
self assert: (types includes: MolCompleteComponent).
self assert: (types includes: MolCompleteComponent2).
]

{ #category : #tests }
MolUtilsTest >> testShowInformation [
MolUtils showInformation: nil.
Expand Down
52 changes: 52 additions & 0 deletions src/Molecule/MolUtils.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,32 @@ MolUtils class >> log: aString [
self traceCr: '[Molecule] ' , string
]

{ #category : #'component contract' }
MolUtils class >> offeredTypes: aComponentContractInterface [
"Get types that are part of a component contract offered as Services, Events, or Parameters interface"

| list |
list := Set new.
aComponentContractInterface ifNil:[ ^ list asOrderedCollection ].
aComponentContractInterface isTrait ifFalse:[ ^ list asOrderedCollection ].
(aComponentContractInterface isComponentServices not and:[aComponentContractInterface isComponentEvents not and:[aComponentContractInterface isComponentParameters not]]) ifTrue:[ ^ list asOrderedCollection ].

"Collect all required"
MolComponentType users do:[ :type |
aComponentContractInterface isComponentServices ifTrue:[
(type isProvideServices: aComponentContractInterface) ifTrue:[ list add: type ].
] ifFalse:[
aComponentContractInterface isComponentEvents ifTrue:[
(type isProduceEvents: aComponentContractInterface) ifTrue:[ list add: type ].
] ifFalse:[
(type isProvideParameters: aComponentContractInterface) ifTrue:[ list add: type ].
].
].
].

^ list asOrderedCollection
]

{ #category : #'quick lifecycle' }
MolUtils class >> passivateComponent: aComponentClass named: aName [
"passivate quickly a component"
Expand Down Expand Up @@ -274,6 +300,32 @@ MolUtils class >> removeComponents: aComponentClassList [
].
]

{ #category : #'component contract' }
MolUtils class >> requiredTypes: aComponentContractInterface [
"Get types that are part of a component contract required as Services, Events, or Parameters interface"

| list |
list := Set new.
aComponentContractInterface ifNil:[ ^ list asOrderedCollection ].
aComponentContractInterface isTrait ifFalse:[ ^ list asOrderedCollection ].
(aComponentContractInterface isComponentServices not and:[aComponentContractInterface isComponentEvents not and:[aComponentContractInterface isComponentParameters not]]) ifTrue:[ ^ list asOrderedCollection ].

"Collect all required"
MolComponentType users do:[ :type |
aComponentContractInterface isComponentServices ifTrue:[
(type isUseServices: aComponentContractInterface) ifTrue:[ list add: type ].
] ifFalse:[
aComponentContractInterface isComponentEvents ifTrue:[
(type isConsumeEvents: aComponentContractInterface) ifTrue:[ list add: type ].
] ifFalse:[
(type isUseParameters: aComponentContractInterface) ifTrue:[ list add: type ].
].
].
].

^ list asOrderedCollection
]

{ #category : #log }
MolUtils class >> showInformation: aString [
"Inform the user with a message into the Pharo UI"
Expand Down
Loading