1
1
package org.utbot.intellij.plugin.javadoc
2
2
3
3
import com.intellij.codeInsight.javadoc.JavaDocExternalFilter
4
- import com.intellij.codeInsight.javadoc.JavaDocInfoGenerator
4
+ import com.intellij.codeInsight.javadoc.JavaDocInfoGeneratorFactory
5
5
import com.intellij.lang.java.JavaDocumentationProvider
6
6
import com.intellij.psi.PsiDocCommentBase
7
7
import com.intellij.psi.PsiJavaDocumentedElement
8
8
9
9
/* *
10
- * To render UtBot custom JavaDoc tags correctly, we need to override the way it generates HTML tags for comments.
11
- * We get JavaDoc info generated by IJ platform and include sections related to UTBot,
12
- * each section relates to the specific JavaDoc tag.
13
- * It renders text, code, and links.
10
+ * To render UtBot custom JavaDoc tags messages, we need to override basic behaviour of [JavaDocumentationProvider].
11
+ * The IJ platform knows only custom tag names, so we need to add their messages in rendered comments to make it look nice.
14
12
*/
15
13
class UtDocumentationProvider : JavaDocumentationProvider () {
16
14
override fun generateRenderedDoc (comment : PsiDocCommentBase ): String? {
@@ -20,16 +18,29 @@ class UtDocumentationProvider : JavaDocumentationProvider() {
20
18
return " "
21
19
}
22
20
23
- val docComment = target.docComment ? : return " "
21
+ val baseJavaDocInfoGenerator = JavaDocInfoGeneratorFactory .getBuilder(target.getProject())
22
+ .setPsiElement(target)
23
+ .setIsGenerationForRenderedDoc(true )
24
+ .create()
24
25
25
- val baseJavaDocInfoGenerator = JavaDocInfoGenerator (target.project, target)
26
- // get JavaDoc comment rendered by the platform.
27
- val baseJavaDocInfo = baseJavaDocInfoGenerator.generateRenderedDocInfo()
28
- val utJavaDocInfoGenerator = UtJavaDocInfoGenerator ()
29
- // add UTBot sections with custom tags.
30
- val javaDocInfoWithUtSections =
31
- utJavaDocInfoGenerator.addUtBotSpecificSectionsToJavaDoc(baseJavaDocInfo, docComment)
26
+ val finalDocContent = replaceTagNamesWithMessages(baseJavaDocInfoGenerator.generateRenderedDocInfo())
32
27
33
- return JavaDocExternalFilter .filterInternalDocInfo(javaDocInfoWithUtSections )
28
+ return JavaDocExternalFilter .filterInternalDocInfo(finalDocContent )
34
29
}
30
+
31
+ /* *
32
+ * Replaces names of plugin's custom JavaDoc tags with their messages in the comment generated by the IJ platform.
33
+ * Example: utbot.MethodUnderTest -> Method under test.
34
+ */
35
+ private fun replaceTagNamesWithMessages (comment : String? ) =
36
+ comment?.let {
37
+ val docTagProvider = UtCustomJavaDocTagProvider ()
38
+ docTagProvider.supportedTags.fold(it) { result, tag ->
39
+ if (result.contains(tag.name)) {
40
+ result.replace(tag.name, " ${tag.getMessage()} :" )
41
+ } else {
42
+ result
43
+ }
44
+ }
45
+ } ? : " "
35
46
}
0 commit comments