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

Refactoring in Model export #769

Merged
merged 1 commit into from
May 14, 2024
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
7 changes: 7 additions & 0 deletions src/Famix-Java-Entities/FamixJavaEntity.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ FamixJavaEntity >> isException [
^ false
]

{ #category : #testing }
FamixJavaEntity >> isFileAnchor [

<generated>
^ false
]

{ #category : #testing }
FamixJavaEntity >> isImplicitVariable [

Expand Down
1 change: 1 addition & 0 deletions src/Famix-MetamodelGeneration/FamixGenerator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -1622,6 +1622,7 @@ FamixGenerator >> defineTraits [

tFileAnchor := builder newTraitNamed: #TFileAnchor.
tFileAnchor comment: self commentForTFileAnchor.
tFileAnchor withTesting.

tFileNavigation := builder newTraitNamed: #TFileNavigation.
tFileNavigation comment: self commentForTFileNavigation.
Expand Down
7 changes: 7 additions & 0 deletions src/Famix-Test1-Entities/FamixTest1Entity.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ FamixTest1Entity >> isClass [
^ false
]

{ #category : #testing }
FamixTest1Entity >> isFileAnchor [

<generated>
^ false
]

{ #category : #testing }
FamixTest1Entity >> isMethod [

Expand Down
2 changes: 2 additions & 0 deletions src/Famix-Traits/FamixTFileAnchor.trait.st
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ FamixTFileAnchor >> isContiguousWith: anotherFileAnchor [

{ #category : #testing }
FamixTFileAnchor >> isFileAnchor [

<generated>
^ true
]

Expand Down
10 changes: 6 additions & 4 deletions src/Moose-Core-Tests/FamixTest3ModelTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ FamixTest3ModelTest >> actualClass [

{ #category : #tests }
FamixTest3ModelTest >> testExport [
self assert: (String streamContents: [ :s | group exportTo: s ]) equals: '()'.

self
assert: (String streamContents: [ :s | group exportToMSEStream: s ])
equals: '()'.
group add: (FamixTest3Class named: 'Foo').
self
assert: (String streamContents: [ :s | group exportTo: s ])
equals:
'(
assert: (String streamContents: [ :s | group exportToMSEStream: s ])
equals: '(
(Famix-Test3-Entities.Class (id: 1)
(name ''Foo'')
(isStub false)
Expand Down
6 changes: 4 additions & 2 deletions src/Moose-Core-Tests/MooseModelTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,10 @@ MooseModelTest >> testDifferenceWithRealCollection [
]

{ #category : #tests }
MooseModelTest >> testExportMetamodelTo [
self denyEmpty: (String streamContents: [ :s | group exportMetamodelTo: s ])
MooseModelTest >> testExportMetamodelToMSEStream [

self denyEmpty:
(String streamContents: [ :s | group exportMetamodelToMSEStream: s ])
]

{ #category : #tests }
Expand Down
128 changes: 58 additions & 70 deletions src/Moose-Core/MooseModel.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,32 @@ MooseModel class >> developerToolsMenuLabel [
]

{ #category : #'import-export' }
MooseModel class >> export: aModel to: aStream [
aModel exportTo: aStream
]
MooseModel class >> export: aModel to: aStream [

{ #category : #'import-export' }
MooseModel class >> export: aModel withMetamodel: aMetamodel to: aStream [
aModel exportWithMetamodel: aMetamodel to: aStream
self
deprecated:
'This method is not used and will be removed in the next Moose version.
Please use an instance side method instead.
The default export is done in a MSE format. JSON is also available'
transformWith: '`@modelClass export: `@model to: `@stream'
-> '`@model exportToMSEStream: `@stream'.

aModel exportToMSEStream: aStream
]

{ #category : #'import-export' }
MooseModel class >> exportMetamodel: aMetamodel to: aStream [
MooseModel class >> exportMetamodel: aMetamodel to: aStream [

aMetamodel exportOn: aStream
]
self
deprecated:
'This method is not used and will be removed in the next Moose version.
Please use an instance side method instead.
The default export is done in a MSE format. JSON is also available'
transformWith:
'`@modelClass exportMetamodel: `@metamodel to: `@stream'
-> '`@metamodel exportMetamodelToMSEStream: `@stream'.

{ #category : #'import-export' }
MooseModel class >> exportMetamodelTo: aStream [
self deprecated: 'Use exportMetamodelTo: in instance side'.
self exportMetamodel: self metamodel to: aStream
aMetamodel exportMetamodelToMSEStream: aStream
]

{ #category : #accessing }
Expand Down Expand Up @@ -389,12 +396,10 @@ MooseModel >> allRootContainers [
^ self allModelContainers select: #isRoot
]

{ #category : #actions }
{ #category : #'import-export' }
MooseModel >> asMSEString [
| stream |
stream := (String new: 1024) writeStream.
self exportToMSEStream: stream.
^ stream contents

^ String streamContents: [ :stream | self exportToMSEStream: stream ]
]

{ #category : #groups }
Expand Down Expand Up @@ -430,15 +435,13 @@ MooseModel >> deadCodeRate [
computedAs: [ self allBehaviouralsWithDeadCode size / self allModelBehaviourals size ]
]

{ #category : #actions }
{ #category : #'import-export' }
MooseModel >> detectEncodingOfAllFileAnchors [

"I can be execute to reduce the time of detection of the encoding of each file anchor because multiple file anchor can point to the same file."

(((self select: [ :entity |
[ entity isFileAnchor ]
on: MessageNotUnderstood
do: [ false ] ]) asOrderedCollection reject: #privateHasEncoding)
groupedBy: #fileName) valuesDo: [ :anchors |
(((self allUsing: FamixTFileAnchor) asOrderedCollection reject:
#privateHasEncoding) groupedBy: #fileName) valuesDo: [ :anchors |
| encoding |
encoding := anchors anyOne detectEncoding.
anchors do: [ :anchor | anchor encoding: encoding ] ]
Expand All @@ -454,70 +457,55 @@ MooseModel >> difference: aGroup [
]

{ #category : #'import-export' }
MooseModel >> exportMetamodel: aMetamodel to: aStream [
MooseModel >> exportMetamodelTo: aStream [

self
deprecated: 'Renamed to specify the format.'
transformWith: '`@receiver exportMetamodelTo: `@arg'
-> '`@receiver exportMetamodelToMSEStream: `@arg'.

self class exportMetamodel: aMetamodel to: aStream
self metamodel exportMetamodelToMSEStream: aStream
]

{ #category : #'import-export' }
MooseModel >> exportMetamodelTo: aStream [
self exportMetamodel: self metamodel to: aStream
MooseModel >> exportMetamodelToMSEStream: aStream [

self metamodel exportToMSEStream: aStream
]

{ #category : #'import-export' }
MooseModel >> exportTo: aStream [
self exportWithMetamodel: self metamodel to: aStream
]

{ #category : #'import-export' }
MooseModel >> exportTo: aStream usingPrinter: aPrinter [
self exportWithMetamodel: self metamodel to: aStream usingPrinter: aPrinter
self
deprecated:
'Please specify the format you want to export to. Default is MSE. JSON is also available.'
transformWith:
'`@model exportTo: `@stream'
-> '`@model exportToMSEStream: `@stream'.

self exportToMSEStream: aStream
]

{ #category : #actions }
{ #category : #'import-export' }
MooseModel >> exportToJSONStream: aStream [
"Benchmarks on Network packages
Time millisecondsToRun: [ self exportToMSEStream: (StandardFileStream forceNewFileNamed: 'network.mse') ]
34408ms -> simon.denier 9/11/2009 11:12 - initial run
35527ms -> simon.denier 9/11/2009 11:51 - IdentityHashSet in FMRepository#elements, worse?
rewind
32236ms -> simon.denier 9/11/2009 17:46 - IdentityHashTable in FMRepositoryVisitor, a bit better but not much
30963ms -> simon.denier 9/15/2009 12:28 - cache for roots (UI process)
24661ms -> simon_denier 9/21/2009 22:32 - removing metrics from MSE
"

self detectEncodingOfAllFileAnchors.
self exportTo: aStream usingPrinter: FMJSONPrinter
self exportWithMetamodelUsingPrinter: (FMJSONPrinter on: aStream)
]

{ #category : #actions }
{ #category : #'import-export' }
MooseModel >> exportToMSEStream: aStream [
"Benchmarks on Network packages
Time millisecondsToRun: [ self exportToMSEStream: (StandardFileStream forceNewFileNamed: 'network.mse') ]
34408ms -> simon.denier 9/11/2009 11:12 - initial run
35527ms -> simon.denier 9/11/2009 11:51 - IdentityHashSet in FMRepository#elements, worse?
rewind
32236ms -> simon.denier 9/11/2009 17:46 - IdentityHashTable in FMRepositoryVisitor, a bit better but not much
30963ms -> simon.denier 9/15/2009 12:28 - cache for roots (UI process)
24661ms -> simon_denier 9/21/2009 22:32 - removing metrics from MSE
"

self detectEncodingOfAllFileAnchors.
self exportTo: aStream usingPrinter: FMMSEPrinter
self exportWithMetamodelUsingPrinter: (FMMSEPrinter on: aStream)
]

{ #category : #'import-export' }
MooseModel >> exportWithMetamodel: aMetamodel to: aStream [
(FMModel withMetamodel: aMetamodel)
addAll: self entities;
exportOn: aStream usingPrinter: FMMSEPrinter
]
MooseModel >> exportWithMetamodelUsingPrinter: aPrinter [

{ #category : #'import-export' }
MooseModel >> exportWithMetamodel: aMetamodel to: aStream usingPrinter: aPrinter [
(FMModel withMetamodel: aMetamodel)
(FMModel withMetamodel: self metamodel)
addAll: self entities;
exportOn: aStream usingPrinter: aPrinter
exportWithPrinter: aPrinter
]

{ #category : #accessing }
Expand All @@ -532,14 +520,14 @@ MooseModel >> flushPrivateState [
self entities do: #flush displayingProgress: [ :entity | 'Cleaning cache of ' , entity mooseName ]
]

{ #category : #actions }
{ #category : #'import-export' }
MooseModel >> importFrom: aFMModel named: aString [

self silentlyAddAll: aFMModel elements.
self name: aString
]

{ #category : #'as yet unclassified' }
{ #category : #'import-export' }
MooseModel >> importFromJSON [

| file |
Expand All @@ -555,7 +543,7 @@ MooseModel >> importFromJSON [
stream close ]
]

{ #category : #actions }
{ #category : #'import-export' }
MooseModel >> importFromJSONStream: aStream [

"Benchmarks
Expand All @@ -572,7 +560,7 @@ MooseModel >> importFromJSONStream: aStream [
named: (aStream localName removeSuffix: '.json')
]

{ #category : #actions }
{ #category : #'import-export' }
MooseModel >> importFromJSONStream: aStream filteredBy: anImportingContext [

^ self
Expand All @@ -599,7 +587,7 @@ MooseModel >> importFromMSE [
stream close ]
]

{ #category : #actions }
{ #category : #'import-export' }
MooseModel >> importFromMSEStream: aStream [

"Benchmarks
Expand All @@ -616,7 +604,7 @@ MooseModel >> importFromMSEStream: aStream [
named: (aStream localName removeSuffix: '.mse')
]

{ #category : #actions }
{ #category : #'import-export' }
MooseModel >> importFromMSEStream: aStream filteredBy: anImportingContext [

^ self
Expand Down
Loading