Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add tags for recursion, switch case, and caught recursion
  • Loading branch information
onewhl committed Sep 8, 2022
commit 4b495e6828fc4f0384249f1e8ee7d6e24127ff08
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ data class CustomJavaDocComment(
var executesCondition: List<String> = listOf(),
var invokes: List<String> = listOf(),
var iterates: List<String> = listOf(),
var switchCase: String = "",
Comment thread
onewhl marked this conversation as resolved.
Outdated
var recursion: String = "",
var returnsFrom: String = "",
var countedReturn: String = "",
var caughtException: String = "",
var throwsException: String = ""
)
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class CustomJavaDocCommentBuilder(
)
val classReference = getClassReference(currentMethod.declaringClass.javaStyleName)

val customJavaDocComment = CustomJavaDocComment(
val comment = CustomJavaDocComment(
classUnderTest = classReference,
methodUnderTest = methodReference,
)
Expand All @@ -49,33 +49,46 @@ class CustomJavaDocCommentBuilder(
val exceptionName = thrownException.javaClass.name
val reason = findExceptionReason(currentMethod, thrownException)

customJavaDocComment.throwsException = "{@link $exceptionName} $reason"
comment.throwsException = "{@link $exceptionName} $reason"
}

// builds Iterates section
rootSentenceBlock.iterationSentenceBlocks.forEach { (loopDesc, sentenceBlocks) ->
customJavaDocComment.iterates += stringTemplates.iterationSentence.format(
stringTemplates.codeSentence.format(loopDesc),
numberOccurrencesToText(
sentenceBlocks.size
)
)
}

// builds Invoke, Execute, Return sections
generateSequence(rootSentenceBlock) { it.nextBlock }.forEach {
for (statement in it.stmtTexts) {
when (statement.stmtType) {
StmtType.Invoke -> customJavaDocComment.invokes += "{@code ${statement.description}}"
StmtType.Condition -> customJavaDocComment.executesCondition += "{@code ${statement.description}}"
StmtType.Return -> customJavaDocComment.returnsFrom = "{@code ${statement.description}}"
else -> {
//TODO: see [issue-773](https://github.com/UnitTestBot/UTBotJava/issues/773)
}
it.stmtTexts.forEach { statement ->
processStatement(statement, comment)
}

it.invokeSentenceBlock?.let {
comment.invokes += it.first
it.second.stmtTexts.forEach { statement ->
processStatement(statement, comment)
}
}

it.iterationSentenceBlocks.forEach { (loopDesc, sentenceBlocks) ->
comment.iterates += stringTemplates.iterationSentence.format(
stringTemplates.codeSentence.format(loopDesc),
numberOccurrencesToText(
sentenceBlocks.size
)
)
}
}

return customJavaDocComment
return comment
}

private fun processStatement(
statement: StmtDescription,
comment: CustomJavaDocComment
) {
when (statement.stmtType) {
StmtType.Invoke -> comment.invokes += "{@code ${statement.description}}"
StmtType.Condition -> comment.executesCondition += "{@code ${statement.description}}"
StmtType.Return -> comment.returnsFrom = "{@code ${statement.description}}"
StmtType.CaughtException -> comment.caughtException = "{@code ${statement.description}}"
StmtType.SwitchCase -> comment.switchCase = "{@code case ${statement.description}}"
StmtType.CountedReturn -> comment.countedReturn = "{@code ${statement.description}}"
StmtType.RecursionAssignment -> comment.recursion = "of {@code ${statement.description}}"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ class CustomJavaDocTagProvider {
CustomJavaDocTag.Executes,
CustomJavaDocTag.Invokes,
CustomJavaDocTag.Iterates,
CustomJavaDocTag.SwitchCase,
CustomJavaDocTag.Recursion,
CustomJavaDocTag.ReturnsFrom,
CustomJavaDocTag.CaughtException,
CustomJavaDocTag.ThrowsException,
)
}
Expand All @@ -41,7 +44,14 @@ sealed class CustomJavaDocTag(

object Invokes : CustomJavaDocTag("utbot.invokes", "Invokes", CustomJavaDocComment::invokes)
object Iterates : CustomJavaDocTag("utbot.iterates", "Iterates", CustomJavaDocComment::iterates)
object SwitchCase : CustomJavaDocTag("utbot.activatesSwitch", "Activates switch", CustomJavaDocComment::switchCase)
object Recursion :
CustomJavaDocTag("utbot.triggersRecursion", "Triggers recursion ", CustomJavaDocComment::recursion)

object ReturnsFrom : CustomJavaDocTag("utbot.returnsFrom", "Returns from", CustomJavaDocComment::returnsFrom)
object CaughtException :
CustomJavaDocTag("utbot.caughtException", "Caught exception", CustomJavaDocComment::caughtException)

object ThrowsException :
CustomJavaDocTag("utbot.throwsException", "Throws exception", CustomJavaDocComment::throwsException)

Expand Down