From cf0c5043887b1dd38808b0fc12bd8700c9f3b6ba Mon Sep 17 00:00:00 2001 From: Andrzej Ratajczak Date: Tue, 3 Mar 2020 14:13:57 +0100 Subject: Refactor extras in ContentNodes --- .../kotlin/model/properties/PropertyContainer.kt | 7 +- core/src/main/kotlin/pages/ContentNodes.kt | 75 +++++++++++++--------- .../src/main/kotlin/pages/contentNodeProperties.kt | 8 +++ 3 files changed, 58 insertions(+), 32 deletions(-) create mode 100644 core/src/main/kotlin/pages/contentNodeProperties.kt (limited to 'core') diff --git a/core/src/main/kotlin/model/properties/PropertyContainer.kt b/core/src/main/kotlin/model/properties/PropertyContainer.kt index d30c6844..7fa46ccb 100644 --- a/core/src/main/kotlin/model/properties/PropertyContainer.kt +++ b/core/src/main/kotlin/model/properties/PropertyContainer.kt @@ -14,8 +14,10 @@ class PropertyContainer internal constructor( else -> throw ClassCastException("Property for $key stored under not matching key type.") } + inline fun allOfType(): List = map.values.filterIsInstance() + companion object { - fun empty(): PropertyContainer = PropertyContainer(emptyMap()) + fun empty(): PropertyContainer = PropertyContainer(emptyMap()) } } @@ -41,7 +43,8 @@ fun C.mergeExtras(left: C, right: C): C where C : Any, C : WithExtraProperti strategies.firstIsInstanceOrNull()?.error?.invoke() - val replaces: List> = strategies.filterIsInstance>().map { it.newProperty } + val replaces: List> = + strategies.filterIsInstance>().map { it.newProperty } val needingFullMerge: List<(preMerged: C, left: C, right: C) -> C> = strategies.filterIsInstance>().map { it.merger } diff --git a/core/src/main/kotlin/pages/ContentNodes.kt b/core/src/main/kotlin/pages/ContentNodes.kt index 797623e1..2e14dfb9 100644 --- a/core/src/main/kotlin/pages/ContentNodes.kt +++ b/core/src/main/kotlin/pages/ContentNodes.kt @@ -1,16 +1,17 @@ package org.jetbrains.dokka.pages import org.jetbrains.dokka.links.DRI +import org.jetbrains.dokka.model.properties.PropertyContainer +import org.jetbrains.dokka.model.properties.WithExtraProperties data class DCI(val dri: Set, val kind: Kind) { override fun toString() = "$dri[$kind]" } -interface ContentNode { +interface ContentNode : WithExtraProperties { val dci: DCI val platforms: Set val style: Set