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

0 commit comments

Comments
 (0)