Skip to content

Commit

Permalink
Start to manage stubs for accesses or references
Browse files Browse the repository at this point in the history
  • Loading branch information
jecisc committed Dec 4, 2024
1 parent 57ec155 commit 0f9c8a1
Show file tree
Hide file tree
Showing 8 changed files with 191 additions and 4 deletions.
26 changes: 26 additions & 0 deletions src/Famix-Python-Entities/FamixPythonContainerEntity.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
| Relation | Origin | Opposite | Type | Comment |
|---|
| `outgoingImports` | `FamixTWithImports` | `importingEntity` | `FamixTImport` | |
| `unknowAccessOrReference` | `FamixPythonContainerEntity` | `accessorOrReferencer` | `FamixPythonUnknowAccessOrReference` | |
Expand All @@ -20,6 +21,9 @@ Class {
#superclass : 'FamixPythonNamedEntity',
#traits : 'FamixTWithClasses + FamixTWithImports',
#classTraits : 'FamixTWithClasses classTrait + FamixTWithImports classTrait',
#instVars : [
'#unknowAccessesOrReferences => FMMany type: #FamixPythonUnknowAccessOrReference opposite: #accessorOrReferencer'
],
#category : 'Famix-Python-Entities-Entities',
#package : 'Famix-Python-Entities',
#tag : 'Entities'
Expand All @@ -41,3 +45,25 @@ FamixPythonContainerEntity class >> isAbstract [
<generated>
^ self == FamixPythonContainerEntity
]

