From ae53f0525c676a5483609fdde144594a36d8d582 Mon Sep 17 00:00:00 2001 From: Kamil Doległo Date: Tue, 5 Nov 2019 22:10:13 +0100 Subject: Add merger (sort of) --- core/src/main/kotlin/Utilities/nodeDebug.kt | 32 ++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'core/src/main/kotlin/Utilities') diff --git a/core/src/main/kotlin/Utilities/nodeDebug.kt b/core/src/main/kotlin/Utilities/nodeDebug.kt index c7a771d8..8e2a7079 100644 --- a/core/src/main/kotlin/Utilities/nodeDebug.kt +++ b/core/src/main/kotlin/Utilities/nodeDebug.kt @@ -1,6 +1,7 @@ package org.jetbrains.dokka.Utilities import org.jetbrains.dokka.Model.DocumentationNode +import org.jetbrains.dokka.pages.* import org.jetbrains.kotlin.descriptors.DeclarationDescriptor const val DOWN = '\u2503' @@ -18,4 +19,33 @@ fun DocumentationNode.pretty(prefix: String = "", .takeIf { it.isNotEmpty() } ?.joinToString(prefix = "\n", separator = "") .orEmpty() + if (children.isEmpty()) "\n" else "" -} \ No newline at end of file +} + +fun Any.genericPretty(prefix: String = "", isLast: Boolean = true): String { + val nextPrefix = prefix + (if (isLast) ' ' else DOWN) + ' ' + + return prefix + (if (isLast) LAST else BRANCH) + this.stringify() + + allChildren().dropLast(1) + .map { it.genericPretty(nextPrefix, false) } + .plus(allChildren().lastOrNull()?.genericPretty(nextPrefix)) + .filterNotNull() + .takeIf { it.isNotEmpty() } + ?.joinToString(prefix = "\n", separator = "") + .orEmpty() + if (allChildren().isEmpty()) "\n" else "" +} +private fun Any.stringify() = when(this) { + is ContentNode -> toString() + this.dci + is PageNode -> this.name + this::class.simpleName + else -> toString() +} +private fun Any.allChildren() = when(this){ + is PageNode -> children + content + is ContentBlock -> this.children + is ContentHeader -> this.items + is ContentStyle -> this.items + is ContentSymbol -> this.parts + is ContentComment -> this.parts + is ContentGroup -> this.children + is ContentList -> this.items + else -> emptyList() +} -- cgit