@@ -29,8 +29,8 @@ import org.utbot.framework.codegen.model.tree.CgValue
29
29
import org.utbot.framework.codegen.model.tree.CgVariable
30
30
import org.utbot.framework.codegen.model.util.at
31
31
import org.utbot.framework.codegen.model.util.canBeSetFrom
32
- import org.utbot.framework.codegen.model.util.fieldThisIsGetterFor
33
- import org.utbot.framework.codegen.model.util.fieldThisIsSetterFor
32
+ import org.utbot.framework.codegen.model.util.fieldThatIsGotWith
33
+ import org.utbot.framework.codegen.model.util.fieldThatIsSetWith
34
34
import org.utbot.framework.codegen.model.util.inc
35
35
import org.utbot.framework.codegen.model.util.isAccessibleFrom
36
36
import org.utbot.framework.codegen.model.util.lessThan
@@ -218,11 +218,11 @@ internal class CgVariableConstructor(val context: CgContext) :
218
218
}
219
219
is UtExecutableCallModel -> {
220
220
val call = createCgExecutableCallFromUtExecutableCall(statementModel)
221
- val callOrAccess : CgStatement = replaceCgExecutableCallWithFieldAccessIfNeeded(call)
222
- if (callOrAccess is CgExecutableCall )
223
- + callOrAccess // smart-cast => CgExecutableCall.unaryPlus()
221
+ val equivalentFieldAccess = replaceCgExecutableCallWithFieldAccessIfNeeded(call)
222
+ if (equivalentFieldAccess != null )
223
+ + equivalentFieldAccess
224
224
else
225
- + callOrAccess // CgStatement.unaryPlus()
225
+ + call
226
226
}
227
227
}
228
228
}
@@ -246,7 +246,6 @@ internal class CgVariableConstructor(val context: CgContext) :
246
246
val initExpr = if (isPrimitiveWrapperOrString(type)) {
247
247
cgLiteralForWrapper(params)
248
248
} else {
249
- // TODO: if instantiation chain could be a setter call, we need to replace it in Kotlin
250
249
createCgExecutableCallFromUtExecutableCall(executableCall)
251
250
}
252
251
newVar(type, model, baseName) {
@@ -272,21 +271,35 @@ internal class CgVariableConstructor(val context: CgContext) :
272
271
return cgCall
273
272
}
274
273
275
- private fun replaceCgExecutableCallWithFieldAccessIfNeeded (call : CgExecutableCall ): CgStatement {
276
- if (call !is CgMethodCall || context.codegenLanguage != CodegenLanguage .KOTLIN )
277
- return call
274
+ /* *
275
+ * If executable is getter/setter that should be syntactically replaced with field access
276
+ * (e.g., getter/setter generated by Kotlin in Kotlin code), this method returns [CgStatement]
277
+ * with which [call] should be replaced.
278
+ *
279
+ * Otherwise, returns null.
280
+ */
281
+ private fun replaceCgExecutableCallWithFieldAccessIfNeeded (call : CgExecutableCall ): CgStatement ? {
282
+ when (context.codegenLanguage) {
283
+ CodegenLanguage .JAVA -> return null
284
+ CodegenLanguage .KOTLIN -> {
285
+ if (call !is CgMethodCall )
286
+ return null
278
287
279
- val caller = call.caller ? : return call
288
+ val caller = call.caller ? : return null
280
289
281
- caller.type.fieldThisIsSetterFor(call.executableId)?.let {
282
- return CgAssignment (caller[it], call.arguments.single())
283
- }
284
- caller.type.fieldThisIsGetterFor(call.executableId)?.let {
285
- require(call.arguments.isEmpty())
286
- return caller[it]
287
- }
290
+ caller.type.fieldThatIsSetWith(call.executableId)?.let {
291
+ return CgAssignment (caller[it], call.arguments.single())
292
+ }
293
+ caller.type.fieldThatIsGotWith(call.executableId)?.let {
294
+ require(call.arguments.isEmpty()) {
295
+ " Method $call was detected as getter for $it , but its arguments list isn't empty"
296
+ }
297
+ return caller[it]
298
+ }
288
299
289
- return call
300
+ return null
301
+ }
302
+ }
290
303
}
291
304
292
305
/* *
0 commit comments