aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/src/main/kotlin/model/properties/PropertyContainer.kt3
-rw-r--r--core/src/main/kotlin/pages/ContentNodes.kt110
-rw-r--r--core/src/main/kotlin/pages/ContentSourceSet.kt1
-rw-r--r--core/src/main/kotlin/transformers/pages/PageTransformer.kt12
4 files changed, 94 insertions, 32 deletions
diff --git a/core/src/main/kotlin/model/properties/PropertyContainer.kt b/core/src/main/kotlin/model/properties/PropertyContainer.kt
index 6009bfe0..b14a30f5 100644
--- a/core/src/main/kotlin/model/properties/PropertyContainer.kt
+++ b/core/src/main/kotlin/model/properties/PropertyContainer.kt
@@ -26,6 +26,7 @@ class PropertyContainer<C : Any> internal constructor(
operator fun <D: Any> PropertyContainer<D>.plus(prop: ExtraProperty<D>?): PropertyContainer<D> =
if (prop == null) this else PropertyContainer(map + (prop.key to prop))
+
interface WithExtraProperties<C : Any> {
val extra: PropertyContainer<C>
@@ -57,4 +58,4 @@ fun <C> C.mergeExtras(left: C, right: C): C where C : Any, C : WithExtraProperti
val newExtras = PropertyContainer((unambiguous.flatten() + replaces).associateBy { it.key })
return needingFullMerge.fold(withNewExtras(newExtras)) { acc, merger -> merger(acc, left, right) }
-} \ No newline at end of file
+}
diff --git a/core/src/main/kotlin/pages/ContentNodes.kt b/core/src/main/kotlin/pages/ContentNodes.kt
index b82c023f..02d6bf61 100644
--- a/core/src/main/kotlin/pages/ContentNodes.kt
+++ b/core/src/main/kotlin/pages/ContentNodes.kt
@@ -1,8 +1,5 @@
package org.jetbrains.dokka.pages
-import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet
-import org.jetbrains.dokka.DokkaSourceSetID
-import org.jetbrains.dokka.Platform
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.model.WithChildren
import org.jetbrains.dokka.model.properties.PropertyContainer
@@ -12,7 +9,6 @@ data class DCI(val dri: Set<DRI>, val kind: Kind) {
override fun toString() = "$dri[$kind]"
}
-
interface ContentNode : WithExtraProperties<ContentNode>, WithChildren<ContentNode> {
val dci: DCI
val sourceSets: Set<ContentSourceSet>
@@ -20,6 +16,8 @@ interface ContentNode : WithExtraProperties<ContentNode>, WithChildren<ContentNo
fun hasAnyContent(): Boolean
+ fun withSourceSets(sourceSets: Set<ContentSourceSet>): ContentNode
+
override val children: List<ContentNode>
get() = emptyList()
}
@@ -32,8 +30,8 @@ data class ContentText(
override val style: Set<Style> = emptySet(),
override val extra: PropertyContainer<ContentNode> = PropertyContainer.empty()
) : ContentNode {
- override fun withNewExtras(newExtras: PropertyContainer<ContentNode>): ContentNode = copy(extra = newExtras)
-
+ override fun withNewExtras(newExtras: PropertyContainer<ContentNode>): ContentText = copy(extra = newExtras)
+ override fun withSourceSets(sourceSets: Set<ContentSourceSet>): ContentText = copy(sourceSets = sourceSets)
override fun hasAnyContent(): Boolean = !text.isBlank()
}
@@ -44,8 +42,8 @@ data class ContentBreakLine(
override val style: Set<Style> = emptySet(),
override val extra: PropertyContainer<ContentNode> = PropertyContainer.empty()
) : ContentNode {
- override fun withNewExtras(newExtras: PropertyContainer<ContentNode>): ContentNode = copy(extra = newExtras)
-
+ override fun withNewExtras(newExtras: PropertyContainer<ContentNode>): ContentBreakLine = copy(extra = newExtras)
+ override fun withSourceSets(sourceSets: Set<ContentSourceSet>): ContentBreakLine = copy(sourceSets = sourceSets)
override fun hasAnyContent(): Boolean = true
}
@@ -61,6 +59,12 @@ data class ContentHeader(
constructor(level: Int, c: ContentComposite) : this(c.children, level, c.dci, c.sourceSets, c.style, c.extra)
override fun withNewExtras(newExtras: PropertyContainer<ContentNode>): ContentHeader = copy(extra = newExtras)
+
+ override fun transformChildren(transformer: (ContentNode) -> ContentNode): ContentHeader =
+ copy(children = children.map(transformer))
+
+ override fun withSourceSets(sourceSets: Set<ContentSourceSet>): ContentHeader =
+ copy(sourceSets = sourceSets)
}
interface ContentCode : ContentComposite
@@ -75,6 +79,13 @@ data class ContentCodeBlock(
override val extra: PropertyContainer<ContentNode> = PropertyContainer.empty()
) : ContentCode {
override fun withNewExtras(newExtras: PropertyContainer<ContentNode>): ContentCodeBlock = copy(extra = newExtras)
+
+ override fun transformChildren(transformer: (ContentNode) -> ContentNode): ContentCodeBlock =
+ copy(children = children.map(transformer))
+
+ override fun withSourceSets(sourceSets: Set<ContentSourceSet>): ContentCodeBlock =
+ copy(sourceSets = sourceSets)
+
}
data class ContentCodeInline(
@@ -86,6 +97,13 @@ data class ContentCodeInline(
override val extra: PropertyContainer<ContentNode> = PropertyContainer.empty()
) : ContentCode {
override fun withNewExtras(newExtras: PropertyContainer<ContentNode>): ContentCodeInline = copy(extra = newExtras)
+
+ override fun transformChildren(transformer: (ContentNode) -> ContentNode): ContentCodeInline =
+ copy(children = children.map(transformer))
+
+ override fun withSourceSets(sourceSets: Set<ContentSourceSet>): ContentCodeInline =
+ copy(sourceSets = sourceSets)
+
}
/** Union type replacement */
@@ -101,6 +119,13 @@ data class ContentDRILink(
override val extra: PropertyContainer<ContentNode> = PropertyContainer.empty()
) : ContentLink {
override fun withNewExtras(newExtras: PropertyContainer<ContentNode>): ContentDRILink = copy(extra = newExtras)
+
+ override fun transformChildren(transformer: (ContentNode) -> ContentNode): ContentDRILink =
+ copy(children = children.map(transformer))
+
+ override fun withSourceSets(sourceSets: Set<ContentSourceSet>): ContentDRILink =
+ copy(sourceSets = sourceSets)
+
}
/** All links that do not need to be resolved */
@@ -114,6 +139,12 @@ data class ContentResolvedLink(
) : ContentLink {
override fun withNewExtras(newExtras: PropertyContainer<ContentNode>): ContentResolvedLink =
copy(extra = newExtras)
+
+ override fun transformChildren(transformer: (ContentNode) -> ContentNode): ContentResolvedLink =
+ copy(children = children.map(transformer))
+
+ override fun withSourceSets(sourceSets: Set<ContentSourceSet>): ContentResolvedLink =
+ copy(sourceSets = sourceSets)
}
/** Embedded resources like images */
@@ -128,12 +159,22 @@ data class ContentEmbeddedResource(
) : ContentLink {
override fun withNewExtras(newExtras: PropertyContainer<ContentNode>): ContentEmbeddedResource =
copy(extra = newExtras)
+
+ override fun transformChildren(transformer: (ContentNode) -> ContentNode): ContentEmbeddedResource =
+ copy(children = children.map(transformer))
+
+ override fun withSourceSets(sourceSets: Set<ContentSourceSet>): ContentEmbeddedResource =
+ copy(sourceSets = sourceSets)
}
/** Logical grouping of [ContentNode]s */
interface ContentComposite : ContentNode {
override val children: List<ContentNode> // overwrite to make it abstract once again
+ override val sourceSets: Set<ContentSourceSet> get() = children.flatMap { it.sourceSets }.toSet()
+
+ fun transformChildren(transformer: (ContentNode) -> ContentNode): ContentComposite
+
override fun hasAnyContent(): Boolean = children.any { it.hasAnyContent() }
}
@@ -147,6 +188,13 @@ data class ContentTable(
override val extra: PropertyContainer<ContentNode> = PropertyContainer.empty()
) : ContentComposite {
override fun withNewExtras(newExtras: PropertyContainer<ContentNode>): ContentTable = copy(extra = newExtras)
+
+ override fun transformChildren(transformer: (ContentNode) -> ContentNode): ContentTable =
+ copy(children = children.map(transformer).filterIsInstance<ContentGroup>())
+
+ override fun withSourceSets(sourceSets: Set<ContentSourceSet>): ContentTable =
+ copy(sourceSets = sourceSets)
+
}
/** Lists */
@@ -159,6 +207,12 @@ data class ContentList(
override val extra: PropertyContainer<ContentNode> = PropertyContainer.empty()
) : ContentComposite {
override fun withNewExtras(newExtras: PropertyContainer<ContentNode>): ContentList = copy(extra = newExtras)
+
+ override fun transformChildren(transformer: (ContentNode) -> ContentNode): ContentList =
+ copy(children = children.map(transformer))
+
+ override fun withSourceSets(sourceSets: Set<ContentSourceSet>): ContentList =
+ copy(sourceSets = sourceSets)
}
/** Default group, eg. for blocks of Functions, Properties, etc. **/
@@ -170,6 +224,12 @@ data class ContentGroup(
override val extra: PropertyContainer<ContentNode> = PropertyContainer.empty()
) : ContentComposite {
override fun withNewExtras(newExtras: PropertyContainer<ContentNode>): ContentGroup = copy(extra = newExtras)
+
+ override fun transformChildren(transformer: (ContentNode) -> ContentNode): ContentGroup =
+ copy(children = children.map(transformer))
+
+ override fun withSourceSets(sourceSets: Set<ContentSourceSet>): ContentGroup =
+ copy(sourceSets = sourceSets)
}
/**
@@ -190,6 +250,12 @@ data class ContentDivergentGroup(
override fun withNewExtras(newExtras: PropertyContainer<ContentNode>): ContentDivergentGroup =
copy(extra = newExtras)
+
+ override fun transformChildren(transformer: (ContentNode) -> ContentNode): ContentDivergentGroup =
+ copy(children = children.map(transformer).filterIsInstance<ContentDivergentInstance>())
+
+ // TODO NOW?
+ override fun withSourceSets(sourceSets: Set<ContentSourceSet>): ContentDivergentGroup = this
}
/** Instance of a divergent content */
@@ -207,6 +273,17 @@ data class ContentDivergentInstance(
override fun withNewExtras(newExtras: PropertyContainer<ContentNode>): ContentDivergentInstance =
copy(extra = newExtras)
+
+ override fun transformChildren(transformer: (ContentNode) -> ContentNode): ContentDivergentInstance =
+ copy(
+ before = before?.let(transformer),
+ divergent = divergent.let(transformer),
+ after = after?.let(transformer)
+ )
+
+ override fun withSourceSets(sourceSets: Set<ContentSourceSet>): ContentDivergentInstance =
+ copy(sourceSets = sourceSets)
+
}
data class PlatformHintedContent(
@@ -226,6 +303,13 @@ data class PlatformHintedContent(
override fun withNewExtras(newExtras: PropertyContainer<ContentNode>) =
throw UnsupportedOperationException("This method should not be called on this PlatformHintedContent")
+
+ override fun transformChildren(transformer: (ContentNode) -> ContentNode): PlatformHintedContent =
+ copy(inner = transformer(inner))
+
+ override fun withSourceSets(sourceSets: Set<ContentSourceSet>): PlatformHintedContent =
+ copy(sourceSets = sourceSets)
+
}
interface Style
@@ -266,14 +350,4 @@ object CommentTable : Style
object MultimoduleTable : Style
-fun ContentNode.dfs(predicate: (ContentNode) -> Boolean): ContentNode? = if (predicate(this)) {
- this
-} else {
- if (this is ContentComposite) {
- this.children.asSequence().mapNotNull { it.dfs(predicate) }.firstOrNull()
- } else {
- null
- }
-}
-
fun ContentNode.hasStyle(style: Style) = this.style.contains(style)
diff --git a/core/src/main/kotlin/pages/ContentSourceSet.kt b/core/src/main/kotlin/pages/ContentSourceSet.kt
index 0ff87edb..f53cdb12 100644
--- a/core/src/main/kotlin/pages/ContentSourceSet.kt
+++ b/core/src/main/kotlin/pages/ContentSourceSet.kt
@@ -26,7 +26,6 @@ data class ContentSourceSet(
}
-//TODO NOW: Test
data class CompositeSourceSetID(
private val children: Set<DokkaSourceSetID>
) {
diff --git a/core/src/main/kotlin/transformers/pages/PageTransformer.kt b/core/src/main/kotlin/transformers/pages/PageTransformer.kt
index 086f6d22..68dc4bc8 100644
--- a/core/src/main/kotlin/transformers/pages/PageTransformer.kt
+++ b/core/src/main/kotlin/transformers/pages/PageTransformer.kt
@@ -1,19 +1,7 @@
package org.jetbrains.dokka.transformers.pages
-import org.jetbrains.dokka.pages.ContentNode
import org.jetbrains.dokka.pages.RootPageNode
interface PageTransformer {
operator fun invoke(input: RootPageNode): RootPageNode
}
-
-object SourceSetMergePageTransformer : PageTransformer {
- override fun invoke(input: RootPageNode): RootPageNode {
-
- return input.transformContentPagesTree { contentPage ->
- val content: ContentNode = contentPage.content
- TODO()
- }
- }
-
-}