Skip to content

Commit 9338f5a

Browse files
committed
fix rendering after updating to idea 2022.1. now we don't need to generate comment content with HTML tags, we need only replace custom tags' names with their messages to make it look nice
1 parent c01d8dd commit 9338f5a

File tree

2 files changed

+25
-237
lines changed

2 files changed

+25
-237
lines changed
Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
package org.utbot.intellij.plugin.javadoc
22

33
import com.intellij.codeInsight.javadoc.JavaDocExternalFilter
4-
import com.intellij.codeInsight.javadoc.JavaDocInfoGenerator
4+
import com.intellij.codeInsight.javadoc.JavaDocInfoGeneratorFactory
55
import com.intellij.lang.java.JavaDocumentationProvider
66
import com.intellij.psi.PsiDocCommentBase
77
import com.intellij.psi.PsiJavaDocumentedElement
88

99
/**
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.
1412
*/
1513
class UtDocumentationProvider : JavaDocumentationProvider() {
1614
override fun generateRenderedDoc(comment: PsiDocCommentBase): String? {
@@ -20,16 +18,29 @@ class UtDocumentationProvider : JavaDocumentationProvider() {
2018
return ""
2119
}
2220

23-
val docComment = target.docComment ?: return ""
21+
val baseJavaDocInfoGenerator = JavaDocInfoGeneratorFactory.getBuilder(target.getProject())
22+
.setPsiElement(target)
23+
.setIsGenerationForRenderedDoc(true)
24+
.create()
2425

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())
3227

33-
return JavaDocExternalFilter.filterInternalDocInfo(javaDocInfoWithUtSections)
28+
return JavaDocExternalFilter.filterInternalDocInfo(finalDocContent)
3429
}
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+
} ?: ""
3546
}

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

Lines changed: 0 additions & 223 deletions
This file was deleted.

0 commit comments

Comments
 (0)