diff --git a/src/Famix-MetamodelBuilder-Core/FmxMBRingEnvironment.class.st b/src/Famix-MetamodelBuilder-Core/FmxMBRingEnvironment.class.st index af62b6e3..1185da33 100644 --- a/src/Famix-MetamodelBuilder-Core/FmxMBRingEnvironment.class.st +++ b/src/Famix-MetamodelBuilder-Core/FmxMBRingEnvironment.class.st @@ -212,6 +212,8 @@ FmxMBRingEnvironment >> slotNamed: slotName cardinality: cardinality type: type { #category : #initialization } FmxMBRingEnvironment >> slotNamed: slotName defaultValue: aValue [ + aValue ifNil: [ ^ self slotNamed: slotName ]. - ^ (RGUnknownSlot named: slotName asSymbol) expression: ('FMProperty defaultValue: {1}' format: { aValue }) + ^ (RGUnknownSlot named: slotName asSymbol) expression: + ('FMProperty defaultValue: {1}' format: { aValue printString }) ] diff --git a/src/Famix-MetamodelBuilder-Core/FmxMBTypedProperty.class.st b/src/Famix-MetamodelBuilder-Core/FmxMBTypedProperty.class.st index 1cda500e..f06ca60d 100644 --- a/src/Famix-MetamodelBuilder-Core/FmxMBTypedProperty.class.st +++ b/src/Famix-MetamodelBuilder-Core/FmxMBTypedProperty.class.st @@ -43,7 +43,7 @@ FmxMBTypedProperty >> generateGetterIn: aClassOrTrait [ pragmaFormat := self defaultValue ifNil: [ '' ] ifNotNil: [ '' ]. propertyDefinition := pragmaFormat - format: { self name. self propertyType. self defaultValue }. + format: { self name. self propertyType. self defaultValue printString}. commentDefinition := self comment ifNotEmpty: [ '' format: { self comment printString } ]. @@ -58,7 +58,7 @@ FmxMBTypedProperty >> generateGetterIn: aClassOrTrait [ ifNotEmpty: [ s tab; nextPutAll: commentDefinition; cr]. s tab; nextPutAll: '^ '; nextPutAll: self name. self defaultValue ifNotNil: [ - s nextPutAll: (' ifNil: [ {1} := {2} ]' format: { self name. self defaultValue }) ] ]. + s nextPutAll: (' ifNil: [ {1} := {2} ]' format: { self name. self defaultValue printString }) ] ]. self builder environment compile: methodSource in: aClassOrTrait classified: 'accessing'. diff --git a/src/Famix-Test6-Entities/FamixTest6Bacon.class.st b/src/Famix-Test6-Entities/FamixTest6Bacon.class.st index 73078eca..3cb39ace 100644 --- a/src/Famix-Test6-Entities/FamixTest6Bacon.class.st +++ b/src/Famix-Test6-Entities/FamixTest6Bacon.class.st @@ -4,6 +4,7 @@ | Name | Type | Default value | Comment | |---| +| `brand` | `String` | '' | | | `eggs` | `Number` | 12 | | | `isFood` | `Boolean` | true | | @@ -12,8 +13,9 @@ Class { #name : #FamixTest6Bacon, #superclass : #FamixTest6Entity, #instVars : [ - '#isFood => FMProperty defaultValue: true', - '#eggs => FMProperty defaultValue: 12' + '#brand => FMProperty defaultValue: \'\'', + '#eggs => FMProperty defaultValue: 12', + '#isFood => FMProperty defaultValue: true' ], #category : #'Famix-Test6-Entities-Entities' } @@ -27,6 +29,20 @@ FamixTest6Bacon class >> annotation [ ^ self ] +{ #category : #accessing } +FamixTest6Bacon >> brand [ + + + + ^ brand ifNil: [ brand := '' ] +] + +{ #category : #accessing } +FamixTest6Bacon >> brand: anObject [ + + brand := anObject +] + { #category : #accessing } FamixTest6Bacon >> eggs [ diff --git a/src/Famix-Test6-Tests/FamixTest6Test.class.st b/src/Famix-Test6-Tests/FamixTest6Test.class.st index ccf8ed60..f8a2156b 100644 --- a/src/Famix-Test6-Tests/FamixTest6Test.class.st +++ b/src/Famix-Test6-Tests/FamixTest6Test.class.st @@ -4,20 +4,37 @@ Class { #category : #'Famix-Test6-Tests' } +{ #category : #running } +FamixTest6Test >> testDefaultValueEmptyString [ + + | bacon brandProperty newBrand | + bacon := FamixTest6Bacon new. + brandProperty := bacon mooseDescription properties detect: [ :each | + each name = #brand ]. + + self assert: bacon brand equals: ''. + self assert: brandProperty defaultValue equals: ''. + + newBrand := 'WonderfulBacon'. + bacon brand: newBrand. + self assert: bacon brand equals: newBrand. + self assert: brandProperty defaultValue equals: '' +] + { #category : #running } FamixTest6Test >> testDefaultValueOnCreation [ - | bacon foodProperty | - + | bacon brandProperty | bacon := FamixTest6Bacon new. - foodProperty := (bacon mooseDescription properties select: [ :each | each name = #isFood ]) at: 1. - - self assert: bacon isFood equals: true. - self assert: foodProperty defaultValue equals: true. - + brandProperty := (bacon mooseDescription properties select: [ :each | + each name = #isFood ]) at: 1. + + self assert: bacon isFood. + self assert: brandProperty defaultValue. + bacon isFood: false. - self assert: bacon isFood equals: false. - self assert: foodProperty defaultValue equals: true. + self deny: bacon isFood. + self assert: brandProperty defaultValue ] { #category : #running } diff --git a/src/Famix-TestGenerators/FamixTest6Generator.class.st b/src/Famix-TestGenerators/FamixTest6Generator.class.st index 50ca971b..030fd111 100644 --- a/src/Famix-TestGenerators/FamixTest6Generator.class.st +++ b/src/Famix-TestGenerators/FamixTest6Generator.class.st @@ -42,5 +42,6 @@ FamixTest6Generator >> defineProperties [ super defineProperties. bacon property: #isFood type: #Boolean defaultValue: true. bacon property: #eggs type: #Number defaultValue: 12. - spam property: #isSomething type: #Boolean defaultValue: false + spam property: #isSomething type: #Boolean defaultValue: false. + bacon property: #brand type: #String defaultValue: '' ]