Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed FileNotFoundExecption during JavaParser work #1303

Merged
merged 2 commits into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 30 additions & 19 deletions utbot-summary/src/main/kotlin/org/utbot/summary/Summarization.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<InvokeDescription>) {
Expand Down Expand Up @@ -326,32 +329,34 @@ class Summarization(val sourceFile: File?, val invokeDescriptions: List<InvokeDe
)
}

/*
* asts of invokes also included
* */
/** ASTs of invokes are also included. */
private fun sootToAST(
testSet: UtMethodTestSet
): MutableMap<SootMethod, JimpleToASTMap>? {
val sootToAST = mutableMapOf<SootMethod, JimpleToASTMap>()
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
}
}

Expand Down Expand Up @@ -386,6 +391,7 @@ private fun makeDiverseExecutions(testSet: UtMethodTestSet) {
private fun invokeDescriptions(testSet: UtMethodTestSet, searchDirectory: Path): List<InvokeDescription> {
val sootInvokes =
testSet.executions.filterIsInstance<UtSymbolicExecution>().flatMap { it.path.invokeJimpleMethods() }.toSet()

return sootInvokes
//TODO(SAT-1170)
.filterNot { "\$lambda" in it.declaringClass.name }
Expand All @@ -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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down