Skip to content

Commit

Permalink
Do not allow changes of property type in association
Browse files Browse the repository at this point in the history
  • Loading branch information
JanBliznicenko committed Nov 23, 2024
1 parent af67c8c commit 17b0d19
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 22 deletions.
26 changes: 23 additions & 3 deletions repository/OpenPonk-ClassEditor/OPTUmlBaseController.trait.st
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,35 @@ OPTUmlBaseController >> descriptionVisibility [
OPTUmlBaseController >> validateProperty: aProperty [

aProperty ifNil: [ ^ self ].
aProperty owningClass
(aProperty association isNotNil and: [
(aProperty respondsTo: #oclIsKindOf:) not or: [
aProperty oclIsKindOf: #Classifier ] ]) ifTrue: [
self validationFailedAssociationPropertyWithoutClassifierType:
aProperty ].
aProperty owningAssociation
ifNil: [
aProperty owningAssociation ifNil: [
aProperty owningClass ifNil: [
self validationFailedPropertyWithoutOwner: aProperty ] ]
ifNotNil: [
aProperty owningAssociation ifNotNil: [
aProperty owningClass ifNotNil: [
self validationFailedPropertyWithTwoOwners: aProperty ] ]
]

{ #category : 'validation' }
OPTUmlBaseController >> validationFailedAssociationPropertyWithoutClassifierType: aProperty [

OPModelInvalid signal: (String streamContents: [ :s |
s << 'Property "' << aProperty name asString << '" has type '
<< aProperty type asString << ' although it is part of '
<< aProperty association asString ]).

"Try to use opposite owningClass as type"
aProperty opposite owningClass ifNotNil: [ :oppositeOwner |
aProperty type: oppositeOwner ]

"No way to fix this - the association end information is lost"
]

{ #category : 'validation' }
OPTUmlBaseController >> validationFailedPropertyWithTwoOwners: aProperty [

Expand Down
32 changes: 21 additions & 11 deletions repository/OpenPonk-ClassEditor/OPUmlAttributeController.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,27 @@ OPUmlAttributeController >> descriptionMultiplicity [
OPUmlAttributeController >> descriptionType [

<magritteDescription>
^ MAStringDescription new
accessor: (MAPluggableAccessor
read: [ :me | me model type ifNil: [ '' ] ifNotNil: #name ]
write: [ :me :newValue |
newValue
ifEmpty: [ me model type: nil ]
ifNotEmpty: [ me model type: (self typeNamed: newValue) ].
self modelChanged ]);
label: 'Type';
priority: 5;
yourself
| description writeBlock |
description := MAStringDescription new.
writeBlock := self model association
ifNotNil: [
description beReadOnly.
[ :me :newValue | ] ]
ifNil: [
[ :me :newValue |
newValue
ifEmpty: [ me model type: nil ]
ifNotEmpty: [
me model type: (self typeNamed: newValue) ].
self modelChanged ] ].
description
accessor: (MAPluggableAccessor
read: [ :me |
me model type ifNil: [ '' ] ifNotNil: [ :type | type name ] ]
write: writeBlock);
label: 'Type';
priority: 5.
^ description
]

{ #category : 'figures' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,19 @@ OPUmlPropertyMagritteDescriptions >> descriptionName [

{ #category : 'descriptions' }
OPUmlPropertyMagritteDescriptions >> descriptionType [

<magritteDescription>
^ MAStringDescription new
beReadOnly;
accessor:
(MAPluggableAccessor
read: [ :me | (reader value: me) type name ]
write: [ :me :newValue | ]);
label: labelPrefix;
priority: 1;
yourself
beReadOnly;
accessor: (MAPluggableAccessor
read: [ :me |
(reader value: me) type
ifNil: [ '' ]
ifNotNil: [ :type | type name ] ]
write: [ :me :newValue | ]);
label: labelPrefix;
priority: 1;
yourself
]

{ #category : 'descriptions' }
Expand Down

0 comments on commit 17b0d19

Please sign in to comment.