diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/javadoc/UtJavaDocInfoGenerator.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/javadoc/UtJavaDocInfoGenerator.kt index ae597280ea..8a359e2044 100644 --- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/javadoc/UtJavaDocInfoGenerator.kt +++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/javadoc/UtJavaDocInfoGenerator.kt @@ -6,7 +6,11 @@ import com.intellij.lang.documentation.DocumentationMarkup import com.intellij.openapi.project.DumbService import com.intellij.openapi.project.IndexNotReadyException import com.intellij.openapi.util.text.StringUtil -import com.intellij.psi.* +import com.intellij.psi.JavaDocTokenType +import com.intellij.psi.PsiElement +import com.intellij.psi.PsiJavaToken +import com.intellij.psi.PsiRecursiveElementWalkingVisitor +import com.intellij.psi.PsiWhiteSpace import com.intellij.psi.javadoc.PsiDocComment import com.intellij.psi.javadoc.PsiDocTag import com.intellij.psi.javadoc.PsiDocToken @@ -22,6 +26,7 @@ private const val MESSAGE_SEPARATOR = ":" private const val PARAGRAPH_TAG = "

" private const val CODE_TAG_START = "" private const val CODE_TAG_END = "" +private const val BR_TAG = "
" private val logger = KotlinLogging.logger {} @@ -51,22 +56,30 @@ class UtJavaDocInfoGenerator { } /** - * Searches for UtBot tag in the comment and generates a related section for it. + * Searches for UtBot tags in the comment and generates a related section for it. */ private fun generateUtTagSection( builder: StringBuilder, comment: PsiDocComment, utTag: UtCustomJavaDocTagProvider.UtCustomTagInfo ) { - val tag = comment.findTagByName(utTag.name) ?: return - startHeaderSection(builder, utTag.getMessage()).append(PARAGRAPH_TAG) - val sectionContent = buildString { - generateValue(this, tag.dataElements) - trim() - } + val tags = comment.findTagsByName(utTag.name) + + if (tags.isNotEmpty()) { + startHeaderSection(builder, utTag.getMessage()).append(PARAGRAPH_TAG) - builder.append(sectionContent) - builder.append(DocumentationMarkup.SECTION_END) + tags.mapIndexed { index, it -> + buildString { + generateValue(this, it.dataElements) + + if (index < tags.size - 1) { + this.append(", $BR_TAG") + } + } + }.forEach { builder.append(it) } + + builder.append(DocumentationMarkup.SECTION_END) + } } private fun startHeaderSection(builder: StringBuilder, message: String): StringBuilder = diff --git a/utbot-summary-tests/src/test/kotlin/examples/exceptions/SummaryExceptionClusteringExamplesTest.kt b/utbot-summary-tests/src/test/kotlin/examples/exceptions/SummaryExceptionClusteringExamplesTest.kt index d86144f380..f2a7ede1ab 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/exceptions/SummaryExceptionClusteringExamplesTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/exceptions/SummaryExceptionClusteringExamplesTest.kt @@ -21,20 +21,20 @@ class SummaryExceptionClusteringExamplesTest : SummaryTestCaseGeneratorTest( val summary2 = "@utbot.classUnderTest {@link ExceptionClusteringExamples}\n" + "@utbot.methodUnderTest {@link org.utbot.examples.exceptions.ExceptionClusteringExamples#differentExceptions(int)}\n" + - "@utbot.executesCondition {@code (i == 0): False},\n" + - "{@code (i == 1): True}\n" + + "@utbot.executesCondition {@code (i == 0): False}\n" + + "@utbot.executesCondition {@code (i == 1): True}\n" + "@utbot.throwsException {@link org.utbot.examples.exceptions.MyCheckedException} after condition: i == 1" val summary3 = "@utbot.classUnderTest {@link ExceptionClusteringExamples}\n" + "@utbot.methodUnderTest {@link org.utbot.examples.exceptions.ExceptionClusteringExamples#differentExceptions(int)}\n" + - "@utbot.executesCondition {@code (i == 0): False},\n" + - "{@code (i == 1): False},\n" + - "{@code (i == 2): True}\n" + + "@utbot.executesCondition {@code (i == 0): False}\n" + + "@utbot.executesCondition {@code (i == 1): False}\n" + + "@utbot.executesCondition {@code (i == 2): True}\n" + "@utbot.throwsException {@link java.lang.IllegalArgumentException} after condition: i == 2" val summary4 = "@utbot.classUnderTest {@link ExceptionClusteringExamples}\n" + "@utbot.methodUnderTest {@link org.utbot.examples.exceptions.ExceptionClusteringExamples#differentExceptions(int)}\n" + - "@utbot.executesCondition {@code (i == 0): False},\n" + - "{@code (i == 1): False},\n" + - "{@code (i == 2): False}\n" + + "@utbot.executesCondition {@code (i == 0): False}\n" + + "@utbot.executesCondition {@code (i == 1): False}\n" + + "@utbot.executesCondition {@code (i == 2): False}\n" + "@utbot.returnsFrom {@code return i * 2;}\n" val methodName1 = "testDifferentExceptions_IEqualsZero" diff --git a/utbot-summary-tests/src/test/kotlin/examples/recursion/SummaryRecursionTest.kt b/utbot-summary-tests/src/test/kotlin/examples/recursion/SummaryRecursionTest.kt index fdfee98edb..eeba46cc16 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/recursion/SummaryRecursionTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/recursion/SummaryRecursionTest.kt @@ -16,8 +16,8 @@ class SummaryRecursionTest : SummaryTestCaseGeneratorTest( fun testFib() { val summary1 = "@utbot.classUnderTest {@link Recursion}\n" + "@utbot.methodUnderTest {@link org.utbot.examples.recursion.Recursion#fib(int)}\n" + - "@utbot.executesCondition {@code (n == 0): False},\n" + - "{@code (n == 1): True}\n" + + "@utbot.executesCondition {@code (n == 0): False}\n" + + "@utbot.executesCondition {@code (n == 1): True}\n" + "@utbot.returnsFrom {@code return 1;}" val summary2 = "@utbot.classUnderTest {@link Recursion}\n" + "@utbot.methodUnderTest {@link org.utbot.examples.recursion.Recursion#fib(int)}\n" + 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 index 4244605b69..4c98d8a379 100644 --- a/utbot-summary/src/main/kotlin/org/utbot/summary/comment/CustomJavaDocTagProvider.kt +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/CustomJavaDocTagProvider.kt @@ -61,9 +61,9 @@ sealed class CustomJavaDocTag( DocRegularStmt("@$name $value\n") } is List<*> -> value.takeIf { it.isNotEmpty() }?.let { - val valueToString = value.joinToString(separator = ",\n", postfix = "\n") + val valueToString = value.joinToString(separator = "\n", postfix = "\n") {"@$name $it"} - DocRegularStmt("@$name $valueToString") + DocRegularStmt(valueToString) } else -> null }