• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

moosetechnology / FAMIX2Java / 6769362094

06 Nov 2023 10:21AM UTC coverage: 48.387% (+0.5%) from 47.872%
6769362094

push

github

badetitou
move to FamixJava

4 of 35 new or added lines in 1 file covered. (11.43%)

3 existing lines in 1 file now uncovered.

225 of 465 relevant lines covered (48.39%)

0.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

38.3
/src/Famix2Java/FAMIX2JavaVisitor.class.st
1
"
2
model := (MooseModel importFromMSEStream: ('D:\path\to\mseFile.mse' asFileReference readStream)).
3
model rootFolder: 'D:\pathy\to\rootFolder'.
4

5
FAMIX2JavaVisitor new
6
        rootFolder: 'D:\Developpement\exported' asFileReference;
7
        export: model.
8
"
9
Class {
10
        #name : #FAMIX2JavaVisitor,
11
        #superclass : #Object,
12
        #traits : 'FamixJavaVisitor',
13
        #classTraits : 'FamixJavaVisitor classTrait',
14
        #instVars : [
15
                'currentStream',
16
                'rootFolder',
17
                'tabs',
18
                'tabulationSize',
19
                'endOfLine'
20
        ],
21
        #category : #Famix2Java
22
}
23

24
{ #category : #'private-exporting' }
25
FAMIX2JavaVisitor >> << aString [
1✔
26
        self indent.
1✔
27
        currentStream << aString
1✔
28
]
1✔
29

30
{ #category : #'private-exporting' }
31
FAMIX2JavaVisitor >> <<< aString [
1✔
32
        "without tab"
1✔
33
        currentStream << aString
1✔
34
]
1✔
35

36
{ #category : #'private-exporting' }
37
FAMIX2JavaVisitor >> crlf [
×
38

×
39
        currentStream << String crlf
×
40
]
×
41

42
{ #category : #accessing }
43
FAMIX2JavaVisitor >> currentStream [
×
44

×
45
        ^ currentStream
×
46
]
×
47

48
{ #category : #accessing }
49
FAMIX2JavaVisitor >> currentStream: aStream [
1✔
50

1✔
51
        currentStream := aStream
1✔
52
]
1✔
53

54
{ #category : #accessing }
55
FAMIX2JavaVisitor >> endOfLine [
1✔
56

1✔
57
        ^ endOfLine
1✔
58
]
1✔
59

60
{ #category : #accessing }
61
FAMIX2JavaVisitor >> endOfLine: anObject [
1✔
62

1✔
63
        endOfLine := anObject
1✔
64
]
1✔
65

66
{ #category : #'private-exporting' }
67
FAMIX2JavaVisitor >> eol [
1✔
68
        "print the end of line that can be configured"
1✔
69
        self <<< self endOfLine
1✔
70
]
1✔
71

72
{ #category : #'public-exporting' }
73
FAMIX2JavaVisitor >> export: aFAMIXCompatibilityModel [
×
NEW
74
        aFAMIXCompatibilityModel allModelPackages
×
NEW
75
                do: [ :package | package accept: self clone ]
×
UNCOV
76
]
×
77

78
{ #category : #printing }
79
FAMIX2JavaVisitor >> extractAnnotationTypesFor: aClass [
×
80
        | annotationInts |
×
81
        annotationInts := OrderedCollection new.
×
82
        annotationInts addAll: aClass annotationInstances.
×
83
        annotationInts addAll: (aClass methods flatCollect: [ :method | method annotationInstances ]).
×
84
        annotationInts addAll: (aClass attributes flatCollect: [ :method | method annotationInstances ]).
×
85
        ^ annotationInts collect: [ :ann | ann annotationType ] as: Set
×
86
]
×
87

88
{ #category : #printing }
89
FAMIX2JavaVisitor >> extractDeclaredTypesFor: aClass [
×
90

×
91
        | declaredTypes |
×
NEW
92
        declaredTypes := ((((aClass queryAllOutgoing collect: #target) flattened
×
93
                                    asSet
×
94
                            ,
×
95
                                    (((aClass allToScope: FamixTParameter) collect:
×
96
                                              #declaredType)
×
97
                                     ,
×
98
                                     ((aClass allToScope: FamixTStructuralEntity) 
×
99
                                              collect: #declaredType)
×
100
                                     , (aClass methods collect: #declaredType)
×
101
                                     , (aClass methods collect: [ :m | 
×
102
                                                      m caughtExceptions "collect: #exceptionClass" ])
×
103
                                     , (aClass methods collect: [ :m | 
×
104
                                                      m thrownExceptions "collect: #exceptionClass" ])
×
105
                                     , (aClass methods collect: [ :m | 
×
106
                                                      m declaredExceptions "collect:
×
107
                                                              #exceptionClass" ]))
×
108
                                            flattened) asSet reject: #isNil) flatCollect: [ 
×
109
                                  :element | 
×
110
                                  element atAnyScope: { 
×
111
                                                  FamixTClass.
×
112
                                                  FamixTParameterizedType.
×
113
                                                  FamixTEnum } ]) asSet.
×
114
        (declaredTypes select: [ :dType | 
×
115
                 dType isKindOf: FamixJavaParameterizedType ]) do: [ 
×
116
                :parameterizedType | 
×
117
                declaredTypes addAll: parameterizedType allParametrizedClasses ].
×
118
        declaredTypes := declaredTypes reject: [ :dType | 
×
119
                                 (dType isKindOf: FamixJavaParameterizedType) or: [ 
×
120
                                         ((dType isKindOf: FamixJavaType) and: [ 
×
121
                                                  dType isAnonymousClass ]) or: [ 
×
122
                                                 dType name = '?' ] ] ].
×
123
        ^ declaredTypes
×
124
]
×
125

126
{ #category : #'private-exporting' }
127
FAMIX2JavaVisitor >> indent [
1✔
128
        tabs * tabulationSize timesRepeat: [ currentStream << String space ].
1✔
129
        
1✔
130
]
1✔
131

132
{ #category : #accessing }
133
FAMIX2JavaVisitor >> indentMinus [
×
134
        tabs := tabs - 1
×
135
]
×
136

137
{ #category : #accessing }
138
FAMIX2JavaVisitor >> indentPlus [
×
139
        tabs := tabs + 1
×
140
]
×
141

142
{ #category : #initialization }
143
FAMIX2JavaVisitor >> initialize [
1✔
144

1✔
145
        super initialize.
1✔
146
        self endOfLine: OSPlatform current lineEnding.
1✔
147
        tabs := 0.
1✔
148
        tabulationSize := 4
1✔
149
]
1✔
150

151
{ #category : #accessing }
152
FAMIX2JavaVisitor >> printDeclaredType: aDeclaredType [
1✔
153
        aDeclaredType isParameterizedType
1✔
154
                ifFalse: [ currentStream << aDeclaredType name.
1✔
155
                        ^ self].
1✔
156
        currentStream
1✔
157
                << aDeclaredType name;
1✔
158
                << '<'.
1✔
159
        1 to: aDeclaredType arguments size - 1 do: [ :index | 
1✔
160
                self printDeclaredType: (aDeclaredType arguments at: index).
1✔
161
                currentStream << ',' ].
1✔
162
        aDeclaredType arguments
1✔
163
                ifNotEmpty: [ :arguments | self printDeclaredType: arguments last ].
1✔
164
        currentStream << '>'
1✔
165
]
1✔
166

167
{ #category : #printing }
168
FAMIX2JavaVisitor >> printExtends: aClass [
×
169
        "Print the extension of the class"
×
170

×
171
        aClass superclass isNil
×
172
                ifFalse: [ "ignore Object"
×
173
                        self
×
174
                                <<< ' extends ';
×
175
                                <<< aClass superclass name ]
×
176
]
×
177

178
{ #category : #printing }
179
FAMIX2JavaVisitor >> printImplements: aClass [
×
180
        "Prints the implementation of interfaces in a class."
×
181

×
182
        | interfaces |
×
183
        "aClass name = 'AbstractActionBean'
×
184
                ifTrue: [ 1 halt ]."
×
185
        interfaces := OrderedCollection new.
×
186
        interfaces addAll: (aClass superInheritances select: [ :inheritances | inheritances target isInterface ]).
×
187
        interfaces isNotEmpty
×
188
                ifTrue: [ self
×
189
                                <<< ' implements ';
×
190
                                <<< interfaces first target name ].
×
191
        2 to: interfaces size do: [ :index | 
×
192
                self
×
193
                        <<< ', ';
×
194
                        <<< (interfaces at: index) to name ]
×
195
]
×
196

197
{ #category : #printing }
198
FAMIX2JavaVisitor >> printImports: aClass [
×
199
        | declaredTypes annotationTypes |
×
200
        declaredTypes := self extractDeclaredTypesFor: aClass.
×
201
        self printImportsDeclaredTypes: declaredTypes. 
×
202
        "fetching annotation imports"
×
203
        annotationTypes := self extractAnnotationTypesFor: aClass.
×
204
        self printImportsAnnotationTypes: annotationTypes.
×
205
        
×
206
]
×
207

208
{ #category : #printing }
209
FAMIX2JavaVisitor >> printImportsAnnotationTypes: annotationTypes [
×
210
        (annotationTypes sorted: #mooseName ascending)
×
211
                do: [ :annotType | 
×
212
                        self << 'import '.
×
213
                        annotType typeContainer fullNamePrintOn: currentStream.
×
214
                        self
×
215
                                <<< '.';
×
216
                                <<< annotType name;
×
217
                                <<< ';';
×
218
                                crlf ]
×
219
]
×
220

221
{ #category : #printing }
222
FAMIX2JavaVisitor >> printImportsDeclaredTypes: declaredTypes [
×
223
        (declaredTypes sorted: #mooseName ascending)
×
224
                do: [ :class | 
×
225
                        self << 'import '.
×
226
                        class fullNamePrintOn: currentStream.
×
227
                        self
×
228
                                <<< ';';
×
229
                                eol ]
×
230
]
×
231

232
{ #category : #printing }
233
FAMIX2JavaVisitor >> printMethodAnnotations: aMethod [
1✔
234

1✔
235
        aMethod annotationInstances do: [ :annotationInstance | 
1✔
236
                annotationInstance accept: self clone.
1✔
237
                self eol ]
1✔
238
]
1✔
239

240
{ #category : #accessing }
241
FAMIX2JavaVisitor >> reset [
×
242
        tabs := 0.
×
243
        tabulationSize := 4
×
244
]
×
245

246
{ #category : #accessing }
247
FAMIX2JavaVisitor >> rootFolder [
×
248
        ^ rootFolder
×
249
]
×
250

251
{ #category : #accessing }
252
FAMIX2JavaVisitor >> rootFolder: anObject [
×
253
        rootFolder := anObject
×
254
]
×
255

256
{ #category : #'private-exporting' }
257
FAMIX2JavaVisitor >> space [
1✔
258
        currentStream << String space
1✔
259
]
1✔
260

261
{ #category : #generated }
262
FAMIX2JavaVisitor >> visitAnnotationInstance: aAnnotationInstance [
×
NEW
263

×
264
        self
×
265
                << '@';
×
266
                <<< aAnnotationInstance annotationType name.
×
NEW
267
        aAnnotationInstance attributes ifNotEmpty: [ :attributes | 
×
NEW
268
                self <<< '('.
×
NEW
269
                1 to: attributes size - 1 do: [ :index | 
×
NEW
270
                        (attributes at: index) accept: self clone.
×
NEW
271
                        self <<< ',' ].
×
NEW
272
                attributes last accept: self clone.
×
NEW
273
                self <<< ')' ]
×
UNCOV
274
]
×
275

276
{ #category : #accessing }
277
FAMIX2JavaVisitor >> visitAnnotationInstanceAttribute: aAnnotationInstanceAttribute [
×
278
        self <<< aAnnotationInstanceAttribute name;
×
279
        <<< ' = ';
×
280
        <<< aAnnotationInstanceAttribute value
×
281
]
×
282

283
{ #category : #accessing }
284
FAMIX2JavaVisitor >> visitAttribute: aAttribute [
1✔
285

1✔
286
        "Visit an attribute to print its annotations and its field."
1✔
287

1✔
288
        " Printing the annotations for the attribute"
1✔
289

1✔
290
        | attributeSource attributeSourceFromName |
1✔
291
        aAttribute annotationInstances do: [ :annotationInstance | 
1✔
292
                annotationInstance accept: self clone .
1✔
293
                self eol ].
1✔
294

1✔
295
        "Printing modifiers"
1✔
296
        self indent.
1✔
297
        "modifiers := aAttribute cacheAt: #modifiers ifAbsent: [ aAttribute modifiers ].
1✔
298
        modifiers isString
1✔
299
                ifTrue: [ self <<< modifiers ]
1✔
300
                ifFalse: [ modifiers do: [ :modifier | self <<< modifier ] separatedBy: [ self space ] ]."
1✔
301
        "Declared Type"
1✔
302
        aAttribute declaredType
1✔
303
                ifNotNil: [ self printDeclaredType: aAttribute declaredType ]
1✔
304
                ifNil: [ self <<< '/* erreur */ Object' ].
1✔
305
        "Attribute name"
1✔
306
        self
1✔
307
                space;
1✔
308
                <<< aAttribute name.
1✔
309

1✔
310
        "This is an hack to get the affectation is any (hack because some problems with annotations that are sometimes part of the sourceAnchor...)"
1✔
311
        attributeSource := aAttribute sourceAnchor ifNil: [ '' ] ifNotNil: [ :sourceAnchor | sourceAnchor sourceText ].
1✔
312
        attributeSource ifNotEmpty: [ 
1✔
313
                attributeSourceFromName := attributeSource copyFrom: (attributeSource findString: aAttribute name) to: attributeSource size.
1✔
314
                (attributeSourceFromName includesSubstring: '=') ifTrue: [ 
1✔
315
                        self
1✔
316
                                space;
1✔
317
                                <<< ((attributeSourceFromName copyFrom: (attributeSourceFromName findString: '=') to: attributeSourceFromName size) removeSuffix: ';') ] ].
1✔
318
        self <<< ';'
1✔
319
]
1✔
320

321
{ #category : #accessing }
322
FAMIX2JavaVisitor >> visitClass: aClass [
×
323

×
324
        | file |
×
325
        file := self rootFolder / (aClass name , '.java').
×
326
        file deleteIfAbsent: [  ].
×
327
        file writeStreamDo: [ :stream | 
×
328
                currentStream := stream.
×
329
                "Printing class package and imports if the class is not an inner class"
×
NEW
330
                (aClass typeContainer isNotNil and: [ 
×
NEW
331
                         aClass typeContainer isKindOf: FamixJavaPackage ]) ifTrue: [ 
×
NEW
332
                        self << 'package '.
×
NEW
333
                        aClass typeContainer fullNamePrintOn: currentStream.
×
NEW
334
                        self
×
NEW
335
                                <<< ';';
×
NEW
336
                                crlf;
×
NEW
337
                                crlf.
×
NEW
338
                        self printImports: aClass.
×
NEW
339
                        self crlf ].
×
340
                "Printing class annotations"
×
341
                aClass annotationInstances do: [ :annotationInstance | 
×
342
                        self clone visit: annotationInstance.
×
343
                        self crlf ].
×
344
                "Printing Class declaration"
×
345
                currentStream << 'public '.
×
346
                aClass isInterface
×
347
                        ifTrue: [ currentStream << 'interface ' ]
×
348
                        ifFalse: [ currentStream << 'class ' ].
×
349
                currentStream << aClass name.
×
350
                "printing inheritance and implementation"
×
351
                self printExtends: aClass.
×
352
                self printImplements: aClass.
×
353
                currentStream
×
354
                        << ' {';
×
355
                        << String crlf.
×
356
                "Printing Attributs"
×
357
                tabs := tabs + 1.
×
358
                aClass attributes do: [ :attribute | 
×
NEW
359
                        attribute accept: self clone.
×
360
                        currentStream << String crlf ].
×
361
                self crlf.
×
362
                "Printing Methods"
×
363
                aClass methods do: [ :method | 
×
364
                        self crlf.
×
NEW
365
                        method accept: self clone.
×
366
                        self crlf ].
×
367
                "Closing Class"
×
368
                currentStream
×
369
                        << String crlf;
×
370
                        << '}' ]
×
371
]
×
372

373
{ #category : #generated }
374
FAMIX2JavaVisitor >> visitEntity: aEntity [
×
375
        "do nothing if unknow"
×
376
]
×
377

378
{ #category : #accessing }
379
FAMIX2JavaVisitor >> visitMethod: aMethod [
1✔
380

1✔
381
        aMethod isStub ifTrue: [ ^ self ].
1✔
382
        "Printing method annotations"
1✔
383
        self printMethodAnnotations: aMethod.
1✔
384
        "Printing modifiers of method ex: static,public/private/protected"
1✔
385
        "aMethod modifiers
1✔
386
                do: [ :modifier | 
1✔
387
                        self
1✔
388
                                << modifier;
1✔
389
                                space ]."
1✔
390
        self indent.
1✔
391
        aMethod isPrivate ifTrue: [ self <<< 'private ' ].
1✔
392
        aMethod isProtected ifTrue: [ self <<< 'protected ' ].
1✔
393
        aMethod isPublic ifTrue: [ self <<< 'public ' ].
1✔
394
        aMethod isClassSide ifTrue: [ self <<< 'static ' ].
1✔
395
        "Printing return type for method"
1✔
396
        aMethod declaredType ifNotNil: [ :declaredType | 
1✔
397
                self printDeclaredType: declaredType.
1✔
398
                currentStream << String space ].
1✔
399
        "Printing name + parameters of method"
1✔
400
        (aMethod name = '<Initializer>' or: [ 
1✔
401
                 aMethod isAnInitializer and: [ aMethod isConstructor not ] ])
1✔
402
                ifFalse: [ 
1✔
403
                        self
1✔
404
                                <<< aMethod name;
1✔
405
                                <<< '('.
1✔
406
                        (aMethod parameters sorted: [ :p :p2 | 
1✔
407
                                 p sourceAnchor startPos < p2 sourceAnchor startPos ])
1✔
408
                                do: [ :parameter | parameter accept: self clone  ]
1✔
409
                                separatedBy: [ self <<< ', ' ].
1✔
410
                        self <<< ')' ]
1✔
411
                ifTrue: [ self << 'static' ].
1✔
412
        "print exception"
1✔
413
        ((aMethod withMethodsOverriding collect: [ :m | 
1✔
414
                  m thrownExceptions , m declaredExceptions ])
1✔
415
                 flattened asSet asOrderedCollection sorted: #name ascending) 
1✔
416
                ifNotEmpty: [ :exceptions | 
1✔
417
                        self <<< ' throws '.
1✔
418
                        exceptions
1✔
419
                                do: [ :exception | self <<< exception name ]
1✔
420
                                separatedBy: [ self <<< ', ' ] ].
1✔
421

1✔
422
        "Printing body of method if class is not abstract or an interface"
1✔
423
        ((aMethod atScope: FamixTClass) anyOne isInterface or: [ 
1✔
424
                 aMethod isAbstract isNotNil and: [ aMethod isAbstract ] ])
1✔
425
                ifTrue: [ self <<< ';' ]
1✔
426
                ifFalse: [ 
1✔
427
                        currentStream << ' {'.
1✔
428
                        self eol.
1✔
429
                        self << aMethod bodySourceText.
1✔
430
                        self
1✔
431
                                eol;
1✔
432
                                << '}' ]
1✔
433
]
1✔
434

435
{ #category : #visiting }
NEW
436
FAMIX2JavaVisitor >> visitPackage: aFamixJavaPackage [
×
NEW
437

×
NEW
438
        aFamixJavaPackage name = '<Default Package>' ifFalse: [ 
×
NEW
439
                aFamixJavaPackage allParents reverse do: [ :namespace | 
×
NEW
440
                        self rootFolder: self rootFolder / namespace name.
×
441
                        self rootFolder ensureCreateDirectory ].
×
NEW
442
                self rootFolder: self rootFolder / aFamixJavaPackage name.
×
NEW
443
                self rootFolder ensureCreateDirectory ].
×
NEW
444
        aFamixJavaPackage children do: [ :child | child accept: self clone ]
×
UNCOV
445
]
×
446

447
{ #category : #generated }
448
FAMIX2JavaVisitor >> visitParameter: aParameter [
×
449
        aParameter declaredType isParameterizedType
×
450
                ifTrue: [ self visitParameterizableType: aParameter declaredType ]
×
451
                ifFalse: [ self <<< aParameter declaredType name ].
×
452
        self
×
453
                space;
×
454
                <<< aParameter name
×
455
]
×
456

457
{ #category : #generated }
458
FAMIX2JavaVisitor >> visitParameterizableType: aParameterizableType [
×
459
        self <<< aParameterizableType name.
×
460
        self <<< '<'.
×
461
        aParameterizableType arguments
×
462
                do: [ :argument | 
×
463
                        argument isParameterType
×
464
                                ifTrue: [ self visitParameterizableType: argument ]
×
465
                                ifFalse: [ self <<< argument name ] ]
×
466
                separatedBy: [ self <<< ',' ].
×
467
        self <<< '>'
×
468
]
×
469

470
{ #category : #generated }
471
FAMIX2JavaVisitor >> visitParameterizedType: aParameterizedType [
×
472

×
473
        self <<< aParameterizedType name.
×
474
        aParameterizedType arguments ifNotEmpty: [ :arguments | 
×
475
                self <<< '<'.
×
476
                arguments
×
477
                        do: [ :argument | 
×
478
                                argument isParameterType
×
479
                                        ifTrue: [ self visitParameterizableType: argument ]
×
480
                                        ifFalse: [ self <<< argument name ] ]
×
481
                        separatedBy: [ self <<< ',' ].
×
482
                self <<< '>' ]
×
483
]
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc