Skip to content

Commit 1dae4a8

Browse files
committed
Renamed field to jField and minor changes
1 parent f8593aa commit 1dae4a8

File tree

17 files changed

+47
-54
lines changed

17 files changed

+47
-54
lines changed

utbot-core/src/main/kotlin/org/utbot/common/KClassUtil.kt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
11
package org.utbot.common
22

3-
import java.lang.reflect.Field
43
import java.lang.reflect.InvocationTargetException
54
import java.lang.reflect.Method
65

76

87
val Class<*>.packageName: String get() = `package`?.name?:""
98

10-
/**
11-
* Returns the Field that would be used by compiler when you try to direct access [fieldName] from code, i.e.
12-
* when you write `${this.name}.$fieldName`.
13-
* If there is no field named [fieldName] in the class, null is returned
14-
*/
15-
fun Class<*>.findDirectAccessedFieldOrNull(fieldName: String): Field? = generateSequence(this) { it.superclass }
16-
.flatMap { it.declaredFields.asSequence() }
17-
.firstOrNull { it.name == fieldName }
18-
199
fun Method.invokeCatching(obj: Any?, args: List<Any?>) = try {
2010
Result.success(invoke(obj, *args.toTypedArray()))
2111
} catch (e: InvocationTargetException) {

utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import org.utbot.framework.plugin.api.util.charClassId
2020
import org.utbot.framework.plugin.api.util.constructor
2121
import org.utbot.framework.plugin.api.util.doubleClassId
2222
import org.utbot.framework.plugin.api.util.executableId
23-
import org.utbot.framework.plugin.api.util.field
2423
import org.utbot.framework.plugin.api.util.floatClassId
2524
import org.utbot.framework.plugin.api.util.id
2625
import org.utbot.framework.plugin.api.util.intClassId
@@ -30,7 +29,7 @@ import org.utbot.framework.plugin.api.util.jClass
3029
import org.utbot.framework.plugin.api.util.longClassId
3130
import org.utbot.framework.plugin.api.util.method
3231
import org.utbot.framework.plugin.api.util.primitiveTypeJvmNameOrNull
33-
import org.utbot.framework.plugin.api.util.safeField
32+
import org.utbot.framework.plugin.api.util.safeJField
3433
import org.utbot.framework.plugin.api.util.shortClassId
3534
import org.utbot.framework.plugin.api.util.toReferenceTypeBytecodeSignature
3635
import org.utbot.framework.plugin.api.util.voidClassId
@@ -856,7 +855,7 @@ open class FieldId(val declaringClass: ClassId, val name: String) {
856855
return result
857856
}
858857

859-
override fun toString() = safeField.toString()
858+
override fun toString() = safeJField.toString()
860859
}
861860

