Skip to content
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
90 changes: 90 additions & 0 deletions src/Molecule-IDE/MolCreateNewComponentCommand.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
Class {
#name : #MolCreateNewComponentCommand,
#superclass : #MolClassesCmdCommand,
#instVars : [
'package',
'packageTag',
'browser'
],
#category : #'Molecule-IDE-Commands'
}

{ #category : #activation }
MolCreateNewComponentCommand class >> browserMenuActivation [

<classAnnotation>
^ CmdContextMenuActivation
byItemOf: MolCmdMenuGroup
order: 80
for: ClyFullBrowserClassContext
]

{ #category : #testing }
MolCreateNewComponentCommand class >> canBeExecutedInContext: aBrowserContext [

^self isAbstract not and:[aBrowserContext isPackageSelected]

]

{ #category : #accessing }
MolCreateNewComponentCommand >> defaultMenuIconName [
^#class
]

{ #category : #accessing }
MolCreateNewComponentCommand >> defaultMenuItemName [

^ 'New component'
]

{ #category : #accessing }
MolCreateNewComponentCommand >> description [

^ 'Initialize an empty component implementation with traits for class, events and services'
]

{ #category : #execution }
MolCreateNewComponentCommand >> execute [

| componentDefinition classGeneratedComp traitType compImplName eventName serviceName traitServices traitEvents |
componentDefinition := self morphicUIManager request: 'Define component name:' initialAnswer: 'MyComponent'.
componentDefinition isEmptyOrNil ifTrue: [ ^ self ].

MolComponentFactory createComponentType: componentDefinition asSymbol in: package tag: packageTag.

traitType := self class environment at: componentDefinition asSymbol.

eventName := (componentDefinition, 'Events') asSymbol.
MolComponentFactory createComponentEvents: eventName in: package tag: packageTag.
traitEvents := self class environment at: eventName.

serviceName := (componentDefinition, 'Services') asSymbol.
MolComponentFactory createComponentServices: serviceName in: package tag: packageTag.
traitServices := self class environment at: serviceName.

compImplName := (componentDefinition, 'Impl') asSymbol.
MolComponentFactory createComponentNamed: compImplName in: package name tag: packageTag.

classGeneratedComp := self class environment at: compImplName.
classGeneratedComp setTraitComposition: traitType.

MolComponentFactory addProvidedServices: traitServices in: traitType.
MolComponentFactory addProducedEvents: traitEvents in: traitType
]

{ #category : #execution }
MolCreateNewComponentCommand >> prepareFullExecutionInContext: aBrowserContext [

super prepareFullExecutionInContext: aBrowserContext.

package := aBrowserContext lastSelectedPackage.
aBrowserContext isPackageTagSelected ifFalse:[^self].
packageTag := aBrowserContext lastSelectedPackageTag

]

{ #category : #execution }
MolCreateNewComponentCommand >> readParametersFromContext: aToolContext [
super readParametersFromContext: aToolContext.
browser := aToolContext browser
]
4 changes: 2 additions & 2 deletions src/Molecule-Tests/MolCompleteComponentOverloadImpl.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ I am a component impl overloading my contract for impl purpose
Class {
#name : #MolCompleteComponentOverloadImpl,
#superclass : #MolAbstractComponentImpl,
#traits : 'MolCompleteComponent + MolUsedEvents + MolUsedEvents2 + MolUsedServices + MolUsedServices2 + MolUsedParameters + MolUsedParameters2',
#classTraits : 'MolCompleteComponent classTrait + MolUsedEvents classTrait + MolUsedEvents2 classTrait + MolUsedServices classTrait + MolUsedServices2 classTrait + MolUsedParameters classTrait + MolUsedParameters2 classTrait',
#traits : 'MolCompleteComponent + MolUsedEvents + MolUsedServices + MolUsedServices2 + MolUsedParameters + MolUsedParameters2 + MolUsedEvents2',
#classTraits : 'MolCompleteComponent classTrait + MolUsedEvents classTrait + MolUsedServices classTrait + MolUsedServices2 classTrait + MolUsedParameters classTrait + MolUsedParameters2 classTrait + MolUsedEvents2 classTrait',
#category : #'Molecule-Tests-Resources - Components'
}

Expand Down
78 changes: 53 additions & 25 deletions src/Molecule-Tests/MolComponentFactoryTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ MolComponentFactoryTest >> cleanGeneratedMethods [
].
]

{ #category : #running }
MolComponentFactoryTest >> cleanGeneratedPackage [

| packageGenerated |
packageGenerated := PackageOrganizer packageOrganizer packages detect:[:p | p name = self generationPackage ] ifNone:[nil].
packageGenerated ifNil:[^self].
packageGenerated removeFromSystem
]

{ #category : #utilities }
MolComponentFactoryTest >> createInstanceMethod: aSelector in: aClassOrTrait protocol: aProtocolString withCode: aSourceCodeString [
"Create an instance method in a Class or Trait with source code implementation"
Expand Down Expand Up @@ -115,9 +124,14 @@ MolComponentFactoryTest >> generatedComponentTypeTrait [
^self class environment at: self generatedComponentTypeSymbolName
]

{ #category : #accessing }
MolComponentFactoryTest >> generationPackage [
^'Molecule-Tests-Resources'
]

{ #category : #accessing }
MolComponentFactoryTest >> generationTag [
^'Molecule-Tests-Resources - Generated'
^'Generated'
]

{ #category : #utilities }
Expand All @@ -129,6 +143,7 @@ MolComponentFactoryTest >> resetSourceCode [
self cleanGeneratedClassesAndTraits.
self restoreRemovedThings.
self cleanGeneratedMethods.
self cleanGeneratedPackage.

MolComponentFactory default activateDynamicContractUpdate: false.

Expand Down Expand Up @@ -274,7 +289,7 @@ MolComponentFactoryTest >> testComponentChangedOnComponentCreationWithoutType [
MolComponentFactory default deactivateDynamicContractUpdate: false.

"remove the testing class, and create a new component without Type, when the type is added check if the component in on the dirty components list"
MolComponentFactory createComponentNamed: self generatedComponentClassSymbolName in: self generationTag.
MolComponentFactory createComponentNamed: self generatedComponentClassSymbolName in: self generationPackage.

"Waiting for event callback"
self assert: (MolComponentFactory default dirtyComponents includes: (self generatedComponentClass)).
Expand All @@ -288,7 +303,7 @@ MolComponentFactoryTest >> testComponentChangedOnComponentCreationWithoutType [

"remove the testing class, and create a new component with Type, check if the component in on the dirty components list"
(self class environment at: self generatedComponentClassSymbolName) removeFromSystem.
MolComponentFactory createComponentForType: MolCompleteComponent named: self generatedComponentClassSymbolName in: self generationTag.
MolComponentFactory createComponentForType: MolCompleteComponent named: self generatedComponentClassSymbolName in: self generationPackage.

"Waiting for event callback"
self assert: (MolComponentFactory default dirtyComponents includes: (self generatedComponentClass)).
Expand Down Expand Up @@ -448,7 +463,7 @@ MolComponentFactoryTest >> testCreateComponentClassWithType [
(self class environment at: self generatedComponentClassSymbolName) removeFromSystem
].

MolComponentFactory createComponentForType: MolCompleteComponent named: self generatedComponentClassSymbolName in: self generationTag.
MolComponentFactory createComponentForType: MolCompleteComponent named: self generatedComponentClassSymbolName in: self generationPackage.

class := self class environment at: self generatedComponentClassSymbolName.
self assert: class notNil.
Expand All @@ -467,7 +482,7 @@ MolComponentFactoryTest >> testCreateComponentClassWithoutType [
(self class environment at: self generatedComponentClassSymbolName) removeFromSystem.
].

MolComponentFactory createComponentNamed: self generatedComponentClassSymbolName in: self generationTag.
MolComponentFactory createComponentNamed: self generatedComponentClassSymbolName in: self generationPackage.

class := self class environment at: self generatedComponentClassSymbolName.
self assert: class notNil.
Expand Down Expand Up @@ -654,6 +669,19 @@ MolComponentFactoryTest >> testCreateComponentForTypeNamedIn [
self assert: error equals: true.
]

{ #category : #'tests - component creation' }
MolComponentFactoryTest >> testCreateComponentForTypeNamedInTag [
"Test errors cases"
| error |
error := false.
[MolComponentFactory createComponentForType: nil named: nil in: nil tag: nil] on: Error do:[ error := true ].
self assert: error.

error := false.
[MolComponentFactory createComponentForType: String named: #ClassName in: #packageName tag: #tagName ] on: NotAComponentTypeError do:[ error := true ].
self assert: error.
]

{ #category : #'tests - contract creation' }
MolComponentFactoryTest >> testCreateComponentParameters [
"Create a Component Parameters from scratch"
Expand Down Expand Up @@ -684,7 +712,7 @@ MolComponentFactoryTest >> testCreateComponentType [
(self class environment at: self generatedComponentTypeSymbolName) removeFromSystem.
].

MolComponentFactory createComponentType: self generatedComponentTypeSymbolName in: self generationTag.
MolComponentFactory createComponentType: self generatedComponentTypeSymbolName in: self generationPackage.

trait := self class environment at: self generatedComponentTypeSymbolName.
self assert: trait notNil.
Expand All @@ -708,7 +736,7 @@ MolComponentFactoryTest >> testCreateEmptyComponentEvents [
(self class environment at: self generatedComponentEventsSymbolName) removeFromSystem.
].

MolComponentFactory createComponentEvents: self generatedComponentEventsSymbolName in: self generationTag.
MolComponentFactory createComponentEvents: self generatedComponentEventsSymbolName in: self generationPackage.

trait := self class environment at: self generatedComponentEventsSymbolName.
self assert: trait notNil.
Expand All @@ -732,7 +760,7 @@ MolComponentFactoryTest >> testCreateEmptyComponentParameters [
(self class environment at: self generatedComponentParametersSymbolName) removeFromSystem.
].

MolComponentFactory createComponentParameters: self generatedComponentParametersSymbolName in: self generationTag.
MolComponentFactory createComponentParameters: self generatedComponentParametersSymbolName in: self generationPackage.

trait := self class environment at: self generatedComponentParametersSymbolName.
self assert: trait notNil.
Expand All @@ -756,7 +784,7 @@ MolComponentFactoryTest >> testCreateEmptyComponentServices [
(self class environment at: self generatedComponentServicesSymbolName) removeFromSystem.
].

MolComponentFactory createComponentServices: self generatedComponentServicesSymbolName in: self generationTag.
MolComponentFactory createComponentServices: self generatedComponentServicesSymbolName in: self generationPackage.

trait := self class environment at: self generatedComponentServicesSymbolName.
self assert: trait notNil.
Expand Down Expand Up @@ -972,7 +1000,7 @@ MolComponentFactoryTest >> testMakeAComponentAndAddATrait [

componentClassNameSymbol := self generatedComponentClass2SymbolName.

class := MolComponentFactory createComponentNamed: componentClassNameSymbol in: self generationTag.
class := MolComponentFactory createComponentNamed: componentClassNameSymbol in: self generationPackage.
class := self class environment at: componentClassNameSymbol.
class comment: 'I am added and removed by test: ', self printString.

Expand All @@ -981,7 +1009,7 @@ MolComponentFactoryTest >> testMakeAComponentAndAddATrait [
self assert: (class canPerform: #methodOfNoComponentTrait).

"Set the component type and check if the existing Trait is already functionnal"
MolComponentFactory createComponentType: self generatedComponentTypeSymbolName in: self generationTag.
MolComponentFactory createComponentType: self generatedComponentTypeSymbolName in: self generationPackage.
class addToComposition: self generatedComponentTypeTrait.

self assert: (class canPerform: #methodOfNoComponentTrait).
Expand All @@ -1000,10 +1028,10 @@ MolComponentFactoryTest >> testMakeAComponentAndAddATraitWithCompleteContract [

componentClassNameSymbol := self generatedComponentClass2SymbolName.

MolComponentFactory createComponentNamed: componentClassNameSymbol in: self generationTag.
MolComponentFactory createComponentNamed: componentClassNameSymbol in: self generationPackage.
componentClass := self class environment at: componentClassNameSymbol.

MolComponentFactory createComponentType: self generatedComponentTypeSymbolName in: self generationTag.
MolComponentFactory createComponentType: self generatedComponentTypeSymbolName in: self generationPackage.
componentClass setTraitComposition: self generatedComponentTypeTrait.

self testCreateEmptyComponentServices.
Expand Down Expand Up @@ -1043,13 +1071,13 @@ MolComponentFactoryTest >> testMakeAComponentAndAddATraitWithCompleteContractAlt

componentClassNameSymbol := self generatedComponentClass2SymbolName.

MolComponentFactory createComponentNamed: componentClassNameSymbol in: self generationTag.
MolComponentFactory createComponentNamed: componentClassNameSymbol in: self generationPackage.
componentClass := self class environment at: componentClassNameSymbol.

"Add a trait"
componentClass setTraitComposition: MolTestNoComponentTraitA.

MolComponentFactory createComponentType: self generatedComponentTypeSymbolName in: self generationTag.
MolComponentFactory createComponentType: self generatedComponentTypeSymbolName in: self generationPackage.
componentClass addToComposition: self generatedComponentTypeTrait.

self testCreateEmptyComponentServices.
Expand Down Expand Up @@ -1086,10 +1114,10 @@ MolComponentFactoryTest >> testMakeAComponentFromScratch [

componentClassNameSymbol := self generatedComponentClass2SymbolName.

MolComponentFactory createComponentNamed: componentClassNameSymbol in: self generationTag.
MolComponentFactory createComponentNamed: componentClassNameSymbol in: self generationPackage.
componentClass := self class environment at: componentClassNameSymbol.

MolComponentFactory createComponentType: self generatedComponentTypeSymbolName in: self generationTag.
MolComponentFactory createComponentType: self generatedComponentTypeSymbolName in: self generationPackage.
componentClass setTraitComposition: self generatedComponentTypeTrait.

self testCreateEmptyComponentServices.
Expand Down Expand Up @@ -1138,7 +1166,7 @@ MolComponentFactoryTest >> testMakeAComponentFromScratchAlternative2 [

componentClassNameSymbol := self generatedComponentClass2SymbolName.

MolComponentFactory createComponentType: self generatedComponentTypeSymbolName in: self generationTag.
MolComponentFactory createComponentType: self generatedComponentTypeSymbolName in: self generationPackage.

self testCreateEmptyComponentServices.
self testCreateEmptyComponentParameters.
Expand All @@ -1158,7 +1186,7 @@ MolComponentFactoryTest >> testMakeAComponentFromScratchAlternative2 [
self createInstanceMethod: 'testGeneratedEventA' in: self generatedComponentEventsTrait protocol: 'events' withCode: nil.
self createInstanceMethod: 'testGeneratedEventB' in: self generatedComponentEventsTrait protocol: 'events' withCode: nil.

MolComponentFactory createComponentForType: self generatedComponentTypeTrait named: componentClassNameSymbol in: self generationTag.
MolComponentFactory createComponentForType: self generatedComponentTypeTrait named: componentClassNameSymbol in: self generationPackage.
componentClass := self class environment at: componentClassNameSymbol.

"Check generated methods"
Expand Down Expand Up @@ -1188,9 +1216,9 @@ MolComponentFactoryTest >> testMakeAComponentFromScratchAlternative3 [

componentClassNameSymbol := self generatedComponentClass2SymbolName.

MolComponentFactory createComponentType: self generatedComponentTypeSymbolName in: self generationTag.
MolComponentFactory createComponentType: self generatedComponentTypeSymbolName in: self generationPackage.

MolComponentFactory createComponentForType: self generatedComponentTypeTrait named: componentClassNameSymbol in: self generationTag.
MolComponentFactory createComponentForType: self generatedComponentTypeTrait named: componentClassNameSymbol in: self generationPackage.
componentClass := self class environment at: componentClassNameSymbol.

self testCreateComponentServices.
Expand Down Expand Up @@ -1233,9 +1261,9 @@ MolComponentFactoryTest >> testMakeAComponentFromScratchAlternative4 [

componentClassNameSymbol := self generatedComponentClass2SymbolName.

MolComponentFactory createComponentType: self generatedComponentTypeSymbolName in: self generationTag.
MolComponentFactory createComponentType: self generatedComponentTypeSymbolName in: self generationPackage.

MolComponentFactory createComponentForType: self generatedComponentTypeTrait named: componentClassNameSymbol in: self generationTag.
MolComponentFactory createComponentForType: self generatedComponentTypeTrait named: componentClassNameSymbol in: self generationPackage.
componentClass := self class environment at: componentClassNameSymbol.

self testCreateComponentServices.
Expand Down Expand Up @@ -1280,12 +1308,12 @@ MolComponentFactoryTest >> testMakeAComponentFromScratchAlternative5 [
| componentClassNameSymbol componentClass |
self assert: MolComponentFactory default isDynamicContractUpdateActivated.

MolComponentFactory createComponentType: self generatedComponentTypeSymbolName in: self generationTag.
MolComponentFactory createComponentType: self generatedComponentTypeSymbolName in: self generationPackage.

self testCreateEmptyComponentEvents.

componentClassNameSymbol := self generatedComponentClass2SymbolName.
MolComponentFactory createComponentForType: self generatedComponentTypeTrait named: componentClassNameSymbol in: self generationTag.
MolComponentFactory createComponentForType: self generatedComponentTypeTrait named: componentClassNameSymbol in: self generationPackage.
componentClass := self class environment at: componentClassNameSymbol.

MolComponentFactory addProducedEvents: self generatedComponentEventsTrait in: self generatedComponentTypeTrait.
Expand Down
4 changes: 2 additions & 2 deletions src/Molecule-Tests/MolDirtyComponentTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ MolDirtyComponentTest >> generatedDirtyTypeImplementationSymbol [
]

{ #category : #accessing }
MolDirtyComponentTest >> generationTag [
MolDirtyComponentTest >> generationPackage [

^ 'Molecule-Tests-Resources - Generated'
]
Expand Down Expand Up @@ -51,7 +51,7 @@ MolDirtyComponentTest >> testDirtyTypeWithInstanceVariableInsteadOfComponentTrai
"Create a component using a dirty Type: a type which is not correct (potentiels bugs)"

| component |
MolComponentFactory createComponentForType: MolDirtyType named: self generatedDirtyTypeImplementationSymbol in: self generationTag.
MolComponentFactory createComponentForType: MolDirtyType named: self generatedDirtyTypeImplementationSymbol in: self generationPackage.
component := self class environment at: self generatedDirtyTypeImplementationSymbol.

"Check if the ComponentType is dirty"
Expand Down
Loading
Loading