1
1
"
2
- A visitor for exporting a FamixValue model to FASTJava.
2
+ A visitor to export a FamixValue model to FASTJava.
3
3
The generated code is a block statement with a variable declared for each value.
4
4
5
5
Object attributes are initialized by finding the corresponding setters.
6
- Collections and Dictionaries are constructed with the `add(element)` and `put(key, value)` methods respectively.
6
+ Collections and Dictionaries are constructed with the methods `add(element)` and `put(key, value)` respectively.
7
7
8
- When exporting a `FamixValueOfObjectAttribute`, if the setter for its `FamixTAttribute` cannot be found, they are set using the Java Reflection API.
9
- All attributes that fall in this category are added as `markedForReflection`.
8
+ When exporting a `FamixValueOfObjectAttribute`, if the setter for its `FamixTAttribute` cannot be found, it is set using the Java Reflection API.
9
+ All attributes that fall into this category are added as `markedForReflection`.
10
10
"
11
11
Class {
12
12
#name : #FamixValue2FASTJavaVisitor ,
@@ -16,10 +16,9 @@ Class {
16
16
' markedForReflection' ,
17
17
' constructorCache' ,
18
18
' staticAttributesCache' ,
19
- ' objectExportStrategy' ,
20
- ' setterCache'
19
+ ' objectExportStrategy'
21
20
],
22
- #category : #' Famix-Value-Exporter'
21
+ #category : #' Famix-Value-Exporter-Visitors '
23
22
}
24
23
25
24
{ #category : #private }
@@ -37,8 +36,10 @@ FamixValue2FASTJavaVisitor >> addAttributesFrom: object asArgumentsTo: newExpres
37
36
object value
38
37
detect: [ :objAttribute | " find the matching value attribute"
39
38
objAttribute attribute == paramAttribute ]
40
- ifFound: [ :objAttribute |
41
- self makeVariableExpression: objAttribute value ]
39
+ ifFound: [ :objAttribute | " dispatch for var naming context"
40
+ objectExportStrategy
41
+ makeVariableExpression: objAttribute value
42
+ on: self ]
42
43
ifNone: [ " the object does not have the attribute set"
43
44
paramAttribute declaredType asFASTJavaDefaultValueOn:
44
45
self model ] ]) ]
@@ -72,21 +73,16 @@ FamixValue2FASTJavaVisitor >> constructObject: object [
72
73
FamixValue2FASTJavaVisitor >> filterAttributesToSet: attributes for: object [
73
74
" No need to set attributes that are set in the constructor."
74
75
75
- ^ (setterCache at: object type ifAbsentPut: [
76
- | famixAttributes |
77
- famixAttributes := attributes collect: [ :attribute |
78
- attribute attribute ].
79
- constructorCache
80
- at: object type
81
- ifPresent: [ :constructor |
82
- constructorCache
83
- at: constructor
84
- ifPresent: [ :constructorAttributes |
85
- famixAttributes difference: constructorAttributes ]
86
- ifAbsent: [ famixAttributes ] ]
87
- ifAbsent: [ famixAttributes ] ]) ifNotEmpty: [ :famixAttributes |
88
- attributes select: [ :attribute |
89
- famixAttributes includes: attribute attribute ] ]
76
+ ^ constructorCache
77
+ at: object type
78
+ ifPresent: [ :constructor |
79
+ constructorCache
80
+ at: constructor
81
+ ifPresent: [ :constructorAttributes |
82
+ attributes reject: [ :attribute |
83
+ constructorAttributes includes: attribute attribute ] ]
84
+ ifAbsent: [ attributes ] ]
85
+ ifAbsent: [ attributes ]
90
86
]
91
87
92
88
{ #category : #private }
@@ -136,7 +132,6 @@ FamixValue2FASTJavaVisitor >> findStaticAttributeMatching: object [
136
132
FamixValue2FASTJavaVisitor >> initialize [
137
133
138
134
constructorCache := IdentityDictionary new .
139
- setterCache := IdentityDictionary new .
140
135
staticAttributesCache := IdentityDictionary new
141
136
]
142
137
@@ -191,49 +186,7 @@ FamixValue2FASTJavaVisitor >> makeHelperClass [
191
186
expression:
192
187
(model newNewExpression type:
193
188
(model newClassTypeExpression typeName:
194
- (model newTypeName name: ' ObjectMapper' )))) }).
195
- (model newMethodEntity
196
- typeParameters:
197
- { (model newTypeParameterExpression name: ' T' ) };
198
- type:
199
- (model newClassTypeExpression typeName:
200
- (model newTypeName name: ' T' ));
201
- name: ' deserialize' ;
202
- parameters: {
203
- (model newParameter
204
- variable: (model newVariableExpression name: ' json' );
205
- type: (model newClassTypeExpression typeName:
206
- (model newTypeName name: ' String' ))).
207
- (model newParameter
208
- variable: (model newVariableExpression name: ' clazz' );
209
- type: (model newClassTypeExpression
210
- typeName: (model newTypeName name: ' Class' );
211
- arguments: { (model newClassTypeExpression typeName:
212
- (model newTypeName name: ' T' )) })) };
213
- modifiers: {
214
- (model newModifier token: ' public' ).
215
- (model newModifier token: ' static' ) };
216
- statementBlock: (model newStatementBlock statements: {
217
- (model newTryCatchStatement
218
- try: (model newStatementBlock statements:
219
- { (model newReturnStatement expression:
220
- (model newMethodInvocation
221
- receiver: (model newIdentifier name: ' mapper' );
222
- name: ' readValue' ;
223
- arguments: {
224
- (model newVariableExpression name: ' json' ).
225
- (model newVariableExpression name: ' clazz' ) })) });
226
- catches: { (model newCatchPartStatement
227
- catchedTypes:
228
- { (model newClassTypeExpression typeName:
229
- (model newTypeName name: ' IOException' )) };
230
- body: (model newStatementBlock statements:
231
- { (model newExpressionStatement expression:
232
- (model newMethodInvocation
233
- receiver: (model newIdentifier name: ' e' );
234
- name: ' printStackTrace' )) });
235
- parameter: (model newVariableExpression name: ' e' )) }).
236
- (model newReturnStatement expression: model newNullLiteral) })) }
189
+ (model newTypeName name: ' ObjectMapper' )))) }) }
237
190
]
238
191
239
192
{ #category : #ast }
@@ -455,20 +408,9 @@ FamixValue2FASTJavaVisitor >> visitObjectOfRegularType: object [
455
408
456
409
{ #category : #visiting }
457
410
FamixValue2FASTJavaVisitor >> visitObjectStub: object [
411
+ " Previously tried to recreate stubs by deserializing their JSON representation, but getting a correct JSON string is a challenge."
458
412
459
- self statementBlock addStatement: (self model newVarDeclStatement
460
- type: (object asFASTJavaTypeExpressionOn: self );
461
- addDeclarator: (self model newVariableDeclarator
462
- variable: (self makeVariableExpression: object);
463
- expression: (model newMethodInvocation
464
- name: ' deserialize' ;
465
- arguments: {
466
- (model newStringLiteral primitiveValue:
467
- object asJsonString).
468
- (model newClassProperty
469
- type: (object asFASTJavaTypeExpressionOn: self );
470
- fieldName: ' class' ) }));
471
- yourself )
413
+ self shouldBeImplemented
472
414
]
473
415
474
416
{ #category : #visiting }
0 commit comments