Skip to content

Commit 0d2c65b

Browse files
authoredSep 27, 2022
Multiple values for custom javadoc tags (#987)
* Add a Javadoc tag for each value in the comment if there are several values for the same tag * Review fixes, fixed broken test * Fix broken test
·
2023.102022.10
1 parent bcece73 commit 0d2c65b

File tree

4 files changed

+35
-22
lines changed

4 files changed

+35
-22
lines changed
 

‎utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/javadoc/UtJavaDocInfoGenerator.kt

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import com.intellij.lang.documentation.DocumentationMarkup
66
import com.intellij.openapi.project.DumbService
77
import com.intellij.openapi.project.IndexNotReadyException
88
import com.intellij.openapi.util.text.StringUtil
9-
import com.intellij.psi.*
9+
import com.intellij.psi.JavaDocTokenType
10+
import com.intellij.psi.PsiElement
11+
import com.intellij.psi.PsiJavaToken
12+
import com.intellij.psi.PsiRecursiveElementWalkingVisitor
13+
import com.intellij.psi.PsiWhiteSpace
1014
import com.intellij.psi.javadoc.PsiDocComment
1115
import com.intellij.psi.javadoc.PsiDocTag
1216
import com.intellij.psi.javadoc.PsiDocToken
@@ -22,6 +26,7 @@ private const val MESSAGE_SEPARATOR = ":"
2226
private const val PARAGRAPH_TAG = "<p>"
2327
private const val CODE_TAG_START = "<code>"
2428
private const val CODE_TAG_END = "</code>"
29+
private const val BR_TAG = "<br>"
2530

2631
private val logger = KotlinLogging.logger {}
2732

@@ -51,22 +56,30 @@ class UtJavaDocInfoGenerator {
5156
}
5257

5358
/**
54-
* Searches for UtBot tag in the comment and generates a related section for it.
59+
* Searches for UtBot tags in the comment and generates a related section for it.
5560
*/
5661
private fun generateUtTagSection(
5762
builder: StringBuilder,
5863
comment: PsiDocComment,
5964
utTag: UtCustomJavaDocTagProvider.UtCustomTagInfo
6065
) {
61-
val tag = comment.findTagByName(utTag.name) ?: return
62-
startHeaderSection(builder, utTag.getMessage()).append(PARAGRAPH_TAG)
63-
val sectionContent = buildString {
64-
generateValue(this, tag.dataElements)
65-
trim()
66-
}
66+
val tags = comment.findTagsByName(utTag.name)
67+
68+
if (tags.isNotEmpty()) {
69+
startHeaderSection(builder, utTag.getMessage()).append(PARAGRAPH_TAG)
6770

68-
builder.append(sectionContent)
69-
builder.append(DocumentationMarkup.SECTION_END)
71+
tags.mapIndexed { index, it ->
72+
buildString {
73+
generateValue(this, it.dataElements)
74+
75+
if (index < tags.size - 1) {
76+
this.append(", $BR_TAG")
77+
}
78+
}
79+
}.forEach { builder.append(it) }
80+
81+
builder.append(DocumentationMarkup.SECTION_END)
82+
}
7083
}
7184

7285
private fun startHeaderSection(builder: StringBuilder, message: String): StringBuilder =

‎utbot-summary-tests/src/test/kotlin/examples/exceptions/SummaryExceptionClusteringExamplesTest.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@ class SummaryExceptionClusteringExamplesTest : SummaryTestCaseGeneratorTest(
2121

2222
val summary2 = "@utbot.classUnderTest {@link ExceptionClusteringExamples}\n" +
2323
"@utbot.methodUnderTest {@link org.utbot.examples.exceptions.ExceptionClusteringExamples#differentExceptions(int)}\n" +
24-
"@utbot.executesCondition {@code (i == 0): False},\n" +
25-
"{@code (i == 1): True}\n" +
24+
"@utbot.executesCondition {@code (i == 0): False}\n" +
25+
"@utbot.executesCondition {@code (i == 1): True}\n" +
2626
"@utbot.throwsException {@link org.utbot.examples.exceptions.MyCheckedException} after condition: i == 1"
2727
val summary3 = "@utbot.classUnderTest {@link ExceptionClusteringExamples}\n" +
2828
"@utbot.methodUnderTest {@link org.utbot.examples.exceptions.ExceptionClusteringExamples#differentExceptions(int)}\n" +
29-
"@utbot.executesCondition {@code (i == 0): False},\n" +
30-
"{@code (i == 1): False},\n" +
31-
"{@code (i == 2): True}\n" +
29+
"@utbot.executesCondition {@code (i == 0): False}\n" +
30+
"@utbot.executesCondition {@code (i == 1): False}\n" +
31+
"@utbot.executesCondition {@code (i == 2): True}\n" +
3232
"@utbot.throwsException {@link java.lang.IllegalArgumentException} after condition: i == 2"
3333
val summary4 = "@utbot.classUnderTest {@link ExceptionClusteringExamples}\n" +
3434
"@utbot.methodUnderTest {@link org.utbot.examples.exceptions.ExceptionClusteringExamples#differentExceptions(int)}\n" +
35-
"@utbot.executesCondition {@code (i == 0): False},\n" +
36-
"{@code (i == 1): False},\n" +
37-
"{@code (i == 2): False}\n" +
35+
"@utbot.executesCondition {@code (i == 0): False}\n" +
36+
"@utbot.executesCondition {@code (i == 1): False}\n" +
37+
"@utbot.executesCondition {@code (i == 2): False}\n" +
3838
"@utbot.returnsFrom {@code return i * 2;}\n"
3939

4040
val methodName1 = "testDifferentExceptions_IEqualsZero"

‎utbot-summary-tests/src/test/kotlin/examples/recursion/SummaryRecursionTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ class SummaryRecursionTest : SummaryTestCaseGeneratorTest(
1616
fun testFib() {
1717
val summary1 = "@utbot.classUnderTest {@link Recursion}\n" +
1818
"@utbot.methodUnderTest {@link org.utbot.examples.recursion.Recursion#fib(int)}\n" +
19-
"@utbot.executesCondition {@code (n == 0): False},\n" +
20-
"{@code (n == 1): True}\n" +
19+
"@utbot.executesCondition {@code (n == 0): False}\n" +
20+
"@utbot.executesCondition {@code (n == 1): True}\n" +
2121
"@utbot.returnsFrom {@code return 1;}"
2222
val summary2 = "@utbot.classUnderTest {@link Recursion}\n" +
2323
"@utbot.methodUnderTest {@link org.utbot.examples.recursion.Recursion#fib(int)}\n" +

‎utbot-summary/src/main/kotlin/org/utbot/summary/comment/CustomJavaDocTagProvider.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ sealed class CustomJavaDocTag(
6161
DocRegularStmt("@$name $value\n")
6262
}
6363
is List<*> -> value.takeIf { it.isNotEmpty() }?.let {
64-
val valueToString = value.joinToString(separator = ",\n", postfix = "\n")
64+
val valueToString = value.joinToString(separator = "\n", postfix = "\n") {"@$name $it"}
6565

66-
DocRegularStmt("@$name $valueToString")
66+
DocRegularStmt(valueToString)
6767
}
6868
else -> null
6969
}

0 commit comments

Comments
 (0)
Please sign in to comment.