aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/model
diff options
context:
space:
mode:
authorsebastian.sellmair <sebastian.sellmair@jetbrains.com>2020-06-30 08:03:38 +0200
committerSebastian Sellmair <34319766+sellmair@users.noreply.github.com>2020-07-01 09:43:03 +0200
commita16e101fad10d024a84aa36069ec6032fcbaf3e6 (patch)
tree64e19695dccd67c3e1b1621eeac2ad469e01cb46 /core/src/main/kotlin/model
parent14e71e40dfab5f18ccd56b0c015383c0dfb5df51 (diff)
downloaddokka-a16e101fad10d024a84aa36069ec6032fcbaf3e6.tar.gz
dokka-a16e101fad10d024a84aa36069ec6032fcbaf3e6.tar.bz2
dokka-a16e101fad10d024a84aa36069ec6032fcbaf3e6.zip
Implement `AbstractJavadocTemplateMapTest` API
Diffstat (limited to 'core/src/main/kotlin/model')
-rw-r--r--core/src/main/kotlin/model/Documentable.kt14
-rw-r--r--core/src/main/kotlin/model/WithChildren.kt64
-rw-r--r--core/src/main/kotlin/model/doc/DocTag.kt4
-rw-r--r--core/src/main/kotlin/model/doc/DocumentationNode.kt2
-rw-r--r--core/src/main/kotlin/model/doc/TagWrapper.kt4
-rw-r--r--core/src/main/kotlin/model/documentableUtils.kt10
6 files changed, 71 insertions, 27 deletions
diff --git a/core/src/main/kotlin/model/Documentable.kt b/core/src/main/kotlin/model/Documentable.kt
index 35278302..21660f86 100644
--- a/core/src/main/kotlin/model/Documentable.kt
+++ b/core/src/main/kotlin/model/Documentable.kt
@@ -7,10 +7,9 @@ import org.jetbrains.dokka.model.properties.PropertyContainer
import org.jetbrains.dokka.model.properties.WithExtraProperties
-abstract class Documentable {
+abstract class Documentable : WithChildren<Documentable> {
abstract val name: String?
abstract val dri: DRI
- abstract val children: List<Documentable>
abstract val documentation: SourceSetDependent<DocumentationNode>
abstract val sourceSets: Set<DokkaSourceSet>
abstract val expectPresentInSet: DokkaSourceSet?
@@ -359,7 +358,7 @@ data class PrimitiveJavaType(val name: String) : Bound()
object Void : Bound()
object JavaObject : Bound()
object Dynamic : Bound()
-data class UnresolvedBound(val name: String): Bound()
+data class UnresolvedBound(val name: String) : Bound()
enum class FunctionModifiers {
NONE, FUNCTION, EXTENSION
@@ -376,15 +375,6 @@ fun Documentable.dfs(predicate: (Documentable) -> Boolean): Documentable? =
this.children.asSequence().mapNotNull { it.dfs(predicate) }.firstOrNull()
}
-fun Documentable.withDescendants(): Sequence<Documentable> {
- return sequence {
- yield(this@withDescendants)
- children.forEach { child ->
- yieldAll(child.withDescendants())
- }
- }
-}
-
sealed class Visibility(val name: String)
sealed class KotlinVisibility(name: String) : Visibility(name) {
object Public : KotlinVisibility("public")
diff --git a/core/src/main/kotlin/model/WithChildren.kt b/core/src/main/kotlin/model/WithChildren.kt
new file mode 100644
index 00000000..589bcd2a
--- /dev/null
+++ b/core/src/main/kotlin/model/WithChildren.kt
@@ -0,0 +1,64 @@
+package org.jetbrains.dokka.model
+
+interface WithChildren<out T> {
+ val children: List<T>
+}
+
+inline fun <reified T> WithChildren<*>.firstChildOfTypeOrNull(): T? =
+ children.filterIsInstance<T>().firstOrNull()
+
+inline fun <reified T> WithChildren<*>.firstChildOfTypeOrNull(predicate: (T) -> Boolean): T? =
+ children.filterIsInstance<T>().firstOrNull(predicate)
+
+inline fun <reified T> WithChildren<*>.firstChildOfType(): T =
+ children.filterIsInstance<T>().first()
+
+inline fun <reified T> WithChildren<*>.firstChildOfType(predicate: (T) -> Boolean): T =
+ children.filterIsInstance<T>().first(predicate)
+
+inline fun <reified T> WithChildren<WithChildren<*>>.firstMemberOfType(): T where T : WithChildren<*> {
+ return withDescendants().filterIsInstance<T>().first()
+}
+
+inline fun <reified T> WithChildren<WithChildren<*>>.firstMemberOfTypeOrNull(): T? where T : WithChildren<*> {
+ return withDescendants().filterIsInstance<T>().firstOrNull()
+}
+
+fun <T> T.withDescendants(): Sequence<T> where T : WithChildren<T> {
+ return sequence {
+ yield(this@withDescendants)
+ children.forEach { child ->
+ yieldAll(child.withDescendants())
+ }
+ }
+}
+
+@JvmName("withDescendantsProjection")
+fun WithChildren<*>.withDescendants(): Sequence<Any?> {
+ return sequence {
+ yield(this@withDescendants)
+ children.forEach { child ->
+ if (child is WithChildren<*>) {
+ yieldAll(child.withDescendants())
+ }
+ }
+ }
+}
+
+@JvmName("withDescendantsAny")
+fun WithChildren<Any>.withDescendants(): Sequence<Any> {
+ return sequence {
+ yield(this@withDescendants)
+ children.forEach { child ->
+ if (child is WithChildren<*>) {
+ yieldAll(child.withDescendants().filterNotNull())
+ }
+ }
+ }
+}
+
+fun <T> T.dfs(predicate: (T) -> Boolean): T? where T : WithChildren<T> = if (predicate(this)) {
+ this
+} else {
+ children.asSequence().mapNotNull { it.dfs(predicate) }.firstOrNull()
+}
diff --git a/core/src/main/kotlin/model/doc/DocTag.kt b/core/src/main/kotlin/model/doc/DocTag.kt
index 902dedec..42836d71 100644
--- a/core/src/main/kotlin/model/doc/DocTag.kt
+++ b/core/src/main/kotlin/model/doc/DocTag.kt
@@ -6,7 +6,7 @@ import org.jetbrains.dokka.model.WithChildren
sealed class DocTag(
override val children: List<DocTag>,
val params: Map<String, String>
-) : WithChildren {
+) : WithChildren<DocTag> {
override fun equals(other: Any?): Boolean =
(
other != null &&
@@ -90,4 +90,4 @@ class DocumentationLink(val dri: DRI, children: List<DocTag> = emptyList(), para
override fun hashCode(): Int = super.hashCode() + dri.hashCode()
}
object HorizontalRule : DocTag(emptyList(), emptyMap())
-class CustomDocTag(children: List<DocTag> = emptyList(), params: Map<String, String> = emptyMap()) : DocTag(children, params) \ No newline at end of file
+class CustomDocTag(children: List<DocTag> = emptyList(), params: Map<String, String> = emptyMap()) : DocTag(children, params)
diff --git a/core/src/main/kotlin/model/doc/DocumentationNode.kt b/core/src/main/kotlin/model/doc/DocumentationNode.kt
index cfac210a..6eb26a6a 100644
--- a/core/src/main/kotlin/model/doc/DocumentationNode.kt
+++ b/core/src/main/kotlin/model/doc/DocumentationNode.kt
@@ -2,4 +2,4 @@ package org.jetbrains.dokka.model.doc
import org.jetbrains.dokka.model.WithChildren
-data class DocumentationNode(override val children: List<TagWrapper>): WithChildren \ No newline at end of file
+data class DocumentationNode(override val children: List<TagWrapper>): WithChildren<TagWrapper>
diff --git a/core/src/main/kotlin/model/doc/TagWrapper.kt b/core/src/main/kotlin/model/doc/TagWrapper.kt
index 458203b0..095f3eaf 100644
--- a/core/src/main/kotlin/model/doc/TagWrapper.kt
+++ b/core/src/main/kotlin/model/doc/TagWrapper.kt
@@ -3,7 +3,7 @@ package org.jetbrains.dokka.model.doc
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.model.WithChildren
-sealed class TagWrapper(val root: DocTag) : WithChildren {
+sealed class TagWrapper(val root: DocTag) : WithChildren<DocTag> {
override val children: List<DocTag>
get() = root.children
@@ -36,4 +36,4 @@ class Sample(root: DocTag, name: String) : NamedTagWrapper(root, name)
class Deprecated(root: DocTag) : TagWrapper(root)
class Property(root: DocTag, name: String) : NamedTagWrapper(root, name)
class Suppress(root: DocTag) : TagWrapper(root)
-class CustomTagWrapper(root: DocTag, name: String) : NamedTagWrapper(root, name) \ No newline at end of file
+class CustomTagWrapper(root: DocTag, name: String) : NamedTagWrapper(root, name)
diff --git a/core/src/main/kotlin/model/documentableUtils.kt b/core/src/main/kotlin/model/documentableUtils.kt
index f49c0967..287cf313 100644
--- a/core/src/main/kotlin/model/documentableUtils.kt
+++ b/core/src/main/kotlin/model/documentableUtils.kt
@@ -20,13 +20,3 @@ fun DTypeParameter.filter(filteredSet: Set<DokkaSourceSet>) =
extra
)
}
-
-interface WithChildren {
- val children: List<*>
-}
-
-inline fun <reified T> WithChildren.firstChildOfType() =
- children.filterIsInstance<T>().firstOrNull()
-
-inline fun <reified T> WithChildren.firstChildOfType(predicate: (T) -> Boolean) =
- children.filterIsInstance<T>().firstOrNull(predicate) \ No newline at end of file