From 1577d1d4dbb535e76da9b80e85ecfb0fc2e2efdd Mon Sep 17 00:00:00 2001 From: CyrilFerlicot Date: Mon, 9 Dec 2024 17:40:59 +0100 Subject: [PATCH] Get the first function references to work --- .../FamixPythonContainerEntity.class.st | 24 ++++++ .../FamixPythonFunction.class.st | 26 +++++++ .../FamixPythonFunctionReference.class.st | 78 +++++++++++++++++++ .../FamixPythonTEntityCreator.trait.st | 7 ++ .../FamixPythonProject1Test.class.st | 12 +-- .../FamixPythonFunction.extension.st | 8 +- 6 files changed, 146 insertions(+), 9 deletions(-) create mode 100644 src/Famix-Python-Entities/FamixPythonFunctionReference.class.st diff --git a/src/Famix-Python-Entities/FamixPythonContainerEntity.class.st b/src/Famix-Python-Entities/FamixPythonContainerEntity.class.st index 201a777..9db5f22 100644 --- a/src/Famix-Python-Entities/FamixPythonContainerEntity.class.st +++ b/src/Famix-Python-Entities/FamixPythonContainerEntity.class.st @@ -10,6 +10,7 @@ ### Outgoing dependencies | Relation | Origin | Opposite | Type | Comment | |---| +| `outgoingFunctionReferences` | `FamixPythonContainerEntity` | `referencer` | `FamixPythonFunctionReference` | | | `outgoingImports` | `FamixTWithImports` | `importingEntity` | `FamixTImport` | | | `unknowAccessesOrReferences` | `FamixPythonContainerEntity` | `accessorOrReferencer` | `FamixPythonUnknowAccessOrReference` | | @@ -22,6 +23,7 @@ Class { #traits : 'FamixTWithClasses + FamixTWithImports', #classTraits : 'FamixTWithClasses classTrait + FamixTWithImports classTrait', #instVars : [ + '#outgoingFunctionReferences => FMMany type: #FamixPythonFunctionReference opposite: #referencer', '#unknowAccessesOrReferences => FMMany type: #FamixPythonUnknowAccessOrReference opposite: #accessorOrReferencer' ], #category : 'Famix-Python-Entities-Entities', @@ -46,12 +48,34 @@ FamixPythonContainerEntity class >> isAbstract [ ^ self == FamixPythonContainerEntity ] +{ #category : 'adding' } +FamixPythonContainerEntity >> addOutgoingFunctionReference: anObject [ + + ^ self outgoingFunctionReferences add: anObject +] + { #category : 'adding' } FamixPythonContainerEntity >> addUnknowAccessesOrReference: anObject [ ^ self unknowAccessesOrReferences add: anObject ] +{ #category : 'accessing' } +FamixPythonContainerEntity >> outgoingFunctionReferences [ + "Relation named: #outgoingFunctionReferences type: #FamixPythonFunctionReference opposite: #referencer" + + + + ^ outgoingFunctionReferences +] + +{ #category : 'accessing' } +FamixPythonContainerEntity >> outgoingFunctionReferences: anObject [ + + + outgoingFunctionReferences value: anObject +] + { #category : 'accessing' } FamixPythonContainerEntity >> unknowAccessesOrReferences [ "Relation named: #unknowAccessesOrReferences type: #FamixPythonUnknowAccessOrReference opposite: #accessorOrReferencer" diff --git a/src/Famix-Python-Entities/FamixPythonFunction.class.st b/src/Famix-Python-Entities/FamixPythonFunction.class.st index 431885b..56ede6e 100644 --- a/src/Famix-Python-Entities/FamixPythonFunction.class.st +++ b/src/Famix-Python-Entities/FamixPythonFunction.class.st @@ -27,6 +27,7 @@ ### Incoming dependencies | Relation | Origin | Opposite | Type | Comment | |---| +| `incomingFunctionReferences` | `FamixPythonFunction` | `referredFunction` | `FamixPythonFunctionReference` | | | `incomingImports` | `FamixTImportable` | `importedEntity` | `FamixTImport` | List of imports of this entity| | `incomingInvocations` | `FamixTInvocable` | `candidates` | `FamixTInvocation` | Incoming invocations from other behaviours computed by the candidate operator.| @@ -55,6 +56,9 @@ Class { #superclass : 'FamixPythonContainerEntity', #traits : 'FamixTFunction + FamixTImportable + FamixTShadowable + FamixTShadower + FamixTWithAnnotationInstances + FamixTWithComments + FamixTWithFunctions + FamixTWithImplicitVariables + FamixTWithInvocations + FamixTWithLambdas', #classTraits : 'FamixTFunction classTrait + FamixTImportable classTrait + FamixTShadowable classTrait + FamixTShadower classTrait + FamixTWithAnnotationInstances classTrait + FamixTWithComments classTrait + FamixTWithFunctions classTrait + FamixTWithImplicitVariables classTrait + FamixTWithInvocations classTrait + FamixTWithLambdas classTrait', + #instVars : [ + '#incomingFunctionReferences => FMMany type: #FamixPythonFunctionReference opposite: #referredFunction' + ], #category : 'Famix-Python-Entities-Entities', #package : 'Famix-Python-Entities', #tag : 'Entities' @@ -68,3 +72,25 @@ FamixPythonFunction class >> annotation [ ^ self ] + +{ #category : 'adding' } +FamixPythonFunction >> addIncomingFunctionReference: anObject [ + + ^ self incomingFunctionReferences add: anObject +] + +{ #category : 'accessing' } +FamixPythonFunction >> incomingFunctionReferences [ + "Relation named: #incomingFunctionReferences type: #FamixPythonFunctionReference opposite: #referredFunction" + + + + ^ incomingFunctionReferences +] + +{ #category : 'accessing' } +FamixPythonFunction >> incomingFunctionReferences: anObject [ + + + incomingFunctionReferences value: anObject +] diff --git a/src/Famix-Python-Entities/FamixPythonFunctionReference.class.st b/src/Famix-Python-Entities/FamixPythonFunctionReference.class.st new file mode 100644 index 0000000..ff3e1eb --- /dev/null +++ b/src/Famix-Python-Entities/FamixPythonFunctionReference.class.st @@ -0,0 +1,78 @@ +" +## Relations +====================== + +### Association source +| Relation | Origin | Opposite | Type | Comment | +|---| +| `referencer` | `FamixPythonFunctionReference` | `outgoingFunctionReferences` | `FamixPythonContainerEntity` | | + +### Association target +| Relation | Origin | Opposite | Type | Comment | +|---| +| `referredFunction` | `FamixPythonFunctionReference` | `incomingFunctionReferences` | `FamixPythonFunction` | | + +### 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 : 'FamixPythonFunctionReference', + #superclass : 'FamixPythonEntity', + #traits : 'FamixTAssociation', + #classTraits : 'FamixTAssociation classTrait', + #instVars : [ + '#referencer => FMOne type: #FamixPythonContainerEntity opposite: #outgoingFunctionReferences', + '#referredFunction => FMOne type: #FamixPythonFunction opposite: #incomingFunctionReferences' + ], + #category : 'Famix-Python-Entities-Entities', + #package : 'Famix-Python-Entities', + #tag : 'Entities' +} + +{ #category : 'meta' } +FamixPythonFunctionReference class >> annotation [ + + + + + ^ self +] + +{ #category : 'accessing' } +FamixPythonFunctionReference >> referencer [ + "Relation named: #referencer type: #FamixPythonContainerEntity opposite: #outgoingFunctionReferences" + + + + ^ referencer +] + +{ #category : 'accessing' } +FamixPythonFunctionReference >> referencer: anObject [ + + + referencer := anObject +] + +{ #category : 'accessing' } +FamixPythonFunctionReference >> referredFunction [ + "Relation named: #referredFunction type: #FamixPythonFunction opposite: #incomingFunctionReferences" + + + + ^ referredFunction +] + +{ #category : 'accessing' } +FamixPythonFunctionReference >> referredFunction: anObject [ + + + referredFunction := anObject +] diff --git a/src/Famix-Python-Entities/FamixPythonTEntityCreator.trait.st b/src/Famix-Python-Entities/FamixPythonTEntityCreator.trait.st index df09f63..e47481f 100644 --- a/src/Famix-Python-Entities/FamixPythonTEntityCreator.trait.st +++ b/src/Famix-Python-Entities/FamixPythonTEntityCreator.trait.st @@ -76,6 +76,13 @@ FamixPythonTEntityCreator >> newFunctionNamed: aName [ ^ self add: (FamixPythonFunction named: aName) ] +{ #category : 'entity creation' } +FamixPythonTEntityCreator >> newFunctionReference [ + + + ^ self add: FamixPythonFunctionReference new +] + { #category : 'entity creation' } FamixPythonTEntityCreator >> newGlobalVariable [ diff --git a/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st b/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st index 9daf00e..00f26a0 100644 --- a/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st +++ b/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st @@ -653,7 +653,7 @@ FamixPythonProject1Test >> testFunctionReferenceFromModule [ | function module reference | function := self functionNamed: 'sort_list'. - module := self moduleNamed: 'moduleAtRoot1'. + module := self moduleNamed: 'moduleAtRoot'. reference := (function incomingFunctionReferences detect: [ :aReference | aReference referencer = module ]). @@ -669,8 +669,8 @@ FamixPythonProject1Test >> testFunctionReferenceFromModule [ FamixPythonProject1Test >> testFunctionReferenceFromPackage [ | function package reference | - function := self functionNamed: 'function_with_common_name'. - package := self packageNamed: 'root'. + function := self functionNamed: 'return2'. + package := self packageNamed: 'subsubpackage1'. reference := (function incomingFunctionReferences detect: [ :aReference | aReference referencer = package ]). @@ -686,13 +686,13 @@ FamixPythonProject1Test >> testFunctionReferenceFromPackage [ FamixPythonProject1Test >> testFunctionReferenceSourceAnchor [ | function package reference | - function := self functionNamed: 'function_with_common_name'. - package := self packageNamed: 'root'. + function := self functionNamed: 'return2'. + package := self packageNamed: 'subsubpackage1'. reference := function incomingFunctionReferences detect: [ :aReference | aReference referencer = package ]. self assert: reference sourceAnchor isNotNil. - self assert: reference sourceText equals: 'function_with_common_name' + self assert: reference sourceText equals: 'return2' ] { #category : 'tests - shadowing' } diff --git a/src/Famix-Python-Importer/FamixPythonFunction.extension.st b/src/Famix-Python-Importer/FamixPythonFunction.extension.st index 57e4454..c4098a0 100644 --- a/src/Famix-Python-Importer/FamixPythonFunction.extension.st +++ b/src/Famix-Python-Importer/FamixPythonFunction.extension.st @@ -2,9 +2,11 @@ Extension { #name : 'FamixPythonFunction' } { #category : '*Famix-Python-Importer' } FamixPythonFunction >> createAccessOrReferenceFrom: anEntity node: aNode [ -1halt. - self flag: #todo. - ^ nil + + ^ anEntity mooseModel newFunctionReference + referredFunction: self; + referencer: anEntity; + yourself ] { #category : '*Famix-Python-Importer' }