Skip to content

Commit 087d96a

Browse files
committed
Corrected behavior for static fields
1 parent bb9faff commit 087d96a

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ infix fun ClassId.isAccessibleFrom(packageName: String): Boolean {
3737
* Returns field of [this], such that [methodId] is a getter for it (or null if methodId doesn't represent a getter)
3838
*/
3939
internal fun ClassId.fieldThisIsGetterFor(methodId: MethodId): FieldId? =
40-
allDeclaredFieldIds.firstOrNull { it.getter == methodId }
40+
allDeclaredFieldIds.firstOrNull { !it.isStatic && it.getter == methodId }
4141

4242
/**
4343
* Returns field of [this], such that [methodId] is a setter for it (or null if methodId doesn't represent a setter)
4444
*/
4545
internal fun ClassId.fieldThisIsSetterFor(methodId: MethodId): FieldId? =
46-
allDeclaredFieldIds.firstOrNull { it.setter == methodId }
46+
allDeclaredFieldIds.firstOrNull { !it.isStatic && it.setter == methodId }

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ 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 (context.codegenLanguage == CodegenLanguage.KOTLIN) {
18+
if (!isStatic && context.codegenLanguage == CodegenLanguage.KOTLIN) {
1919
// Here we call field accessible iff its getter is accessible, checks for setter are made in FieldId.canBeSetIn
2020
return declaringClass.allMethods.contains(getter) && getter.isAccessibleFrom(context.testClassPackageName)
2121
}
@@ -31,7 +31,7 @@ internal infix fun FieldId.isAccessibleFrom(context: CgContext): Boolean {
3131
* Whether or not a field can be set without reflection
3232
*/
3333
internal fun FieldId.canBeSetIn(context: CgContext): Boolean {
34-
if (context.codegenLanguage == CodegenLanguage.KOTLIN) {
34+
if (!isStatic && context.codegenLanguage == CodegenLanguage.KOTLIN) {
3535
return declaringClass.allMethods.contains(setter) && setter.isAccessibleFrom(context.testClassPackageName)
3636
}
3737
return isAccessibleFrom(context) && !isFinal

utbot-sample/src/main/java/org/utbot/examples/annotations/ClassWithRefField.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static void setStaticBoxedInt(@NotNull Integer staticBoxedInt) {
2121
}
2222

2323
@SuppressWarnings("NullableProblems")
24-
public Integer getBoxedInt() {
24+
public @NotNull Integer getBoxedInt() {
2525
return boxedInt;
2626
}
2727
}

0 commit comments

Comments
 (0)