@@ -41,6 +41,8 @@ import org.utbot.framework.plugin.api.UtPrimitiveModel
41
41
import org.utbot.framework.plugin.api.UtReferenceModel
42
42
import org.utbot.framework.plugin.api.UtStatementCallModel
43
43
import org.utbot.framework.plugin.api.UtVoidModel
44
+ import org.utbot.framework.plugin.api.util.booleanClassId
45
+ import org.utbot.framework.plugin.api.util.booleanWrapperClassId
44
46
import org.utbot.framework.plugin.api.util.classClassId
45
47
import org.utbot.framework.plugin.api.util.defaultValueModel
46
48
import org.utbot.framework.plugin.api.util.jField
@@ -51,6 +53,8 @@ import org.utbot.framework.plugin.api.util.isArray
51
53
import org.utbot.framework.plugin.api.util.isEnum
52
54
import org.utbot.framework.plugin.api.util.isPrimitiveWrapperOrString
53
55
import org.utbot.framework.plugin.api.util.isStatic
56
+ import org.utbot.framework.plugin.api.util.primitiveWrappers
57
+ import org.utbot.framework.plugin.api.util.primitives
54
58
import org.utbot.framework.plugin.api.util.stringClassId
55
59
import org.utbot.framework.plugin.api.util.supertypeOfAnonymousClass
56
60
import org.utbot.framework.plugin.api.util.wrapperByPrimitive
@@ -171,12 +175,13 @@ open class CgVariableConstructor(val context: CgContext) :
171
175
172
176
for ((fieldId, fieldModel) in model.fields) {
173
177
val variableForField = getOrCreateVariable(fieldModel)
174
- setFieldValue(obj, fieldId, variableForField)
178
+ if (! variableForField.hasDefaultValue())
179
+ setFieldValue(obj, fieldId, variableForField)
175
180
}
176
181
return obj
177
182
}
178
183
179
- fun setFieldValue (obj : CgValue , fieldId : FieldId , variableForField : CgValue ){
184
+ fun setFieldValue (obj : CgValue , fieldId : FieldId , valueForField : CgValue ) {
180
185
val field = fieldId.jField
181
186
val fieldFromVariableSpecifiedType = obj.type.findFieldByIdOrNull(fieldId)
182
187
@@ -187,14 +192,27 @@ open class CgVariableConstructor(val context: CgContext) :
187
192
// branchRegisterRequest.byteBuffer = heapByteBuffer;
188
193
// byteBuffer is field of type ByteBuffer and upper line is incorrect
189
194
val canFieldBeDirectlySetByVariableAndFieldTypeRestrictions =
190
- fieldFromVariableSpecifiedType != null && fieldFromVariableSpecifiedType.type.id == variableForField .type
195
+ fieldFromVariableSpecifiedType != null && fieldFromVariableSpecifiedType.type.id == valueForField .type
191
196
if (canFieldBeDirectlySetByVariableAndFieldTypeRestrictions && fieldId.canBeSetFrom(context, obj.type)) {
192
197
// TODO: check if it is correct to use declaringClass of a field here
193
198
val fieldAccess = if (field.isStatic) CgStaticFieldAccess (fieldId) else CgFieldAccess (obj, fieldId)
194
- fieldAccess `= ` variableForField
199
+ fieldAccess `= ` valueForField
195
200
} else {
196
201
// composite models must not have info about static fields, hence only non-static fields are set here
197
- + utilsClassId[setField](obj, fieldId.declaringClass.name, fieldId.name, variableForField)
202
+ + utilsClassId[setField](obj, fieldId.declaringClass.name, fieldId.name, valueForField)
203
+ }
204
+ }
205
+
206
+ private fun CgValue.hasDefaultValue (): Boolean {
207
+ if (this !is CgLiteral ) {
208
+ return false ;
209
+ }
210
+
211
+ return when {
212
+ this .value == null -> true
213
+ (this .type == booleanClassId || this .type == booleanWrapperClassId) && this .value == false -> true
214
+ (this .type in primitives || this .type in primitiveWrappers) && this .value == 0 -> true
215
+ else -> false
198
216
}
199
217
}
200
218
0 commit comments