Skip to content

Commit

Permalink
Merge pull request #50 from moosetechnology/copy-generator
Browse files Browse the repository at this point in the history
A generator for a copy visitor (ie. a visitor that creates a copy of …
  • Loading branch information
NicolasAnquetil authored Feb 22, 2024
2 parents bfd5bfc + f566f11 commit 0a65387
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions src/FAST-Core-Tools/FASTCopyVisitorCodeGenerator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Class {
{ #category : #Fame }
FASTCopyVisitorCodeGenerator >> fmDescription: aModelClass [

^metamodel fmTypeOf: aModelClass
^metamodel descriptionOf: aModelClass ifAbsent: [ nil ]
]

{ #category : #Fame }
Expand Down Expand Up @@ -72,18 +72,18 @@ FASTCopyVisitorCodeGenerator >> generateObjectCopy: aModelClass in: stream [
{ #category : #'code generation' }
FASTCopyVisitorCodeGenerator >> generatePropertiesCopy: aModelClass in: stream [

(self fmDescription: aModelClass) allProperties do: [ :property |
self generatePropertyCopy: property for: aModelClass in: stream ]
(self fmDescription: aModelClass)
ifNotNil: [ :fmDescription |
fmDescription allProperties do: [ :property |
(self shouldCopyProperty: property for: aModelClass)
ifTrue: [ self generatePropertyCopy: property for: aModelClass in: stream ]
]
]
]

{ #category : #'code generation' }
FASTCopyVisitorCodeGenerator >> generatePropertyCopy: property for: aModelClass in: stream [

(property name beginsWith: 'parent') ifTrue: [ ^self ].
(property hasOpposite and: [ property isTarget ]) ifTrue: [ ^self].
property isContainer ifTrue: [ ^self].
(self isSamePackage: property) ifFalse: [ ^self ].

stream
tab ;
tab ;
Expand Down Expand Up @@ -148,3 +148,22 @@ FASTCopyVisitorCodeGenerator >> rootClass: aFASTEntityClass visitorClass: aFASTV
self generateVisit: modelClass in: aFASTVisitorClass.
].
]

{ #category : #'code generation' }
FASTCopyVisitorCodeGenerator >> shouldCopyProperty: property for: aModelClass [

"Dealing with some special cases (errors in the meta-model, they should be marked #isContainer)"
(property name beginsWith: 'parent') ifTrue: [ ^false ].

(#(assignedIn invokedIn container) anySatisfy: [ :specialCase | property name = specialCase ])
ifTrue: [ ^false ].

(#(startPos endPos) anySatisfy: [ :specialCase | property name = specialCase ])
ifTrue: [ ^true ].

(property hasOpposite and: [ property isTarget ]) ifTrue: [ ^false].
property isContainer ifTrue: [ ^false].
(self isSamePackage: property) ifFalse: [ ^false ].

^true
]

0 comments on commit 0a65387

Please sign in to comment.