Skip to content

Commit

Permalink
Fix symbol resolution of accesses and references with multiple imports
Browse files Browse the repository at this point in the history
  • Loading branch information
jecisc committed Dec 13, 2024
1 parent 6f30ae4 commit 4adb844
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
19 changes: 19 additions & 0 deletions src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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 [

Expand Down
10 changes: 0 additions & 10 deletions src/Famix-Python-Importer/FamixPythonImport.extension.st

This file was deleted.

2 changes: 1 addition & 1 deletion src/Famix-Python-Importer/FamixPythonImporter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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
]

Expand Down
12 changes: 9 additions & 3 deletions src/Famix-Python-Importer/FamixPythonImporterVisitor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Class {
#classTraits : 'SRTSolverUserVisitor classTrait',
#instVars : [
'model',
'rootFilePath'
'rootFilePath',
'importPaths'
],
#category : 'Famix-Python-Importer-Visitors',
#package : 'Famix-Python-Importer',
Expand Down Expand Up @@ -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: [
Expand Down Expand Up @@ -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' }
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4adb844

Please sign in to comment.