{ #category : 'adding' }
FamixPythonContainerEntity >> addUnknowAccessesOrReferences: anObject [
<generated>
^ self unknowAccessesOrReferences add: anObject
]

{ #category : 'accessing' }
FamixPythonContainerEntity >> unknowAccessesOrReferences [
"Relation named: #unknowAccessOrReference type: #FamixPythonUnknowAccessOrReference opposite: #accessorOrReferencer"

<generated>
<derived>
^ unknowAccessesOrReferences
]

{ #category : 'accessing' }
FamixPythonContainerEntity >> unknowAccessesOrReferences: anObject [

<generated>
unknowAccessesOrReferences value: anObject
]
7 changes: 7 additions & 0 deletions src/Famix-Python-Entities/FamixPythonTEntityCreator.trait.st
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,13 @@ FamixPythonTEntityCreator >> newTypeNamed: aName [
^ self add: (FamixPythonType named: aName)
]

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

<generated>
^ self add: FamixPythonUnknowAccessOrReference new
]

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
"
## Relations
======================
### Association source
| Relation | Origin | Opposite | Type | Comment |
|---|
| `accessorOrReferencer` | `FamixPythonUnknowAccessOrReference` | `unknowAccessOrReference` | `FamixPythonContainerEntity` | |
### Association target
| Relation | Origin | Opposite | Type | Comment |
|---|
| `unknownEntity` | `FamixPythonUnknowAccessOrReference` | `accessesOrReferences` | `FamixPythonUnknownAccessedOrReferencedEntity` | |
### Other
| Relation | Origin | Opposite | Type | Comment |
|---|
| `next` | `FamixTAssociation` | `previous` | `FamixTAssociation` | Next association in an ordered collection of associations. Currently not supported by the Moose importer|
| `previous` | `FamixTAssociation` | `next` | `FamixTAssociation` | Previous association in an ordered collection of associations. Currently not supported by the Moose importer|
| `sourceAnchor` | `FamixTSourceEntity` | `element` | `FamixTSourceAnchor` | SourceAnchor entity linking to the original source code for this entity|
"
Class {
#name : 'FamixPythonUnknowAccessOrReference',
#superclass : 'FamixPythonEntity',
#traits : 'FamixTAssociation',
#classTraits : 'FamixTAssociation classTrait',
#instVars : [
'#accessorOrReferencer => FMOne type: #FamixPythonContainerEntity opposite: #unknowAccessesOrReferences',
'#unknownEntity => FMOne type: #FamixPythonUnknownAccessedOrReferencedEntity opposite: #accessesOrReferences'
],
#category : 'Famix-Python-Entities-Entities',
#package : 'Famix-Python-Entities',
#tag : 'Entities'
}

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

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

{ #category : 'accessing' }
FamixPythonUnknowAccessOrReference >> accessorOrReferencer [
"Relation named: #accessorOrReferencer type: #FamixPythonContainerEntity opposite: #unknowAccessOrReference"

<generated>
<source>
^ accessorOrReferencer
]

{ #category : 'accessing' }
FamixPythonUnknowAccessOrReference >> accessorOrReferencer: anObject [

<generated>
accessorOrReferencer := anObject
]

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

<generated>
<target>
^ unknownEntity
]

{ #category : 'accessing' }
FamixPythonUnknowAccessOrReference >> unknownEntity: anObject [

<generated>
unknownEntity := anObject
]
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
"
## Relations
======================
### Incoming dependencies
| Relation | Origin | Opposite | Type | Comment |
|---|
| `accessesOrReferences` | `FamixPythonUnknownAccessedOrReferencedEntity` | `unknownEntity` | `FamixPythonUnknowAccessOrReference` | |
"
Class {
#name : 'FamixPythonUnknownAccessedOrReferencedEntity',
#superclass : 'FamixPythonNamedEntity',
#instVars : [
'#accessesOrReferences => FMMany type: #FamixPythonUnknowAccessOrReference opposite: #unknownEntity'
],
#category : 'Famix-Python-Entities-Entities',
#package : 'Famix-Python-Entities',
#tag : 'Entities'
Expand All @@ -15,6 +30,28 @@ FamixPythonUnknownAccessedOrReferencedEntity class >> annotation [
^ self
]

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

<generated>
<derived>
^ accessesOrReferences
]

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

<generated>
accessesOrReferences value: anObject
]

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

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

Expand Down
14 changes: 10 additions & 4 deletions src/Famix-Python-Generator/FamixPythonGenerator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ FamixPythonGenerator >> defineClasses [
type := builder newClassNamed: #Type.
globalVariable := builder newClassNamed: #GlobalVariable.
unknownImportedEntity := builder newClassNamed: #UnknownImportedEntity.
unknownAccessedOrReferencedEntity := builder newClassNamed: #UnknownAccessedOrReferencedEntity
unknownAccessedOrReferencedEntity := builder newClassNamed: #UnknownAccessedOrReferencedEntity.
unknowAccessOrReference := builder newClassNamed: #UnknowAccessOrReference
]

{ #category : 'definition' }
Expand Down Expand Up @@ -195,7 +196,9 @@ FamixPythonGenerator >> defineHierarchy [
unknownImportedEntity --|> #TImportable.
unknownImportedEntity--|> #TPackageable .

unknownAccessedOrReferencedEntity --|> namedEntity
unknownAccessedOrReferencedEntity --|> namedEntity.

unknowAccessOrReference --|> #TAssociation
]

{ #category : 'definition' }
Expand All @@ -213,6 +216,9 @@ FamixPythonGenerator >> defineRelations [

super defineRelations.

((class property: #metaclass) comment: '')
*- ((class property: #instancedClasses) comment: '')
((class property: #metaclass) comment: '') *- ((class property: #instancedClasses) comment: '').

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

(unknowAccessOrReference property: #unknownEntity) target *- (unknownAccessedOrReferencedEntity property: #accessesOrReferences)
]
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ FamixPythonAbstractImporterTest >> parameterNamed: aName [
^ self entityNamed: aName in: self model allParameters
]

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

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

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

Expand Down
17 changes: 17 additions & 0 deletions src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,23 @@ FamixPythonProject1Test >> model [
^ FamixPythonProject1TestResource current model
]

{ #category : 'tests - unknown access or reference' }
FamixPythonProject1Test >> testAccessOrReferenceToStubEntity [

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

access := stub accessesOrReferences detect: [ :anAccess | anAccess accessorOrReferencer = module ].

self assert: access class equals: FamixPythonUnknowAccessOrReference.
self assert: access source equals: module.
self assert: access accessorOrReferencer equals: module.
self assert: access target equals: stub.
self assert: access unknownEntity equals: stub.
self assert: (module unknowAccessesOrReferences anySatisfy: [ :anAccess | anAccess unknownEntity = stub ])
]

{ #category : 'tests - from-import' }
FamixPythonProject1Test >> testClassImportsClassFromAModule [

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Extension { #name : 'FamixPythonUnknownAccessedOrReferencedEntity' }

{ #category : '*Famix-Python-Importer' }
FamixPythonUnknownAccessedOrReferencedEntity >> createAccessOrReferenceFrom: anEntity node: aNode [

^ anEntity mooseModel newUnknowAccessOrReference
unknownEntity: self;
accessorOrReferencer: anEntity;
yourself
]

0 comments on commit 0f9c8a1

Please sign in to comment.