Skip to content

Commit eb7393b

Browse files
committed
renamed fieldById->findFieldById, deleted redundant stuff
1 parent f080f49 commit eb7393b

File tree

9 files changed

+25
-25
lines changed

9 files changed

+25
-25
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ 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.fieldByIdOrNull
23+
import org.utbot.framework.plugin.api.util.findFieldByIdOrNull
2424
import org.utbot.framework.plugin.api.util.floatClassId
2525
import org.utbot.framework.plugin.api.util.id
2626
import org.utbot.framework.plugin.api.util.intClassId
@@ -856,7 +856,7 @@ open class FieldId(val declaringClass: ClassId, val name: String) {
856856
return result
857857
}
858858

859-
override fun toString() = declaringClass.fieldByIdOrNull(this).toString()
859+
override fun toString() = declaringClass.findFieldByIdOrNull(this).toString()
860860
}
861861

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

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -285,17 +285,24 @@ val ClassId.isMap: Boolean
285285
val ClassId.isIterableOrMap: Boolean
286286
get() = isIterable || isMap
287287

288-
fun ClassId.fieldById(fieldId: FieldId): Field =
289-
fieldByIdOrNull(fieldId) ?: error("Can't find field ${fieldId.name} in $name")
290-
291-
fun ClassId.fieldByIdOrNull(fieldId: FieldId): Field? =
288+
// TODO: needs to be refactored (do we really need receiver? Can't we specify cases where we should return null?)
289+
fun ClassId.findFieldByIdOrNull(fieldId: FieldId): Field? {
292290
if (isNotSubtypeOf(fieldId.declaringClass)) {
293-
null
294-
} else {
295-
fieldId.declaringClass.jClass.declaredFields.firstOrNull { it.name == fieldId.name }
291+
error("findFieldByIdOrNull is called on class ${name}, which is not a subclass of ${fieldId.name}'s declaring class")
296292
}
297293

298-
fun ClassId.hasField(fieldId: FieldId): Boolean = fieldByIdOrNull(fieldId) != null
294+
return fieldId.declaringClass.jClass.declaredFields.firstOrNull { it.name == fieldId.name }
295+
}
296+
297+
// TODO: maybe we could replace its usages with FieldId.field
298+
fun ClassId.findFieldById(fieldId: FieldId): Field =
299+
findFieldByIdOrNull(fieldId) ?: error("Can't find field ${fieldId.name} in $name")
300+
301+
// TODO: check if we need this function
302+
fun ClassId.hasField(fieldId: FieldId): Boolean {
303+
assert(findFieldByIdOrNull(fieldId) != null)
304+
return findFieldByIdOrNull(fieldId) != null
305+
}
299306

