Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ import org.utbot.framework.codegen.tree.CgComponents.getStatementConstructorBy
import org.utbot.framework.codegen.tree.CgComponents.getTestFrameworkManagerBy
import org.utbot.framework.codegen.tree.CgComponents.getVariableConstructorBy
import org.utbot.framework.codegen.util.canBeReadFrom
import org.utbot.framework.codegen.util.canBeReadViaGetterFrom
import org.utbot.framework.codegen.util.canBeSetFrom
import org.utbot.framework.codegen.util.equalTo
import org.utbot.framework.codegen.util.escapeControlChars
import org.utbot.framework.codegen.util.getter
import org.utbot.framework.codegen.util.inc
import org.utbot.framework.codegen.util.length
import org.utbot.framework.codegen.util.lessThan
Expand Down Expand Up @@ -1154,6 +1156,10 @@ open class CgMethodConstructor(val context: CgContext) : CgContextOwner by conte
// and is accessible from current package
if (variable.type.hasField(this) && canBeReadFrom(context, variable.type)) {
if (jField.isStatic) CgStaticFieldAccess(this) else CgFieldAccess(variable, this)
} else if (context.codegenLanguage == CodegenLanguage.JAVA &&
!jField.isStatic && canBeReadViaGetterFrom(context)
) {
CgMethodCall(variable, getter, emptyList())
} else {
utilsClassId[getFieldValue](variable, this.declaringClass.name, this.name)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ import org.utbot.framework.codegen.tree.CgComponents.getNameGeneratorBy
import org.utbot.framework.codegen.tree.CgComponents.getStatementConstructorBy
import org.utbot.framework.codegen.util.at
import org.utbot.framework.codegen.util.canBeSetFrom
import org.utbot.framework.codegen.util.canBeSetViaSetterFrom
import org.utbot.framework.codegen.util.fieldThatIsGotWith
import org.utbot.framework.codegen.util.fieldThatIsSetWith
import org.utbot.framework.codegen.util.inc
import org.utbot.framework.codegen.util.isAccessibleFrom
import org.utbot.framework.codegen.util.lessThan
import org.utbot.framework.codegen.util.nullLiteral
import org.utbot.framework.codegen.util.resolve
import org.utbot.framework.codegen.util.setter
import org.utbot.framework.plugin.api.BuiltinClassId
import org.utbot.framework.plugin.api.ClassId
import org.utbot.framework.plugin.api.FieldId
Expand Down Expand Up @@ -209,6 +211,10 @@ open class CgVariableConstructor(val context: CgContext) :
// TODO: check if it is correct to use declaringClass of a field here
val fieldAccess = if (field.isStatic) CgStaticFieldAccess(fieldId) else CgFieldAccess(obj, fieldId)
fieldAccess `=` valueForField
} else if (context.codegenLanguage == CodegenLanguage.JAVA &&
!field.isStatic && fieldId.canBeSetViaSetterFrom(context)
) {
+CgMethodCall(obj, fieldId.setter, listOf(valueForField))
} else {
// composite models must not have info about static fields, hence only non-static fields are set here
+utilsClassId[setField](obj, fieldId.declaringClass.name, fieldId.name, valueForField)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fun FieldId.isAccessibleFrom(packageName: String, callerClassId: ClassId): Boole
return isClassAccessible && isAccessibleFromPackageByModifiers
}

private fun FieldId.canBeReadViaGetterFrom(context: CgContext): Boolean =
internal fun FieldId.canBeReadViaGetterFrom(context: CgContext): Boolean =
declaringClass.allMethods.contains(getter) && getter.isAccessibleFrom(context.testClassPackageName)

/**
Expand All @@ -52,7 +52,7 @@ internal fun FieldId.canBeReadFrom(context: CgContext, callerClassId: ClassId):
return isAccessibleFrom(context.testClassPackageName, callerClassId)
}

private fun FieldId.canBeSetViaSetterFrom(context: CgContext): Boolean =
internal fun FieldId.canBeSetViaSetterFrom(context: CgContext): Boolean =
declaringClass.allMethods.contains(setter) && setter.isAccessibleFrom(context.testClassPackageName)

/**
Expand Down