Skip to content

Commit c1cdf43

Browse files
authored
Merge pull request #757 from moosetechnology/smalltalk-importer-cleaning
Use a trait for the smalltalk importers utilities
2 parents cb0951e + 81b3243 commit c1cdf43

5 files changed

+104
-148
lines changed

src/Moose-SmalltalkImporter/FamixStAbstractImporter.class.st

-50
This file was deleted.

src/Moose-SmalltalkImporter/FamixStImportClassesTask.class.st

+4-9
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ is trigged by the MooseCompositeImporterTask and implemented by InstallElementsO
1111
"
1212
Class {
1313
#name : #FamixStImportClassesTask,
14-
#superclass : #FamixStAbstractImporter,
14+
#superclass : #MooseTask,
15+
#traits : 'FamixStTImportUtils',
16+
#classTraits : 'FamixStTImportUtils classTrait',
1517
#instVars : [
16-
'classes',
1718
'classExtensions'
1819
],
1920
#category : #'Moose-SmalltalkImporter-Importers'
@@ -47,7 +48,7 @@ FamixStImportClassesTask >> addClassExtension: aClassExtension [
4748
FamixStImportClassesTask >> basicRun [
4849

4950
| importer |
50-
importer := FamixStImporter new importingContext: importingContext.
51+
importer := FamixStImporter new importingContext: self importingContext.
5152
importer factory: self factory.
5253
self classes do: [ :class |
5354
importer importClass: class.
@@ -62,12 +63,6 @@ FamixStImportClassesTask >> classExtensions [
6263
^classExtensions
6364
]
6465

65-
{ #category : #accessing }
66-
FamixStImportClassesTask >> classes [
67-
68-
^classes
69-
]
70-
7166
{ #category : #accessing }
7267
FamixStImportClassesTask >> description [
7368

src/Moose-SmalltalkImporter/FamixStImporter.class.st

+41-77
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ I'm mainly invoked by the MooseImportClassesTask
44
"
55
Class {
66
#name : #FamixStImporter,
7-
#superclass : #FamixStAbstractImporter,
7+
#superclass : #Object,
8+
#traits : 'FamixStTImportUtils',
9+
#classTraits : 'FamixStTImportUtils classTrait',
810
#instVars : [
911
'methods',
10-
'classes',
1112
'namespaces',
1213
'packages',
1314
'globals',
@@ -65,8 +66,7 @@ FamixStImporter >> basicClassCreation: aClass [
6566
class := classes at: aClass put: self factory classEntity new.
6667
class name: (aClass name replaceAll: Character space with: $_).
6768
class stub: true.
68-
importingContext shouldImportNamespace ifTrue: [
69-
class typeContainer: (self ensureNamespace: aClass environment) ].
69+
self importingContext shouldImportNamespace ifTrue: [ class typeContainer: (self ensureNamespace: aClass environment) ].
7070
anchor := self factory anchor new
7171
element: class;
7272
pharoEntity: aClass;
@@ -93,12 +93,6 @@ FamixStImporter >> checkAbstractClass: class [
9393
class isAbstract: (class methods contains: [ :each | each isAbstract ])
9494
]
9595

96-
{ #category : #'private accessing' }
97-
FamixStImporter >> classes [
98-
99-
^ classes
100-
]
101-
10296
{ #category : #'private-entity-creation' }
10397
FamixStImporter >> createAnnotationType: aPragmaNode [
10498
| pragmaAnnotationType |
@@ -119,77 +113,58 @@ FamixStImporter >> createAnnotationType: aPragmaNode [
119113

120114
{ #category : #'private-entity-creation' }
121115
FamixStImporter >> createAttribute: name for: aClass [
116+
122117
| attribute realName possibleTypes |
123118
realName := self nameForInstanceVariable: name class: aClass.
124-
attribute := (self scopeOfClass: aClass)
125-
at: realName
126-
bind: self factory attribute new.
119+
attribute := (self scopeOfClass: aClass) at: realName bind: self factory attribute new.
127120
attribute stub: true.
128121
attribute name: realName asSymbol.
129-
importingContext shouldMergeClassAndMetaclass
122+
self importingContext shouldMergeClassAndMetaclass
130123
ifTrue: [ attribute parentType: (self ensureClass: aClass instanceSide) ]
131124
ifFalse: [ attribute parentType: (self ensureClass: aClass) ].
132125
attribute isClassSide: aClass isMeta.
133126
"now we use RoelTyper to see a unique type can be retrieve for this attribute: "
134-
importingContext shouldComputeTypeOfAttributes
135-
ifTrue: [ possibleTypes := (TypeCollector
136-
typeInstvar: name asSymbol
137-
ofClassWithLookup: aClass) types.
138-
possibleTypes size = 1
139-
ifTrue: [ attribute
140-
declaredType: (self ensureClass: possibleTypes first instanceSide) ] ].
127+
self importingContext shouldComputeTypeOfAttributes ifTrue: [
128+
possibleTypes := (TypeCollector typeInstvar: name asSymbol ofClassWithLookup: aClass) types.
129+
possibleTypes size = 1 ifTrue: [ attribute declaredType: (self ensureClass: possibleTypes first instanceSide) ] ].
141130
^ attribute
142131
]
143132

144133
{ #category : #'private-entity-creation' }
145134
FamixStImporter >> createClass: aClass [
146135

147136
| class inheritance |
148-
class := (importingContext shouldMergeClassAndMetaclass and: [
149-
aClass isMeta ])
150-
ifTrue: [
151-
classes
152-
at: aClass
153-
put: (self ensureClass: aClass soleInstance) ]
137+
class := (self importingContext shouldMergeClassAndMetaclass and: [ aClass isMeta ])
138+
ifTrue: [ classes at: aClass put: (self ensureClass: aClass soleInstance) ]
154139
ifFalse: [ self basicClassCreation: aClass ].
155140

156-
importingContext shouldImportPackage ifTrue: [
157-
class parentPackage: (self ensurePackage: aClass package) ].
141+
self importingContext shouldImportPackage ifTrue: [ class parentPackage: (self ensurePackage: aClass package) ].
158142

159-
importingContext shouldImportInheritance ifTrue: [
160-
(aClass superclass isNotNil and: [
161-
importingContext shouldMergeClassAndMetaclass
143+
self importingContext shouldImportInheritance ifTrue: [
144+
(aClass superclass isNotNil and: [
145+
self importingContext shouldMergeClassAndMetaclass
162146
ifFalse: [ true ]
163-
ifTrue: [ aClass isMeta not ] ]) ifTrue: [
147+
ifTrue: [ aClass isMeta not ] ]) ifTrue: [
164148
inheritance := self addEntity: self factory inheritance new.
165149
inheritance superclass: (self ensureClass: aClass superclass).
166150
inheritance subclass: class ] ].
167151

168152
aClass isMeta ifFalse: [ self ensureClass: aClass class ].
169153

170-
importingContext shouldImportAttribute ifTrue: [
171-
aClass instVarNames do: [ :eachName |
172-
self ensureAttribute: eachName for: aClass ].
154+
self importingContext shouldImportAttribute ifTrue: [
155+
aClass instVarNames do: [ :eachName | self ensureAttribute: eachName for: aClass ].
173156
"since the classVar of a class are not the same as the classVar of the class class"
174157
"with latest pharo class classVar = class class classVar so we should not need that anymore"
175158
aClass isMeta
176-
ifTrue: [
177-
aClass soleInstance classVarNames do: [ :eachClassVarName |
178-
self
179-
ensureClassVarAttribute: eachClassVarName
180-
for: aClass soleInstance ] ]
181-
ifFalse: [
182-
aClass classVarNames do: [ :eachClassVarName |
183-
self ensureClassVarAttribute: eachClassVarName for: aClass ] ] ].
184-
185-
(importingContext shouldImportComment and: [ aClass hasComment ])
186-
ifTrue: [
187-
(importingContext shouldMergeClassAndMetaclass and: [
188-
aClass isMeta ]) ifFalse: [
189-
| comment |
190-
comment := self addEntity: self factory comment new.
191-
comment content: aClass comment asString.
192-
comment commentedEntity: class ] ].
159+
ifTrue: [ aClass soleInstance classVarNames do: [ :eachClassVarName | self ensureClassVarAttribute: eachClassVarName for: aClass soleInstance ] ]
160+
ifFalse: [ aClass classVarNames do: [ :eachClassVarName | self ensureClassVarAttribute: eachClassVarName for: aClass ] ] ].
161+
162+
(self importingContext shouldImportComment and: [ aClass hasComment ]) ifTrue: [
163+
(self importingContext shouldMergeClassAndMetaclass and: [ aClass isMeta ]) ifFalse: [
164+
| comment |
165+
comment := self addEntity: self factory comment new.
166+
comment content: aClass comment asString.
167+
comment commentedEntity: class ] ].
193168

194169
^ class
195170
]
@@ -227,7 +202,7 @@ FamixStImporter >> createMethod: aCompiledMethod [
227202

228203
| method anchor |
229204
method := self createStubMethod: aCompiledMethod.
230-
importingContext shouldImportMethodBody ifTrue: [
205+
self importingContext shouldImportMethodBody ifTrue: [
231206
| visitor |
232207
visitor := SmalltalkMethodVisitor on: self.
233208
visitor runWith: aCompiledMethod and: method ].
@@ -443,14 +418,10 @@ FamixStImporter >> ensureSmalltalkStubMethod: aCompiledMethod [
443418
FamixStImporter >> ensureSmalltalkStubMethodsFor: aSignature [
444419

445420
| implementors |
446-
importingContext shouldImportSmalltalkStubMethod ifFalse: [ ^ #( ) ].
421+
self importingContext shouldImportSmalltalkStubMethod ifFalse: [ ^ #( ) ].
447422
implementors := self allImplementorsOf: aSignature.
448-
implementors ifEmpty: [
449-
^ { (self
450-
basicCreateMethod: (aSignature copyUpTo: $()
451-
withSignature: aSignature) } ].
452-
^ implementors collect: [ :meth |
453-
self ensureSmalltalkStubMethod: meth ]
423+
implementors ifEmpty: [ ^ { (self basicCreateMethod: (aSignature copyUpTo: $() withSignature: aSignature) } ].
424+
^ implementors collect: [ :meth | self ensureSmalltalkStubMethod: meth ]
454425
]
455426

456427
{ #category : #'public-entity-creation' }
@@ -472,21 +443,18 @@ FamixStImporter >> famixClasses [
472443
FamixStImporter >> importClass: aClass [
473444

474445
| class |
475-
importingContext shouldImportClass ifFalse: [ ^ self ].
446+
self importingContext shouldImportClass ifFalse: [ ^ self ].
476447

477448
class := self ensureClass: aClass.
478449
class stub: false.
479450
class attributes do: [ :each | each stub: false ].
480451

481-
importingContext shouldImportPackage ifTrue: [
482-
class parentPackage stub: false ].
452+
self importingContext shouldImportPackage ifTrue: [ class parentPackage stub: false ].
483453

484-
importingContext shouldImportSubclasses ifTrue: [
485-
aClass subclasses do: [ :each | self ensureClass: each ] ].
454+
self importingContext shouldImportSubclasses ifTrue: [ aClass subclasses do: [ :each | self ensureClass: each ] ].
486455

487-
importingContext shouldImportMethod ifTrue: [
488-
aClass methods do: [ :each |
489-
(self ensureMethod: each) isStub: false ].
456+
self importingContext shouldImportMethod ifTrue: [
457+
aClass methods do: [ :each | (self ensureMethod: each) isStub: false ].
490458
self checkAbstractClass: class ].
491459

492460
aClass isMeta ifFalse: [ self importClass: aClass class ]
@@ -496,12 +464,11 @@ FamixStImporter >> importClass: aClass [
496464
FamixStImporter >> importClassExtension: aClassExtension [
497465

498466
| method |
499-
importingContext shouldImportClassExtension ifFalse: [ ^ self ].
467+
self importingContext shouldImportClassExtension ifFalse: [ ^ self ].
500468

501469
method := (self ensureMethod: aClassExtension) isStub: false.
502470

503-
importingContext shouldImportPackage ifTrue: [
504-
method parentPackage isStub: false ]
471+
self importingContext shouldImportPackage ifTrue: [ method parentPackage isStub: false ]
505472
]
506473

507474
{ #category : #initialization }
@@ -526,12 +493,9 @@ FamixStImporter >> methods [
526493

527494
{ #category : #'private utils' }
528495
FamixStImporter >> nameForInstanceVariable: name class: aClass [
529-
530-
(importingContext shouldMergeClassAndMetaclass)
531-
and: [aClass isMeta ifTrue: [ ^ self CIVString, name]].
496+
497+
self importingContext shouldMergeClassAndMetaclass and: [ aClass isMeta ifTrue: [ ^ self CIVString , name ] ].
532498
^ name
533-
534-
535499
]
536500

537501
{ #category : #'private-entity-creation' }

src/Moose-SmalltalkImporter/FamixStPharoImporterTask.class.st

+10-12
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ This class specifies that the Smalltalk classes are identified using packages
33
"
44
Class {
55
#name : #FamixStPharoImporterTask,
6-
#superclass : #FamixStAbstractImporter,
6+
#superclass : #MooseTask,
7+
#traits : 'FamixStTImportUtils',
8+
#classTraits : 'FamixStTImportUtils classTrait',
79
#instVars : [
8-
'classes',
910
'packages',
1011
'classExtensions',
1112
'runSelector',
@@ -66,7 +67,7 @@ FamixStPharoImporterTask >> basicRun [
6667
"importerTask applies an import filter definition (context) on a set of classes (allClasses) and yields elements"
6768
importerTask := FamixStImportClassesTask new.
6869
importerTask factory: self factory.
69-
importerTask importingContext: importingContext.
70+
importerTask importingContext: self importingContext.
7071
importerTask addAll: self classes.
7172
importerTask addAllExtensions: self classExtensions.
7273
importer := importerTask runSelector: runSelector.
@@ -96,18 +97,14 @@ FamixStPharoImporterTask >> classExtensions [
9697
^classExtensions
9798
]
9899

99-
{ #category : #accessing }
100-
FamixStPharoImporterTask >> classes [
101-
^classes
102-
]
103-
104100
{ #category : #initialization }
105101
FamixStPharoImporterTask >> defaultImportingContext [
106102
"does not import stub methods by default because it can create a lot of methods"
103+
107104
| context |
108-
context := super defaultImportingContext.
109-
context entityKindsToBeExtracted remove: (context class importingSmalltalkStubMethod).
110-
^context
105+
context := MooseImportingContext new importMaximum.
106+
context entityKindsToBeExtracted remove: context class importingSmalltalkStubMethod.
107+
^ context
111108
]
112109

113110
{ #category : #accessing }
@@ -124,7 +121,8 @@ FamixStPharoImporterTask >> doNotRunCandidateOperator [
124121

125122
{ #category : #accessing }
126123
FamixStPharoImporterTask >> factory [
127-
^ super factory ifNil: [ factory := self model factory ]
124+
125+
^ factory ifNil: [ factory := self model factory ]
128126
]
129127

130128
{ #category : #initialization }

0 commit comments

Comments
 (0)