diff options
-rw-r--r-- | src/Kotlin/KotlinLanguageService.kt | 12 | ||||
-rw-r--r-- | test/data/format/accessor.get.md | 12 | ||||
-rw-r--r-- | test/data/format/accessor.kt | 5 | ||||
-rw-r--r-- | test/data/format/accessor.set.md | 12 | ||||
-rw-r--r-- | test/data/format/deprecated.class.html | 2 | ||||
-rw-r--r-- | test/src/format/MarkdownFormatTest.kt | 11 |
6 files changed, 51 insertions, 3 deletions
diff --git a/src/Kotlin/KotlinLanguageService.kt b/src/Kotlin/KotlinLanguageService.kt index 80a76791..b7723285 100644 --- a/src/Kotlin/KotlinLanguageService.kt +++ b/src/Kotlin/KotlinLanguageService.kt @@ -25,7 +25,8 @@ class KotlinLanguageService : LanguageService { DocumentationNode.Kind.Modifier -> renderModifier(node) DocumentationNode.Kind.Constructor, DocumentationNode.Kind.Function, - DocumentationNode.Kind.ClassObjectFunction -> renderFunction(node) + DocumentationNode.Kind.ClassObjectFunction, + DocumentationNode.Kind.PropertyAccessor -> renderFunction(node) DocumentationNode.Kind.Property, DocumentationNode.Kind.ClassObjectProperty -> renderProperty(node) else -> ContentText("${node.kind}: ${node.name}") @@ -214,6 +215,7 @@ class KotlinLanguageService : LanguageService { DocumentationNode.Kind.Constructor -> identifier(node.owner!!.name) DocumentationNode.Kind.Function, DocumentationNode.Kind.ClassObjectFunction -> keyword("fun ") + DocumentationNode.Kind.PropertyAccessor -> {} else -> throw IllegalArgumentException("Node $node is not a function-like object") } renderTypeParametersForNode(node) @@ -231,12 +233,18 @@ class KotlinLanguageService : LanguageService { renderParameter(it) } symbol(")") - if (node.kind != org.jetbrains.dokka.DocumentationNode.Kind.Constructor) { + if (needReturnType(node)) { symbol(": ") renderType(node.detail(DocumentationNode.Kind.Type)) } } + private fun needReturnType(node: DocumentationNode) = when(node.kind) { + DocumentationNode.Kind.Constructor -> false + DocumentationNode.Kind.PropertyAccessor -> node.name == "get" + else -> true + } + private fun ContentNode.renderProperty(node: DocumentationNode) { renderModifiersForNode(node) renderAnnotationsForNode(node) diff --git a/test/data/format/accessor.get.md b/test/data/format/accessor.get.md new file mode 100644 index 00000000..b4da2a03 --- /dev/null +++ b/test/data/format/accessor.get.md @@ -0,0 +1,12 @@ +[test](out.md) / [](out.md) / [C](out.md) / [x](out.md) / [get](out.md) + + +# get + + +``` +get(): String +``` + + + diff --git a/test/data/format/accessor.kt b/test/data/format/accessor.kt new file mode 100644 index 00000000..b6ed9624 --- /dev/null +++ b/test/data/format/accessor.kt @@ -0,0 +1,5 @@ +class C() { + var x: String + get() = "" + set(value) { } +} diff --git a/test/data/format/accessor.set.md b/test/data/format/accessor.set.md new file mode 100644 index 00000000..8b9db263 --- /dev/null +++ b/test/data/format/accessor.set.md @@ -0,0 +1,12 @@ +[test](out.md) / [](out.md) / [C](out.md) / [x](out.md) / [set](out.md) + + +# set + + +``` +set(value: String) +``` + + + diff --git a/test/data/format/deprecated.class.html b/test/data/format/deprecated.class.html index 87599082..1442026c 100644 --- a/test/data/format/deprecated.class.html +++ b/test/data/format/deprecated.class.html @@ -38,7 +38,7 @@ <td> <a href="out.html">get</a></td> <td> -<code></code></td> +<code><span class="identifier">get</span><span class="symbol">(</span><span class="symbol">)</span><span class="symbol">: </span><span class="identifier">Int</span></code></td> </tr> </tbody> </table> diff --git a/test/src/format/MarkdownFormatTest.kt b/test/src/format/MarkdownFormatTest.kt index 5a4bacb2..efde3139 100644 --- a/test/src/format/MarkdownFormatTest.kt +++ b/test/src/format/MarkdownFormatTest.kt @@ -81,4 +81,15 @@ public class MarkdownFormatTest { markdownService.appendNodes(tempLocation, output, model.members.single().members) } } + + Test fun accessor() { + verifyOutput("test/data/format/accessor.kt", ".get.md") { model, output -> + val propertyNode = model.members.single().members.first { it.name == "C" }.members.first { it.name == "x" } + markdownService.appendNodes(tempLocation, output, listOf(propertyNode.members[0])) + } + verifyOutput("test/data/format/accessor.kt", ".set.md") { model, output -> + val propertyNode = model.members.single().members.first { it.name == "C" }.members.first { it.name == "x" } + markdownService.appendNodes(tempLocation, output, listOf(propertyNode.members[1])) + } + } } |