diff options
author | Dmitry Jemerov <yole@jetbrains.com> | 2016-01-05 18:01:13 +0100 |
---|---|---|
committer | Dmitry Jemerov <yole@jetbrains.com> | 2016-01-05 18:01:13 +0100 |
commit | ada91f40f716b20a69d8372dc5c6e250312543f7 (patch) | |
tree | 74c3cb25f8662c5c3db30f572b9abae764a59664 /core/src/main/kotlin/Kotlin/KotlinLanguageService.kt | |
parent | 9b9b689d67a20abb52fcde5ed4655d9a5092b8df (diff) | |
download | dokka-ada91f40f716b20a69d8372dc5c6e250312543f7.tar.gz dokka-ada91f40f716b20a69d8372dc5c6e250312543f7.tar.bz2 dokka-ada91f40f716b20a69d8372dc5c6e250312543f7.zip |
render multiple type parameter constraints according to current Kotlin syntax
Diffstat (limited to 'core/src/main/kotlin/Kotlin/KotlinLanguageService.kt')
-rw-r--r-- | core/src/main/kotlin/Kotlin/KotlinLanguageService.kt | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/core/src/main/kotlin/Kotlin/KotlinLanguageService.kt b/core/src/main/kotlin/Kotlin/KotlinLanguageService.kt index 9c9c9fc7..a5bb5ee7 100644 --- a/core/src/main/kotlin/Kotlin/KotlinLanguageService.kt +++ b/core/src/main/kotlin/Kotlin/KotlinLanguageService.kt @@ -115,8 +115,8 @@ class KotlinLanguageService : LanguageService { identifier(node.name) } - private fun ContentBlock.renderList(nodes: List<DocumentationNode>, separator: String = ", ", - noWrap: Boolean = false, renderItem: (DocumentationNode) -> Unit) { + private fun <T> ContentBlock.renderList(nodes: List<T>, separator: String = ", ", + noWrap: Boolean = false, renderItem: (T) -> Unit) { if (nodes.none()) return renderItem(nodes.first()) @@ -201,7 +201,7 @@ class KotlinLanguageService : LanguageService { identifier(node.name) val constraints = node.details(NodeKind.UpperBound) - if (constraints.any()) { + if (constraints.size == 1) { nbsp() symbol(":") nbsp() @@ -240,6 +240,22 @@ class KotlinLanguageService : LanguageService { } } + private fun ContentBlock.renderExtraTypeParameterConstraints(node: DocumentationNode, renderMode: RenderMode) { + val parametersWithMultipleConstraints = node.details(NodeKind.TypeParameter).filter { it.details(NodeKind.UpperBound).size > 1 } + val parametersWithConstraints = parametersWithMultipleConstraints + .flatMap { parameter -> parameter.details(NodeKind.UpperBound).map { constraint -> parameter to constraint } } + if (parametersWithMultipleConstraints.isNotEmpty()) { + keyword(" where ") + renderList(parametersWithConstraints) { + identifier(it.first.name) + nbsp() + symbol(":") + nbsp() + renderType(it.second, renderMode) + } + } + } + private fun ContentBlock.renderSupertypesForNode(node: DocumentationNode, renderMode: RenderMode) { val supertypes = node.details(NodeKind.Supertype) if (supertypes.any()) { @@ -305,6 +321,7 @@ class KotlinLanguageService : LanguageService { identifierOrDeprecated(node) renderTypeParametersForNode(node, renderMode) renderSupertypesForNode(node, renderMode) + renderExtraTypeParameterConstraints(node, renderMode) } private fun ContentBlock.renderFunction(node: DocumentationNode, @@ -347,6 +364,7 @@ class KotlinLanguageService : LanguageService { else { symbol(")") } + renderExtraTypeParameterConstraints(node, renderMode) } private fun ContentBlock.renderReceiver(node: DocumentationNode, renderMode: RenderMode, signatureMapper: SignatureMapper?) { @@ -391,6 +409,7 @@ class KotlinLanguageService : LanguageService { identifierOrDeprecated(node) symbol(": ") renderType(node.detail(NodeKind.Type), renderMode) + renderExtraTypeParameterConstraints(node, renderMode) } fun DocumentationNode.getPropertyKeyword() = |