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

moosetechnology / Famix-Value / 15300296622

28 May 2025 12:36PM UTC coverage: 22.756% (-0.2%) from 22.913%
15300296622

push

github

Gabriel-Darbord
Fix Pharo exporter
Only blocks are problematic now

1 of 82 new or added lines in 3 files covered. (1.22%)

26 existing lines in 2 files now uncovered.

796 of 3498 relevant lines covered (22.76%)

0.23 hits per line

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

0.0
/src/Famix-Value-Exporter/FamixValueHelperObjectExportStrategy.class.st
1
"
2
I generate the code to recreate objects in helper functions.
3
For each object, a dedicated function is generated that takes no arguments and returns the recreated object.
4
"
5
Class {
6
        #name : 'FamixValueHelperObjectExportStrategy',
7
        #superclass : 'FamixValueAbstractObjectExportStrategy',
8
        #instVars : [
9
                'currentDeclarations',
10
                'helpers'
11
        ],
12
        #category : 'Famix-Value-Exporter-Strategies',
13
        #package : 'Famix-Value-Exporter',
14
        #tag : 'Strategies'
15
}
16

17
{ #category : 'ast' }
18
FamixValueHelperObjectExportStrategy >> buildMethodFor: object withParametersFor: attributes on: visitor [
×
19
        "Build the helper method to construct objects of the same type as the one given in argument.
×
20
        Use only the relevant attributes that are given, rather than all attributes."
×
21

×
22
        | model oldStatementBlock helper |
×
23
        model := visitor model.
×
24
        "swap visitor context: the 'sheet' on which the visitor writes"
×
25
        oldStatementBlock := visitor statementBlock.
×
26
        visitor statementBlock: model newStatementBlock.
×
27
        visitor builder processType: object type.
×
28

×
29
        "make the method entity"
×
30
        helper := self
×
31
                          makeMethodFor: object type
×
32
                          withParametersFor: attributes
×
33
                          on: visitor.
×
34

×
35
        "make the method body: instantiate object, set attributes and return it"
×
36
        visitor constructObject: object.
×
37
        self
×
38
                makeSetterInvocationsFor:
×
39
                (visitor filterAttributesToSet: attributes for: object type)
×
40
                on: visitor.
×
41
        visitor statementBlock addStatement:
×
42
                (model newReturnStatement expression:
×
43
                         (model newVariableExpression name: (visitor varNameFor: object))).
×
44

×
45
        "restore original visitor context"
×
UNCOV
46
        visitor statementBlock: oldStatementBlock.
×
UNCOV
47
        ^ helper
×
48
]
×
49

50
{ #category : 'accessing' }
51
FamixValueHelperObjectExportStrategy >> currentDeclarations [
×
UNCOV
52

×
UNCOV
53
        ^ currentDeclarations
×
54
]
×
55

56
{ #category : 'ast' }
57
FamixValueHelperObjectExportStrategy >> dependencyImportsOn: aFASTModel [
×
58
        "To have access to some protected classes, there may be helpers in different packages"
×
59

×
60
        "Current implementation imports all helpers whether they need it or not"
×
61

×
UNCOV
62
        ^ helpers keys collect: [ :package |
×
UNCOV
63
                  (aFASTModel newImportDeclaration qualifiedName:
×
64
                                   (aFASTModel newQualifiedName name: package , '.ModestHelper'))
×
65
                          isStatic: true;
×
66
                          isOnDemand: true ]
×
67
]
×
68

69
{ #category : 'exporting' }
70
FamixValueHelperObjectExportStrategy >> export: object on: visitor [
×
71
        "Use a helper method to instantiate the object and set its attributes."
×
72

×
73
        | attributes helper model |
×
74
        "ensure all relevant attributes are set up"
×
75
        (attributes := object relevantAttributes) do: [ :attribute |
×
76
                visitor ensureVisited: attribute value ].
×
77
        "check if the object was not set up in the previous step"
×
78
        (visitor varNameDict includesKey: object) ifTrue: [ ^ self ].
×
79

×
80
        "get the helper method, or build it if it does not exist"
×
81
        currentDeclarations := helpers
×
82
                                       at: (visitor helperPackageFor: object type)
×
83
                                       ifAbsentPut: [ Dictionary new ].
×
84
        helper := currentDeclarations
×
85
                          at: object constructorSignature
×
86
                          ifAbsentPut: [
×
87
                                  self
×
88
                                          buildMethodFor: object
×
89
                                          withParametersFor: attributes
×
90
                                          on: visitor ].
×
91

×
92
        "call the helper method to build the object and store it in a variable"
×
93
        model := visitor model.
×
94
        visitor statementBlock addStatement: (model newVarDeclStatement
×
95
                         type: (object asFASTJavaTypeExpressionOn: visitor);
×
96
                         addDeclarator: (model newVariableDeclarator
×
97
                                          variable:
×
98
                                                  (model newVariableExpression name:
×
99
                                                                   (visitor varNameFor: object));
×
100
                                          expression:
×
UNCOV
101
                                                  (self
×
UNCOV
102
                                                           makeHelperInvocation: helper
×
103
                                                           arguments: attributes
×
104
                                                           on: visitor));
×
105
                         yourself)
×
106
]
×
107

108
{ #category : 'initialization' }
109
FamixValueHelperObjectExportStrategy >> initialize [
×
110

×
111
        helpers := Dictionary new
×
112
]
×
113

114
{ #category : 'exporting' }
115
FamixValueHelperObjectExportStrategy >> makeHelperInvocation: helper arguments: arguments on: visitor [
×
116

×
117
        | model |
×
118
        model := visitor model.
×
119
        ^ model newMethodInvocation
×
120
                  name: helper name;
×
121
                  arguments: (arguments
×
122
                                   with: helper parameters
×
123
                                   collect: [ :argument :parameter | "reference the value with a variable"
×
124
                                           | ref |
×
125
                                           ref := visitor makeVariableExpression: argument value.
×
126
                                           ((argument value type name sameAs: 'long') not and: [
×
127
                                                            (FASTJavaExportVisitor new export: parameter type) sameAs:
×
128
                                                                            'long' ])
×
129
                                                   ifTrue: [ "try casting"
×
UNCOV
130
                                                           model newCastExpression
×
UNCOV
131
                                                                   type: (model newClassTypeExpression typeName:
×
132
                                                                                            (model newTypeName name: 'long'));
×
133
                                                                   expression: ref ]
×
134
                                                   ifFalse: [ ref ] ])
×
135
]
×
136

137
{ #category : 'ast' }
138
FamixValueHelperObjectExportStrategy >> makeHelpersOn: visitor [
×
139

×
UNCOV
140
        helpers keysAndValuesDo: [ :package :methodDeclarations |
×
UNCOV
141
                | helperClass |
×
142
                helperClass := visitor makeHelperInPackage: package.
×
143
                methodDeclarations do: [ :declaration |
×
144
                        helperClass addDeclaration: declaration ] ]
×
145
]
×
146

147
{ #category : 'ast' }
148
FamixValueHelperObjectExportStrategy >> makeMethodFor: aFamixType withParametersFor: attributes on: visitor [
×
149
        "Make the method entity, handles its signature and modifiers."
×
150

×
151
        | model |
×
152
        model := visitor model.
×
153
        ^ model newMethodEntity
×
154
                  name: 'new' , aFamixType baseName;
×
155
                  addModifier: (model newModifier token: 'public');
×
156
                  addModifier: (model newModifier token: 'static');
×
157
                  type: (aFamixType asFASTJavaTypeExpressionOn: visitor);
×
158
                  parameters: (attributes collect: [ :attribute |
×
159
                                           model newParameter
×
160
                                                   type: (attribute attribute declaredType
×
161
                                                                    ifNotNil: [ :declaredType |
×
162
                                                                            attribute value type
×
163
                                                                                    decorate: declaredType
×
164
                                                                                    asFASTJavaTypeExpressionOn: visitor ]
×
165
                                                                    ifNil: [
×
UNCOV
166
                                                                            model newClassTypeExpression typeName:
×
UNCOV
167
                                                                                            (model newTypeName name: 'Object') ]);
×
168
                                                   variable:
×
169
                                                           (model newVariableExpression name: attribute varName) ]);
×
170
                  statementBlock: visitor statementBlock
×
171
]
×
172

173
{ #category : 'ast' }
174
FamixValueHelperObjectExportStrategy >> makeSetterInvocationsFor: attributes on: visitor [
×
175
        "Build the helper method's body: set the value of each argument to the corresponding attribute using setters or reflection."
×
176

×
177
        attributes do: [ :attribute |
×
178
                attribute attribute declaredType ifNotNil: [ :declaredType |
×
179
                        visitor builder processType: declaredType ].
×
180

×
181
                (attribute object type findSetterOf: attribute attribute)
×
182
                        ifNotNil: [ :setter |
×
UNCOV
183
                                visitor
×
UNCOV
184
                                        makeSetterInvocation: setter
×
185
                                        for: attribute
×
186
                                        named: attribute varName ]
×
187
                        ifNil: [ visitor makeReflectionSetterInvocation: attribute ] ]
×
188
]
×
189

190
{ #category : 'ast' }
UNCOV
191
FamixValueHelperObjectExportStrategy >> makeVariableExpression: value on: visitor [
×
UNCOV
192
        "Used when constructing an object to correctly name the argument variable.
×
UNCOV
193
        For helpers, the var name is the same as the helper method parameter."
×
UNCOV
194

×
UNCOV
195
        ^ visitor model newVariableExpression name: value varName
×
UNCOV
196
]
×
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

© 2026 Coveralls, Inc