862861
inline fun <T> withReflection(block: () -> T): T {

utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/impl/FieldIdStrategies.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package org.utbot.framework.plugin.api.impl
33
import org.utbot.framework.plugin.api.ClassId
44
import org.utbot.framework.plugin.api.FieldId
55
import org.utbot.framework.plugin.api.classId
6-
import org.utbot.framework.plugin.api.util.field
6+
import org.utbot.framework.plugin.api.util.jField
77
import org.utbot.framework.plugin.api.util.id
88
import java.lang.reflect.Modifier
99
import soot.Scene
@@ -32,25 +32,25 @@ interface FieldIdStrategy {
3232
class FieldIdReflectionStrategy(val fieldId: FieldId) : FieldIdStrategy {
3333

3434
override val isPublic: Boolean
35-
get() = Modifier.isPublic(fieldId.field.modifiers)
35+
get() = Modifier.isPublic(fieldId.jField.modifiers)
3636

3737
override val isProtected: Boolean
38-
get() = Modifier.isProtected(fieldId.field.modifiers)
38+
get() = Modifier.isProtected(fieldId.jField.modifiers)
3939

4040
override val isPrivate: Boolean
41-
get() = Modifier.isPrivate(fieldId.field.modifiers)
41+
get() = Modifier.isPrivate(fieldId.jField.modifiers)
4242

4343
override val isFinal: Boolean
44-
get() = Modifier.isFinal(fieldId.field.modifiers)
44+
get() = Modifier.isFinal(fieldId.jField.modifiers)
4545

4646
override val isStatic: Boolean
47-
get() = Modifier.isStatic(fieldId.field.modifiers)
47+
get() = Modifier.isStatic(fieldId.jField.modifiers)
4848

4949
override val isSynthetic: Boolean
50-
get() = fieldId.field.isSynthetic
50+
get() = fieldId.jField.isSynthetic
5151

5252
override val type: ClassId
53-
get() = fieldId.field.type.id
53+
get() = fieldId.jField.type.id
5454
}
5555

5656
class FieldIdSootStrategy(val declaringClass: ClassId, val fieldId: FieldId) : FieldIdStrategy {

utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/util/IdUtil.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ fun ClassId.findFieldByIdOrNull(fieldId: FieldId): Field? {
290290
return null
291291
}
292292

293-
return fieldId.safeField
293+
return fieldId.safeJField
294294
}
295295

296296
fun ClassId.hasField(fieldId: FieldId): Boolean {
@@ -310,12 +310,12 @@ fun ClassId.defaultValueModel(): UtModel = when (this) {
310310
}
311311

312312
// FieldId utils
313-
val FieldId.safeField: Field?
313+
val FieldId.safeJField: Field?
314314
get() = declaringClass.jClass.declaredFields.firstOrNull { it.name == name }
315315

316316
// TODO: maybe cache it somehow in the future
317-
val FieldId.field: Field
318-
get() = safeField ?: error("Field $name is not found in class ${declaringClass.jClass.name}")
317+
val FieldId.jField: Field
318+
get() = safeJField ?: error("Field $name is not declared in class ${declaringClass.jClass.name}")
319319

320320
// https://docstore.mik.ua/orelly/java-ent/jnut/ch03_13.htm
321321
val FieldId.isInnerClassEnclosingClassReference: Boolean

utbot-framework/src/main/kotlin/org/utbot/engine/Strings.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ sealed class UtAbstractStringBuilderWrapper(className: String) : BaseOverriddenW
313313

314314
val arrayValuesChunkId = typeRegistry.arrayChunkId(charArrayType)
315315

316-
val valuesFieldChunkId = hierarchy.chunkIdForField(utStringClass.type, utStringClass.valueField)
316+
val valuesFieldChunkId = hierarchy.chunkIdForField(overriddenClass.type, overriddenClass.valueField)
317317
val valuesArrayAddrDescriptor = MemoryChunkDescriptor(valuesFieldChunkId, wrapper.type, charType)
318318
val valuesArrayAddr = findArray(valuesArrayAddrDescriptor, MemoryState.CURRENT).select(wrapper.addr)
319319

utbot-framework/src/main/kotlin/org/utbot/engine/Traverser.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ import org.utbot.framework.plugin.api.MethodId
8989
import org.utbot.framework.plugin.api.UtMethod
9090
import org.utbot.framework.plugin.api.classId
9191
import org.utbot.framework.plugin.api.id
92-
import org.utbot.framework.plugin.api.util.field
92+
import org.utbot.framework.plugin.api.util.jField
9393
import org.utbot.framework.plugin.api.util.jClass
9494
import org.utbot.framework.plugin.api.util.id
9595
import org.utbot.framework.plugin.api.util.signature
@@ -640,9 +640,13 @@ class Traverser(
640640
FIELD_FILTER_MAP_FIELD_SIGNATURE -> mapOf(Reflection::class to arrayOf("fieldFilterMap", "methodFilterMap"))
641641
METHOD_FILTER_MAP_FIELD_SIGNATURE -> emptyMap<Class<*>, Array<String>>()
642642
else -> {
643-
val id = field.fieldId
644-
val jField = id.field
645-
jField.let { it.withAccessibility { it.get(null) } }
643+
val fieldId = field.fieldId
644+
val jField = fieldId.jField
645+
jField.let {
646+
it.withAccessibility {
647+
it.get(null)
648+
}
649+
}
646650
}
647651
}
648652

utbot-framework/src/main/kotlin/org/utbot/engine/ValueConstructor.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import org.utbot.framework.plugin.api.UtValueExecutionState
3535
import org.utbot.framework.plugin.api.UtVoidModel
3636
import org.utbot.framework.plugin.api.isMockModel
3737
import org.utbot.framework.plugin.api.util.constructor
38-
import org.utbot.framework.plugin.api.util.field
38+
import org.utbot.framework.plugin.api.util.jField
3939
import org.utbot.framework.plugin.api.util.jClass
4040
import org.utbot.framework.plugin.api.util.method
4141
import org.utbot.framework.plugin.api.util.utContext
@@ -212,7 +212,7 @@ class ValueConstructor {
212212
constructedObjects[model] = classInstance
213213

214214
model.fields.forEach { (fieldId, fieldModel) ->
215-
val declaredField = fieldId.field
215+
val declaredField = fieldId.jField
216216
val accessible = declaredField.isAccessible
217217

218218
try {
@@ -358,7 +358,7 @@ class ValueConstructor {
358358
val instanceClassId = instanceModel.classId
359359
val fieldModel = directSetterModel.fieldModel
360360

361-
val field = directSetterModel.fieldId.field
361+
val field = directSetterModel.fieldId.jField
362362
val isAccessible = field.isAccessible
363363

364364
try {

utbot-framework/src/main/kotlin/org/utbot/engine/util/statics/concrete/EnumConcreteUtils.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import org.utbot.engine.pc.select
1010
import org.utbot.engine.symbolic.SymbolicStateUpdate
1111
import org.utbot.engine.symbolic.asHardConstraint
1212
import org.utbot.framework.plugin.api.FieldId
13-
import org.utbot.framework.plugin.api.util.field
13+
import org.utbot.framework.plugin.api.util.jField
1414
import soot.SootClass
1515
import soot.SootField
1616
import soot.SootMethod
@@ -43,7 +43,7 @@ fun associateEnumSootFieldsWithConcreteValues(
4343
enumConstants: List<Enum<*>>
4444
): List<Pair<SootField, List<Any>>> =
4545
enumFields.map { enumSootField ->
46-
val enumField = enumSootField.fieldId.field
46+
val enumField = enumSootField.fieldId.jField
4747

4848
val fieldValues = if (enumSootField.isStatic) {
4949
val staticFieldValue = enumField.withAccessibility { enumField.get(null) }

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgMethodConstructor.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ import org.utbot.framework.plugin.api.util.booleanClassId
129129
import org.utbot.framework.plugin.api.util.doubleArrayClassId
130130
import org.utbot.framework.plugin.api.util.doubleClassId
131131
import org.utbot.framework.plugin.api.util.doubleWrapperClassId
132-
import org.utbot.framework.plugin.api.util.field
132+
import org.utbot.framework.plugin.api.util.jField
133133
import org.utbot.framework.plugin.api.util.floatArrayClassId
134134
import org.utbot.framework.plugin.api.util.floatClassId
135135
import org.utbot.framework.plugin.api.util.floatWrapperClassId
@@ -929,7 +929,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
929929
// Can directly access field only if it is declared in variable class (or in its ancestors)
930930
// and is accessible from current package
931931
if (variable.type.hasField(this) && isAccessibleFrom(testClassPackageName)) {
932-
if (field.isStatic) CgStaticFieldAccess(this) else CgFieldAccess(variable, this)
932+
if (jField.isStatic) CgStaticFieldAccess(this) else CgFieldAccess(variable, this)
933933
} else {
934934
testClassThisInstance[getFieldValue](variable, stringLiteral(name))
935935
}

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgVariableConstructor.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import org.utbot.framework.plugin.api.UtPrimitiveModel
4646
import org.utbot.framework.plugin.api.UtReferenceModel
4747
import org.utbot.framework.plugin.api.UtVoidModel
4848
import org.utbot.framework.plugin.api.util.defaultValueModel
49-
import org.utbot.framework.plugin.api.util.field
49+
import org.utbot.framework.plugin.api.util.jField
5050
import org.utbot.framework.plugin.api.util.findFieldByIdOrNull
5151
import org.utbot.framework.plugin.api.util.id
5252
import org.utbot.framework.plugin.api.util.intClassId
@@ -127,7 +127,7 @@ internal class CgVariableConstructor(val context: CgContext) :
127127
}
128128

129129
for ((fieldId, fieldModel) in model.fields) {
130-
val field = fieldId.field
130+
val field = fieldId.jField
131131
val variableForField = getOrCreateVariable(fieldModel)
132132
val fieldFromVariableSpecifiedType = obj.type.findFieldByIdOrNull(fieldId)
133133

utbot-framework/src/main/kotlin/org/utbot/framework/concrete/MockValueConstructor.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import org.utbot.framework.plugin.api.UtVoidModel
3131
import org.utbot.framework.plugin.api.isMockModel
3232
import org.utbot.framework.plugin.api.util.constructor
3333
import org.utbot.framework.plugin.api.util.executableId
34-
import org.utbot.framework.plugin.api.util.field
34+
import org.utbot.framework.plugin.api.util.jField
3535
import org.utbot.framework.plugin.api.util.jClass
3636
import org.utbot.framework.plugin.api.util.method
3737
import org.utbot.framework.plugin.api.util.utContext
@@ -169,7 +169,7 @@ class MockValueConstructor(
169169
}
170170

171171
model.fields.forEach { (fieldId, fieldModel) ->
172-
val declaredField = fieldId.field
172+
val declaredField = fieldId.jField
173173
val accessible = declaredField.isAccessible
174174
declaredField.isAccessible = true
175175

@@ -392,7 +392,7 @@ class MockValueConstructor(
392392
val instanceClassId = instanceModel.classId
393393
val fieldModel = directSetterModel.fieldModel
394394

395-
val field = directSetterModel.fieldId.field
395+
val field = directSetterModel.fieldId.jField
396396
val isAccessible = field.isAccessible
397397

398398
try {

utbot-framework/src/main/kotlin/org/utbot/framework/concrete/UtExecutionInstrumentation.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import org.utbot.framework.plugin.api.UtNewInstanceInstrumentation
2323
import org.utbot.framework.plugin.api.UtStaticMethodInstrumentation
2424
import org.utbot.framework.plugin.api.UtTimeoutException
2525
import org.utbot.framework.plugin.api.util.UtContext
26-
import org.utbot.framework.plugin.api.util.field
26+
import org.utbot.framework.plugin.api.util.jField
2727
import org.utbot.framework.plugin.api.util.id
2828
import org.utbot.framework.plugin.api.util.singleExecutableId
2929
import org.utbot.framework.plugin.api.util.utContext
@@ -178,7 +178,7 @@ object UtExecutionInstrumentation : Instrumentation<UtConcreteExecutionResult> {
178178
val stateAfterParametersWithThis = params.map { construct(it.value, it.clazz.id) }
179179
val stateAfterStatics = (staticFields.keys/* + traceHandler.computePutStatics()*/)
180180
.associateWith { fieldId ->
181-
fieldId.field.run { construct(withAccessibility { get(null) }, fieldId.type) }
181+
fieldId.jField.run { construct(withAccessibility { get(null) }, fieldId.type) }
182182
}
183183
val (stateAfterThis, stateAfterParameters) = if (stateBefore.thisInstance == null) {
184184
null to stateAfterParametersWithThis
@@ -258,7 +258,7 @@ object UtExecutionInstrumentation : Instrumentation<UtConcreteExecutionResult> {
258258
val savedFields = mutableMapOf<FieldId, Any?>()
259259
try {
260260
staticFields.forEach { (fieldId, value) ->
261-
fieldId.field.run {
261+
fieldId.jField.run {
262262
withAccessibility {
263263
savedFields[fieldId] = get(null)
264264
set(null, value)
@@ -268,7 +268,7 @@ object UtExecutionInstrumentation : Instrumentation<UtConcreteExecutionResult> {
268268
return block()
269269
} finally {
270270
savedFields.forEach { (fieldId, value) ->
271-
fieldId.field.run {
271+
fieldId.jField.run {
272272
withAccessibility {
273273
set(null, value)
274274
}

utbot-framework/src/test/kotlin/org/utbot/examples/enums/ClassWithEnumTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import org.utbot.framework.plugin.api.FieldId
1212
import org.utbot.framework.plugin.api.util.id
1313
import org.junit.jupiter.api.Disabled
1414
import org.junit.jupiter.api.Test
15-
import org.utbot.framework.plugin.api.util.field
15+
import org.utbot.framework.plugin.api.util.jField
1616

1717
class ClassWithEnumTest : UtValueTestCaseChecker(testClass = ClassWithEnum::class) {
1818
@Test
@@ -111,7 +111,7 @@ class ClassWithEnumTest : UtValueTestCaseChecker(testClass = ClassWithEnum::clas
111111
eq(1),
112112
{ t, staticsAfter, r ->
113113
// for some reasons x is inaccessible
114-
val x = FieldId(t.javaClass.id, "x").field.get(t) as Int
114+
val x = FieldId(t.javaClass.id, "x").jField.get(t) as Int
115115

116116
val y = staticsAfter[FieldId(ClassWithEnum.ClassWithStaticField::class.id, "y")]!!.value as Int
117117

utbot-framework/src/test/kotlin/org/utbot/examples/objects/HiddenFieldAccessModifiersTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import org.junit.jupiter.api.Test
77
internal class HiddenFieldAccessModifiersTest : UtValueTestCaseChecker(testClass = HiddenFieldAccessModifiersExample::class) {
88
@Test
99
fun testCheckSuperFieldEqualsOne() {
10-
// TODO: currently, codegen can't handle tests with field hiding
10+
// TODO: currently, codegen can't handle tests with field hiding (see #646)
1111
withEnabledTestingCodeGeneration(testCodeGeneration = false) {
1212
check(
1313
HiddenFieldAccessModifiersExample::checkSuperFieldEqualsOne,

utbot-framework/src/test/kotlin/org/utbot/examples/objects/HiddenFieldExampleTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ internal class HiddenFieldExampleTest : UtValueTestCaseChecker(testClass = Hidde
2121

2222
@Test
2323
fun testCheckSuccField() {
24-
// TODO: currently, codegen can't handle tests with field hiding
24+
// TODO: currently, codegen can't handle tests with field hiding (see #646)
2525
withEnabledTestingCodeGeneration(testCodeGeneration = false) {
2626
check(
2727
HiddenFieldExample::checkSuccField,

utbot-instrumentation-tests/src/test/kotlin/org/utbot/examples/et/TestStaticsUsage.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package org.utbot.examples.et
33
import org.utbot.examples.objects.ObjectWithStaticFieldsClass
44
import org.utbot.examples.objects.ObjectWithStaticFieldsExample
55
import org.utbot.framework.plugin.api.util.UtContext
6-
import org.utbot.framework.plugin.api.util.field
6+
import org.utbot.framework.plugin.api.util.jField
77
import org.utbot.instrumentation.execute
88
import org.utbot.instrumentation.instrumentation.et.ExecutionTraceInstrumentation
99
import org.utbot.instrumentation.withInstrumentation
@@ -39,7 +39,7 @@ class StaticsUsageDetectionTest {
3939
classInstance.x = 200
4040
classInstance.y = 200
4141
val result = it.execute(ObjectWithStaticFieldsExample::setStaticField, arrayOf(instance, classInstance))
42-
assertEquals(ObjectWithStaticFieldsClass::staticValue.javaField, result.usedStatics.single().field)
42+
assertEquals(ObjectWithStaticFieldsClass::staticValue.javaField, result.usedStatics.single().jField)
4343
}
4444
}
4545

utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/InvokeWithStaticsInstrumentation.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.utbot.instrumentation.instrumentation
22

33
import org.utbot.common.withAccessibility
4-
import org.utbot.framework.plugin.api.util.field
4+
import org.utbot.framework.plugin.api.util.jField
55
import org.utbot.instrumentation.util.StaticEnvironment
66
import java.lang.reflect.Field
77
import java.lang.reflect.Modifier
@@ -46,7 +46,7 @@ class InvokeWithStaticsInstrumentation : Instrumentation<Result<*>> {
4646
private fun setStaticFields(staticEnvironment: StaticEnvironment?) {
4747
staticEnvironment?.run {
4848
listOfFields.forEach { (fieldId, value) ->
49-
fieldId.field.run {
49+
fieldId.jField.run {
5050
withAccessibility {
5151
set(null, value)
5252
}

0 commit comments

Comments
 (0)