diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/AbstractTextBuilder.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/AbstractTextBuilder.kt index f15ca4f9c2..8080f647c7 100644 --- a/utbot-summary/src/main/kotlin/org/utbot/summary/AbstractTextBuilder.kt +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/AbstractTextBuilder.kt @@ -11,10 +11,10 @@ import com.github.javaparser.ast.stmt.SwitchStmt import com.github.javaparser.ast.stmt.WhileStmt import org.utbot.framework.plugin.api.Step import org.utbot.summary.ast.JimpleToASTMap -import org.utbot.summary.comment.IterationDescription -import org.utbot.summary.comment.SimpleSentenceBlock -import org.utbot.summary.comment.StmtDescription -import org.utbot.summary.comment.StmtType +import org.utbot.summary.comment.classic.symbolic.IterationDescription +import org.utbot.summary.comment.classic.symbolic.SimpleSentenceBlock +import org.utbot.summary.comment.classic.symbolic.StmtDescription +import org.utbot.summary.comment.classic.symbolic.StmtType import org.utbot.summary.comment.getTextIterationDescription import org.utbot.summary.comment.getTextTypeIterationDescription import org.utbot.summary.comment.numberWithSuffix 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 07aa300275..b67d08e4fd 100644 --- a/utbot-summary/src/main/kotlin/org/utbot/summary/Summarization.kt +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/Summarization.kt @@ -17,7 +17,7 @@ import org.utbot.summary.analysis.ExecutionStructureAnalysis import org.utbot.summary.ast.JimpleToASTMap import org.utbot.summary.ast.SourceCodeParser import org.utbot.summary.comment.cluster.SymbolicExecutionClusterCommentBuilder -import org.utbot.summary.comment.SimpleCommentBuilder +import org.utbot.summary.comment.classic.symbolic.SimpleCommentBuilder import org.utbot.summary.name.SimpleNameBuilder import java.io.File import java.nio.file.Path diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/UtSummarySettings.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/UtSummarySettings.kt index 70f318ad39..3e36d3d72c 100644 --- a/utbot-summary/src/main/kotlin/org/utbot/summary/UtSummarySettings.kt +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/UtSummarySettings.kt @@ -64,4 +64,7 @@ object SummarySentenceConstants { const val AT_CODE = "@code" const val OPEN_BRACKET = "{" const val CLOSE_BRACKET = "}" + + const val JAVA_CLASS_DELIMITER = "$" + const val JAVA_DOC_CLASS_DELIMITER = "." } \ No newline at end of file diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/comment/SentenceUtil.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/SentenceUtil.kt index 8057a5e74c..6972aa0395 100644 --- a/utbot-summary/src/main/kotlin/org/utbot/summary/comment/SentenceUtil.kt +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/SentenceUtil.kt @@ -14,6 +14,8 @@ import org.utbot.summary.SummarySentenceConstants.COMMA_SYMBOL import org.utbot.summary.SummarySentenceConstants.DOT_SYMBOL import org.utbot.summary.SummarySentenceConstants.NEW_LINE import org.utbot.summary.SummarySentenceConstants.TAB +import org.utbot.summary.comment.classic.symbolic.SquashedStmtTexts +import org.utbot.summary.comment.classic.symbolic.StmtType fun numberWithSuffix(number: Int) = when (number % 10) { 1 -> "${number}st" 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 index 02f7736eff..feec3bf19f 100644 --- 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 @@ -1,18 +1,45 @@ package org.utbot.summary.comment.classic.fuzzer import org.utbot.framework.plugin.api.DocPreTagStatement +import org.utbot.framework.plugin.api.DocRegularStmt 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.NEW_LINE +import org.utbot.summary.comment.customtags.getClassReference +import org.utbot.summary.comment.customtags.getMethodReferenceForFuzzingTest -// TODO: https://github.com/UnitTestBot/UTBotJava/issues/1127 class SimpleCommentForTestProducedByFuzzerBuilder( - description: FuzzedMethodDescription, - values: List, - result: UtExecutionResult? + val methodDescription: FuzzedMethodDescription, + val values: List, + val result: UtExecutionResult? ) { fun buildDocStatements(): List { - return listOf(DocPreTagStatement(emptyList())) + val packageName = methodDescription.packageName + val className = methodDescription.className + val methodName = methodDescription.compilableName + + val result = if (packageName != null && className != null && methodName != null) { + val fullClassName = "$packageName.$className" + + val methodReference = getMethodReferenceForFuzzingTest( + fullClassName, + methodName, + methodDescription.parameters, + false + ) + + val classReference = getClassReference(fullClassName) + + val docStatements = mutableListOf() + docStatements.add(DocRegularStmt("Class under test: $classReference$NEW_LINE")) + docStatements.add(DocRegularStmt("Method under test: $methodReference$NEW_LINE")) + docStatements + } else { + emptyList() + } + + return listOf(DocPreTagStatement(result)) } } \ No newline at end of file diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/comment/classic/symbolic/SimpleCommentBuilder.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/classic/symbolic/SimpleCommentBuilder.kt index 781902a05b..003d3c0116 100644 --- a/utbot-summary/src/main/kotlin/org/utbot/summary/comment/classic/symbolic/SimpleCommentBuilder.kt +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/classic/symbolic/SimpleCommentBuilder.kt @@ -1,4 +1,4 @@ -package org.utbot.summary.comment +package org.utbot.summary.comment.classic.symbolic import com.github.javaparser.ast.body.MethodDeclaration import com.github.javaparser.ast.stmt.CatchClause @@ -16,7 +16,8 @@ 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.comment.* +import org.utbot.summary.comment.customtags.getMethodReferenceForSymbolicTest import org.utbot.summary.tag.BasicTypeTag import org.utbot.summary.tag.CallOrderTag import org.utbot.summary.tag.StatementTag @@ -196,7 +197,7 @@ open class SimpleCommentBuilder( if (!sentenceInvoke.isEmpty()) { sentenceBlock.invokeSentenceBlock = Pair( - getMethodReference(className, methodName, methodParameterTypes, invokeSootMethod.isPrivate), + getMethodReferenceForSymbolicTest(className, methodName, methodParameterTypes, invokeSootMethod.isPrivate), sentenceInvoke ) createNextBlock = true @@ -333,7 +334,7 @@ open class SimpleCommentBuilder( sentenceBlock.stmtTexts.add( StmtDescription( StmtType.Invoke, - getMethodReference(className, methodName, methodParameterTypes, isPrivate), + getMethodReferenceForSymbolicTest(className, methodName, methodParameterTypes, isPrivate), frequency ) ) diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/comment/classic/symbolic/SimpleSentenceBlock.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/classic/symbolic/SimpleSentenceBlock.kt index 0caa0eaf42..2b7783d8c0 100644 --- a/utbot-summary/src/main/kotlin/org/utbot/summary/comment/classic/symbolic/SimpleSentenceBlock.kt +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/classic/symbolic/SimpleSentenceBlock.kt @@ -1,4 +1,4 @@ -package org.utbot.summary.comment +package org.utbot.summary.comment.classic.symbolic import org.utbot.framework.plugin.api.DocCodeStmt import org.utbot.framework.plugin.api.DocRegularStmt @@ -12,6 +12,7 @@ import org.utbot.summary.SummarySentenceConstants.NEW_LINE import org.utbot.summary.SummarySentenceConstants.OPEN_BRACKET import org.utbot.summary.SummarySentenceConstants.SENTENCE_SEPARATION import org.utbot.summary.SummarySentenceConstants.TAB +import org.utbot.summary.comment.* class SimpleSentenceBlock(val stringTemplates: StringsTemplatesInterface) { val iterationSentenceBlocks = mutableListOf>>() diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/comment/cluster/SymbolicExecutionClusterCommentBuilder.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/cluster/SymbolicExecutionClusterCommentBuilder.kt index ea09506ab3..6b4de29844 100644 --- a/utbot-summary/src/main/kotlin/org/utbot/summary/comment/cluster/SymbolicExecutionClusterCommentBuilder.kt +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/cluster/SymbolicExecutionClusterCommentBuilder.kt @@ -7,7 +7,8 @@ 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.comment.classic.symbolic.* +import org.utbot.summary.comment.customtags.getMethodReferenceForSymbolicTest import org.utbot.summary.tag.BasicTypeTag import org.utbot.summary.tag.CallOrderTag import org.utbot.summary.tag.StatementTag @@ -42,7 +43,7 @@ class SymbolicExecutionClusterCommentBuilder( sentence = splitLongSentence(sentence) sentence = lastCommaToDot(sentence) - return "
\n$sentence
".replace(CARRIAGE_RETURN, "") + return "
\n$sentence
".replace(CARRIAGE_RETURN, EMPTY_STRING) } override fun buildDocStmts(currentMethod: SootMethod): List { @@ -98,7 +99,7 @@ class SymbolicExecutionClusterCommentBuilder( if (!sentenceInvoke.isEmpty()) { sentenceBlock.invokeSentenceBlock = Pair( - getMethodReference(className, methodName, methodParameterTypes, isPrivate), + getMethodReferenceForSymbolicTest(className, methodName, methodParameterTypes, isPrivate), sentenceInvoke ) createNextBlock = true 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 index 496f6d1ef6..46d7677d8a 100644 --- 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 @@ -1,6 +1,10 @@ package org.utbot.summary.comment.customtags import org.utbot.framework.plugin.api.ClassId +import org.utbot.summary.SummarySentenceConstants.CARRIAGE_RETURN +import org.utbot.summary.SummarySentenceConstants.JAVA_CLASS_DELIMITER +import org.utbot.summary.SummarySentenceConstants.JAVA_DOC_CLASS_DELIMITER +import org.utbot.summary.comment.classic.symbolic.EMPTY_STRING import soot.Type /** @@ -12,34 +16,15 @@ import soot.Type * In case when an enclosing class in nested, we need to replace '$' with '.' * to render the reference. */ -fun getMethodReference( +fun getMethodReferenceForSymbolicTest( className: String, methodName: String, methodParameterTypes: List, isPrivate: Boolean ): String { - val prettyClassName: String = className.replace("$", ".") + val methodParametersAsString = if (methodParameterTypes.isNotEmpty()) methodParameterTypes.joinToString(",") else EMPTY_STRING - 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("$", ".")}}" + return formMethodReferenceForJavaDoc(className, methodName, methodParametersAsString, isPrivate) } /** @@ -51,12 +36,24 @@ fun getClassReference(fullClassName: String): String { * to render the reference. */ fun getMethodReferenceForFuzzingTest(className: String, methodName: String, methodParameterTypes: List, isPrivate: Boolean): String { - val prettyClassName: String = className.replace("$", ".") + val methodParametersAsString = if (methodParameterTypes.isNotEmpty()) methodParameterTypes.joinToString(",") { it.canonicalName } else EMPTY_STRING + + return formMethodReferenceForJavaDoc(className, methodName, methodParametersAsString, isPrivate).replace( + CARRIAGE_RETURN, EMPTY_STRING + ) +} + +private fun formMethodReferenceForJavaDoc( + className: String, + methodName: String, + methodParametersAsString: String, + isPrivate: Boolean +): String { + val prettyClassName: String = className.replace(JAVA_CLASS_DELIMITER, JAVA_DOC_CLASS_DELIMITER) - val text = if (methodParameterTypes.isEmpty()) { + val text = if (methodParametersAsString == EMPTY_STRING) { "$prettyClassName#$methodName()" } else { - val methodParametersAsString = methodParameterTypes.joinToString(",") { it.canonicalName } "$prettyClassName#$methodName($methodParametersAsString)" } @@ -65,4 +62,12 @@ fun getMethodReferenceForFuzzingTest(className: String, methodName: String, meth } 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(JAVA_CLASS_DELIMITER, JAVA_DOC_CLASS_DELIMITER)}}".replace(CARRIAGE_RETURN, EMPTY_STRING) } \ 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 index d3f99b66cc..6cefc2c888 100644 --- 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 @@ -1,6 +1,6 @@ package org.utbot.summary.comment.customtags.fuzzer -import org.utbot.summary.comment.EMPTY_STRING +import org.utbot.summary.comment.classic.symbolic.EMPTY_STRING /** * Represents a set of plugin's custom JavaDoc tags. 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 index 367eacc541..a61247e247 100644 --- 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 @@ -42,9 +42,9 @@ class CommentWithCustomTagForTestProducedByFuzzerBuilder( methodName, methodDescription.parameters, false - ).replace(CARRIAGE_RETURN, "") + ) - val classReference = getClassReference(fullClassName).replace(CARRIAGE_RETURN, "") + val classReference = getClassReference(fullClassName) CommentWithCustomTagForTestProducedByFuzzer( classUnderTest = classReference, diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/comment/customtags/symbolic/CustomJavaDocComment.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/customtags/symbolic/CustomJavaDocComment.kt index e0043cd4ea..24f237318e 100644 --- a/utbot-summary/src/main/kotlin/org/utbot/summary/comment/customtags/symbolic/CustomJavaDocComment.kt +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/customtags/symbolic/CustomJavaDocComment.kt @@ -1,6 +1,6 @@ package org.utbot.summary.comment.customtags.symbolic -import org.utbot.summary.comment.EMPTY_STRING +import org.utbot.summary.comment.classic.symbolic.EMPTY_STRING /** * Represents a set of plugin's custom JavaDoc tags. diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/comment/customtags/symbolic/CustomJavaDocCommentBuilder.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/customtags/symbolic/CustomJavaDocCommentBuilder.kt index 9c19b4e521..1724357570 100644 --- a/utbot-summary/src/main/kotlin/org/utbot/summary/comment/customtags/symbolic/CustomJavaDocCommentBuilder.kt +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/customtags/symbolic/CustomJavaDocCommentBuilder.kt @@ -6,8 +6,9 @@ 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.classic.symbolic.* import org.utbot.summary.comment.customtags.getClassReference -import org.utbot.summary.comment.customtags.getMethodReference +import org.utbot.summary.comment.customtags.getMethodReferenceForSymbolicTest import org.utbot.summary.tag.TraceTagWithoutExecution import soot.SootMethod @@ -30,7 +31,7 @@ class CustomJavaDocCommentBuilder( } private fun buildCustomJavaDocComment(currentMethod: SootMethod): CustomJavaDocComment { - val methodReference = getMethodReference( + val methodReference = getMethodReferenceForSymbolicTest( currentMethod.declaringClass.name, currentMethod.name, currentMethod.parameterTypes, @@ -39,8 +40,8 @@ class CustomJavaDocCommentBuilder( val classReference = getClassReference(currentMethod.declaringClass.javaStyleName) val comment = CustomJavaDocComment( - classUnderTest = classReference.replace(CARRIAGE_RETURN, ""), - methodUnderTest = methodReference.replace(CARRIAGE_RETURN, ""), + classUnderTest = classReference, + methodUnderTest = methodReference, ) val rootSentenceBlock = SimpleSentenceBlock(stringTemplates = stringTemplates) 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 823717f604..51a079cda1 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 @@ -5,6 +5,7 @@ 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.UtSummarySettings import org.utbot.summary.comment.classic.fuzzer.SimpleCommentForTestProducedByFuzzerBuilder import org.utbot.summary.comment.customtags.fuzzer.CommentWithCustomTagForTestProducedByFuzzerBuilder import java.util.* @@ -32,9 +33,9 @@ class ModelBasedNameSuggester( return sequenceOf( TestSuggestedInfo( - testName = createTestName(description, values, result), + testName = createTestName(description, values, result), displayName = createDisplayName(description, values, result), - javaDoc = createJavaDoc(description, values, result) + javaDoc = if (UtSummarySettings.GENERATE_COMMENTS) createJavaDoc(description, values, result) else null ) ) } 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 a18e630d27..17fa0d3d17 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,7 +9,8 @@ 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.comment.classic.symbolic.SimpleCommentBuilder +import org.utbot.summary.comment.customtags.getMethodReferenceForSymbolicTest import org.utbot.summary.tag.StatementTag import org.utbot.summary.tag.TraceTag import soot.SootMethod @@ -67,7 +68,7 @@ class SimpleCommentBuilderTest { @Test fun `builds inline link for method`() { - val methodReference = getMethodReference("org.utbot.ClassName", "methodName", listOf(), false) + val methodReference = getMethodReferenceForSymbolicTest("org.utbot.ClassName", "methodName", listOf(), false) val expectedMethodReference = "{@link org.utbot.ClassName#methodName()}" assertEquals(methodReference, expectedMethodReference) } @@ -75,9 +76,8 @@ class SimpleCommentBuilderTest { @Test fun `builds inline link for method in nested class`() { val methodReference = - getMethodReference("org.utbot.ClassName\$NestedClassName", "methodName", listOf(), false) + getMethodReferenceForSymbolicTest("org.utbot.ClassName\$NestedClassName", "methodName", listOf(), false) val expectedMethodReference = "{@link org.utbot.ClassName.NestedClassName#methodName()}" assertEquals(methodReference, expectedMethodReference) } - } \ No newline at end of file