Skip to content

Commit c45244f

Browse files
committed
Treat java-accessible fields as accessible properties in Kotlin
1 parent 6cecf85 commit c45244f

File tree

1 file changed

+13
-5
lines changed
  • utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/util

1 file changed

+13
-5
lines changed

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/util/FieldIdUtil.kt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ import org.utbot.framework.plugin.api.util.voidClassId
1515
*/
1616
// TODO: change parameter from packageName: String to context: CgContext in ClassId.isAccessibleFrom and ExecutableId.isAccessibleFrom ?
1717
internal infix fun FieldId.isAccessibleFrom(context: CgContext): Boolean {
18-
if (!isStatic && context.codegenLanguage == CodegenLanguage.KOTLIN) {
18+
if (context.codegenLanguage == CodegenLanguage.KOTLIN) {
1919
// Here we call field accessible iff its getter is accessible, checks for setter are made in FieldId.canBeSetIn
20-
return declaringClass.allMethods.contains(getter) && getter.isAccessibleFrom(context.testClassPackageName)
20+
if (!isStatic && declaringClass.allMethods.contains(getter) && getter.isAccessibleFrom(context.testClassPackageName))
21+
return true
2122
}
2223
val packageName = context.testClassPackageName
2324
val isClassAccessible = declaringClass.isAccessibleFrom(packageName)
@@ -31,10 +32,17 @@ internal infix fun FieldId.isAccessibleFrom(context: CgContext): Boolean {
3132
* Whether or not a field can be set without reflection
3233
*/
3334
internal fun FieldId.canBeSetIn(context: CgContext): Boolean {
34-
if (!isStatic && context.codegenLanguage == CodegenLanguage.KOTLIN) {
35-
return declaringClass.allMethods.contains(setter) && setter.isAccessibleFrom(context.testClassPackageName)
35+
if (!isAccessibleFrom(context)) {
36+
return false
3637
}
37-
return isAccessibleFrom(context) && !isFinal
38+
39+
if (context.codegenLanguage == CodegenLanguage.KOTLIN) {
40+
if (!isStatic && declaringClass.allMethods.contains(setter) && setter.isAccessibleFrom(context.testClassPackageName)) {
41+
return true
42+
}
43+
}
44+
45+
return !isFinal
3846
}
3947

4048
/**

0 commit comments

Comments
 (0)