Skip to content

Commit

Permalink
Merge pull request #186 from OpenSmock/185-MolUtilsrequiredTypes-not-…
Browse files Browse the repository at this point in the history
…return-interfaces-of-MolComponentType-which-are-using-another-Type

185 mol utilsrequired types not return interfaces of mol component type which are using another type
  • Loading branch information
labordep authored Sep 13, 2024
2 parents 7a05035 + 320ecf1 commit 851079d
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 45 deletions.
5 changes: 3 additions & 2 deletions src/Molecule-IDE-Tests/MolInterfacesPresenterTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,22 @@ MolInterfacesPresenterTest >> testBrowseButtonActivated [
{ #category : #running }
MolInterfacesPresenterTest >> testRequiredAnd [

localTimeEvents dropList selectItem: 'Required AND Offered'.
localTimeEvents dropList selectItem: 'Required and Offered'.
self assert: [ localTimeEvents requiredList items size = 0 ]
]

{ #category : #running }
MolInterfacesPresenterTest >> testRequiredOr [
"no need to select an option since OR is selected by default"

localTimeEvents dropList selectItem: 'Required and/or Offered'.
self assert: [ localTimeEvents requiredList items size = 2 ]
]

{ #category : #running }
MolInterfacesPresenterTest >> testRequiredXor [

localTimeEvents dropList selectItem: 'Required XOR Offered'.
localTimeEvents dropList selectItem: 'Required or Offered (XOR)'.
self assert: [ localTimeEvents requiredList items size = 2 ]
]

Expand Down
60 changes: 25 additions & 35 deletions src/Molecule-IDE/MolInterfacesPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Class {
'requiredList',
'offeredList',
'dropList',
'typeInterface',
'servicesProvidedList',
'eventsConsumedList',
'parametersUsedList',
Expand Down Expand Up @@ -39,7 +38,7 @@ MolInterfacesPresenter >> addTrait: trait IfInterfaceCorrespondsIn: interfaceLis
MolInterfacesPresenter >> addTypesInInterfaceList: trait [
"add a Trait to the lists if it corresponds to a part of their component contract"

typeInterface = 'Events' ifTrue: [
selectedInterface isComponentEvents ifTrue: [
eventsConsumed := trait allConsumedEvents.
self
addTrait: trait
Expand All @@ -52,7 +51,7 @@ MolInterfacesPresenter >> addTypesInInterfaceList: trait [
IfInterfaceCorrespondsIn: eventsProduced
forList: eventsProducedList ].

typeInterface = 'Parameters' ifTrue: [
selectedInterface isComponentParameters ifTrue: [
parametersUsed := trait allUsedParameters.
self
addTrait: trait
Expand All @@ -65,7 +64,7 @@ MolInterfacesPresenter >> addTypesInInterfaceList: trait [
IfInterfaceCorrespondsIn: parametersProvided
forList: parametersProvidedList ].

typeInterface = 'Services' ifTrue: [
selectedInterface isComponentServices ifTrue: [
servicesUsed := trait allUsedServices.
self
addTrait: trait
Expand All @@ -82,7 +81,7 @@ MolInterfacesPresenter >> addTypesInInterfaceList: trait [
{ #category : #adding }
MolInterfacesPresenter >> addTypesInInterfaceLists [

selectedInterface = '' ifTrue: [ ^ self ].
selectedInterface ifNil: [ ^ self ].

(MolUtils requiredTypes: selectedInterface) do: [ :trait |
self addTypesInInterfaceList: trait ].
Expand All @@ -91,7 +90,7 @@ MolInterfacesPresenter >> addTypesInInterfaceLists [
self addTypesInInterfaceList: trait ]
]

{ #category : #'as yet unclassified' }
{ #category : #private }
MolInterfacesPresenter >> andMode [
"if a Type appears in both columns (is both required and offered), show it in both columns"
"doesn't show it in either if it only appears once"
Expand Down Expand Up @@ -175,23 +174,6 @@ MolInterfacesPresenter >> defaultLayout [
yourself
]

{ #category : #initialization }
MolInterfacesPresenter >> determineTypeInterface [
"determines the type of the selected interface (Events, Parameters or Services) using the relevant Molecule methods (isComponent[Events/Parameters/Services])"

| events parameters services |
events := 'Events'.
parameters := 'Parameters'.
services := 'Services'.

selectedInterface isComponentEvents ifTrue: [
typeInterface := events ].
selectedInterface isComponentParameters ifTrue: [
typeInterface := parameters ].
selectedInterface isComponentServices ifTrue: [
typeInterface := services ]
]

{ #category : #initialization }
MolInterfacesPresenter >> dropList [
"used for test purposes"
Expand Down Expand Up @@ -225,7 +207,7 @@ MolInterfacesPresenter >> enableBrowseButton: listOnScreen [
listOnScreen selectedItem ifNotNil: [ buttonBrowse enable ] ]
]

{ #category : #'as yet unclassified' }
{ #category : #private }
MolInterfacesPresenter >> fillRequiredAndOfferedLists [
"used for the and mode"

Expand All @@ -241,7 +223,7 @@ MolInterfacesPresenter >> initializePresenters [
super initializePresenters.

"set to a placeholder value since the name of the interface is given after in execute: in the contextual menu side of things (MolInspectInterfaceImplementationsCmdCommand)"
selectedInterface := ''.
selectedInterface := nil.

eventsConsumedList := OrderedCollection new.
parametersUsedList := OrderedCollection new.
Expand All @@ -254,11 +236,11 @@ MolInterfacesPresenter >> initializePresenters [
"drop list, no width property"
dropList := self newDropList
help: 'Component Types which are using this interface:';
addItemLabeled: 'Required OR Offered'
addItemLabeled: 'Required and/or Offered'
do: [ self orMode ];
addItemLabeled: 'Required AND Offered'
addItemLabeled: 'Required and Offered'
do: [ self andMode ];
addItemLabeled: 'Required XOR Offered'
addItemLabeled: 'Required or Offered (XOR)'
do: [ self xorMode ].

requiredList := MolSpFilteringListDoubleClickPresenter new.
Expand All @@ -279,7 +261,6 @@ MolInterfacesPresenter >> interface: anInterface [
"only one interface can be selected at a time"

selectedInterface := anInterface.
self determineTypeInterface.
implemList := self listImplementations: anInterface.

self orMode
Expand Down Expand Up @@ -312,7 +293,7 @@ MolInterfacesPresenter >> offeredList [
^ offeredList
]

{ #category : #'as yet unclassified' }
{ #category : #private }
MolInterfacesPresenter >> orMode [
"if an implementation requires or provides the selected interface, make it appear in the correct column"

Expand All @@ -327,7 +308,7 @@ MolInterfacesPresenter >> orMode [
self applyFilter
]

{ #category : #'as yet unclassified' }
{ #category : #private }
MolInterfacesPresenter >> require: listRequired andOffer: listOffered [
"adds the items in the lists shown on screen if the interface is both required and offered by an implementation"

Expand All @@ -337,7 +318,7 @@ MolInterfacesPresenter >> require: listRequired andOffer: listOffered [
listImplementationBoth add: interfaceRequired ] ] ]
]

{ #category : #'as yet unclassified' }
{ #category : #private }
MolInterfacesPresenter >> require: listRequired xorOffer: listOffered [
"removes the items in the lists shown on screen if the interface is both required and offered by an implementation"

Expand All @@ -348,7 +329,7 @@ MolInterfacesPresenter >> require: listRequired xorOffer: listOffered [
listOffered remove: interfaceRequired ] ] ]
]

{ #category : #'as yet unclassified' }
{ #category : #private }
MolInterfacesPresenter >> requireOrOffer [
"adds the items in the lists shown on screen if the interface is required or offered by a Type"

Expand Down Expand Up @@ -384,10 +365,19 @@ MolInterfacesPresenter >> seeComponentImplementations [
{ #category : #initialization }
MolInterfacesPresenter >> title [

^ selectedInterface asString , ' ' , typeInterface asLowercase
| typeName |
selectedInterface ifNil: [ ^ 'No Molecule interface' ].

typeName := 'events'.
selectedInterface isComponentParameters ifTrue: [
typeName := 'parameters' ].
selectedInterface isComponentServices ifTrue: [
typeName := 'services' ].

^ selectedInterface asString , ' ' , typeName
]

{ #category : #'as yet unclassified' }
{ #category : #private }
MolInterfacesPresenter >> xorMode [
"boolean operator equivalent to OR minus AND, show a Type only if it exists and doesn't appear in both columns (requires or offers the interface, but not both)"

Expand Down
9 changes: 9 additions & 0 deletions src/Molecule-Tests/MolCompleteComponentTypeUser.trait.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"
This type use another type to extend it.
"
Trait {
#name : #MolCompleteComponentTypeUser,
#traits : 'MolCompleteComponent',
#classTraits : 'MolCompleteComponent classTrait',
#category : #'Molecule-Tests-Resources - Contracts'
}
18 changes: 12 additions & 6 deletions src/Molecule-Tests/MolUtilsTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -250,21 +250,24 @@ MolUtilsTest >> testOfferedTypes [

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

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

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

{ #category : #tests }
Expand Down Expand Up @@ -434,21 +437,24 @@ MolUtilsTest >> testRequiredTypes [

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

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

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

{ #category : #tests }
Expand Down
11 changes: 9 additions & 2 deletions src/Molecule/MolUtils.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ MolUtils class >> allComponentInstancesOfType: aComponentType [
^oc
]

{ #category : #private }
MolUtils class >> allComponentTypes [
"Return all ComponentTypes traits"

^ self environment allTraits select: [ :t | t isComponentType ]
]

{ #category : #'component contract' }
MolUtils class >> componentType: aComponentOrComponentClass [
"Get component type of a component or a component class, return nil if no type was found"
Expand Down Expand Up @@ -211,7 +218,7 @@ MolUtils class >> offeredTypes: aComponentContractInterface [
(aComponentContractInterface isComponentServices not and:[aComponentContractInterface isComponentEvents not and:[aComponentContractInterface isComponentParameters not]]) ifTrue:[ ^ list asOrderedCollection ].

"Collect all required"
MolComponentType users do:[ :type |
self allComponentTypes do:[ :type |
aComponentContractInterface isComponentServices ifTrue:[
(type isProvideServices: aComponentContractInterface) ifTrue:[ list add: type ].
] ifFalse:[
Expand Down Expand Up @@ -311,7 +318,7 @@ MolUtils class >> requiredTypes: aComponentContractInterface [
(aComponentContractInterface isComponentServices not and:[aComponentContractInterface isComponentEvents not and:[aComponentContractInterface isComponentParameters not]]) ifTrue:[ ^ list asOrderedCollection ].

"Collect all required"
MolComponentType users do:[ :type |
self allComponentTypes do:[ :type |
aComponentContractInterface isComponentServices ifTrue:[
(type isUseServices: aComponentContractInterface) ifTrue:[ list add: type ].
] ifFalse:[
Expand Down

0 comments on commit 851079d

Please sign in to comment.