diff options
author | Kamil Doległo <kamilok1965@interia.pl> | 2019-11-05 22:10:13 +0100 |
---|---|---|
committer | Kamil Doległo <kamilok1965@interia.pl> | 2019-11-05 22:11:14 +0100 |
commit | ae53f0525c676a5483609fdde144594a36d8d582 (patch) | |
tree | d20827c0c86344c7741e81a12641b2a33e7aa34b /core/src/main/kotlin/Utilities | |
parent | 508afa4fa2bddf4b05cb888340d0dbfc0ec40d9b (diff) | |
download | dokka-ae53f0525c676a5483609fdde144594a36d8d582.tar.gz dokka-ae53f0525c676a5483609fdde144594a36d8d582.tar.bz2 dokka-ae53f0525c676a5483609fdde144594a36d8d582.zip |
Add merger (sort of)
Diffstat (limited to 'core/src/main/kotlin/Utilities')
-rw-r--r-- | core/src/main/kotlin/Utilities/nodeDebug.kt | 32 |
1 files changed, 31 insertions, 1 deletions
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 <T : DeclarationDescriptor> DocumentationNode<T>.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() +} |