From ad43b96ea52b3e0e92b449e4bdaa2daf2e2ac3eb Mon Sep 17 00:00:00 2001 From: fabiovandewaeter Date: Wed, 22 May 2024 17:26:50 +0200 Subject: [PATCH 1/2] --- .../Dictionary.extension.st | 23 ++++++++++++++++ .../FamixValuePharoJacksonImporter.class.st | 27 +++++++++++++++++-- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/Famix-Value-Importer/Dictionary.extension.st b/src/Famix-Value-Importer/Dictionary.extension.st index 0ef2cb5..4cc7dcd 100644 --- a/src/Famix-Value-Importer/Dictionary.extension.st +++ b/src/Famix-Value-Importer/Dictionary.extension.st @@ -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 [ diff --git a/src/Famix-Value-Importer/FamixValuePharoJacksonImporter.class.st b/src/Famix-Value-Importer/FamixValuePharoJacksonImporter.class.st index 06748cd..8b92ebd 100644 --- a/src/Famix-Value-Importer/FamixValuePharoJacksonImporter.class.st +++ b/src/Famix-Value-Importer/FamixValuePharoJacksonImporter.class.st @@ -67,8 +67,8 @@ 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 ] @@ -104,12 +104,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." @@ -151,6 +168,12 @@ FamixValuePharoJacksonImporter >> specialTypes [ 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 ] ] From 6f7134d3bdadf2cbbf0061118a9e8c3d7329bb34 Mon Sep 17 00:00:00 2001 From: fabiovandewaeter Date: Thu, 23 May 2024 15:16:58 +0200 Subject: [PATCH 2/2] fix Dictionnary and Collection --- .../Collection.extension.st | 2 +- .../FamixValuePharoJacksonImporter.class.st | 41 ++++++++++++------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/Famix-Value-Importer/Collection.extension.st b/src/Famix-Value-Importer/Collection.extension.st index e071bd0..35f585a 100644 --- a/src/Famix-Value-Importer/Collection.extension.st +++ b/src/Famix-Value-Importer/Collection.extension.st @@ -27,7 +27,7 @@ Collection >> asJavaJacksonValueOn: importer [ Collection >> asPharoJacksonValueOn: importer [ ^ importer - importCollection: self + importArray: self of: (importer loadTypeNamed: self className) ] diff --git a/src/Famix-Value-Importer/FamixValuePharoJacksonImporter.class.st b/src/Famix-Value-Importer/FamixValuePharoJacksonImporter.class.st index 8b92ebd..df709a9 100644 --- a/src/Famix-Value-Importer/FamixValuePharoJacksonImporter.class.st +++ b/src/Famix-Value-Importer/FamixValuePharoJacksonImporter.class.st @@ -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 [ @@ -75,23 +84,23 @@ FamixValuePharoJacksonImporter >> importClosure: value of: 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 ] @@ -159,12 +168,10 @@ 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 ]. @@ -174,6 +181,12 @@ FamixValuePharoJacksonImporter >> specialTypes [ 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 ] ]