Skip to content

Multiple values for custom javadoc tags #987

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,6 +26,7 @@ private const val MESSAGE_SEPARATOR = ":"
private const val PARAGRAPH_TAG = "<p>"
private const val CODE_TAG_START = "<code>"
private const val CODE_TAG_END = "</code>"
private const val BR_TAG = "<br>"

private val logger = KotlinLogging.logger {}

Expand Down Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down