File tree Expand file tree Collapse file tree 2 files changed +7
-6
lines changed
utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api Expand file tree Collapse file tree 2 files changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ import org.utbot.framework.plugin.api.util.charClassId
20
20
import org.utbot.framework.plugin.api.util.constructor
21
21
import org.utbot.framework.plugin.api.util.doubleClassId
22
22
import org.utbot.framework.plugin.api.util.executableId
23
- import org.utbot.framework.plugin.api.util.findFieldByIdOrNull
23
+ import org.utbot.framework.plugin.api.util.field
24
24
import org.utbot.framework.plugin.api.util.floatClassId
25
25
import org.utbot.framework.plugin.api.util.id
26
26
import org.utbot.framework.plugin.api.util.intClassId
@@ -30,6 +30,7 @@ import org.utbot.framework.plugin.api.util.jClass
30
30
import org.utbot.framework.plugin.api.util.longClassId
31
31
import org.utbot.framework.plugin.api.util.method
32
32
import org.utbot.framework.plugin.api.util.primitiveTypeJvmNameOrNull
33
+ import org.utbot.framework.plugin.api.util.safeField
33
34
import org.utbot.framework.plugin.api.util.shortClassId
34
35
import org.utbot.framework.plugin.api.util.toReferenceTypeBytecodeSignature
35
36
import org.utbot.framework.plugin.api.util.voidClassId
@@ -856,7 +857,7 @@ open class FieldId(val declaringClass: ClassId, val name: String) {
856
857
return result
857
858
}
858
859
859
- override fun toString () = declaringClass.findFieldByIdOrNull( this ) .toString()
860
+ override fun toString () = safeField .toString()
860
861
}
861
862
862
863
inline fun <T > withReflection (block : () -> T ): T {
Original file line number Diff line number Diff line change @@ -290,7 +290,7 @@ fun ClassId.findFieldByIdOrNull(fieldId: FieldId): Field? {
290
290
return null
291
291
}
292
292
293
- return fieldId.declaringClass.jClass.declaredFields.firstOrNull { it.name == fieldId.name }
293
+ return fieldId.safeField
294
294
}
295
295
296
296
fun ClassId.hasField (fieldId : FieldId ): Boolean {
@@ -310,11 +310,11 @@ fun ClassId.defaultValueModel(): UtModel = when (this) {
310
310
}
311
311
312
312
// FieldId utils
313
+ val FieldId .safeField: Field ?
314
+ get() = declaringClass.jClass.declaredFields.firstOrNull { it.name == name }
313
315
314
- // TODO: maybe cache it somehow in the future
315
316
val FieldId .field: Field
316
- get() = declaringClass.jClass.declaredFields.firstOrNull { it.name == name }
317
- ? : error(" Field $name is not found in class ${declaringClass.jClass.name} " )
317
+ get() = safeField ? : error(" Field $name is not found in class ${declaringClass.jClass.name} " )
318
318
319
319
// https://docstore.mik.ua/orelly/java-ent/jnut/ch03_13.htm
320
320
val FieldId .isInnerClassEnclosingClassReference: Boolean
You can’t perform that action at this time.
0 commit comments