Skip to content

Commit ad5860b

Browse files
committed
Be able to invoke all public methods in Fuzzer
1 parent 6b0e133 commit ad5860b

File tree

1 file changed

+44
-0
lines changed
  • utbot-java-fuzzing/src/main/kotlin/org/utbot/fuzzing/providers

1 file changed

+44
-0
lines changed

utbot-java-fuzzing/src/main/kotlin/org/utbot/fuzzing/providers/Objects.kt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,17 @@ class ObjectValueProvider(
100100
}
101101
}
102102
}
103+
findAllPublicMethods(description, classId, description.description.packageName).forEach { md ->
104+
yield(Routine.Call(md.parameterTypes) { self, values ->
105+
val model = self.model as UtAssembleModel
106+
model.modificationsChain as MutableList +=
107+
UtExecutableCallModel(
108+
model,
109+
md.executableId,
110+
values.map { it.model }
111+
)
112+
})
113+
}
103114
},
104115
empty = nullRoutine(classId)
105116
)
@@ -219,6 +230,13 @@ internal class FieldDescription(
219230
val getter: Method?
220231
)
221232

233+
internal class MethodDescription(
234+
val name: String,
235+
// val returnType: FuzzedType,
236+
val parameterTypes: List<FuzzedType>,
237+
val executableId: ExecutableId
238+
)
239+
222240
internal fun findAccessibleModifiableFields(description: FuzzedDescription?, classId: ClassId, packageName: String?): List<FieldDescription> {
223241
return generateSequence(classId.jClass) { it.superclass }.flatMap { jClass ->
224242
jClass.declaredFields.map { field ->
@@ -240,6 +258,32 @@ internal fun findAccessibleModifiableFields(description: FuzzedDescription?, cla
240258
}.toList()
241259
}
242260

261+
internal fun findAllPublicMethods(
262+
description: FuzzedDescription?,
263+
classId: ClassId,
264+
packageName: String?
265+
): List<MethodDescription> {
266+
return classId.jClass.declaredMethods.mapNotNull { method ->
267+
if (isAccessible(method, packageName)) {
268+
val parameterTypes =
269+
method
270+
.parameterTypes
271+
.map {
272+
if (description != null) toFuzzerType(
273+
it,
274+
description.typeCache
275+
) else FuzzedType(method.returnType.id)
276+
}
277+
278+
MethodDescription(
279+
name = method.name,
280+
parameterTypes = parameterTypes,
281+
executableId = method.executableId
282+
)
283+
} else null
284+
}
285+
}
286+
243287
internal fun Class<*>.findPublicSetterGetterIfHasPublicGetter(field: Field, packageName: String?): PublicSetterGetter? {
244288
@Suppress("DEPRECATION") val postfixName = field.name.capitalize()
245289
val setterName = "set$postfixName"

0 commit comments

Comments
 (0)