aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/api/core.api1
-rw-r--r--core/src/main/kotlin/pages/utils.kt46
2 files changed, 38 insertions, 9 deletions
diff --git a/core/api/core.api b/core/api/core.api
index 82b58711..2e263b62 100644
--- a/core/api/core.api
+++ b/core/api/core.api
@@ -3988,6 +3988,7 @@ public final class org/jetbrains/dokka/pages/TextStyle : java/lang/Enum, org/jet
public final class org/jetbrains/dokka/pages/UtilsKt {
public static final fun mapTransform (Lorg/jetbrains/dokka/pages/ContentNode;Lkotlin/reflect/KClass;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/dokka/pages/ContentNode;
+ public static final fun recursiveMapTransform (Lorg/jetbrains/dokka/pages/ContentNode;Lkotlin/reflect/KClass;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/dokka/pages/ContentNode;
}
public final class org/jetbrains/dokka/pages/WrongRendererTypeException : java/lang/Exception {
diff --git a/core/src/main/kotlin/pages/utils.kt b/core/src/main/kotlin/pages/utils.kt
index c9039416..4afc0a26 100644
--- a/core/src/main/kotlin/pages/utils.kt
+++ b/core/src/main/kotlin/pages/utils.kt
@@ -5,6 +5,9 @@ import kotlin.reflect.KClass
inline fun <reified T : ContentNode, R : ContentNode> R.mapTransform(noinline operation: (T) -> T): R =
mapTransform(T::class, operation)
+inline fun <reified T : ContentNode, R : ContentNode> R.recursiveMapTransform(noinline operation: (T) -> T): R =
+ recursiveMapTransform(T::class, operation)
+
@PublishedApi
@Suppress("UNCHECKED_CAST")
internal fun <T : ContentNode, R : ContentNode> R.mapTransform(type: KClass<T>, operation: (T) -> T): R {
@@ -12,20 +15,45 @@ internal fun <T : ContentNode, R : ContentNode> R.mapTransform(type: KClass<T>,
return operation(this as T) as R
}
val new = when (this) {
- is ContentGroup -> this.copy(children.map { it.mapTransform(type, operation) })
- is ContentHeader -> this.copy(children.map { it.mapTransform(type, operation) })
- is ContentCodeBlock -> this.copy(children.map { it.mapTransform(type, operation) })
- is ContentCodeInline -> this.copy(children.map { it.mapTransform(type, operation) })
- is ContentTable -> this.copy(children.map { it.mapTransform(type, operation) })
- is ContentList -> this.copy(children.map { it.mapTransform(type, operation) })
- is ContentDivergentGroup -> this.copy(children.map { it.mapTransform(type, operation) })
- is ContentDivergentInstance -> this.copy(
+ is ContentGroup -> copy(children = children.map { it.mapTransform(type, operation) })
+ is ContentHeader -> copy(children = children.map { it.mapTransform(type, operation) })
+ is ContentCodeBlock -> copy(children = children.map { it.mapTransform(type, operation) })
+ is ContentCodeInline -> copy(children = children.map { it.mapTransform(type, operation) })
+ is ContentTable -> copy(header = header.map { it.recursiveMapTransform(type, operation) }, children = children.map { it.recursiveMapTransform(type, operation) })
+ is ContentList -> copy(children = children.map { it.mapTransform(type, operation) })
+ is ContentDivergentGroup -> copy(children = children.map { it.mapTransform(type, operation) })
+ is ContentDivergentInstance -> copy(
before = before?.mapTransform(type, operation),
divergent = divergent.mapTransform(type, operation),
after = after?.mapTransform(type, operation)
)
- is PlatformHintedContent -> this.copy(inner.mapTransform(type, operation))
+ is PlatformHintedContent -> copy(inner = inner.mapTransform(type, operation))
else -> this
}
return new as R
}
+
+@PublishedApi
+@Suppress("UNCHECKED_CAST")
+internal fun <T : ContentNode, R : ContentNode> R.recursiveMapTransform(type: KClass<T>, operation: (T) -> T): R {
+ val new = when (this) {
+ is ContentGroup -> copy(children = children.map { it.recursiveMapTransform(type, operation) })
+ is ContentHeader -> copy(children = children.map { it.recursiveMapTransform(type, operation) })
+ is ContentCodeBlock -> copy(children = children.map { it.recursiveMapTransform(type, operation) })
+ is ContentCodeInline -> copy(children = children.map { it.recursiveMapTransform(type, operation) })
+ is ContentTable -> copy(header = header.map { it.recursiveMapTransform(type, operation) }, children = children.map { it.recursiveMapTransform(type, operation) })
+ is ContentList -> copy(children = children.map { it.recursiveMapTransform(type, operation) })
+ is ContentDivergentGroup -> copy(children = children.map { it.recursiveMapTransform(type, operation) })
+ is ContentDivergentInstance -> copy(
+ before = before?.recursiveMapTransform(type, operation),
+ divergent = divergent.recursiveMapTransform(type, operation),
+ after = after?.recursiveMapTransform(type, operation)
+ )
+ is PlatformHintedContent -> copy(inner = inner.recursiveMapTransform(type, operation))
+ else -> this
+ }
+ if (new::class == type) {
+ return operation(new as T) as R
+ }
+ return new as R
+}