aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Java/JavaDocumentationBuilder.kt18
-rw-r--r--src/Kotlin/DocumentationBuilder.kt9
-rw-r--r--src/Model/Content.kt7
-rw-r--r--test/src/model/JavaTest.kt11
4 files changed, 37 insertions, 8 deletions
diff --git a/src/Java/JavaDocumentationBuilder.kt b/src/Java/JavaDocumentationBuilder.kt
index 0737e504..660ffafb 100644
--- a/src/Java/JavaDocumentationBuilder.kt
+++ b/src/Java/JavaDocumentationBuilder.kt
@@ -15,6 +15,8 @@ import com.intellij.psi.PsiModifierListOwner
import com.intellij.psi.PsiModifier
import com.intellij.psi.PsiArrayType
import com.intellij.psi.PsiTypeParameter
+import com.intellij.psi.javadoc.PsiDocTag
+import com.intellij.psi.javadoc.PsiDocTagValue
public class JavaDocumentationBuilder() {
fun appendFile(file: PsiJavaFile, module: DocumentationModule) {
@@ -29,9 +31,25 @@ public class JavaDocumentationBuilder() {
val text = if (result.isEmpty()) it.getText().trimLeading() else it.getText()
result.append(ContentText(text))
}
+ docComment.getTags().forEach {
+ val subjectName = it.getSubjectName()
+ val section = result.addSection(javadocSectionDisplayName(it.getName()), subjectName)
+ it.getDataElements().forEach {
+ if (it !is PsiDocTagValue) {
+ section.append(ContentText(it.getText()))
+ }
+ }
+ }
return result
}
+ fun PsiDocTag.getSubjectName(): String? {
+ if (getName() == "param") {
+ return getValueElement()?.getText()
+ }
+ return null
+ }
+
fun DocumentationNode(element: PsiNamedElement,
kind: Kind,
name: String = element.getName() ?: "<anonymous>"): DocumentationNode {
diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt
index 1ad1e9e8..775c959a 100644
--- a/src/Kotlin/DocumentationBuilder.kt
+++ b/src/Kotlin/DocumentationBuilder.kt
@@ -61,7 +61,7 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati
"see" ->
content.addTagToSeeAlso(it)
else -> {
- val section = content.addSection(displayName(it.getName()), it.getSubjectName())
+ val section = content.addSection(javadocSectionDisplayName(it.getName()), it.getSubjectName())
val sectionContent = it.getContent()
val markdownNode = parseMarkdown(sectionContent)
buildInlineContentTo(markdownNode, section)
@@ -74,13 +74,6 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati
fun KDocSection.getTags(): Array<KDocTag> = PsiTreeUtil.getChildrenOfType(this, javaClass<KDocTag>()) ?: array()
- fun displayName(sectionName: String?): String? =
- when(sectionName) {
- "param" -> "Parameters"
- "throws", "exception" -> "Exceptions"
- else -> sectionName?.capitalize()
- }
-
private fun Content.addTagToSeeAlso(seeTag: KDocTag) {
val subjectName = seeTag.getSubjectName()
if (subjectName != null) {
diff --git a/src/Model/Content.kt b/src/Model/Content.kt
index f74a4461..9864ee42 100644
--- a/src/Model/Content.kt
+++ b/src/Model/Content.kt
@@ -132,3 +132,10 @@ public class Content() : ContentBlock() {
val Empty = Content()
}
}
+
+fun javadocSectionDisplayName(sectionName: String?): String? =
+ when(sectionName) {
+ "param" -> "Parameters"
+ "throws", "exception" -> "Exceptions"
+ else -> sectionName?.capitalize()
+ }
diff --git a/test/src/model/JavaTest.kt b/test/src/model/JavaTest.kt
index fcfae21a..2f67d7e8 100644
--- a/test/src/model/JavaTest.kt
+++ b/test/src/model/JavaTest.kt
@@ -13,6 +13,17 @@ public class JavaTest {
assertEquals("fn", name)
assertEquals(DocumentationNode.Kind.Function, kind)
assertEquals("Summary for Function", content.summary.toTestString())
+ assertEquals(2, content.sections.size())
+ with(content.sections[0]) {
+ assertEquals("Parameters", tag)
+ assertEquals("name", subjectName)
+ assertEquals("is String parameter ", toTestString())
+ }
+ with(content.sections[1]) {
+ assertEquals("Parameters", tag)
+ assertEquals("value", subjectName)
+ assertEquals("is int parameter", toTestString())
+ }
assertEquals("Unit", detail(DocumentationNode.Kind.Type).name)
assertTrue(members.none())
assertTrue(links.none())