@@ -118,9 +118,8 @@ import org.utbot.framework.plugin.api.FieldId
118118import org.utbot.framework.plugin.api.MethodId
119119import org.utbot.framework.plugin.api.classId
120120import org.utbot.framework.plugin.api.id
121- import org.utbot.framework.plugin.api.util.allDeclaredFieldIds
122121import org.utbot.framework.plugin.api.util.executable
123- import org.utbot.framework.plugin.api.util.fieldId
122+ import org.utbot.framework.plugin.api.util.findFieldByIdOrNull
124123import org.utbot.framework.plugin.api.util.jField
125124import org.utbot.framework.plugin.api.util.jClass
126125import org.utbot.framework.plugin.api.util.id
@@ -2119,11 +2118,8 @@ class Traverser(
21192118
21202119 // We must have `runCatching` here since might be a situation when we do not have
21212120 // such declaring class in a classpath, that might (but should not) lead to an exception
2122- val jClass = field.declaringClass.id.jClass
2123- val requiredField = generateSequence(jClass) { it.superclass }
2124- .flatMap { it.declaredFields.asSequence() }
2125- .singleOrNull { it.name == field.name && it.declaringClass.name == field.declaringClass.name }
2126-
2121+ val classId = field.declaringClass.id
2122+ val requiredField = classId.findFieldByIdOrNull(field.fieldId)
21272123 val genericInfo = requiredField?.genericType as ? ParameterizedType ? : return
21282124
21292125 updateGenericTypeInfo(genericInfo, createdField)
@@ -2552,10 +2548,14 @@ class Traverser(
25522548 ): List <InvocationTarget > {
25532549 val visitor = solver.simplificator.axiomInstantiationVisitor
25542550 val simplifiedAddr = instance.addr.accept(visitor)
2551+
25552552 // UtIsExpression for object with address the same as instance.addr
2556- val instanceOfConstraint = solver.assertions.singleOrNull {
2557- it is UtIsExpression && it.addr == simplifiedAddr
2558- } as ? UtIsExpression
2553+ // If there are several such constraints, take the one with the least number of possible types
2554+ val instanceOfConstraint = solver.assertions
2555+ .filter { it is UtIsExpression && it.addr == simplifiedAddr }
2556+ .takeIf { it.isNotEmpty() }
2557+ ?.minBy { (it as UtIsExpression ).typeStorage.possibleConcreteTypes.size } as ? UtIsExpression
2558+
25592559 // if we have UtIsExpression constraint for [instance], then find invocation targets
25602560 // for possibleTypes from this constraints, instead of the type maintained by solver.
25612561
@@ -2565,6 +2565,9 @@ class Traverser(
25652565 val types = instanceOfConstraint
25662566 ?.typeStorage
25672567 ?.possibleConcreteTypes
2568+ // we should take this constraint into consideration only if it has less
2569+ // possible types than our current object, otherwise, it doesn't add
2570+ // any helpful information
25682571 ?.takeIf { it.size < instance.possibleConcreteTypes.size }
25692572 ? : instance.possibleConcreteTypes
25702573
@@ -2703,21 +2706,14 @@ class Traverser(
27032706 // If we have some method 'foo` and a method `bar(List<Integer>), and inside `foo`
27042707 // there is an invocation `bar(object)`, this object must have information about
27052708 // its `Integer` generic type.
2706-
2707- // Note that we must have `runCatching` here since might be a situation when we do not have
2708- // such declaring class in a classpath, that might (but should not) lead to an exception
27092709 invocation.parameters.forEachIndexed { index, param ->
27102710 if (param !is ReferenceValue ) return @forEachIndexed
27112711
2712- runCatching {
2713- updateGenericTypeInfoFromMethod(method, param, parameterIndex = index + 1 )
2714- }
2712+ updateGenericTypeInfoFromMethod(method, param, parameterIndex = index + 1 )
27152713 }
27162714
27172715 if (invocation.instance != null ) {
2718- runCatching {
2719- updateGenericTypeInfoFromMethod(method, invocation.instance, parameterIndex = 0 )
2720- }
2716+ updateGenericTypeInfoFromMethod(method, invocation.instance, parameterIndex = 0 )
27212717 }
27222718
27232719 /* *
0 commit comments