Skip to content

Commit e4b1395

Browse files
committed
Follow symbol resolver changes
1 parent 8e17bfd commit e4b1395

11 files changed

+77
-161
lines changed

src/Famix-Python-Importer/FamixPythonAbstractImportResolvable.class.st

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ Class {
22
#name : 'FamixPythonAbstractImportResolvable',
33
#superclass : 'SRResolvable',
44
#instVars : [
5-
'path',
6-
'entity'
5+
'path'
76
],
87
#category : 'Famix-Python-Importer-SymbolResolution',
98
#package : 'Famix-Python-Importer',
@@ -16,23 +15,6 @@ FamixPythonAbstractImportResolvable class >> isAbstract [
1615
^ self = FamixPythonAbstractImportResolvable
1716
]
1817

19-
{ #category : 'hooks' }
20-
FamixPythonAbstractImportResolvable >> applyReplacementStrategyWithCurrentEntity: aCurrentEntity [
21-
22-
self entity: (self notFoundReplacementEntity cull: self cull: aCurrentEntity)
23-
]
24-
25-
{ #category : 'accessing' }
26-
FamixPythonAbstractImportResolvable >> entity [
27-
^ entity
28-
]
29-
30-
{ #category : 'accessing' }
31-
FamixPythonAbstractImportResolvable >> entity: anObject [
32-
33-
entity := anObject
34-
]
35-
3618
{ #category : 'resolution' }
3719
FamixPythonAbstractImportResolvable >> findTargetEntityFor: aPath from: startEntities [
3820

src/Famix-Python-Importer/FamixPythonAbstractInvocationOrInstantiationResolvable.class.st

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ Class {
22
#name : 'FamixPythonAbstractInvocationOrInstantiationResolvable',
33
#superclass : 'SRResolvable',
44
#instVars : [
5-
'identifier',
6-
'entity'
5+
'identifier'
76
],
87
#category : 'Famix-Python-Importer-SymbolResolution',
98
#package : 'Famix-Python-Importer',
@@ -18,24 +17,6 @@ FamixPythonAbstractInvocationOrInstantiationResolvable class >> identifier: anId
1817
yourself
1918
]
2019

21-
{ #category : 'hooks' }
22-
FamixPythonAbstractInvocationOrInstantiationResolvable >> applyReplacementStrategyWithCurrentEntity: aCurrentEntity [
23-
24-
self entity: (self notFoundReplacementEntity cull: self cull: aCurrentEntity)
25-
]
26-
27-
{ #category : 'accessing' }
28-
FamixPythonAbstractInvocationOrInstantiationResolvable >> entity [
29-
30-
^ entity
31-
]
32-
33-
{ #category : 'accessing' }
34-
FamixPythonAbstractInvocationOrInstantiationResolvable >> entity: anObject [
35-
36-
entity := anObject
37-
]
38-
3920
{ #category : 'accessing' }
4021
FamixPythonAbstractInvocationOrInstantiationResolvable >> identifier [
4122

src/Famix-Python-Importer/FamixPythonFromImportResolvable.class.st

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,23 @@ FamixPythonFromImportResolvable >> resolveInScope: aScope currentEntity: current
4444
targetModule := path = '.'
4545
ifTrue: [ (currentEntity query ancestors ofType: FamixTPackage) anyOne ]
4646
ifFalse: [
47-
| remainingPath |
48-
(path beginsWith: '.')
49-
ifTrue: [
50-
| currentPackage |
51-
"In case of a relative path we need to find the origin package for the resolution"
52-
remainingPath := path allButFirst.
53-
currentPackage := (currentEntity query ancestors ofType: FamixTPackage) anyOne. "If we have a module, we need to start with its parent package. If we have a package, it starts in itself."
54-
[ remainingPath beginsWith: '.' ] whileTrue: [
55-
currentPackage := currentPackage parentPackage.
56-
remainingPath := remainingPath allButFirst ].
57-
possibleEntities := currentPackage children ]
58-
ifFalse: [ "If we have an absolute path we just start at the root."
59-
remainingPath := path.
60-
possibleEntities := currentEntity rootParents flatCollect: #children ].
47+
| remainingPath |
48+
(path beginsWith: '.')
49+
ifTrue: [
50+
| currentPackage |
51+
"In case of a relative path we need to find the origin package for the resolution"
52+
remainingPath := path allButFirst.
53+
currentPackage := (currentEntity query ancestors ofType: FamixTPackage) anyOne. "If we have a module, we need to start with its parent package. If we have a package, it starts in itself."
54+
[ remainingPath beginsWith: '.' ] whileTrue: [
55+
currentPackage := currentPackage parentPackage.
56+
remainingPath := remainingPath allButFirst ].
57+
possibleEntities := currentPackage children ]
58+
ifFalse: [ "If we have an absolute path we just start at the root."
59+
remainingPath := path.
60+
possibleEntities := currentEntity rootParents flatCollect: #children ].
6161

62-
"We trim the path because we can have spaces after the dots in relativ paths."
63-
self findTargetEntityFor: remainingPath trim from: possibleEntities ].
62+
"We trim the path because we can have spaces after the dots in relativ paths."
63+
self findTargetEntityFor: remainingPath trim from: possibleEntities ].
6464

6565

6666
"If we have an import all then we import the targeted module directly."
@@ -69,8 +69,8 @@ FamixPythonFromImportResolvable >> resolveInScope: aScope currentEntity: current
6969
ifFalse: [ targetModule allChildren select: [ :child | child isNamedEntity and: [ child name = entityName ] ] ].
7070

7171
"It is possible that we have multiple entities with the same name and in that case, python select the last one declared. So we sort by source anchor position to find this one."
72-
entity := possibleEntities detectMax: [ :possibleEntity |
73-
possibleEntity sourceAnchor
74-
ifNil: [ 1 "Packages might not have sources." ]
75-
ifNotNil: #startPos ]
72+
self result: (possibleEntities detectMax: [ :possibleEntity |
73+
possibleEntity sourceAnchor
74+
ifNil: [ 1 "Packages might not have sources." ]
75+
ifNotNil: #startPos ])
7676
]

src/Famix-Python-Importer/FamixPythonImportResolvable.class.st

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,6 @@ FamixPythonImportResolvable class >> path: aStringPath [
1414
yourself
1515
]
1616

17-
{ #category : 'accessing' }
18-
FamixPythonImportResolvable >> entity [
19-
^ entity
20-
]
21-
22-
{ #category : 'accessing' }
23-
FamixPythonImportResolvable >> entity: anObject [
24-
25-
entity := anObject
26-
]
27-
2817
{ #category : 'accessing' }
2918
FamixPythonImportResolvable >> path [
3019
^ path
@@ -38,5 +27,5 @@ FamixPythonImportResolvable >> path: anObject [
3827
{ #category : 'resolution' }
3928
FamixPythonImportResolvable >> resolveInScope: aScope currentEntity: currentEntity [
4029

41-
entity := self findTargetEntityFor: path from: currentEntity mooseModel
30+
self result: (self findTargetEntityFor: path from: currentEntity mooseModel)
4231
]

src/Famix-Python-Importer/FamixPythonImportedEntityResolvable.class.st

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ Class {
1212
#superclass : 'SRResolvable',
1313
#instVars : [
1414
'import',
15-
'identifier',
16-
'entity'
15+
'identifier'
1716
],
1817
#category : 'Famix-Python-Importer-SymbolResolution',
1918
#package : 'Famix-Python-Importer',
@@ -29,24 +28,6 @@ FamixPythonImportedEntityResolvable class >> identifier: aString import: anImpor
2928
yourself
3029
]
3130

32-
{ #category : 'hooks' }
33-
FamixPythonImportedEntityResolvable >> applyReplacementStrategyWithCurrentEntity: aCurrentEntity [
34-
35-
self entity: (self notFoundReplacementEntity cull: self cull: aCurrentEntity)
36-
]
37-
38-
{ #category : 'accessing' }
39-
FamixPythonImportedEntityResolvable >> entity [
40-
41-
^ entity
42-
]
43-
44-
{ #category : 'accessing' }
45-
FamixPythonImportedEntityResolvable >> entity: anObject [
46-
47-
entity := anObject
48-
]
49-
5031
{ #category : 'accessing' }
5132
FamixPythonImportedEntityResolvable >> identifier [
5233

@@ -74,9 +55,9 @@ FamixPythonImportedEntityResolvable >> import: anObject [
7455
{ #category : 'resolution' }
7556
FamixPythonImportedEntityResolvable >> resolveInScope: aScope currentEntity: currentEntity [
7657

77-
import importedEntity name = identifier ifTrue: [ ^ self entity: import importedEntity ].
58+
import importedEntity name = identifier ifTrue: [ ^ self result: import importedEntity ].
7859

7960
^ (import importedEntity definedEntitiesNamed: identifier ofKinds: self expectedKinds)
8061
ifEmpty: [ SRNoResolutionPossible signal ]
81-
ifNotEmpty: [ :entities | self entity: entities anyOne ]
62+
ifNotEmpty: [ :entities | self result: entities anyOne ]
8263
]

src/Famix-Python-Importer/FamixPythonInvocationOrInstantiationResolvable.class.st

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,16 @@ Class {
1010
FamixPythonInvocationOrInstantiationResolvable >> resolveInScope: aScope currentEntity: currentEntity [
1111

1212
| matchingEntities |
13-
(self expectedKinds anySatisfy: [ :expectedPossibility | aScope canContainsEntitiesOfType: expectedPossibility ]) ifFalse: [ NotFound signal ].
14-
1513
matchingEntities := (aScope reachableEntitiesNamed: self identifier ofKinds: self expectedKinds) ifEmpty: [ NotFound signal ].
1614

1715
matchingEntities := matchingEntities sorted: [ :anEntity | anEntity sourceAnchor startPos ] ascending.
1816
(matchingEntities collectAsSet: #class) size = 1
1917
ifTrue: [ "This is an instantiation"
20-
matchingEntities last isClass ifTrue: [ ^ self entity: matchingEntities last ].
18+
matchingEntities last isClass ifTrue: [ ^ self result: matchingEntities last ].
2119

22-
^ self entity: matchingEntities ]
20+
^ self result: matchingEntities ]
2321
ifFalse: [
24-
^ self entity: (matchingEntities last isClass
25-
ifTrue: [ matchingEntities last ]
26-
ifFalse: [ { matchingEntities last } ]) ]
22+
^ self result: (matchingEntities last isClass
23+
ifTrue: [ matchingEntities last ]
24+
ifFalse: [ { matchingEntities last } ]) ]
2725
]

src/Famix-Python-Importer/FamixPythonInvocationOrInstantiationWithNamespaceResolvable.class.st

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ FamixPythonInvocationOrInstantiationWithNamespaceResolvable >> resolveInScope: a
2828
import importedEntity name = identifier ifTrue: [ ^ self entity: import importedEntity ].
2929

3030
^ (import importedEntity definedEntitiesNamed: identifier ofKinds: self expectedKinds) ifEmpty: [ SRNoResolutionPossible signal ] ifNotEmpty: [ :entities |
31-
| matchingEntities |
32-
self flag: #todo. "This could probably be simplified? Or at least remove duplication with sibling classes.."
33-
matchingEntities := entities sorted: [ :anEntity | anEntity sourceAnchor startPos ] ascending.
34-
(matchingEntities collectAsSet: #class) size = 1
35-
ifTrue: [ "This is an instantiation"
36-
matchingEntities last isClass ifTrue: [ ^ self entity: matchingEntities last ].
31+
| matchingEntities |
32+
self flag: #todo. "This could probably be simplified? Or at least remove duplication with sibling classes.."
33+
matchingEntities := entities sorted: [ :anEntity | anEntity sourceAnchor startPos ] ascending.
34+
(matchingEntities collectAsSet: #class) size = 1
35+
ifTrue: [ "This is an instantiation"
36+
matchingEntities last isClass ifTrue: [ ^ self entity: matchingEntities last ].
3737

38-
self entity: matchingEntities ]
39-
ifFalse: [
40-
self entity: (matchingEntities last isClass
41-
ifTrue: [ matchingEntities last ]
42-
ifFalse: [ { matchingEntities last } ]) ] ]
38+
self result: matchingEntities ]
39+
ifFalse: [
40+
self entity: (matchingEntities last isClass
41+
ifTrue: [ matchingEntities last ]
42+
ifFalse: [ { matchingEntities last } ]) ] ]
4343
]

src/Famix-Python-Importer/FamixPythonInvocationOrInstantiationWithUnknownReceiverResolvable.class.st

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -49,36 +49,36 @@ FamixPythonInvocationOrInstantiationWithUnknownReceiverResolvable >> resolveInSc
4949
"First we check if the receiver is an imported module or package. If it is not, we have a method invocation that we are treating later."
5050

5151
(receiver includes: $.) ifFalse: [
52-
((currentEntity withAllParents flatCollect: [ :anEntity | anEntity query outgoing local dependenciesOfType: FamixPythonImport ]) select: [ :import |
53-
import importedEntity isNotNil "It's nil if we did not resolve it yet but that means the import is not relevent here." ])
54-
detect: [ :import |
55-
({
56-
FamixPythonModule.
57-
FamixPythonPackage.
58-
FamixPythonUnknownEntity } anySatisfy: [ :class | import importedEntity isOfType: class ]) and: [
59-
import hasAlias
60-
ifTrue: [ import alias = receiver ]
61-
ifFalse: [ import importedEntity name = receiver ] ] ]
62-
ifFound: [ :import |
63-
correspondingImport := import.
64-
^ (import importedEntity definedEntitiesNamed: identifier ofKinds: {
65-
FamixPythonFunction.
66-
FamixPythonClass }) ifEmpty: [ SRNoResolutionPossible signal ] ifNotEmpty: [ :entities |
67-
| matchingEntities |
68-
self flag: #todo. "This could probably be simplified? Or at least remove duplication with sibling classes.."
69-
self flag: #todo. "Do we need the sorting? If no update also the other resolvable with this code."
70-
matchingEntities := entities sorted: [ :anEntity | anEntity sourceAnchor startPos ] ascending.
71-
(matchingEntities collectAsSet: #class) size = 1
72-
ifTrue: [ "This is an instantiation"
73-
matchingEntities last isClass ifTrue: [ ^ self entity: matchingEntities last ].
52+
((currentEntity withAllParents flatCollect: [ :anEntity | anEntity query outgoing local dependenciesOfType: FamixPythonImport ]) select: [ :import |
53+
import importedEntity isNotNil "It's nil if we did not resolve it yet but that means the import is not relevent here." ])
54+
detect: [ :import |
55+
({
56+
FamixPythonModule.
57+
FamixPythonPackage.
58+
FamixPythonUnknownEntity } anySatisfy: [ :class | import importedEntity isOfType: class ]) and: [
59+
import hasAlias
60+
ifTrue: [ import alias = receiver ]
61+
ifFalse: [ import importedEntity name = receiver ] ] ]
62+
ifFound: [ :import |
63+
correspondingImport := import.
64+
^ (import importedEntity definedEntitiesNamed: identifier ofKinds: {
65+
FamixPythonFunction.
66+
FamixPythonClass }) ifEmpty: [ SRNoResolutionPossible signal ] ifNotEmpty: [ :entities |
67+
| matchingEntities |
68+
self flag: #todo. "This could probably be simplified? Or at least remove duplication with sibling classes.."
69+
self flag: #todo. "Do we need the sorting? If no update also the other resolvable with this code."
70+
matchingEntities := entities sorted: [ :anEntity | anEntity sourceAnchor startPos ] ascending.
71+
(matchingEntities collectAsSet: #class) size = 1
72+
ifTrue: [ "This is an instantiation"
73+
matchingEntities last isClass ifTrue: [ ^ self entity: matchingEntities last ].
7474

75-
self entity: matchingEntities ]
76-
ifFalse: [
77-
self entity: (matchingEntities last isClass
78-
ifTrue: [ matchingEntities last ]
79-
ifFalse: [ { matchingEntities last } ]) ] ] ] ].
75+
self result: matchingEntities ]
76+
ifFalse: [
77+
self entity: (matchingEntities last isClass
78+
ifTrue: [ matchingEntities last ]
79+
ifFalse: [ { matchingEntities last } ]) ] ] ] ].
8080

8181
^ (aScope entity withAllParents flatCollectAsSet: [ :anEntity | anEntity reachableEntitiesNamed: identifier ofKinds: { FamixPythonMethod } ])
82-
ifNotEmpty: [ :methods | entity := methods ]
82+
ifNotEmpty: [ :methods | self result: methods ]
8383
ifEmpty: [ SRNoResolutionPossible signal ]
8484
]

src/Famix-Python-Importer/FamixPythonLocalMethodInvocationResolvable.class.st

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ FamixPythonLocalMethodInvocationResolvable >> resolveInScope: aScope currentEnti
1313
aScope entity isClass ifFalse: [ NotFound signal ].
1414

1515
(aScope reachableEntitiesNamed: identifier ofKinds: { FamixPythonMethod }) ifNotEmpty: [ :entities | "I don't think we can have multiple results here."
16-
self assert: entities size = 1.
17-
^ entity := entities anyOne ].
16+
self assert: entities size = 1.
17+
^ self result: entities anyOne ].
1818

1919
SRNoResolutionPossible signal
2020
]

src/Famix-Python-Importer/FamixPythonMethodInvocationResolvable.class.st

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)