Skip to content

Commit

Permalink
Importing Class attributes and Method localVariables
Browse files Browse the repository at this point in the history
  • Loading branch information
anquetil committed May 13, 2024
1 parent 1c74f22 commit b3a0eb0
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/MoosePy/FamixPythonClass.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Extension { #name : #FamixPythonClass }

{ #category : #'*MoosePy' }
FamixPythonClass >> createLocalVariable: aString [
^mooseModel newAttribute
name: aString ;
parentType: self ;
yourself
]

{ #category : #'*MoosePy' }
FamixPythonClass >> dictLocalVariables [
^self attributeAt: #dictLocalVariables ifAbsentPut: [ Dictionary new ]
]
14 changes: 14 additions & 0 deletions src/MoosePy/FamixPythonMethod.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Extension { #name : #FamixPythonMethod }

{ #category : #'*MoosePy' }
FamixPythonMethod >> createLocalVariable: aString [
^mooseModel newLocalVariable
name: aString ;
parentBehaviouralEntity: self ;
yourself
]

{ #category : #'*MoosePy' }
FamixPythonMethod >> dictLocalVariables [
^self attributeAt: #dictLocalVariables ifAbsentPut: [ Dictionary new ]
]
10 changes: 10 additions & 0 deletions src/MoosePy/FamixPythonModule.extension.st
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
Extension { #name : #FamixPythonModule }

{ #category : #'*MoosePy' }
FamixPythonModule >> createLocalVariable: aString [

]

{ #category : #'*MoosePy' }
FamixPythonModule >> dictLocalVariables [
^self attributeAt: #dictLocalVariables ifAbsentPut: [ Dictionary new ]
]

{ #category : #'*MoosePy' }
FamixPythonModule >> manualAddImport: aFamixImport [

Expand Down
14 changes: 14 additions & 0 deletions src/MoosePy/MSEPythonImporterTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,20 @@ MSEPythonImporterTest >> testImportClassKnowsItsMethods [

]

{ #category : #'tests - classes' }
MSEPythonImporterTest >> testImportFamixAttribute [

| clazz |
importer accept: pyDoc.
clazz := importer classNamed: 'Player'.
self assert: clazz attributes size equals: 3.
clazz attributes do: [ :att |
self assert: (#(width height my_joystick) anySatisfy: [:name | name = att name]).
].


]

{ #category : #'tests - classes' }
MSEPythonImporterTest >> testImportFamixClass [

Expand Down
20 changes: 20 additions & 0 deletions src/MoosePy/MSEPythonToFamixImporterVisitor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,14 @@ MSEPythonToFamixImporterVisitor >> ensureParameters: theParameters inBehavioural
self createParameter: parameter inBehavioural: aFamixBehavioural ] ] ]
]

{ #category : #visiting }
MSEPythonToFamixImporterVisitor >> ensureVariable: aName localTo: aFamixEntity [

aFamixEntity dictLocalVariables
at: aName
ifAbsent: [ aFamixEntity createLocalVariable: aName ]
]

{ #category : #accessing }
MSEPythonToFamixImporterVisitor >> extractArgumentsInformation: aSignature [

Expand Down Expand Up @@ -635,6 +643,13 @@ MSEPythonToFamixImporterVisitor >> visitAnnotatedSymbol: anAnnotatedSymbol [
^ super visitAnnotatedSymbol: anAnnotatedSymbol
]

{ #category : #visiting }
MSEPythonToFamixImporterVisitor >> visitAssignmentStmt: anExprStmt [

(anExprStmt testlist class = PySymbolNode)
ifTrue: [ ^self ensureVariable: anExprStmt testlist nameToken value localTo: context top]
]

{ #category : #visiting }
MSEPythonToFamixImporterVisitor >> visitClassdef: aClassDef [

Expand Down Expand Up @@ -671,6 +686,11 @@ MSEPythonToFamixImporterVisitor >> visitDottedName: anDottedNameNode [
^$. join: (anDottedNameNode names collect: [:name | self acceptNode: name])
]

{ #category : #visiting }
MSEPythonToFamixImporterVisitor >> visitExprStmt: anExprStmt [
anExprStmt isAssignment ifTrue: [ self visitAssignmentStmt: anExprStmt ]
]

{ #category : #visiting }
MSEPythonToFamixImporterVisitor >> visitFileInput: aFileInputNode [

Expand Down

0 comments on commit b3a0eb0

Please sign in to comment.