Skip to content

Commit

Permalink
Get the first function references to work
Browse files Browse the repository at this point in the history
  • Loading branch information
jecisc committed Dec 9, 2024
1 parent a2cf8ef commit 1577d1d
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 9 deletions.
24 changes: 24 additions & 0 deletions src/Famix-Python-Entities/FamixPythonContainerEntity.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
### Outgoing dependencies
| Relation | Origin | Opposite | Type | Comment |
|---|
| `outgoingFunctionReferences` | `FamixPythonContainerEntity` | `referencer` | `FamixPythonFunctionReference` | |
| `outgoingImports` | `FamixTWithImports` | `importingEntity` | `FamixTImport` | |
| `unknowAccessesOrReferences` | `FamixPythonContainerEntity` | `accessorOrReferencer` | `FamixPythonUnknowAccessOrReference` | |
Expand All @@ -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',
Expand All @@ -46,12 +48,34 @@ FamixPythonContainerEntity class >> isAbstract [
^ self == FamixPythonContainerEntity
]

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

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

{ #category : 'accessing' }
FamixPythonContainerEntity >> outgoingFunctionReferences [
"Relation named: #outgoingFunctionReferences type: #FamixPythonFunctionReference opposite: #referencer"

<generated>
<derived>
^ outgoingFunctionReferences
]

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

<generated>
outgoingFunctionReferences value: anObject
]

{ #category : 'accessing' }
FamixPythonContainerEntity >> unknowAccessesOrReferences [
"Relation named: #unknowAccessesOrReferences type: #FamixPythonUnknowAccessOrReference opposite: #accessorOrReferencer"
Expand Down
26 changes: 26 additions & 0 deletions src/Famix-Python-Entities/FamixPythonFunction.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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.|
Expand Down Expand Up @@ -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'
Expand All @@ -68,3 +72,25 @@ FamixPythonFunction class >> annotation [
<generated>
^ self
]

{ #category : 'adding' }
FamixPythonFunction >> addIncomingFunctionReference: anObject [
<generated>
^ self incomingFunctionReferences add: anObject
]

{ #category : 'accessing' }
FamixPythonFunction >> incomingFunctionReferences [
"Relation named: #incomingFunctionReferences type: #FamixPythonFunctionReference opposite: #referredFunction"

<generated>
<derived>
^ incomingFunctionReferences
]

{ #category : 'accessing' }
FamixPythonFunction >> incomingFunctionReferences: anObject [

<generated>
incomingFunctionReferences value: anObject
]
78 changes: 78 additions & 0 deletions src/Famix-Python-Entities/FamixPythonFunctionReference.class.st
Original file line number Diff line number Diff line change
@@ -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 [

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

{ #category : 'accessing' }
FamixPythonFunctionReference >> referencer [
"Relation named: #referencer type: #FamixPythonContainerEntity opposite: #outgoingFunctionReferences"

<generated>
<source>
^ referencer
]

{ #category : 'accessing' }
FamixPythonFunctionReference >> referencer: anObject [

<generated>
referencer := anObject
]

{ #category : 'accessing' }
FamixPythonFunctionReference >> referredFunction [
"Relation named: #referredFunction type: #FamixPythonFunction opposite: #incomingFunctionReferences"

<generated>
<target>
^ referredFunction
]

{ #category : 'accessing' }
FamixPythonFunctionReference >> referredFunction: anObject [

<generated>
referredFunction := 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 @@ -76,6 +76,13 @@ FamixPythonTEntityCreator >> newFunctionNamed: aName [
^ self add: (FamixPythonFunction named: aName)
]

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

<generated>
^ self add: FamixPythonFunctionReference new
]

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

Expand Down
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 @@ -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 ]).

Expand All @@ -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 ]).

Expand All @@ -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' }
Expand Down
8 changes: 5 additions & 3 deletions src/Famix-Python-Importer/FamixPythonFunction.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand Down

0 comments on commit 1577d1d

Please sign in to comment.