Skip to content

Avoid summary duplication #985 #1015

New issue

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

By clicking “No 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? No Sign in to your account

Merged
merged 2 commits into from
Sep 28, 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 @@ -5,6 +5,7 @@ import com.intellij.codeInsight.javadoc.JavaDocInfoGenerator
import com.intellij.lang.java.JavaDocumentationProvider
import com.intellij.psi.PsiDocCommentBase
import com.intellij.psi.PsiJavaDocumentedElement
import com.intellij.psi.javadoc.PsiDocComment

/**
* To render UtBot custom JavaDoc tags messages, we need to override basic behaviour of [JavaDocumentationProvider].
Expand All @@ -25,12 +26,27 @@ class UtDocumentationProvider : JavaDocumentationProvider() {
// get JavaDoc comment rendered by the platform.
val baseJavaDocInfo = baseJavaDocInfoGenerator.generateRenderedDocInfo()

return getRenderedDoc(baseJavaDocInfo, docComment, comment)
}

/**
* Processes JavaDoc generated by IJ platform to render plugin's custom tags correctly.
*/
private fun getRenderedDoc(
baseJavaDocInfo: String?,
docComment: PsiDocComment,
comment: PsiDocCommentBase
): String? {
// add UTBot sections with custom tags.
val utJavaDocInfoGenerator = UtJavaDocInfoGenerator()
val javaDocInfoWithUtSections =
utJavaDocInfoGenerator.addUtBotSpecificSectionsToJavaDoc(baseJavaDocInfo, docComment)

return JavaDocExternalFilter.filterInternalDocInfo(javaDocInfoWithUtSections)
return if (baseJavaDocInfo != null && baseJavaDocInfo.contains("utbot")) {
val javaDocInfoWithUtSections =
utJavaDocInfoGenerator.addUtBotSpecificSectionsToJavaDoc(docComment)
val finalJavaDoc = replaceTagNamesWithMessages(javaDocInfoWithUtSections)
JavaDocExternalFilter.filterInternalDocInfo(finalJavaDoc)
} else {
super.generateRenderedDoc(comment)
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,14 @@ private val logger = KotlinLogging.logger {}
* so delete it after updating and use basic [com.intellij.codeInsight.javadoc.JavaDocInfoGenerator].
*/
class UtJavaDocInfoGenerator {
fun addUtBotSpecificSectionsToJavaDoc(javadoc: String?, comment: PsiDocComment): String {
val builder = if (javadoc == null) {
StringBuilder()
} else {
StringBuilder(javadoc)
}
fun addUtBotSpecificSectionsToJavaDoc(comment: PsiDocComment): String {
val builder = StringBuilder()

val docTagProvider = UtCustomJavaDocTagProvider()
docTagProvider.supportedTags.forEach {
generateUtTagSection(builder, comment, it)
}

return builder.toString()
}

Expand Down