11package org.utbot.fuzzing.providers
22
33import mu.KotlinLogging
4+ import org.utbot.common.isStatic
45import org.utbot.framework.UtSettings
56import org.utbot.framework.plugin.api.*
67import org.utbot.framework.plugin.api.util.*
@@ -47,32 +48,31 @@ class ObjectValueProvider(
4748 type : FuzzedType
4849 ) = sequence {
4950 val classId = type.classId
50- val constructors = classId.allConstructors
51- .filter {
52- isAccessible(it.constructor , description.description.packageName)
53- }
54- constructors.forEach { constructorId ->
55- yield (createValue(classId, constructorId, description))
51+ findAccessibleCreators(description, classId).forEach { creatorExecutableId ->
52+ yield (createValue(classId, creatorExecutableId, description))
5653 }
5754 }
5855
59- private fun createValue (classId : ClassId , constructorId : ConstructorId , description : FuzzedDescription ): Seed .Recursive <FuzzedType , FuzzedValue > {
56+ private fun createValue (classId : ClassId , creatorExecutableId : ExecutableId , description : FuzzedDescription ): Seed .Recursive <FuzzedType , FuzzedValue > {
6057 return Seed .Recursive (
61- construct = Routine .Create (constructorId .executable.genericParameterTypes.map {
58+ construct = Routine .Create (creatorExecutableId .executable.genericParameterTypes.map {
6259 toFuzzerType(it, description.typeCache)
6360 }) { values ->
6461 val id = idGenerator.createId()
6562 UtAssembleModel (
6663 id = id,
6764 classId = classId,
68- modelName = " ${constructorId .classId.name}${constructorId.parameters } #" + id.hex(),
65+ modelName = " ${creatorExecutableId .classId.name} . ${creatorExecutableId.signature } #" + id.hex(),
6966 instantiationCall = UtExecutableCallModel (
7067 null ,
71- constructorId ,
68+ creatorExecutableId ,
7269 values.map { it.model }),
7370 modificationsChainProvider = { mutableListOf () }
7471 ).fuzzed {
75- summary = " %var% = ${classId.simpleName} (${constructorId.parameters.joinToString { it.simpleName }} )"
72+ summary = " %var% = ${when (creatorExecutableId) {
73+ is ConstructorId -> classId.simpleName
74+ is MethodId -> creatorExecutableId.simpleNameWithClass
75+ }} (${creatorExecutableId.parameters.joinToString { it.simpleName }} )"
7676 }
7777 },
7878 modify = sequence {
@@ -164,7 +164,7 @@ class AbstractsObjectValueProvider(
164164 }
165165 val jClass = sc.id.jClass
166166 return isAccessible(jClass, description.description.packageName) &&
167- jClass.declaredConstructors.any { isAccessible(it, description.description.packageName) }
167+ findAccessibleCreators(description, jClass.id).any()
168168 } catch (ignore: Throwable ) {
169169 return false
170170 }
@@ -186,6 +186,12 @@ class AbstractsObjectValueProvider(
186186 }
187187}
188188
189+ private fun findAccessibleCreators (description : FuzzedDescription , classId : ClassId ): Sequence <ExecutableId > =
190+ (classId.allConstructors + (classId.jClass.methods
191+ .filter { it.isStatic && it.returnType.id.isSubtypeOf(classId) }
192+ .map { it.executableId })
193+ ).filter { isAccessible(it.executable, description.description.packageName) }
194+
189195internal class PublicSetterGetter (
190196 val setter : Method ,
191197 val getter : Method ,
0 commit comments