Skip to content

Commit

Permalink
Merge 6f7134d
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel-Darbord committed Jun 4, 2024
2 parents 15484fb + 6f7134d commit dd3b1ab
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/Famix-Value-Importer/Collection.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Collection >> asJavaJacksonValueOn: importer [
Collection >> asPharoJacksonValueOn: importer [

^ importer
importCollection: self
importArray: self
of: (importer loadTypeNamed: self className)
]

Expand Down
23 changes: 23 additions & 0 deletions src/Famix-Value-Importer/Dictionary.extension.st
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
Extension { #name : #Dictionary }

{ #category : #'*Famix-Value-Importer' }
Dictionary >> asPharoJacksonValueOn: importer [

^ (self removeKey: importer typeKey ifAbsent: nil)
ifNotNil: [ :className | "object of an unloaded class"
className = 'Class'
ifTrue: [
importer
importClassReference: self
of: (importer loadTypeNamed: className) ]
ifFalse: [
importer
importObject: self
of: (importer loadTypeNamed: className) ] ]
ifNil: [ "species of dictionary"
(self removeKey: importer refKey ifAbsent: nil)
ifNotNil: [ :refId | "if @ref"
importer
getObjectFromIdentity: refId
ifAbsent: [ Error signal: 'unknown id: ' , refId asString ] ]
ifNil: [ Error signal: 'Unknown state' ] ]
]

{ #category : #'*Famix-Value-Importer' }
Dictionary >> asPharoSTONValueOn: importer [

Expand Down
68 changes: 52 additions & 16 deletions src/Famix-Value-Importer/FamixValuePharoJacksonImporter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ FamixValuePharoJacksonImporter >> idKey: aString [
idKey := aString
]

{ #category : #importing }
FamixValuePharoJacksonImporter >> importArray: rawValue of: type [

^ objectDict
at: rawValue first
ifAbsentPut: [
super importCollection: rawValue allButFirst of: type ]
]

{ #category : #importing }
FamixValuePharoJacksonImporter >> importAssociation: rawValue of: type [

Expand Down Expand Up @@ -67,31 +76,31 @@ FamixValuePharoJacksonImporter >> importClassReference: rawValue of: type [
FamixValuePharoJacksonImporter >> importClosure: value of: type [

self flag: #TODO. "handle FullBlockClosure, add FamixValueOfClosure entity with `variables` relation to FamixValueOfType"
^ self model newOfUnknownType
value: value;
^ self model newOfPrimitiveType
value: nil;
type: type
]

{ #category : #importing }
FamixValuePharoJacksonImporter >> importCollection: rawValue of: type [

^ objectDict
at: rawValue first
ifAbsentPut: [
super importCollection: rawValue allButFirst of: type ]
| collection |
collection := self model newOfCollection type: type.
objectDict at: (self getObjectIdentity: rawValue) put: collection.
(rawValue at: '@') do: [ :rawElement |
collection addValue: (self model newOfCollectionElement value:
(self importValue: rawElement)) ].
^ collection
]

{ #category : #importing }
FamixValuePharoJacksonImporter >> importDictionary: rawValue of: type [

| dictionary assoc |
| dictionary |
dictionary := self model newOfDictionary type: type.
objectDict at: (self getObjectIdentity: rawValue) put: dictionary.
rawValue associationsDo: [ :rawAssoc |
assoc := self model newOfDictionaryAssociation dictionary:
dictionary.
assoc key: (self importValue: rawAssoc key).
assoc value: (self importValue: rawAssoc value) ].
(rawValue at: '@') do: [ :rawAssoc |
(rawAssoc asPharoJacksonValueOn: self) dictionary: dictionary ].
^ dictionary
]

Expand All @@ -104,12 +113,29 @@ FamixValuePharoJacksonImporter >> importObject: rawObject of: type [
^ super importObject: rawObject of: type
]

{ #category : #importing }
FamixValuePharoJacksonImporter >> importSymbol: rawObject of: type [

^ objectDict
at: (self getObjectIdentity: rawObject)
put: (self model newOfPrimitiveType
value: (rawObject at: 'value') asSymbol;
type: type)
]

{ #category : #importing }
FamixValuePharoJacksonImporter >> importValue: rawValue [

^ rawValue asPharoJacksonValueOn: self
]

{ #category : #importing }
FamixValuePharoJacksonImporter >> newReader [

^ super newReader.
"^ STONReader new acceptUnknownClasses: true"
]

{ #category : #parsing }
FamixValuePharoJacksonImporter >> parseList: serializedValues [
"Ignore first element which is the id of the array."
Expand Down Expand Up @@ -142,15 +168,25 @@ FamixValuePharoJacksonImporter >> specialTypes [
put: [ :value :type | self importAssociation: value of: type ].
specialTypes
at: 'OrderedCollection'
put: [ :value :type |
self importCollection: (value at: 'array') of: type ].
put: [ :value :type | self importCollection: value of: type ].
specialTypes
at: 'Set'
put: [ :value :type |
self importCollection: (value at: 'array') of: type ].
put: [ :value :type | self importCollection: value of: type ].
specialTypes
at: 'FullBlockClosure'
put: [ :value :type | self importClosure: value of: type ].
specialTypes
at: 'ByteSymbol'
put: [ :value :type | self importSymbol: value of: type ].
specialTypes
at: 'WideSymbol'
put: [ :value :type | self importSymbol: value of: type ].
specialTypes
at: 'Dictionary'
put: [ :value :type | self importDictionary: value of: type ].
specialTypes
at: 'OrderedDictionary'
put: [ :value :type | self importDictionary: value of: type ].
specialTypes ]
]

Expand Down

0 comments on commit dd3b1ab

Please sign in to comment.