300307
fun ClassId.defaultValueModel(): UtModel = when (this) {
301308
intClassId -> UtPrimitiveModel(0)

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

Lines changed: 2 additions & 2 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.fieldById
92+
import org.utbot.framework.plugin.api.util.findFieldById
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
@@ -639,7 +639,7 @@ class Traverser(
639639
SECURITY_FIELD_SIGNATURE -> SecurityManager()
640640
FIELD_FILTER_MAP_FIELD_SIGNATURE -> mapOf(Reflection::class to arrayOf("fieldFilterMap", "methodFilterMap"))
641641
METHOD_FILTER_MAP_FIELD_SIGNATURE -> emptyMap<Class<*>, Array<String>>()
642-
else -> declaringClass.id.fieldById(field.fieldId).let { it.withAccessibility { it.get(null) } }
642+
else -> declaringClass.id.findFieldById(field.fieldId).let { it.withAccessibility { it.get(null) } }
643643
}
644644

645645
private fun isStaticInstanceInMethodResult(id: ClassId, methodResult: MethodResult?) =

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import org.utbot.framework.plugin.api.UtVoidModel
3636
import org.utbot.framework.plugin.api.isMockModel
3737
import org.utbot.framework.plugin.api.util.constructor
3838
import org.utbot.framework.plugin.api.util.field
39-
import org.utbot.framework.plugin.api.util.fieldById
39+
import org.utbot.framework.plugin.api.util.findFieldById
4040
import org.utbot.framework.plugin.api.util.jClass
4141
import org.utbot.framework.plugin.api.util.method
4242
import org.utbot.framework.plugin.api.util.utContext
@@ -213,7 +213,7 @@ class ValueConstructor {
213213
constructedObjects[model] = classInstance
214214

215215
model.fields.forEach { (field, fieldModel) ->
216-
val declaredField = model.classId.fieldById(field)
216+
val declaredField = model.classId.findFieldById(field)
217217
val accessible = declaredField.isAccessible
218218

219219
try {

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
@@ -45,7 +45,7 @@ import org.utbot.framework.plugin.api.UtPrimitiveModel
4545
import org.utbot.framework.plugin.api.UtReferenceModel
4646
import org.utbot.framework.plugin.api.UtVoidModel
4747
import org.utbot.framework.plugin.api.util.defaultValueModel
48-
import org.utbot.framework.plugin.api.util.fieldByIdOrNull
48+
import org.utbot.framework.plugin.api.util.findFieldByIdOrNull
4949
import org.utbot.framework.plugin.api.util.id
5050
import org.utbot.framework.plugin.api.util.intClassId
5151
import org.utbot.framework.plugin.api.util.isArray
@@ -126,7 +126,7 @@ internal class CgVariableConstructor(val context: CgContext) :
126126

127127
for ((fieldId, fieldModel) in model.fields) {
128128
val variableForField = getOrCreateVariable(fieldModel)
129-
val field = obj.type.fieldByIdOrNull(fieldId)
129+
val field = obj.type.findFieldByIdOrNull(fieldId)
130130

131131
// we cannot set field directly if variable declared type does not have such field
132132
// or we cannot directly create variable for field with the specified type (it is private, for example)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import org.mockito.Mockito
4545
import org.mockito.stubbing.Answer
4646
import org.objectweb.asm.Type
4747
import org.utbot.common.withAccessibility
48-
import org.utbot.framework.plugin.api.util.fieldById
48+
import org.utbot.framework.plugin.api.util.findFieldById
4949

5050
/**
5151
* Constructs values (including mocks) from models.
@@ -170,7 +170,7 @@ class MockValueConstructor(
170170
}
171171

172172
model.fields.forEach { (field, fieldModel) ->
173-
val declaredField = model.classId.fieldById(field)
173+
val declaredField = model.classId.findFieldById(field)
174174
val accessible = declaredField.isAccessible
175175
declaredField.isAccessible = true
176176

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ internal class HiddenFieldAccessModifiersTest : UtValueTestCaseChecker(testClass
1414
{ o, _ -> o == null },
1515
{ _, r -> r == true },
1616
{ _, r -> r == false},
17-
coverage = DoNotCalculate
1817
)
1918
}
2019
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ internal class HiddenFieldExampleTest : UtValueTestCaseChecker(testClass = Hidde
2929
{ o, r -> o.a != 1 && o.b == 2.0 && r == 2 },
3030
{ o, r -> o.a != 1 && o.b != 2.0 && (o as HiddenFieldSuperClass).b == 3 && r == 3 },
3131
{ o, r -> o.a != 1 && o.b != 2.0 && (o as HiddenFieldSuperClass).b != 3 && r == 4 },
32-
coverage = DoNotCalculate
3332
)
3433
}
3534
}

utbot-sample/src/main/java/org/utbot/examples/objects/HiddenFieldSuccClass.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,4 @@
22

33
public class HiddenFieldSuccClass extends HiddenFieldSuperClass {
44
public double b;
5-
6-
@Override
7-
public String toString() {
8-
return b + ". Super b: " + super.b;
9-
}
105
}

0 commit comments

Comments
 (0)