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

Deprecated instanciate in favor of instantiation (correct grammatical form) #115

Merged
merged 5 commits into from
Oct 24, 2023
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
13 changes: 7 additions & 6 deletions src/Molecule/MolComponentFactory.class.st
Eliott-Guevel marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -572,16 +572,16 @@ MolComponentFactory >> dirtyComponents [
]

{ #category : #'private - code generation' }
MolComponentFactory >> generateComponentAccessorsFor: aSymbol withList: aCollection in: aComponent suffix: suffix [
MolComponentFactory >> generateComponentAccessorsFor: aSymbol withList: aCollection in: aComponent suffix: suffix [ [
| selector sourceCode sourceMethod method |

aCollection copy do: [ :e | | trait |

"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: [
Expand All @@ -600,10 +600,11 @@ MolComponentFactory >> generateComponentAccessorsFor: aSymbol withList: aCollect
].
].
].

].
]
]
]

{ #category : #'code generation' }
MolComponentFactory >> generateOrRemoveConsumedEventsComponentAccessorsFor: aComponent [
Expand Down
26 changes: 24 additions & 2 deletions src/Molecule/MolComponentImpl.trait.st
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,35 @@ MolComponentImpl classSide >> haveOwnComponentType [
{ #category : #'life cycle' }
MolComponentImpl classSide >> instanciate [

^ MolComponentManager default homeServices instanciateComponent: self
self
deprecated: 'Use instantiate'
transformWith:
'`@receiver instanciate' -> '`@receiver instantiate'.
^ self instantiate
]

{ #category : #'life cycle' }
MolComponentImpl classSide >> instanciate: aComponentName [

^ MolComponentManager default homeServices instanciateComponent: self named: aComponentName
self
deprecated: 'Use instantiate:'
transformWith: '`@receiver instanciate: `@aComponentName'
-> '`@receiver instantiate: `@aComponentName'.
^ self instantiate: aComponentName
]

{ #category : #'life cycle' }
MolComponentImpl classSide >> instantiate [

^ MolComponentManager default homeServices instantiateComponent: self
]

{ #category : #'life cycle' }
MolComponentImpl classSide >> instantiate: aComponentName [

^ MolComponentManager default homeServices
instantiateComponent: self
named: aComponentName
]

{ #category : #testing }
Expand Down
52 changes: 29 additions & 23 deletions src/Molecule/MolComponentType.trait.st
Eliott-Guevel marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -19,88 +19,94 @@ Trait {
}

{ #category : #actions }
MolComponentType classSide >> allConsumedEvents [
MolComponentType classSide >> allConsumedEvents [ [
| collection |

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 [
MolComponentType classSide >> allProducedEvents [ [
| collection |

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 [
MolComponentType classSide >> allProvidedParameters [ [
| collection |

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 [
MolComponentType classSide >> allProvidedServices [ [
| collection |

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 [
MolComponentType classSide >> allUsedParameters [ [
| collection |

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 [
MolComponentType classSide >> allUsedServices [ [
| collection |

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
]
]

{ #category : #'accessing - events' }
MolComponentType classSide >> consumedComponentEvents [
Expand Down
129 changes: 112 additions & 17 deletions src/Molecule/MolHomeServices.class.st
Eliott-Guevel marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ MolHomeServices >> activateComponent: aComponentClass named: aName [
waitingForActivation
remove: component
ifAbsent: [ ^ComponentAlreadyActivatedError signal: 'Component is already activated.' ].

component componentConnector activateComponent.

"Manage connexion between components"
MolComponentManager default locatorServices resolveWaitingSubscriptions: component.

component componentActivate.
component triggerEvent: #activateComponent with: component.

Expand All @@ -69,7 +69,7 @@ MolHomeServices >> addDeployedComponent: aComponentClass [
]

{ #category : #private }
MolHomeServices >> checkInstanciationOfComponent: aComponentClass named: aComponentName [
MolHomeServices >> checkInstanciationOfComponent: aComponentClass named: aComponentName [ [

| deployed component overridedTypes |
aComponentName ifNil: [
Expand Down Expand Up @@ -126,6 +126,67 @@ MolHomeServices >> checkInstanciationOfComponent: aComponentClass named: aCompon
'(Inheritance problem) Can not instanciate a component with the same parameters and name of another component, please change the name of the component' ] ] ] ].
^ nil
]
]

{ #category : #private }
MolHomeServices >> checkInstantiationOfComponent: aComponentClass named: aComponentName [

| deployed component overridedTypes |
aComponentName ifNil: [
^ WrongComponentNameError new messageText:
'Can not instantiate a component without name' ].

aComponentName isSymbol ifFalse: [
^ WrongComponentNameError new messageText:
'Can not instantiate a component with a name wish is not a symbol' ].

deployed := self deployedComponents at: aComponentClass ifAbsent: [
^ ComponentNotDeployedError new messageText:
'Can not instantiate a non deployed component' ].
deployed at: aComponentName ifPresent: [ :e |
e ifNotNil: [
^ ComponentAlreadyExistsError new messageText:
'Can not instantiate a component with the same name of another component, please change the name of the component' ] ].

component := MolComponentManager default locatorServices
searchComponentTypeImplementorFor:
aComponentClass componentType
named: aComponentName.
component ifNotNil: [
^ ComponentAlreadyExistsError new messageText:
'Can not instantiate a component with the same type and name of another component, please change the name of the component' ].

aComponentClass componentType allProvidedServices do: [ :e |
(MolComponentManager default locatorServices
searchServicesProviderFor: e
named: aComponentName) isNotFoundServices ifFalse: [
^ ComponentProvidedServicesAlreadyExistsError new messageText:
'Can not instantiate a component with the same services and name of another component, please change the name of the component' ] ].

aComponentClass componentType allProvidedParameters do: [ :e |
(MolComponentManager default locatorServices
searchParametersProviderFor: e
named: aComponentName) isNotFoundParameters ifFalse: [
^ ComponentProvidedParametersAlreadyExistsError new messageText:
'Can not instantiate a component with the same parameters and name of another component, please change the name of the component' ] ].

aComponentClass isOverrideComponentType ifTrue: [
overridedTypes := aComponentClass overridedComponentTypes.
overridedTypes do: [ :type |
type allProvidedServices do: [ :e |
(MolComponentManager default locatorServices
searchServicesProviderFor: e
named: aComponentName) isNotFoundServices ifFalse: [
^ ComponentProvidedServicesAlreadyExistsError new messageText:
'(Inheritance problem) Can not instantiate a component with the same services and name of another component, please change the name of the component' ] ].
type allProvidedParameters do: [ :e |
(MolComponentManager default locatorServices
searchParametersProviderFor: e
named: aComponentName) isNotFoundParameters ifFalse: [
^ ComponentProvidedServicesAlreadyExistsError new messageText:
'(Inheritance problem) Can not instantiate a component with the same parameters and name of another component, please change the name of the component' ] ] ] ].
^ nil
]

{ #category : #accessing }
MolHomeServices >> deployedComponents [
Expand All @@ -146,39 +207,73 @@ MolHomeServices >> instanceOf: aClass named: aName [

{ #category : #'life cycle' }
MolHomeServices >> instanciateAllComponents [
self deployedComponents keysDo: [ :aClass | self instanciateComponent: aClass ]

self deprecated: 'Use instantiateAllComponents'
transformWith: '`@receiver instanciateAllComponents' -> '`@receiver instantiateAllComponents'.
self instantiateAllComponents
]

{ #category : #'life cycle' }
MolHomeServices >> instanciateComponent: aComponentClass [

^ self instanciateComponent: aComponentClass named: MolUtils defaultComponentName
self deprecated: 'Use instantiateComponent:'
transformWith: '`@receiver instanciateComponent: `@aComponentClass' -> '`@receiver instantiateComponent: `@aComponentClass'.
^ self instantiateComponent: aComponentClass
]

{ #category : #'life cycle' }
MolHomeServices >> instanciateComponent: aComponentClass named: aName [

self deprecated: 'Use instantiateComponent: named:'
transformWith: '`@receiver instanciateComponent: `@aComponentClass named: `@aName' ->'`@receiver instantiateComponent: `@aComponentClass named: `@aName'.
^ self instantiateComponent: aComponentClass named: aName
]

{ #category : #'life cycle' }
MolHomeServices >> instantiateAllComponents [

self deployedComponents keysDo: [ :aClass |
self instantiateComponent: aClass ]
]

{ #category : #'life cycle' }
MolHomeServices >> instantiateComponent: aComponentClass [

^ self instantiateComponent: aComponentClass named: MolUtils defaultComponentName
]

{ #category : #'life cycle' }
MolHomeServices >> instantiateComponent: aComponentClass named: aName [

| error component connector deployed |

aComponentClass ifNil:[^nil].
error := self checkInstanciationOfComponent: aComponentClass named: aName.
error ifNotNil:[error signal. ^nil].

component := aComponentClass new componentName: aName; yourself.
MolUtils log: aComponentClass printString , ' named: ' , aName printString , ' is instanciated.'.
aComponentClass ifNil: [ ^ nil ].
error := self
checkInstantiationOfComponent: aComponentClass
named: aName.
error ifNotNil: [
error signal.
^ nil ].

component := aComponentClass new
componentName: aName;
yourself.
MolUtils log:
aComponentClass printString , ' named: ' , aName printString
, ' is instanciated.'.

deployed := self deployedComponents at: aComponentClass.
deployed at: component componentName put: component.

"connect the component to the component model and initialize it"
connector := MolComponentConnector new.
component componentConnector: connector.
component componentInitialize.
component triggerEvent: #instanciateComponent with: component.

"add the component to waiting activation list"
waitingForActivation add: component.
^component

^ component
]

{ #category : #private }
Expand Down
Loading
Loading