Skip to content

Commit

Permalink
Refactor management of unknown entities
Browse files Browse the repository at this point in the history
  • Loading branch information
jecisc committed Jan 23, 2025
1 parent 6b7e94d commit bde9ca0
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 158 deletions.
11 changes: 2 additions & 9 deletions src/Famix-Python-Entities/FamixPythonTEntityCreator.trait.st
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,8 @@ FamixPythonTEntityCreator >> newUnknowAccessOrReference [
]

{ #category : 'entity creation' }
FamixPythonTEntityCreator >> newUnknownAccessedOrReferencedEntity [
FamixPythonTEntityCreator >> newUnknownEntity [

<generated>
^ self add: FamixPythonUnknownAccessedOrReferencedEntity new
]

{ #category : 'entity creation' }
FamixPythonTEntityCreator >> newUnknownImportedEntity [

<generated>
^ self add: FamixPythonUnknownImportedEntity new
^ self add: FamixPythonUnknownEntity new
]
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
### Association target
| Relation | Origin | Opposite | Type | Comment |
|---|
| `unknownEntity` | `FamixPythonUnknowAccessOrReference` | `accessesOrReferences` | `FamixPythonUnknownAccessedOrReferencedEntity` | |
| `unknownEntity` | `FamixPythonUnknowAccessOrReference` | `accessesOrReferences` | `FamixPythonUnknownEntity` | |
### Other
| Relation | Origin | Opposite | Type | Comment |
Expand All @@ -29,7 +29,7 @@ Class {
#classTraits : 'FamixTAssociation classTrait',
#instVars : [
'#accessorOrReferencer => FMOne type: #FamixPythonContainerEntity opposite: #unknowAccessesOrReferences',
'#unknownEntity => FMOne type: #FamixPythonUnknownAccessedOrReferencedEntity opposite: #accessesOrReferences'
'#unknownEntity => FMOne type: #FamixPythonUnknownEntity opposite: #accessesOrReferences'
],
#category : 'Famix-Python-Entities-Entities',
#package : 'Famix-Python-Entities',
Expand Down Expand Up @@ -63,7 +63,7 @@ FamixPythonUnknowAccessOrReference >> accessorOrReferencer: anObject [

{ #category : 'accessing' }
FamixPythonUnknowAccessOrReference >> unknownEntity [
"Relation named: #unknownEntity type: #FamixPythonUnknownAccessedOrReferencedEntity opposite: #accessesOrReferences"
"Relation named: #unknownEntity type: #FamixPythonUnknownEntity opposite: #accessesOrReferences"

<generated>
<target>
Expand Down

This file was deleted.

67 changes: 67 additions & 0 deletions src/Famix-Python-Entities/FamixPythonUnknownEntity.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"
## Relations
======================
### Parents
| Relation | Origin | Opposite | Type | Comment |
|---|
| `parentPackage` | `FamixTPackageable` | `childEntities` | `FamixTPackage` | Package containing the entity in the code structure (if applicable)|
### Incoming dependencies
| Relation | Origin | Opposite | Type | Comment |
|---|
| `accessesOrReferences` | `FamixPythonUnknownEntity` | `unknownEntity` | `FamixPythonUnknowAccessOrReference` | |
| `incomingImports` | `FamixTImportable` | `importedEntity` | `FamixTImport` | List of imports of this entity|
"
Class {
#name : 'FamixPythonUnknownEntity',
#superclass : 'FamixPythonNamedEntity',
#traits : 'FamixTImportable + FamixTPackageable',
#classTraits : 'FamixTImportable classTrait + FamixTPackageable classTrait',
#instVars : [
'#accessesOrReferences => FMMany type: #FamixPythonUnknowAccessOrReference opposite: #unknownEntity'
],
#category : 'Famix-Python-Entities-Entities',
#package : 'Famix-Python-Entities',
#tag : 'Entities'
}

{ #category : 'meta' }
FamixPythonUnknownEntity class >> annotation [

<FMClass: #UnknownEntity super: #FamixPythonNamedEntity>
<package: #'Famix-Python-Entities'>
<generated>
^ self
]

{ #category : 'accessing' }
FamixPythonUnknownEntity >> accessesOrReferences [
"Relation named: #accessesOrReferences type: #FamixPythonUnknowAccessOrReference opposite: #unknownEntity"

<generated>
<derived>
^ accessesOrReferences
]

{ #category : 'accessing' }
FamixPythonUnknownEntity >> accessesOrReferences: anObject [

<generated>
accessesOrReferences value: anObject
]

{ #category : 'adding' }
FamixPythonUnknownEntity >> addAccessesOrReference: anObject [
<generated>
^ self accessesOrReferences add: anObject
]

{ #category : 'testing' }
FamixPythonUnknownEntity >> isStub [

^ true
]

This file was deleted.

20 changes: 8 additions & 12 deletions src/Famix-Python-Generator/FamixPythonGenerator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ Class {
'module',
'indexedFileAnchor',
'globalVariable',
'unknownImportedEntity',
'unknownAccessedOrReferencedEntity',
'unknowAccessOrReference',
'lambda'
'lambda',
'unknownEntity'
],
#category : 'Famix-Python-Generator',
#package : 'Famix-Python-Generator'
Expand Down Expand Up @@ -67,9 +66,8 @@ FamixPythonGenerator >> defineClasses [
primitiveType := builder newClassNamed: #PrimitiveType.
reference := builder newClassNamed: #Reference.
type := builder newClassNamed: #Type.
unknownImportedEntity := builder newClassNamed: #UnknownImportedEntity.
unknownAccessedOrReferencedEntity := builder newClassNamed: #UnknownAccessedOrReferencedEntity.
unknowAccessOrReference := builder newClassNamed: #UnknowAccessOrReference
unknowAccessOrReference := builder newClassNamed: #UnknowAccessOrReference.
unknownEntity := builder newClassNamed: #UnknownEntity
]

{ #category : 'definition' }
Expand Down Expand Up @@ -202,11 +200,9 @@ FamixPythonGenerator >> defineHierarchy [
type --|> containerEntity.
type --|> #TType.

unknownImportedEntity --|> containerEntity.
unknownImportedEntity --|> #TImportable.
unknownImportedEntity--|> #TPackageable .

unknownAccessedOrReferencedEntity --|> namedEntity.
unknownEntity --|> namedEntity.
unknownEntity --|> #TImportable.
unknownEntity--|> #TPackageable .

unknowAccessOrReference --|> #TAssociation
]
Expand All @@ -231,5 +227,5 @@ FamixPythonGenerator >> defineRelations [

(unknowAccessOrReference property: #accessorOrReferencer) source *- (containerEntity property: #unknowAccessesOrReferences).

(unknowAccessOrReference property: #unknownEntity) target *- (unknownAccessedOrReferencedEntity property: #accessesOrReferences)
(unknowAccessOrReference property: #unknownEntity) target *- (unknownEntity property: #accessesOrReferences)
]
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,7 @@ FamixPythonAbstractImporterTest >> parameterNamed: aName [
]

{ #category : 'accessing' }
FamixPythonAbstractImporterTest >> unknownAccessedOrReferencedEntityNamed: aName [
FamixPythonAbstractImporterTest >> unknownEntityNamed: aName [

^ self model entities detect: [ :entity | entity class = FamixPythonUnknownAccessedOrReferencedEntity and: [ entity name = aName ] ]
]

{ #category : 'accessing' }
FamixPythonAbstractImporterTest >> unknownContainerNamed: aName [

^ self model entities detect: [ :entity | entity class = FamixPythonUnknownImportedEntity and: [ entity name = aName ] ]
^ self model entities detect: [ :entity | entity class = FamixPythonUnknownEntity and: [ entity name = aName ] ]
]
12 changes: 6 additions & 6 deletions src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ FamixPythonProject1Test >> model [
FamixPythonProject1Test >> testAccessOrReferenceToStubEntity [

| stub module access |
stub := self unknownAccessedOrReferencedEntityNamed: 'MissingClass'.
stub := self unknownEntityNamed: 'MissingClass'.
module := self moduleNamed: 'moduleWithRelativeFromImportStub'.

access := stub accessesOrReferences detect: [ :anAccess | anAccess accessorOrReferencer = module ].
Expand All @@ -38,7 +38,7 @@ FamixPythonProject1Test >> testAccessOrReferenceToStubEntity [
FamixPythonProject1Test >> testAccessOrReferenceToStubEntitySourceAnchor [

| stub module access |
stub := self unknownAccessedOrReferencedEntityNamed: 'MissingClass'.
stub := self unknownEntityNamed: 'MissingClass'.
module := self moduleNamed: 'moduleWithRelativeFromImportStub'.

access := stub accessesOrReferences detect: [ :anAccess | anAccess accessorOrReferencer = module ].
Expand Down Expand Up @@ -615,15 +615,15 @@ FamixPythonProject1Test >> testFromImportStubPackages [
| matplotlib pyglot plot module import |
self denyEmpty: self model allImports.
module := self moduleNamed: 'moduleWithStubs2'.
plot := self unknownContainerNamed: 'plot'.
plot := self unknownEntityNamed: 'plot'.
import := module outgoingImports detect: [ :pimport | pimport target name = 'plot' ].

pyglot := self packageNamed: 'pyplot'.
matplotlib := pyglot parentPackage.

self assert: import importingEntity equals: module.
self assert: import importedEntity equals: plot.
self assert: import importedEntity class equals: FamixPythonUnknownImportedEntity.
self assert: import importedEntity class equals: FamixPythonUnknownEntity.
self assert: import importedEntity parentPackage equals: pyglot.
self assert: import importedEntity parentPackage parentPackage equals: matplotlib.
self assert: import importedEntity isStub.
Expand Down Expand Up @@ -3931,15 +3931,15 @@ FamixPythonProject1Test >> testSuperclass2 [
FamixPythonProject1Test >> testTwoAccessOrReferencesToStubEntityCreateOneStub [

| stub module accesses |
stub := self unknownAccessedOrReferencedEntityNamed: 'MissingClass'.
stub := self unknownEntityNamed: 'MissingClass'.
module := self moduleNamed: 'moduleWithRelativeFromImportStub'.

accesses := stub accessesOrReferences select: [ :anAccess | anAccess accessorOrReferencer = module ].

self assert: accesses size equals: 2.
self assert: (accesses allSatisfy: [ :access | access unknownEntity = stub ]).
self
assert: (self model entities select: [ :entity | entity class = FamixPythonUnknownAccessedOrReferencedEntity and: [ entity name = 'MissingClass' ] ]) size
assert: (self model entities select: [ :entity | entity class = FamixPythonUnknownEntity and: [ entity name = 'MissingClass' ] ]) size
equals: 1.
self assert: stub isStub
]
Expand Down
26 changes: 9 additions & 17 deletions src/Famix-Python-Importer/FamixPythonImporterVisitor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ FamixPythonImporterVisitor >> ensureStubClassNamed: aName [
{ #category : 'private-entity-creation' }
FamixPythonImporterVisitor >> ensureStubContainerNamed: aString [

^ (self unknownImportedNamed: aString) ifNil: [
model newUnknownImportedEntity
^ (self unknownEntityNamed: aString) ifNil: [
model newUnknownEntity
name: aString;
yourself ]
]
Expand Down Expand Up @@ -306,10 +306,10 @@ FamixPythonImporterVisitor >> ensureStubPackagesFromPath: aPythonImportPath [
]

{ #category : 'private-entity-creation' }
FamixPythonImporterVisitor >> ensureStubUnknownAccessedOrReferencedEntityNamed: aString [
FamixPythonImporterVisitor >> ensureStubUnknownEntityNamed: aString [

^ (self unknownAccessedOrReferencedEntityNamed: aString) ifNil: [
model newUnknownAccessedOrReferencedEntity
^ (self unknownEntityNamed: aString) ifNil: [
model newUnknownEntity
name: aString;
yourself ]
]
Expand Down Expand Up @@ -467,17 +467,9 @@ FamixPythonImporterVisitor >> setSuperclassesOf: classDefinitionNode from: class
]

{ #category : 'private - searching' }
FamixPythonImporterVisitor >> unknownAccessedOrReferencedEntityNamed: aString [
FamixPythonImporterVisitor >> unknownEntityNamed: aString [

^ (self model allWithType: FamixPythonUnknownAccessedOrReferencedEntity)
detect: [ :e | e name = aString ]
ifNone: [ nil ]
]

{ #category : 'private - searching' }
FamixPythonImporterVisitor >> unknownImportedNamed: aString [

^ (self model allWithType: FamixPythonUnknownImportedEntity)
^ (self model allWithType: FamixPythonUnknownEntity)
detect: [ :e | e name = aString ]
ifNone: [ nil ]
]
Expand Down Expand Up @@ -555,7 +547,7 @@ FamixPythonImporterVisitor >> visitFieldAccessExpression: aFieldAccessExpression
ifFound: [ :import |
self
resolve: ((FamixPythonImportedAccessOrReferenceResolvable identifier: aFieldAccessExpression name import: import)
notFoundReplacementEntity: [ :unresolved :currentEntity | self ensureStubUnknownAccessedOrReferencedEntityNamed: unresolved identifier ];
notFoundReplacementEntity: [ :unresolved :currentEntity | self ensureStubUnknownEntityNamed: unresolved identifier ];
yourself)
foundAction: [ :entity :currentEntity |
| association |
Expand Down Expand Up @@ -805,7 +797,7 @@ FamixPythonImporterVisitor >> visitVariableExpression: aVariableExpression [
FamixPythonGlobalVariable.
FamixPythonAttribute.
FamixPythonParameter };
notFoundReplacementEntity: [ :unresolved :currentEntity | "1 halt." self ensureStubUnknownAccessedOrReferencedEntityNamed: unresolved identifier ];
notFoundReplacementEntity: [ :unresolved :currentEntity | "1 halt." self ensureStubUnknownEntityNamed: unresolved identifier ];
yourself)
foundAction: [ :entity :currentEntity |
| association |
Expand Down
Loading

0 comments on commit bde9ca0

Please sign in to comment.