diff --git a/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st b/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st index 3426de5..e7f5450 100644 --- a/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st +++ b/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st @@ -2242,6 +2242,25 @@ FamixPythonProject1Test >> testReadAccessFromImportedGlobalWithNamespaceAliasSou self assert: access sourceText equals: 'rss.subSubPackage1Variable' ] +{ #category : 'tests - accesses' } +FamixPythonProject1Test >> testReadAccessFromImportedGlobalWithNamespaceAndMultipleImports [ + + | global module access | + global := self globalVariableNamed: 'moduleAtRootVariable3'. + module := self moduleNamed: 'moduleImportingMultipleItems'. + + access := global incomingAccesses detect: [ :anAccess | anAccess accessor = module ]. + + self assert: access class equals: FamixPythonAccess. + self assert: access source equals: module. + self assert: access accessor equals: module. + self assert: access target equals: global. + self assert: access variable equals: global. + self deny: access isWrite. + self assert: access isRead. + self assert: (module accesses anySatisfy: [ :anAccess | anAccess variable = global ]) +] + { #category : 'tests - accesses' } FamixPythonProject1Test >> testReadAccessFromImportedGlobalWithNamespaceSourceAnchor [ diff --git a/src/Famix-Python-Importer/FamixPythonImport.extension.st b/src/Famix-Python-Importer/FamixPythonImport.extension.st deleted file mode 100644 index 3f8d1db..0000000 --- a/src/Famix-Python-Importer/FamixPythonImport.extension.st +++ /dev/null @@ -1,10 +0,0 @@ -Extension { #name : 'FamixPythonImport' } - -{ #category : '*Famix-Python-Importer' } -FamixPythonImport >> importPath [ - | path | - path := self sourceText withoutPrefix: 'import '. - path := path copyUpToSubString: 'as'. - path := path copyWithout: ' '. - ^ path -] diff --git a/src/Famix-Python-Importer/FamixPythonImporter.class.st b/src/Famix-Python-Importer/FamixPythonImporter.class.st index 6825f18..4a4af4b 100644 --- a/src/Famix-Python-Importer/FamixPythonImporter.class.st +++ b/src/Famix-Python-Importer/FamixPythonImporter.class.st @@ -78,7 +78,7 @@ FamixPythonImporter >> importFileReference: aFileReference [ FamixPythonImporter >> importPythonFile: aFileReference [ ('Importing ' , aFileReference pathString) traceCr. - "(aFileReference basename = #'moduleAtRoot.py') ifTrue: [ 1halt ]." + "(aFileReference basename = #'moduleImportingMultipleItems.py') ifTrue: [ 1halt ]." (PythonParser parseFileWithErrors: aFileReference) acceptVisitor: visitor ] diff --git a/src/Famix-Python-Importer/FamixPythonImporterVisitor.class.st b/src/Famix-Python-Importer/FamixPythonImporterVisitor.class.st index 61d40f3..81217de 100644 --- a/src/Famix-Python-Importer/FamixPythonImporterVisitor.class.st +++ b/src/Famix-Python-Importer/FamixPythonImporterVisitor.class.st @@ -5,7 +5,8 @@ Class { #classTraits : 'SRTSolverUserVisitor classTrait', #instVars : [ 'model', - 'rootFilePath' + 'rootFilePath', + 'importPaths' ], #category : 'Famix-Python-Importer-Visitors', #package : 'Famix-Python-Importer', @@ -99,6 +100,10 @@ FamixPythonImporterVisitor >> createImport: anImport ofName: aName from: fromNam self currentEntity addOutgoingImport: import. + importPaths at: import put: (fromName + ifNil: [ aName ] + ifNotNil: [ fromName ]). + self solver resolve: (fromName ifNil: [ @@ -483,7 +488,8 @@ FamixPythonImporterVisitor >> initialize [ super initialize. model := FamixPythonModel new name: 'default Python Model'. - self initialiseSolver + self initialiseSolver. + importPaths := IdentityDictionary new ] { #category : 'private - searching' } @@ -758,7 +764,7 @@ FamixPythonImporterVisitor >> visitFieldAccessExpression: aFieldAccessExpression | importPath | importPath := (import hasAlias ifTrue: [ import alias ] - ifFalse: [ import importPath ]) , '.'. + ifFalse: [ importPaths at: import ]) , '.'. (source beginsWith: importPath) and: [ ((source withoutPrefix: importPath) includes: $.) not ] ] ifFound: [ :import | self