From e4b8f4cbd5b6a630ba1f1ddc92d97471bd37df4b Mon Sep 17 00:00:00 2001 From: amandelpie Date: Thu, 3 Nov 2022 15:59:22 +0300 Subject: [PATCH] Added a solution --- .../kotlin/org/utbot/summary/Summarization.kt | 49 ++++++++++++------- .../org/utbot/summary/ast/SourceCodeParser.kt | 1 - 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/Summarization.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/Summarization.kt index d05c71a84e..976dfe7c05 100644 --- a/utbot-summary/src/main/kotlin/org/utbot/summary/Summarization.kt +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/Summarization.kt @@ -70,7 +70,10 @@ fun UtMethodTestSet.summarize(sourceFile: File?, searchDirectory: Path = Paths.g } fun UtMethodTestSet.summarize(searchDirectory: Path): UtMethodTestSet = - this.summarize(Instrumenter.adapter.computeSourceFileByClass(this.method.classId.jClass, searchDirectory), searchDirectory) + this.summarize( + Instrumenter.adapter.computeSourceFileByClass(this.method.classId.jClass, searchDirectory), + searchDirectory + ) class Summarization(val sourceFile: File?, val invokeDescriptions: List) { @@ -326,32 +329,34 @@ class Summarization(val sourceFile: File?, val invokeDescriptions: List? { val sootToAST = mutableMapOf() val jimpleBody = testSet.jimpleBody if (jimpleBody == null) { - logger.info { "No jimple body of method under test" } + logger.debug { "No jimple body of method under test ${testSet.method.name}." } return null } - val methodUnderTestAST = sourceFile?.let { - SourceCodeParser(it, testSet).methodAST - } - if (methodUnderTestAST == null) { - logger.info { "Couldn't parse source file of method under test" } - return null - } + if (sourceFile != null && sourceFile.exists()) { + val methodUnderTestAST = SourceCodeParser(sourceFile, testSet).methodAST + + if (methodUnderTestAST == null) { + logger.debug { "Couldn't parse source file with path ${sourceFile.absolutePath} of method under test ${testSet.method.name}." } + return null + } - sootToAST[jimpleBody.method] = JimpleToASTMap(jimpleBody.units, methodUnderTestAST) - invokeDescriptions.forEach { - sootToAST[it.sootMethod] = JimpleToASTMap(it.sootMethod.jimpleBody().units, it.ast) + sootToAST[jimpleBody.method] = JimpleToASTMap(jimpleBody.units, methodUnderTestAST) + invokeDescriptions.forEach { + sootToAST[it.sootMethod] = JimpleToASTMap(it.sootMethod.jimpleBody().units, it.ast) + } + return sootToAST + } else { + logger.debug { "Couldn't find source file of method under test ${testSet.method.name}." } + return null } - return sootToAST } } @@ -386,6 +391,7 @@ private fun makeDiverseExecutions(testSet: UtMethodTestSet) { private fun invokeDescriptions(testSet: UtMethodTestSet, searchDirectory: Path): List { val sootInvokes = testSet.executions.filterIsInstance().flatMap { it.path.invokeJimpleMethods() }.toSet() + return sootInvokes //TODO(SAT-1170) .filterNot { "\$lambda" in it.declaringClass.name } @@ -395,10 +401,15 @@ private fun invokeDescriptions(testSet: UtMethodTestSet, searchDirectory: Path): sootMethod.declaringClass.javaPackageName.replace(".", File.separator), searchDirectory ) - val ast = methodFile?.let { - SourceCodeParser(sootMethod, it).methodAST + + if (methodFile != null && methodFile.exists()) { + val ast = methodFile.let { + SourceCodeParser(sootMethod, it).methodAST + } + if (ast != null) InvokeDescription(sootMethod, ast) else null + } else { + null } - if (ast != null) InvokeDescription(sootMethod, ast) else null } } diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/ast/SourceCodeParser.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/ast/SourceCodeParser.kt index d3e59d79a4..a6e226fca5 100644 --- a/utbot-summary/src/main/kotlin/org/utbot/summary/ast/SourceCodeParser.kt +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/ast/SourceCodeParser.kt @@ -36,7 +36,6 @@ class SourceCodeParser { val methodName = sootMethod.name val className = sootMethod.declaredClassName - val maxLineNumber = if (sootMethod.hasActiveBody()) sootMethod.retrieveActiveBody()?.units?.maxOfOrNull { it.javaSourceStartLineNumber }