diff options
4 files changed, 36 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() = diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt index 81e0cb6b..a723cb2a 100644 --- a/core/src/test/kotlin/format/MarkdownFormatTest.kt +++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt @@ -222,6 +222,10 @@ public class MarkdownFormatTest { verifyMarkdownNodeByName("arrayAverage", "XArray") } + @Test fun multipleTypeParameterConstraints() { + verifyMarkdownNode("multipleTypeParameterConstraints", withKotlinRuntime = true) + } + private fun verifyMarkdownPackage(fileName: String, withKotlinRuntime: Boolean = false) { verifyOutput("testdata/format/$fileName.kt", ".package.md", withKotlinRuntime = withKotlinRuntime) { model, output -> markdownService.appendNodes(tempLocation, output, model.members) diff --git a/core/testdata/format/multipleTypeParameterConstraints.kt b/core/testdata/format/multipleTypeParameterConstraints.kt new file mode 100644 index 00000000..8fd62e11 --- /dev/null +++ b/core/testdata/format/multipleTypeParameterConstraints.kt @@ -0,0 +1,2 @@ +fun f<T> where T: Appendable, T: CharSequence { +} diff --git a/core/testdata/format/multipleTypeParameterConstraints.md b/core/testdata/format/multipleTypeParameterConstraints.md new file mode 100644 index 00000000..d6b4e853 --- /dev/null +++ b/core/testdata/format/multipleTypeParameterConstraints.md @@ -0,0 +1,8 @@ +[test](test/index) / [f](test/f) + + +# f + +`fun <T> f(): Unit where T : Appendable, T : CharSequence` + + |