@@ -70,7 +70,10 @@ fun UtMethodTestSet.summarize(sourceFile: File?, searchDirectory: Path = Paths.g
70
70
}
71
71
72
72
fun UtMethodTestSet.summarize (searchDirectory : Path ): UtMethodTestSet =
73
- this .summarize(Instrumenter .adapter.computeSourceFileByClass(this .method.classId.jClass, searchDirectory), searchDirectory)
73
+ this .summarize(
74
+ Instrumenter .adapter.computeSourceFileByClass(this .method.classId.jClass, searchDirectory),
75
+ searchDirectory
76
+ )
74
77
75
78
76
79
class Summarization (val sourceFile : File ? , val invokeDescriptions : List <InvokeDescription >) {
@@ -326,32 +329,34 @@ class Summarization(val sourceFile: File?, val invokeDescriptions: List<InvokeDe
326
329
)
327
330
}
328
331
329
- /*
330
- * asts of invokes also included
331
- * */
332
+ /* * ASTs of invokes are also included. */
332
333
private fun sootToAST (
333
334
testSet : UtMethodTestSet
334
335
): MutableMap <SootMethod , JimpleToASTMap >? {
335
336
val sootToAST = mutableMapOf<SootMethod , JimpleToASTMap >()
336
337
val jimpleBody = testSet.jimpleBody
337
338
if (jimpleBody == null ) {
338
- logger.info { " No jimple body of method under test" }
339
+ logger.debug { " No jimple body of method under test ${testSet.method.name} . " }
339
340
return null
340
341
}
341
- val methodUnderTestAST = sourceFile?.let {
342
- SourceCodeParser (it, testSet).methodAST
343
- }
344
342
345
- if (methodUnderTestAST == null ) {
346
- logger.info { " Couldn't parse source file of method under test" }
347
- return null
348
- }
343
+ if (sourceFile != null && sourceFile.exists()) {
344
+ val methodUnderTestAST = SourceCodeParser (sourceFile, testSet).methodAST
345
+
346
+ if (methodUnderTestAST == null ) {
347
+ logger.debug { " Couldn't parse source file with path ${sourceFile.absolutePath} of method under test ${testSet.method.name} ." }
348
+ return null
349
+ }
349
350
350
- sootToAST[jimpleBody.method] = JimpleToASTMap (jimpleBody.units, methodUnderTestAST)
351
- invokeDescriptions.forEach {
352
- sootToAST[it.sootMethod] = JimpleToASTMap (it.sootMethod.jimpleBody().units, it.ast)
351
+ sootToAST[jimpleBody.method] = JimpleToASTMap (jimpleBody.units, methodUnderTestAST)
352
+ invokeDescriptions.forEach {
353
+ sootToAST[it.sootMethod] = JimpleToASTMap (it.sootMethod.jimpleBody().units, it.ast)
354
+ }
355
+ return sootToAST
356
+ } else {
357
+ logger.debug { " Couldn't find source file of method under test ${testSet.method.name} ." }
358
+ return null
353
359
}
354
- return sootToAST
355
360
}
356
361
}
357
362
@@ -386,6 +391,7 @@ private fun makeDiverseExecutions(testSet: UtMethodTestSet) {
386
391
private fun invokeDescriptions (testSet : UtMethodTestSet , searchDirectory : Path ): List <InvokeDescription > {
387
392
val sootInvokes =
388
393
testSet.executions.filterIsInstance<UtSymbolicExecution >().flatMap { it.path.invokeJimpleMethods() }.toSet()
394
+
389
395
return sootInvokes
390
396
// TODO(SAT-1170)
391
397
.filterNot { " \$ lambda" in it.declaringClass.name }
@@ -395,10 +401,15 @@ private fun invokeDescriptions(testSet: UtMethodTestSet, searchDirectory: Path):
395
401
sootMethod.declaringClass.javaPackageName.replace(" ." , File .separator),
396
402
searchDirectory
397
403
)
398
- val ast = methodFile?.let {
399
- SourceCodeParser (sootMethod, it).methodAST
404
+
405
+ if (methodFile != null && methodFile.exists()) {
406
+ val ast = methodFile.let {
407
+ SourceCodeParser (sootMethod, it).methodAST
408
+ }
409
+ if (ast != null ) InvokeDescription (sootMethod, ast) else null
410
+ } else {
411
+ null
400
412
}
401
- if (ast != null ) InvokeDescription (sootMethod, ast) else null
402
413
}
403
414
}
404
415
0 commit comments