aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Kotlin/KotlinLanguageService.kt43
-rw-r--r--test/data/format/summarizeSignaturesProperty.kt20
-rw-r--r--test/data/format/summarizeSignaturesProperty.md23
-rw-r--r--test/src/format/MarkdownFormatTest.kt6
4 files changed, 74 insertions, 18 deletions
diff --git a/src/Kotlin/KotlinLanguageService.kt b/src/Kotlin/KotlinLanguageService.kt
index 513e1a58..c08a6cbb 100644
--- a/src/Kotlin/KotlinLanguageService.kt
+++ b/src/Kotlin/KotlinLanguageService.kt
@@ -49,7 +49,12 @@ class KotlinLanguageService : LanguageService {
val functionWithTypeParameter = nodes.firstOrNull { it.details(DocumentationNode.Kind.TypeParameter).any() } ?: return null
return content {
val typeParameter = functionWithTypeParameter.details(DocumentationNode.Kind.TypeParameter).first()
- renderFunction(functionWithTypeParameter, RenderMode.SUMMARY, SummarizingMapper(receiverKind, typeParameter.name))
+ if (functionWithTypeParameter.kind == DocumentationNode.Kind.Function) {
+ renderFunction(functionWithTypeParameter, RenderMode.SUMMARY, SummarizingMapper(receiverKind, typeParameter.name))
+ }
+ else {
+ renderProperty(functionWithTypeParameter, RenderMode.SUMMARY, SummarizingMapper(receiverKind, typeParameter.name))
+ }
}
}
@@ -62,7 +67,7 @@ class KotlinLanguageService : LanguageService {
}
private fun DocumentationNode.getReceiverQName(): String? {
- if (kind != DocumentationNode.Kind.Function) return null
+ if (kind != DocumentationNode.Kind.Function && kind != DocumentationNode.Kind.Property) return null
val receiver = details(DocumentationNode.Kind.Receiver).singleOrNull() ?: return null
val receiverType = receiver.detail(DocumentationNode.Kind.Type)
return (receiverType.links.firstOrNull() ?: receiverType.hiddenLinks.firstOrNull())?.qualifiedName()
@@ -322,16 +327,7 @@ class KotlinLanguageService : LanguageService {
text(" ")
}
- val receiver = node.details(DocumentationNode.Kind.Receiver).singleOrNull()
- if (receiver != null) {
- if (signatureMapper != null) {
- signatureMapper.renderReceiver(receiver, this)
- }
- else {
- renderType(receiver.detail(DocumentationNode.Kind.Type))
- }
- symbol(".")
- }
+ renderReceiver(node, signatureMapper)
if (node.kind != org.jetbrains.dokka.DocumentationNode.Kind.Constructor)
identifierOrDeprecated(node)
@@ -352,6 +348,18 @@ class KotlinLanguageService : LanguageService {
}
}
+ private fun ContentBlock.renderReceiver(node: DocumentationNode, signatureMapper: SignatureMapper?) {
+ val receiver = node.details(DocumentationNode.Kind.Receiver).singleOrNull()
+ if (receiver != null) {
+ if (signatureMapper != null) {
+ signatureMapper.renderReceiver(receiver, this)
+ } else {
+ renderType(receiver.detail(DocumentationNode.Kind.Type))
+ }
+ symbol(".")
+ }
+ }
+
private fun needReturnType(node: DocumentationNode) = when(node.kind) {
DocumentationNode.Kind.Constructor -> false
else -> !node.isUnitReturnType()
@@ -360,7 +368,9 @@ class KotlinLanguageService : LanguageService {
fun DocumentationNode.isUnitReturnType(): Boolean =
detail(DocumentationNode.Kind.Type).hiddenLinks.firstOrNull()?.qualifiedName() == "kotlin.Unit"
- private fun ContentBlock.renderProperty(node: DocumentationNode, renderMode: RenderMode) {
+ private fun ContentBlock.renderProperty(node: DocumentationNode,
+ renderMode: RenderMode,
+ signatureMapper: SignatureMapper? = null) {
if (renderMode == RenderMode.FULL) {
renderAnnotationsForNode(node)
}
@@ -374,11 +384,8 @@ class KotlinLanguageService : LanguageService {
if (node.details(DocumentationNode.Kind.TypeParameter).any()) {
text(" ")
}
- val receiver = node.details(DocumentationNode.Kind.Receiver).singleOrNull()
- if (receiver != null) {
- renderType(receiver.detail(DocumentationNode.Kind.Type))
- symbol(".")
- }
+
+ renderReceiver(node, signatureMapper)
identifierOrDeprecated(node)
symbol(": ")
diff --git a/test/data/format/summarizeSignaturesProperty.kt b/test/data/format/summarizeSignaturesProperty.kt
new file mode 100644
index 00000000..fbbdd328
--- /dev/null
+++ b/test/data/format/summarizeSignaturesProperty.kt
@@ -0,0 +1,20 @@
+package kotlin
+
+class Array<T>
+class IntArray
+class CharArray
+
+/**
+ * Returns true if foo.
+ */
+val IntArray.foo: Int = 0
+
+/**
+ * Returns true if foo.
+ */
+val CharArray.foo: Int = 0
+
+/**
+ * Returns true if foo.
+ */
+val <T> Array<T>.foo: Int = 0
diff --git a/test/data/format/summarizeSignaturesProperty.md b/test/data/format/summarizeSignaturesProperty.md
new file mode 100644
index 00000000..9646b0f1
--- /dev/null
+++ b/test/data/format/summarizeSignaturesProperty.md
@@ -0,0 +1,23 @@
+[test](test/index) / [kotlin](test/kotlin/index)
+
+
+## Package kotlin
+
+
+### Types
+
+
+| [Array](test/kotlin/-array/index) | `class Array&lt;T&gt;` |
+| [CharArray](test/kotlin/-char-array/index) | `class CharArray` |
+| [IntArray](test/kotlin/-int-array/index) | `class IntArray` |
+
+
+### Properties
+
+
+| [foo](test/kotlin/foo) | `val &lt;T&gt; any_array&lt;T&gt;.foo: Int`
+
+Returns true if foo.
+
+ |
+
diff --git a/test/src/format/MarkdownFormatTest.kt b/test/src/format/MarkdownFormatTest.kt
index d981561f..64c8eeae 100644
--- a/test/src/format/MarkdownFormatTest.kt
+++ b/test/src/format/MarkdownFormatTest.kt
@@ -185,4 +185,10 @@ public class MarkdownFormatTest {
markdownService.appendNodes(tempLocation, output, model.members)
}
}
+
+ @Test fun summarizeSignaturesProperty() {
+ verifyOutput("test/data/format/summarizeSignaturesProperty.kt", ".md") { model, output ->
+ markdownService.appendNodes(tempLocation, output, model.members)
+ }
+ }
}