Skip to content

Commit

Permalink
Merge pull request #6 from moosetechnology/functions-in-function
Browse files Browse the repository at this point in the history
Functions in function
  • Loading branch information
NicolasAnquetil authored Jan 8, 2024
2 parents 230256b + df03147 commit 78eef89
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 108 deletions.
4 changes: 2 additions & 2 deletions src/Famix-Python-Entities/FamixPythonFunction.class.st
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Class {
#name : #FamixPythonFunction,
#superclass : #FamixPythonContainerEntity,
#traits : 'FamixTFunction + FamixTImportable + FamixTInvocable + FamixTWithAnnotationInstances + FamixTWithComments + FamixTWithImplicitVariables + FamixTWithInvocations',
#classTraits : 'FamixTFunction classTrait + FamixTImportable classTrait + FamixTInvocable classTrait + FamixTWithAnnotationInstances classTrait + FamixTWithComments classTrait + FamixTWithImplicitVariables classTrait + FamixTWithInvocations classTrait',
#traits : 'FamixTFunction + FamixTImportable + FamixTInvocable + FamixTWithAnnotationInstances + FamixTWithComments + FamixTWithFunctions + FamixTWithImplicitVariables + FamixTWithInvocations',
#classTraits : 'FamixTFunction classTrait + FamixTImportable classTrait + FamixTInvocable classTrait + FamixTWithAnnotationInstances classTrait + FamixTWithComments classTrait + FamixTWithFunctions classTrait + FamixTWithImplicitVariables classTrait + FamixTWithInvocations classTrait',
#category : #'Famix-Python-Entities-Entities'
}

Expand Down
4 changes: 2 additions & 2 deletions src/Famix-Python-Entities/FamixPythonMethod.class.st
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Class {
#name : #FamixPythonMethod,
#superclass : #FamixPythonContainerEntity,
#traits : 'FamixTImportable + FamixTInvocable + FamixTMethod + FamixTWithAnnotationInstances + FamixTWithComments + FamixTWithInvocations',
#classTraits : 'FamixTImportable classTrait + FamixTInvocable classTrait + FamixTMethod classTrait + FamixTWithAnnotationInstances classTrait + FamixTWithComments classTrait + FamixTWithInvocations classTrait',
#traits : 'FamixTImportable + FamixTInvocable + FamixTMethod + FamixTWithAnnotationInstances + FamixTWithComments + FamixTWithFunctions + FamixTWithInvocations',
#classTraits : 'FamixTImportable classTrait + FamixTInvocable classTrait + FamixTMethod classTrait + FamixTWithAnnotationInstances classTrait + FamixTWithComments classTrait + FamixTWithFunctions classTrait + FamixTWithInvocations classTrait',
#category : #'Famix-Python-Entities-Entities'
}

Expand Down
2 changes: 2 additions & 0 deletions src/Famix-Python-Generator/FamixPythonGenerator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ FamixPythonGenerator >> defineHierarchy [
function --|> #TImportable.
function --|> #TWithImplicitVariables.
function --|> #TWithInvocations.
function --|> #TWithFunctions.
function --|> #TInvocable.
function --|> #TWithAnnotationInstances.

Expand Down Expand Up @@ -125,6 +126,7 @@ FamixPythonGenerator >> defineHierarchy [
method --|> #TWithComments.
method --|> #TImportable.
method --|> #TWithInvocations.
method --|> #TWithFunctions.
method --|> #TInvocable.
method --|> #TWithAnnotationInstances.

Expand Down
49 changes: 38 additions & 11 deletions src/MoosePy/MSEPythonImporterTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ MSEPythonImporterTest >> testImportFamixFunctionWithParameter [
| param func |
importer accept: pyDoc2.

param := importer parameterNamed: 'word' inFunction: 'tryToPlaceWord'.
param := importer
parameterNamed: 'word'
inBehavioural: (importer functionNamed: 'tryToPlaceWord').
func := param parentBehaviouralEntity.

self assert: func class equals: FamixPythonFunction.
Expand All @@ -251,7 +253,7 @@ MSEPythonImporterTest >> testImportFamixMethod [

| mth |
importer accept: pyDoc.
mth := importer methodNamed: '__init__' inClass: 'Player'.
mth := importer methodNamed: '__init__' inClassNamed: 'Player'.
self assert: mth class equals: FamixPythonMethod.
self assert: mth name equals: '__init__'.
self assert: mth signature equals: 'self, x, y, joystick_no'
Expand All @@ -262,7 +264,7 @@ MSEPythonImporterTest >> testImportFamixMethodKnowsItsClass [

| mth cl |
importer accept: pyDoc.
mth := importer methodNamed: '__init__' inClass: 'Player'.
mth := importer methodNamed: '__init__' inClassNamed: 'Player'.
cl := importer classNamed: 'Player'.
self assert: mth parentType equals: cl.
self assert: mth parentType class equals: FamixPythonClass
Expand All @@ -275,9 +277,8 @@ MSEPythonImporterTest >> testImportFamixMethodWithParameter [
importer accept: pyDoc.

param := importer
parameterNamed: 'y'
inMethod: '__init__'
inClass: 'Player'.
parameterNamed: 'y'
inBehavioural: (importer methodNamed: '__init__' inClassNamed: 'Player').

mth := param parentBehaviouralEntity.

Expand All @@ -293,12 +294,17 @@ MSEPythonImporterTest >> testImportFamixParameter [

| param |
importer accept: pyDoc.
param := importer parameterNamed: 'joystick_no' inMethod: '__init__' inClass: 'Player'.
param := importer
parameterNamed: 'joystick_no'
inBehavioural: (importer methodNamed: '__init__' inClassNamed: 'Player').

self assert: param class equals: FamixPythonParameter.
self assert: param name equals: 'joystick_no'.

importer accept: pyDoc2.
param := importer parameterNamed: 'word' inFunction: 'tryToPlaceWord'.
param := importer
parameterNamed: 'word'
inBehavioural: (importer functionNamed: 'tryToPlaceWord').
self assert: param class equals: FamixPythonParameter.
self assert: param name equals: 'word'.
]
Expand Down Expand Up @@ -336,17 +342,38 @@ MSEPythonImporterTest >> testImportFunctions [
self assert: (importer functionNamed: 'printGrid') isNotNil
]

{ #category : #tests }
MSEPythonImporterTest >> testImportLambda [

| famix |
importer accept: (self parseCode: '
def identity:
lambda x : x
').

self assert: (importer model allWithType: FamixPythonFunction) size equals: 2.

famix := importer functionNamed: 'identity'.
self assert: famix isNotNil.
self assert: famix functions size equals: 1.

famix := famix functions anyOne.
self assert: famix name equals: ''.
self assert: famix functionOwner name equals: 'identity'.

]

{ #category : #tests }
MSEPythonImporterTest >> testImportMethods [

importer accept: pyDoc.
self assert: importer methods size equals: 5.
self assert:
(importer methodNamed: 'update' inClass: 'Ball') isNotNil.
(importer methodNamed: 'update' inClassNamed: 'Ball') isNotNil.
self assert:
(importer methodNamed: '__init__' inClass: 'Wall') isNotNil.
(importer methodNamed: '__init__' inClassNamed: 'Wall') isNotNil.
self assert:
(importer methodNamed: '__init__' inClass: 'Player') isNotNil
(importer methodNamed: '__init__' inClassNamed: 'Player') isNotNil

]

Expand Down
Loading

0 comments on commit 78eef89

Please sign in to comment.