diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/javadoc/UtCustomJavaDocTagProvider.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/javadoc/UtCustomJavaDocTagProvider.kt index c82e37b027..cd3dd4566c 100644 --- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/javadoc/UtCustomJavaDocTagProvider.kt +++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/javadoc/UtCustomJavaDocTagProvider.kt @@ -6,8 +6,8 @@ import com.intellij.psi.PsiReference import com.intellij.psi.javadoc.CustomJavadocTagProvider import com.intellij.psi.javadoc.JavadocTagInfo import com.intellij.psi.javadoc.PsiDocTagValue -import org.utbot.summary.comment.CustomJavaDocTag -import org.utbot.summary.comment.CustomJavaDocTagProvider +import org.utbot.summary.comment.customtags.symbolic.CustomJavaDocTag +import org.utbot.summary.comment.customtags.symbolic.CustomJavaDocTagProvider /** * Provides plugin's custom JavaDoc tags to make test summaries structured. 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 40922e2845..7c71f4a3f4 100644 --- a/utbot-summary/src/main/kotlin/org/utbot/summary/Summarization.kt +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/Summarization.kt @@ -16,7 +16,7 @@ import org.utbot.summary.UtSummarySettings.GENERATE_NAMES import org.utbot.summary.analysis.ExecutionStructureAnalysis import org.utbot.summary.ast.JimpleToASTMap import org.utbot.summary.ast.SourceCodeParser -import org.utbot.summary.comment.SymbolicExecutionClusterCommentBuilder +import org.utbot.summary.comment.cluster.SymbolicExecutionClusterCommentBuilder import org.utbot.summary.comment.SimpleCommentBuilder import org.utbot.summary.name.SimpleNameBuilder import java.io.File @@ -37,7 +37,7 @@ import org.utbot.fuzzer.FuzzedValue import org.utbot.fuzzer.UtFuzzedExecution import org.utbot.summary.fuzzer.names.MethodBasedNameSuggester import org.utbot.summary.fuzzer.names.ModelBasedNameSuggester -import org.utbot.summary.comment.CustomJavaDocCommentBuilder +import org.utbot.summary.comment.customtags.symbolic.CustomJavaDocCommentBuilder import soot.SootMethod private val logger = KotlinLogging.logger {} @@ -241,6 +241,7 @@ class Summarization(val sourceFile: File?, val invokeDescriptions: List unsuccessfulFuzzerExecutions.add(utExecution) diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/comment/CustomJavaDocTagProvider.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/CustomJavaDocTagProvider.kt deleted file mode 100644 index 4c98d8a379..0000000000 --- a/utbot-summary/src/main/kotlin/org/utbot/summary/comment/CustomJavaDocTagProvider.kt +++ /dev/null @@ -1,70 +0,0 @@ -package org.utbot.summary.comment - -import org.utbot.framework.plugin.api.DocRegularStmt - -/** - * Provides a list of supported custom JavaDoc tags. - */ -class CustomJavaDocTagProvider { - // The tags' order is important because plugin builds final JavaDoc comment according to it. - fun getPluginCustomTags(): List = - listOf( - CustomJavaDocTag.ClassUnderTest, - CustomJavaDocTag.MethodUnderTest, - CustomJavaDocTag.ExpectedResult, - CustomJavaDocTag.ActualResult, - CustomJavaDocTag.Executes, - CustomJavaDocTag.Invokes, - CustomJavaDocTag.Iterates, - CustomJavaDocTag.SwitchCase, - CustomJavaDocTag.Recursion, - CustomJavaDocTag.ReturnsFrom, - CustomJavaDocTag.CaughtException, - CustomJavaDocTag.ThrowsException, - ) -} - -sealed class CustomJavaDocTag( - val name: String, - val message: String, - private val valueRetriever: (CustomJavaDocComment) -> Any -) { - object ClassUnderTest : - CustomJavaDocTag("utbot.classUnderTest", "Class under test", CustomJavaDocComment::classUnderTest) - - object MethodUnderTest : - CustomJavaDocTag("utbot.methodUnderTest", "Method under test", CustomJavaDocComment::methodUnderTest) - - object ExpectedResult : - CustomJavaDocTag("utbot.expectedResult", "Expected result", CustomJavaDocComment::expectedResult) - - object ActualResult : CustomJavaDocTag("utbot.actualResult", "Actual result", CustomJavaDocComment::actualResult) - object Executes : - CustomJavaDocTag("utbot.executesCondition", "Executes condition", CustomJavaDocComment::executesCondition) - - 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) - - fun generateDocStatement(comment: CustomJavaDocComment): DocRegularStmt? = - when (val value = valueRetriever.invoke(comment)) { - is String -> value.takeIf { it.isNotEmpty() }?.let { - DocRegularStmt("@$name $value\n") - } - is List<*> -> value.takeIf { it.isNotEmpty() }?.let { - val valueToString = value.joinToString(separator = "\n", postfix = "\n") {"@$name $it"} - - DocRegularStmt(valueToString) - } - else -> null - } -} \ No newline at end of file diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/comment/classic/fuzzer/SimpleCommentForTestProducedByFuzzerBuilder.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/classic/fuzzer/SimpleCommentForTestProducedByFuzzerBuilder.kt new file mode 100644 index 0000000000..02f7736eff --- /dev/null +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/classic/fuzzer/SimpleCommentForTestProducedByFuzzerBuilder.kt @@ -0,0 +1,18 @@ +package org.utbot.summary.comment.classic.fuzzer + +import org.utbot.framework.plugin.api.DocPreTagStatement +import org.utbot.framework.plugin.api.DocStatement +import org.utbot.framework.plugin.api.UtExecutionResult +import org.utbot.fuzzer.FuzzedMethodDescription +import org.utbot.fuzzer.FuzzedValue + +// TODO: https://github.com/UnitTestBot/UTBotJava/issues/1127 +class SimpleCommentForTestProducedByFuzzerBuilder( + description: FuzzedMethodDescription, + values: List, + result: UtExecutionResult? +) { + fun buildDocStatements(): List { + return listOf(DocPreTagStatement(emptyList())) + } +} \ No newline at end of file diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/comment/SimpleCommentBuilder.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/classic/symbolic/SimpleCommentBuilder.kt similarity index 92% rename from utbot-summary/src/main/kotlin/org/utbot/summary/comment/SimpleCommentBuilder.kt rename to utbot-summary/src/main/kotlin/org/utbot/summary/comment/classic/symbolic/SimpleCommentBuilder.kt index 8d86ea777e..781902a05b 100644 --- a/utbot-summary/src/main/kotlin/org/utbot/summary/comment/SimpleCommentBuilder.kt +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/classic/symbolic/SimpleCommentBuilder.kt @@ -16,6 +16,7 @@ import org.utbot.framework.plugin.api.exceptionOrNull import org.utbot.summary.AbstractTextBuilder import org.utbot.summary.SummarySentenceConstants.CARRIAGE_RETURN import org.utbot.summary.ast.JimpleToASTMap +import org.utbot.summary.comment.customtags.getMethodReference import org.utbot.summary.tag.BasicTypeTag import org.utbot.summary.tag.CallOrderTag import org.utbot.summary.tag.StatementTag @@ -356,45 +357,6 @@ open class SimpleCommentBuilder( ) } - /** - * Returns a reference to the invoked method. IDE can't resolve references to private methods in comments, - * so we add @link tag only if the invoked method is not private. - * - * It looks like {@link packageName.className#methodName(type1, type2)}. - * - * In case when an enclosing class in nested, we need to replace '$' with '.' - * to render the reference. - */ - fun getMethodReference( - className: String, - methodName: String, - methodParameterTypes: List, - isPrivate: Boolean - ): String { - val prettyClassName: String = className.replace("$", ".") - - val text = if (methodParameterTypes.isEmpty()) { - "$prettyClassName#$methodName()" - } else { - val methodParametersAsString = methodParameterTypes.joinToString(",") - "$prettyClassName#$methodName($methodParametersAsString)" - } - - return if (isPrivate) { - text - } else { - "{@link $text}" - } - } - - /** - * Returns a reference to the class. - * Replaces '$' with '.' in case a class is nested. - */ - fun getClassReference(fullClasName: String): String { - return "{@link ${fullClasName.replace("$", ".")}}" - } - protected fun buildIterationsBlock( iterations: List, activatedStep: Step, diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/comment/SimpleSentenceBlock.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/classic/symbolic/SimpleSentenceBlock.kt similarity index 100% rename from utbot-summary/src/main/kotlin/org/utbot/summary/comment/SimpleSentenceBlock.kt rename to utbot-summary/src/main/kotlin/org/utbot/summary/comment/classic/symbolic/SimpleSentenceBlock.kt diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/comment/SymbolicExecutionClusterCommentBuilder.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/cluster/SymbolicExecutionClusterCommentBuilder.kt similarity index 98% rename from utbot-summary/src/main/kotlin/org/utbot/summary/comment/SymbolicExecutionClusterCommentBuilder.kt rename to utbot-summary/src/main/kotlin/org/utbot/summary/comment/cluster/SymbolicExecutionClusterCommentBuilder.kt index 76f760d66f..ea09506ab3 100644 --- a/utbot-summary/src/main/kotlin/org/utbot/summary/comment/SymbolicExecutionClusterCommentBuilder.kt +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/cluster/SymbolicExecutionClusterCommentBuilder.kt @@ -1,12 +1,13 @@ -package org.utbot.summary.comment +package org.utbot.summary.comment.cluster import com.github.javaparser.ast.stmt.CatchClause import com.github.javaparser.ast.stmt.ForStmt import org.utbot.framework.plugin.api.DocPreTagStatement -import org.utbot.framework.plugin.api.DocRegularStmt import org.utbot.framework.plugin.api.DocStatement import org.utbot.summary.SummarySentenceConstants.CARRIAGE_RETURN import org.utbot.summary.ast.JimpleToASTMap +import org.utbot.summary.comment.* +import org.utbot.summary.comment.customtags.getMethodReference import org.utbot.summary.tag.BasicTypeTag import org.utbot.summary.tag.CallOrderTag import org.utbot.summary.tag.StatementTag diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/comment/customtags/CustomJavaDocTagProvider.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/customtags/CustomJavaDocTagProvider.kt new file mode 100644 index 0000000000..3c2ed9bd6d --- /dev/null +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/customtags/CustomJavaDocTagProvider.kt @@ -0,0 +1,106 @@ +package org.utbot.summary.comment.customtags.symbolic + +import org.utbot.framework.plugin.api.DocRegularStmt +import org.utbot.summary.comment.customtags.fuzzer.CommentWithCustomTagForTestProducedByFuzzer + +/** + * Provides a list of supported custom JavaDoc tags. + */ +class CustomJavaDocTagProvider { + // The tags' order is important because plugin builds final JavaDoc comment according to it. + fun getPluginCustomTags(): List = + listOf( + CustomJavaDocTag.ClassUnderTest, + CustomJavaDocTag.MethodUnderTest, + CustomJavaDocTag.ExpectedResult, + CustomJavaDocTag.ActualResult, + CustomJavaDocTag.Executes, + CustomJavaDocTag.Invokes, + CustomJavaDocTag.Iterates, + CustomJavaDocTag.SwitchCase, + CustomJavaDocTag.Recursion, + CustomJavaDocTag.ReturnsFrom, + CustomJavaDocTag.CaughtException, + CustomJavaDocTag.ThrowsException, + ) +} + +sealed class CustomJavaDocTag( + val name: String, + val message: String, + private val valueRetriever: (CustomJavaDocComment) -> Any, + private val valueRetrieverFuzzer: ((CommentWithCustomTagForTestProducedByFuzzer) -> Any)? // TODO: remove after refactoring +) { + object ClassUnderTest : + CustomJavaDocTag( + "utbot.classUnderTest", + "Class under test", + CustomJavaDocComment::classUnderTest, + CommentWithCustomTagForTestProducedByFuzzer::classUnderTest + ) + + object MethodUnderTest : + CustomJavaDocTag( + "utbot.methodUnderTest", + "Method under test", + CustomJavaDocComment::methodUnderTest, + CommentWithCustomTagForTestProducedByFuzzer::methodUnderTest + ) + + object ExpectedResult : + CustomJavaDocTag("utbot.expectedResult", "Expected result", CustomJavaDocComment::expectedResult, null) + + object ActualResult : + CustomJavaDocTag("utbot.actualResult", "Actual result", CustomJavaDocComment::actualResult, null) + + object Executes : + CustomJavaDocTag("utbot.executesCondition", "Executes condition", CustomJavaDocComment::executesCondition, null) + + object Invokes : CustomJavaDocTag("utbot.invokes", "Invokes", CustomJavaDocComment::invokes, null) + object Iterates : CustomJavaDocTag("utbot.iterates", "Iterates", CustomJavaDocComment::iterates, null) + object SwitchCase : + CustomJavaDocTag("utbot.activatesSwitch", "Activates switch", CustomJavaDocComment::switchCase, null) + + object Recursion : + CustomJavaDocTag("utbot.triggersRecursion", "Triggers recursion ", CustomJavaDocComment::recursion, null) + + object ReturnsFrom : CustomJavaDocTag("utbot.returnsFrom", "Returns from", CustomJavaDocComment::returnsFrom, null) + object CaughtException : + CustomJavaDocTag("utbot.caughtException", "Caught exception", CustomJavaDocComment::caughtException, null) + + object ThrowsException : + CustomJavaDocTag("utbot.throwsException", "Throws exception", CustomJavaDocComment::throwsException, null) + + fun generateDocStatement(comment: CustomJavaDocComment): DocRegularStmt? = + when (val value = valueRetriever.invoke(comment)) { + is String -> value.takeIf { it.isNotEmpty() }?.let { + DocRegularStmt("@$name $value\n") + } + is List<*> -> value.takeIf { it.isNotEmpty() }?.let { + val valueToString = value.joinToString(separator = "\n", postfix = "\n") { "@$name $it" } + + DocRegularStmt(valueToString) + } + else -> null + } + + // TODO: could be universal with the function above after creation of hierarchy data classes related to the comments + fun generateDocStatementForTestProducedByFuzzer(comment: CommentWithCustomTagForTestProducedByFuzzer): DocRegularStmt? { + if (valueRetrieverFuzzer != null) { //TODO: it required only when we have two different retrievers + return when (val value = valueRetrieverFuzzer!!.invoke(comment)) { // TODO: unsafe !! - resolve + is String -> value.takeIf { it.isNotEmpty() }?.let { + DocRegularStmt("@$name $value\n") + } + + is List<*> -> value.takeIf { it.isNotEmpty() }?.let { + val valueToString = value.joinToString(separator = ",\n", postfix = "\n") + + DocRegularStmt("@$name $valueToString") + } + + else -> null + } + } + return null + } +} \ No newline at end of file diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/comment/customtags/CustomTagsUtil.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/customtags/CustomTagsUtil.kt new file mode 100644 index 0000000000..496f6d1ef6 --- /dev/null +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/customtags/CustomTagsUtil.kt @@ -0,0 +1,68 @@ +package org.utbot.summary.comment.customtags + +import org.utbot.framework.plugin.api.ClassId +import soot.Type + +/** + * Returns a reference to the invoked method. IDE can't resolve references to private methods in comments, + * so we add @link tag only if the invoked method is not private. + * + * It looks like {@link packageName.className#methodName(type1, type2)}. + * + * In case when an enclosing class in nested, we need to replace '$' with '.' + * to render the reference. + */ +fun getMethodReference( + className: String, + methodName: String, + methodParameterTypes: List, + isPrivate: Boolean +): String { + val prettyClassName: String = className.replace("$", ".") + + val text = if (methodParameterTypes.isEmpty()) { + "$prettyClassName#$methodName()" + } else { + val methodParametersAsString = methodParameterTypes.joinToString(",") + "$prettyClassName#$methodName($methodParametersAsString)" + } + + return if (isPrivate) { + text + } else { + "{@link $text}" + } +} + +/** + * Returns a reference to the class. + * Replaces '$' with '.' in case a class is nested. + */ +fun getClassReference(fullClassName: String): String { + return "{@link ${fullClassName.replace("$", ".")}}" +} + +/** + * Returns a reference to the invoked method. + * + * It looks like {@link packageName.className#methodName(type1, type2)}. + * + * In case when an enclosing class in nested, we need to replace '$' with '.' + * to render the reference. + */ +fun getMethodReferenceForFuzzingTest(className: String, methodName: String, methodParameterTypes: List, isPrivate: Boolean): String { + val prettyClassName: String = className.replace("$", ".") + + val text = if (methodParameterTypes.isEmpty()) { + "$prettyClassName#$methodName()" + } else { + val methodParametersAsString = methodParameterTypes.joinToString(",") { it.canonicalName } + "$prettyClassName#$methodName($methodParametersAsString)" + } + + return if (isPrivate) { + text + } else { + "{@link $text}" + } +} \ No newline at end of file diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/comment/customtags/fuzzer/CommentWithCustomTagForTestProducedByFuzzer.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/customtags/fuzzer/CommentWithCustomTagForTestProducedByFuzzer.kt new file mode 100644 index 0000000000..d3f99b66cc --- /dev/null +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/customtags/fuzzer/CommentWithCustomTagForTestProducedByFuzzer.kt @@ -0,0 +1,15 @@ +package org.utbot.summary.comment.customtags.fuzzer + +import org.utbot.summary.comment.EMPTY_STRING + +/** + * Represents a set of plugin's custom JavaDoc tags. + */ +data class CommentWithCustomTagForTestProducedByFuzzer( + val classUnderTest: String = EMPTY_STRING, + val methodUnderTest: String = EMPTY_STRING, + val expectedResult: String = EMPTY_STRING, + val actualResult: String = EMPTY_STRING, + var returnsFrom: String = EMPTY_STRING, + var throwsException: String = EMPTY_STRING +) \ No newline at end of file diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/comment/customtags/fuzzer/CommentWithCustomTagForTestProducedByFuzzerBuilder.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/customtags/fuzzer/CommentWithCustomTagForTestProducedByFuzzerBuilder.kt new file mode 100644 index 0000000000..367eacc541 --- /dev/null +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/customtags/fuzzer/CommentWithCustomTagForTestProducedByFuzzerBuilder.kt @@ -0,0 +1,57 @@ +package org.utbot.summary.comment.customtags.fuzzer + +import org.utbot.framework.plugin.api.DocCustomTagStatement +import org.utbot.framework.plugin.api.DocStatement +import org.utbot.framework.plugin.api.UtExecutionResult +import org.utbot.fuzzer.FuzzedMethodDescription +import org.utbot.fuzzer.FuzzedValue +import org.utbot.summary.SummarySentenceConstants.CARRIAGE_RETURN +import org.utbot.summary.comment.customtags.getClassReference +import org.utbot.summary.comment.customtags.getMethodReferenceForFuzzingTest +import org.utbot.summary.comment.customtags.symbolic.CustomJavaDocTagProvider + +/** + * Builds JavaDoc comments for generated tests using plugin's custom JavaDoc tags. + */ +class CommentWithCustomTagForTestProducedByFuzzerBuilder( + val methodDescription: FuzzedMethodDescription, + val values: List, + val result: UtExecutionResult? +) { + /** + * Collects statements for final JavaDoc comment. + */ + fun buildDocStatements(): List { + val comment = buildCustomJavaDocComment() + val docStatementList = + CustomJavaDocTagProvider().getPluginCustomTags() + .mapNotNull { it.generateDocStatementForTestProducedByFuzzer(comment) } + return listOf(DocCustomTagStatement(docStatementList)) + } + + private fun buildCustomJavaDocComment(): CommentWithCustomTagForTestProducedByFuzzer { + val packageName = methodDescription.packageName + val className = methodDescription.className + val methodName = methodDescription.compilableName + + return if (packageName != null && className != null && methodName != null) { + val fullClassName = "$packageName.$className" + + val methodReference = getMethodReferenceForFuzzingTest( + fullClassName, + methodName, + methodDescription.parameters, + false + ).replace(CARRIAGE_RETURN, "") + + val classReference = getClassReference(fullClassName).replace(CARRIAGE_RETURN, "") + + CommentWithCustomTagForTestProducedByFuzzer( + classUnderTest = classReference, + methodUnderTest = methodReference, + ) + } else { + CommentWithCustomTagForTestProducedByFuzzer() + } + } +} diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/comment/CustomJavaDocComment.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/customtags/symbolic/CustomJavaDocComment.kt similarity index 87% rename from utbot-summary/src/main/kotlin/org/utbot/summary/comment/CustomJavaDocComment.kt rename to utbot-summary/src/main/kotlin/org/utbot/summary/comment/customtags/symbolic/CustomJavaDocComment.kt index fffe9cbf8b..e0043cd4ea 100644 --- a/utbot-summary/src/main/kotlin/org/utbot/summary/comment/CustomJavaDocComment.kt +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/customtags/symbolic/CustomJavaDocComment.kt @@ -1,4 +1,6 @@ -package org.utbot.summary.comment +package org.utbot.summary.comment.customtags.symbolic + +import org.utbot.summary.comment.EMPTY_STRING /** * Represents a set of plugin's custom JavaDoc tags. diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/comment/CustomJavaDocCommentBuilder.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/customtags/symbolic/CustomJavaDocCommentBuilder.kt similarity index 95% rename from utbot-summary/src/main/kotlin/org/utbot/summary/comment/CustomJavaDocCommentBuilder.kt rename to utbot-summary/src/main/kotlin/org/utbot/summary/comment/customtags/symbolic/CustomJavaDocCommentBuilder.kt index 04e412a3c7..9c19b4e521 100644 --- a/utbot-summary/src/main/kotlin/org/utbot/summary/comment/CustomJavaDocCommentBuilder.kt +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/customtags/symbolic/CustomJavaDocCommentBuilder.kt @@ -1,10 +1,13 @@ -package org.utbot.summary.comment +package org.utbot.summary.comment.customtags.symbolic import org.utbot.framework.plugin.api.DocCustomTagStatement import org.utbot.framework.plugin.api.DocStatement import org.utbot.framework.plugin.api.exceptionOrNull import org.utbot.summary.SummarySentenceConstants.CARRIAGE_RETURN import org.utbot.summary.ast.JimpleToASTMap +import org.utbot.summary.comment.* +import org.utbot.summary.comment.customtags.getClassReference +import org.utbot.summary.comment.customtags.getMethodReference import org.utbot.summary.tag.TraceTagWithoutExecution import soot.SootMethod diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/fuzzer/names/ModelBasedNameSuggester.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/fuzzer/names/ModelBasedNameSuggester.kt index 38160e4ddd..823717f604 100644 --- a/utbot-summary/src/main/kotlin/org/utbot/summary/fuzzer/names/ModelBasedNameSuggester.kt +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/fuzzer/names/ModelBasedNameSuggester.kt @@ -1,16 +1,12 @@ package org.utbot.summary.fuzzer.names -import org.utbot.framework.plugin.api.UtExecutionFailure -import org.utbot.framework.plugin.api.UtExecutionResult -import org.utbot.framework.plugin.api.UtExecutionSuccess -import org.utbot.framework.plugin.api.UtExplicitlyThrownException -import org.utbot.framework.plugin.api.UtImplicitlyThrownException -import org.utbot.framework.plugin.api.UtNullModel -import org.utbot.framework.plugin.api.UtPrimitiveModel -import org.utbot.framework.plugin.api.exceptionOrNull +import org.utbot.framework.UtSettings +import org.utbot.framework.plugin.api.* import org.utbot.framework.plugin.api.util.voidClassId import org.utbot.fuzzer.FuzzedMethodDescription import org.utbot.fuzzer.FuzzedValue +import org.utbot.summary.comment.classic.fuzzer.SimpleCommentForTestProducedByFuzzerBuilder +import org.utbot.summary.comment.customtags.fuzzer.CommentWithCustomTagForTestProducedByFuzzerBuilder import java.util.* class ModelBasedNameSuggester( @@ -37,7 +33,8 @@ class ModelBasedNameSuggester( return sequenceOf( TestSuggestedInfo( testName = createTestName(description, values, result), - displayName = createDisplayName(description, values, result) + displayName = createDisplayName(description, values, result), + javaDoc = createJavaDoc(description, values, result) ) ) } @@ -142,6 +139,19 @@ class ModelBasedNameSuggester( return listOfNotNull(parameters, returnValue).joinToString(separator = " ") } + /** + * Builds the JavaDoc. + */ + private fun createJavaDoc( + description: FuzzedMethodDescription, + values: List, + result: UtExecutionResult? + ): List { + return if (UtSettings.useCustomJavaDocTags) { + CommentWithCustomTagForTestProducedByFuzzerBuilder(description, values, result).buildDocStatements() + } else SimpleCommentForTestProducedByFuzzerBuilder(description, values, result).buildDocStatements() + } + companion object { private fun prettifyNumber(value: T): String? { return when { diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/fuzzer/names/TestSuggestedInfo.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/fuzzer/names/TestSuggestedInfo.kt index e7b47c7ed1..ba36379bcf 100644 --- a/utbot-summary/src/main/kotlin/org/utbot/summary/fuzzer/names/TestSuggestedInfo.kt +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/fuzzer/names/TestSuggestedInfo.kt @@ -1,9 +1,12 @@ package org.utbot.summary.fuzzer.names +import org.utbot.framework.plugin.api.DocStatement + /** - * Information that can be used to generate test names. + * Information that can be used to generate test meta-information, including name, display name and JavaDoc. */ class TestSuggestedInfo( val testName: String, - val displayName: String? = null + val displayName: String? = null, + val javaDoc: List? = null ) \ No newline at end of file diff --git a/utbot-summary/src/test/kotlin/org/utbot/summary/comment/SimpleCommentBuilderTest.kt b/utbot-summary/src/test/kotlin/org/utbot/summary/comment/SimpleCommentBuilderTest.kt index 738adb39be..a18e630d27 100644 --- a/utbot-summary/src/test/kotlin/org/utbot/summary/comment/SimpleCommentBuilderTest.kt +++ b/utbot-summary/src/test/kotlin/org/utbot/summary/comment/SimpleCommentBuilderTest.kt @@ -9,6 +9,7 @@ import org.mockito.Mockito.`when` import org.utbot.framework.plugin.api.Step import org.utbot.framework.plugin.api.UtOverflowFailure import org.utbot.summary.ast.JimpleToASTMap +import org.utbot.summary.comment.customtags.getMethodReference import org.utbot.summary.tag.StatementTag import org.utbot.summary.tag.TraceTag import soot.SootMethod @@ -66,17 +67,15 @@ class SimpleCommentBuilderTest { @Test fun `builds inline link for method`() { - val commentBuilder = SimpleCommentBuilder(traceTag, sootToAst) - val methodReference = commentBuilder.getMethodReference("org.utbot.ClassName", "methodName", listOf(), false) + val methodReference = getMethodReference("org.utbot.ClassName", "methodName", listOf(), false) val expectedMethodReference = "{@link org.utbot.ClassName#methodName()}" assertEquals(methodReference, expectedMethodReference) } @Test fun `builds inline link for method in nested class`() { - val commentBuilder = SimpleCommentBuilder(traceTag, sootToAst) val methodReference = - commentBuilder.getMethodReference("org.utbot.ClassName\$NestedClassName", "methodName", listOf(), false) + getMethodReference("org.utbot.ClassName\$NestedClassName", "methodName", listOf(), false) val expectedMethodReference = "{@link org.utbot.ClassName.NestedClassName#methodName()}" assertEquals(methodReference, expectedMethodReference) } diff --git a/utbot-summary/src/test/kotlin/org/utbot/summary/comment/SymbolicExecutionClusterCommentBuilderTest.kt b/utbot-summary/src/test/kotlin/org/utbot/summary/comment/SymbolicExecutionClusterCommentBuilderTest.kt index ab4c93c06e..5a3b7fe255 100644 --- a/utbot-summary/src/test/kotlin/org/utbot/summary/comment/SymbolicExecutionClusterCommentBuilderTest.kt +++ b/utbot-summary/src/test/kotlin/org/utbot/summary/comment/SymbolicExecutionClusterCommentBuilderTest.kt @@ -9,6 +9,7 @@ import org.mockito.Mockito.`when` import org.utbot.framework.plugin.api.Step import org.utbot.framework.plugin.api.UtOverflowFailure import org.utbot.summary.ast.JimpleToASTMap +import org.utbot.summary.comment.cluster.SymbolicExecutionClusterCommentBuilder import org.utbot.summary.tag.StatementTag import org.utbot.summary.tag.TraceTag import soot.SootMethod