Skip to content

Commit 66f58c9

Browse files
committed
Be able to invoke all public methods in Fuzzer
1 parent ae79145 commit 66f58c9

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
)
@@ -199,6 +210,13 @@ internal class FieldDescription(
199210
val getter: Method?
200211
)
201212

213+
internal class MethodDescription(
214+
val name: String,
215+
// val returnType: FuzzedType,
216+
val parameterTypes: List<FuzzedType>,
217+
val executableId: ExecutableId
218+
)
219+
202220
internal fun findAccessibleModifiableFields(description: FuzzedDescription?, classId: ClassId, packageName: String?): List<FieldDescription> {
203221
return generateSequence(classId.jClass) { it.superclass }.flatMap { jClass ->
204222
jClass.declaredFields.map { field ->
@@ -220,6 +238,32 @@ internal fun findAccessibleModifiableFields(description: FuzzedDescription?, cla
220238
}.toList()
221239
}
222240

241+
internal fun findAllPublicMethods(
242+
description: FuzzedDescription?,
243+
classId: ClassId,
244+
packageName: String?
245+
): List<MethodDescription> {
246+
return classId.jClass.declaredMethods.mapNotNull { method ->
247+
if (isAccessible(method, packageName)) {
248+
val parameterTypes =
249+
method
250+
.parameterTypes
251+
.map {
252+
if (description != null) toFuzzerType(
253+
it,
254+
description.typeCache
255+
) else FuzzedType(method.returnType.id)
256+
}
257+
258+
MethodDescription(
259+
name = method.name,
260+
parameterTypes = parameterTypes,
261+
executableId = method.executableId
262+
)
263+
} else null
264+
}
265+
}
266+
223267
internal fun Class<*>.findPublicSetterGetterIfHasPublicGetter(field: Field, packageName: String?): PublicSetterGetter? {
224268
@Suppress("DEPRECATION") val postfixName = field.name.capitalize()
225269
val setterName = "set$postfixName"

0 commit comments

Comments
 (0)