aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Kotlin/KotlinLanguageService.kt12
-rw-r--r--test/data/format/classWithClassObject.kt7
-rw-r--r--test/data/format/classWithClassObject.md53
-rw-r--r--test/src/TestAPI.kt3
-rw-r--r--test/src/format/MarkdownFormatTest.kt6
5 files changed, 76 insertions, 5 deletions
diff --git a/src/Kotlin/KotlinLanguageService.kt b/src/Kotlin/KotlinLanguageService.kt
index c9275879..a4016849 100644
--- a/src/Kotlin/KotlinLanguageService.kt
+++ b/src/Kotlin/KotlinLanguageService.kt
@@ -31,8 +31,10 @@ class KotlinLanguageService : LanguageService {
DocumentationNode.Kind.Modifier -> renderModifier(node)
DocumentationNode.Kind.Constructor,
- DocumentationNode.Kind.Function -> renderFunction(node)
- DocumentationNode.Kind.Property -> renderProperty(node)
+ DocumentationNode.Kind.Function,
+ DocumentationNode.Kind.ClassObjectFunction -> renderFunction(node)
+ DocumentationNode.Kind.Property,
+ DocumentationNode.Kind.ClassObjectProperty -> renderProperty(node)
else -> ContentText("${node.kind}: ${node.name}")
}
}
@@ -189,7 +191,8 @@ class KotlinLanguageService : LanguageService {
renderModifiersForNode(node)
when (node.kind) {
DocumentationNode.Kind.Constructor -> identifier(node.owner!!.name)
- DocumentationNode.Kind.Function -> keyword("fun ")
+ DocumentationNode.Kind.Function,
+ DocumentationNode.Kind.ClassObjectFunction -> keyword("fun ")
else -> throw IllegalArgumentException("Node $node is not a function-like object")
}
renderTypeParametersForNode(node)
@@ -216,7 +219,8 @@ class KotlinLanguageService : LanguageService {
private fun ContentNode.renderProperty(node: DocumentationNode) {
renderModifiersForNode(node)
when (node.kind) {
- DocumentationNode.Kind.Property -> keyword("val ")
+ DocumentationNode.Kind.Property,
+ DocumentationNode.Kind.ClassObjectProperty -> keyword("val ")
else -> throw IllegalArgumentException("Node $node is not a property")
}
renderTypeParametersForNode(node)
diff --git a/test/data/format/classWithClassObject.kt b/test/data/format/classWithClassObject.kt
new file mode 100644
index 00000000..459efad6
--- /dev/null
+++ b/test/data/format/classWithClassObject.kt
@@ -0,0 +1,7 @@
+class Klass() {
+ class object {
+ val x = 1
+
+ fun foo() {}
+ }
+}
diff --git a/test/data/format/classWithClassObject.md b/test/data/format/classWithClassObject.md
new file mode 100644
index 00000000..10cac365
--- /dev/null
+++ b/test/data/format/classWithClassObject.md
@@ -0,0 +1,53 @@
+[test](out.md) / [](out.md) / [Klass](out.md)
+
+
+# Klass
+
+
+```
+class Klass
+```
+
+
+
+
+### Constructors
+
+
+|
+[<init>](out.md)
+
+ |
+```
+public Klass()
+```
+
+ |
+
+
+### Class Object Properties
+
+
+|
+[x](out.md)
+
+ |
+```
+val x: Int
+```
+
+ |
+
+
+### Class Object Functions
+
+
+|
+[foo](out.md)
+
+ |
+```
+fun foo(): Unit
+```
+
+ |
diff --git a/test/src/TestAPI.kt b/test/src/TestAPI.kt
index a16a0b57..6f4e34c2 100644
--- a/test/src/TestAPI.kt
+++ b/test/src/TestAPI.kt
@@ -55,8 +55,9 @@ public fun verifyOutput(path: String, outputGenerator: (DocumentationModule, Str
verifyModel(path) {
val output = StringBuilder()
outputGenerator(it, output)
+ val trimmedOutput = output.toString().split('\n').map { it.trimTrailing() }.join("\n")
val expectedOutput = File(path.replace(".kt", ".md")).readText()
- assertEquals(expectedOutput, output.toString())
+ assertEquals(expectedOutput.trimTrailing(), trimmedOutput)
}
}
diff --git a/test/src/format/MarkdownFormatTest.kt b/test/src/format/MarkdownFormatTest.kt
index beb727da..ea501c53 100644
--- a/test/src/format/MarkdownFormatTest.kt
+++ b/test/src/format/MarkdownFormatTest.kt
@@ -13,4 +13,10 @@ public class MarkdownFormatTest {
markdownService.appendNodes(tempLocation, output, model.members.single().members)
}
}
+
+ Test fun classWithClassObject() {
+ verifyOutput("test/data/format/classWithClassObject.kt") { model, output ->
+ markdownService.appendNodes(tempLocation, output, model.members.single().members)
+ }
+ }
}