diff --git a/src/Molecule-Tests/MolUtilsTest.class.st b/src/Molecule-Tests/MolUtilsTest.class.st index f4a53d0..bc061b8 100644 --- a/src/Molecule-Tests/MolUtilsTest.class.st +++ b/src/Molecule-Tests/MolUtilsTest.class.st @@ -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 [ @@ -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. diff --git a/src/Molecule/MolUtils.class.st b/src/Molecule/MolUtils.class.st index 36ada38..6f8761a 100644 --- a/src/Molecule/MolUtils.class.st +++ b/src/Molecule/MolUtils.class.st @@ -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" @@ -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"