diff options
19 files changed, 214 insertions, 69 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 diff --git a/core/src/main/kotlin/pages/PageNodes.kt b/core/src/main/kotlin/pages/PageNodes.kt index b9f1025f..71ec8597 100644 --- a/core/src/main/kotlin/pages/PageNodes.kt +++ b/core/src/main/kotlin/pages/PageNodes.kt @@ -2,11 +2,11 @@ package org.jetbrains.dokka.pages import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.Documentable +import org.jetbrains.dokka.model.WithChildren import java.util.* -interface PageNode { +interface PageNode: WithChildren<PageNode> { val name: String - val children: List<PageNode> fun modified( name: String = this.name, @@ -149,16 +149,6 @@ class MemberPageNode( else MemberPageNode(name, content, dri, documentable, children, embeddedResources) } -fun PageNode.dfs(predicate: (PageNode) -> Boolean): PageNode? = if (predicate(this)) { - this -} else { - this.children.asSequence().mapNotNull { it.dfs(predicate) }.firstOrNull() -} - -fun PageNode.asSequence(): Sequence<PageNode> = sequence { - yield(this@asSequence) - children.asSequence().flatMap { it.asSequence() }.forEach { yield(it) } -} class MultimoduleRootPageNode( override val name: String, diff --git a/plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProvider.kt b/plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProvider.kt index 34b570a9..ba4523a1 100644 --- a/plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProvider.kt +++ b/plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProvider.kt @@ -4,6 +4,7 @@ import org.jetbrains.dokka.DokkaConfiguration import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet import org.jetbrains.dokka.base.resolvers.external.ExternalLocationProvider import org.jetbrains.dokka.links.DRI +import org.jetbrains.dokka.model.withDescendants import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.plugability.DokkaContext import java.net.HttpURLConnection @@ -19,7 +20,7 @@ open class DefaultLocationProvider( ) : BaseLocationProvider(dokkaContext) { protected open val extension = ".html" - protected val pagesIndex: Map<DRI, ContentPage> = pageGraphRoot.asSequence().filterIsInstance<ContentPage>() + protected val pagesIndex: Map<DRI, ContentPage> = pageGraphRoot.withDescendants().filterIsInstance<ContentPage>() .map { it.dri.map { dri -> dri to it } }.flatten() .groupingBy { it.first } .aggregate { dri, _, (_, page), first -> diff --git a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt index 7c797233..76f8319d 100644 --- a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt @@ -33,7 +33,6 @@ import org.jetbrains.kotlin.load.java.propertyNamesBySetMethodName import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.psiUtil.getChildOfType import org.jetbrains.kotlin.resolve.DescriptorUtils -import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull import org.jetbrains.kotlin.utils.addToStdlib.safeAs import java.io.File @@ -266,9 +265,9 @@ class DefaultPsiToDocumentableTranslator( dri.copy(target = dri.target.nextTarget()), psiParameter.name, DocumentationNode( - listOfNotNull(docs.firstChildOfType<Param> { - it.firstChildOfType<DocumentationLink>() - ?.firstChildOfType<Text>()?.body == psiParameter.name + listOfNotNull(docs.firstChildOfTypeOrNull<Param> { + it.firstChildOfTypeOrNull<DocumentationLink>() + ?.firstChildOfTypeOrNull<Text>()?.body == psiParameter.name })).toSourceSetDependent(), null, getBound(psiParameter.type), diff --git a/plugins/base/src/test/kotlin/basic/DRITest.kt b/plugins/base/src/test/kotlin/basic/DRITest.kt index b09932fe..1f4c7d93 100644 --- a/plugins/base/src/test/kotlin/basic/DRITest.kt +++ b/plugins/base/src/test/kotlin/basic/DRITest.kt @@ -1,11 +1,12 @@ package basic import org.jetbrains.dokka.links.* -import org.jetbrains.dokka.model.DClass -import org.jetbrains.dokka.model.DFunction -import org.jetbrains.dokka.model.DParameter -import org.jetbrains.dokka.model.OtherParameter +import org.jetbrains.dokka.links.Callable +import org.jetbrains.dokka.links.Nullable +import org.jetbrains.dokka.links.TypeConstructor +import org.jetbrains.dokka.model.* import org.jetbrains.dokka.pages.* +import org.jetbrains.dokka.pages.dfs import org.junit.jupiter.api.Assertions.assertEquals import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest @@ -158,7 +159,7 @@ class DRITest : AbstractCoreTest() { ) val driCount = module - .asSequence() + .withDescendants() .filterIsInstance<ContentPage>() .sumBy { it.dri.count { dri -> dri == expectedDRI } } diff --git a/plugins/base/src/test/kotlin/content/params/ContentForParamsTest.kt b/plugins/base/src/test/kotlin/content/params/ContentForParamsTest.kt index 2e05d241..f6e80891 100644 --- a/plugins/base/src/test/kotlin/content/params/ContentForParamsTest.kt +++ b/plugins/base/src/test/kotlin/content/params/ContentForParamsTest.kt @@ -3,6 +3,7 @@ package content.params import matchers.content.* import org.jetbrains.dokka.Platform import org.jetbrains.dokka.model.DFunction +import org.jetbrains.dokka.model.dfs import org.jetbrains.dokka.model.doc.DocumentationNode import org.jetbrains.dokka.model.doc.Param import org.jetbrains.dokka.model.doc.Text @@ -607,4 +608,4 @@ class ContentForParamsTest : AbstractCoreTest() { private fun DocumentationNode.paramsDescription(): String = children.firstIsInstanceOrNull<Param>()?.root?.children?.firstIsInstanceOrNull<Text>()?.body.orEmpty() -}
\ No newline at end of file +} diff --git a/plugins/base/src/test/kotlin/enums/EnumsTest.kt b/plugins/base/src/test/kotlin/enums/EnumsTest.kt index dba5c24a..be910b5c 100644 --- a/plugins/base/src/test/kotlin/enums/EnumsTest.kt +++ b/plugins/base/src/test/kotlin/enums/EnumsTest.kt @@ -3,6 +3,7 @@ package enums import matchers.content.* import org.jetbrains.dokka.model.ConstructorValues import org.jetbrains.dokka.model.DEnum +import org.jetbrains.dokka.model.dfs import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest import org.junit.jupiter.api.Assertions.* @@ -230,4 +231,4 @@ class EnumsTest : AbstractCoreTest() { private fun ContentGroup.constructorSignature(): String = (children.single() as ContentGroup).children.drop(1).joinToString(separator = "") { (it as ContentText).text } -}
\ No newline at end of file +} diff --git a/plugins/base/src/test/kotlin/model/JavaTest.kt b/plugins/base/src/test/kotlin/model/JavaTest.kt index bd7e3b55..4cad784b 100644 --- a/plugins/base/src/test/kotlin/model/JavaTest.kt +++ b/plugins/base/src/test/kotlin/model/JavaTest.kt @@ -34,7 +34,7 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { with((this / "fn").cast<DFunction>()) { name equals "fn" val params = parameters.map { it.documentation.values.first().children.first() as Param } - params.mapNotNull { it.firstChildOfType<Text>()?.body } equals listOf("is String parameter", "is int parameter") + params.mapNotNull { it.firstChildOfTypeOrNull<Text>()?.body } equals listOf("is String parameter", "is int parameter") } } } @@ -449,4 +449,4 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { // assertEquals(1, inheritors.size) // } // } -}
\ No newline at end of file +} diff --git a/plugins/javadoc/src/main/kotlin/javadoc/JavadocPageCreator.kt b/plugins/javadoc/src/main/kotlin/javadoc/JavadocPageCreator.kt index 767e0c68..ebe223e5 100644 --- a/plugins/javadoc/src/main/kotlin/javadoc/JavadocPageCreator.kt +++ b/plugins/javadoc/src/main/kotlin/javadoc/JavadocPageCreator.kt @@ -163,7 +163,7 @@ open class JavadocPageCreator( private val firstSentenceRegex = Regex("^((?:[^.?!]|[.!?](?!\\s))*[.!?])") private inline fun <reified T : TagWrapper> Documentable.findNodeInDocumentation(sourceSetData: DokkaSourceSet?): T? = - documentation[sourceSetData]?.firstChildOfType<T>() + documentation[sourceSetData]?.firstChildOfTypeOrNull<T>() private fun Documentable.descriptionToContentNodes(sourceSet: DokkaSourceSet? = highestJvmSourceSet) = findNodeInDocumentation<Description>(sourceSet)?.let { DocTagToContentConverter.buildContent( diff --git a/plugins/javadoc/src/main/kotlin/javadoc/renderer/JavadocContentToTemplateMapTranslator.kt b/plugins/javadoc/src/main/kotlin/javadoc/renderer/JavadocContentToTemplateMapTranslator.kt index 50a971ea..c9dfdbfc 100644 --- a/plugins/javadoc/src/main/kotlin/javadoc/renderer/JavadocContentToTemplateMapTranslator.kt +++ b/plugins/javadoc/src/main/kotlin/javadoc/renderer/JavadocContentToTemplateMapTranslator.kt @@ -1,6 +1,7 @@ package javadoc.renderer import javadoc.pages.* +import javadoc.toNormalized import org.jetbrains.dokka.Platform import org.jetbrains.dokka.base.resolvers.local.LocationProvider import org.jetbrains.dokka.links.DRI @@ -9,22 +10,23 @@ import org.jetbrains.dokka.model.ImplementedInterfaces import org.jetbrains.dokka.model.InheritedFunction import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.plugability.DokkaContext +import java.nio.file.Paths internal class JavadocContentToTemplateMapTranslator( private val locationProvider: LocationProvider, private val context: DokkaContext, ) { - fun templateMapForPageNode(node: JavadocPageNode, pathToRoot: String): TemplateMap = + fun templateMapForPageNode(node: JavadocPageNode): TemplateMap = mapOf<String, Any?>( "docName" to "docName", // todo docname - "pathToRoot" to pathToRoot, + "pathToRoot" to pathToRoot(node), "contextRoot" to node, "kind" to "main", ) + templateMapForNode(node) - fun templateMapForNode(node: JavadocPageNode): TemplateMap = + private fun templateMapForNode(node: JavadocPageNode): TemplateMap = when (node) { is JavadocModulePageNode -> InnerTranslator(node).templateMapForJavadocContentNode(node.content) is JavadocClasslikePageNode -> InnerTranslator(node).templateMapForClasslikeNode(node) @@ -34,6 +36,21 @@ internal class JavadocContentToTemplateMapTranslator( else -> emptyMap() } + private fun pathToRoot(node: JavadocPageNode): String { + return when(node){ + is JavadocModulePageNode -> "" + else -> run { + val link = locationProvider.resolve(node, skipExtension = true) + val dir = Paths.get(link).parent?.toNormalized().orEmpty() + return dir.split("/").filter { it.isNotEmpty() }.joinToString("/") { ".." }.let { + if (it.isNotEmpty()) "$it/" else it + } + } + } + } + + private fun String.toNormalized() = Paths.get(this).toNormalized() + private inner class InnerTranslator(val contextNode: PageNode) { private val htmlTranslator = JavadocContentToHtmlTranslator(locationProvider, context) diff --git a/plugins/javadoc/src/main/kotlin/javadoc/renderer/KorteJavadocRenderer.kt b/plugins/javadoc/src/main/kotlin/javadoc/renderer/KorteJavadocRenderer.kt index a7d18100..f7d75924 100644 --- a/plugins/javadoc/src/main/kotlin/javadoc/renderer/KorteJavadocRenderer.kt +++ b/plugins/javadoc/src/main/kotlin/javadoc/renderer/KorteJavadocRenderer.kt @@ -4,6 +4,7 @@ import com.soywiz.korte.* import javadoc.location.JavadocLocationProvider import javadoc.pages.* import javadoc.renderer.JavadocContentToHtmlTranslator.Companion.buildLink +import javadoc.toNormalized import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -62,9 +63,8 @@ class KorteJavadocRenderer(private val outputWriter: OutputWriter, val context: private fun CoroutineScope.renderModulePageNode(node: JavadocModulePageNode) { val link = "." val name = "index" - val pathToRoot = "" - val contentMap = contentToTemplateMapTranslator.templateMapForPageNode(node, pathToRoot) + val contentMap = contentToTemplateMapTranslator.templateMapForPageNode(node) writeFromTemplate(outputWriter, "$link/$name".toNormalized(), "tabPage.korte", contentMap.toList()) node.children.forEach { renderNode(it, link) } @@ -72,12 +72,7 @@ class KorteJavadocRenderer(private val outputWriter: OutputWriter, val context: private fun CoroutineScope.renderJavadocPageNode(node: JavadocPageNode) { val link = locationProvider.resolve(node, skipExtension = true) - val dir = Paths.get(link).parent?.let { it.toNormalized() }.orEmpty() - val pathToRoot = dir.split("/").filter { it.isNotEmpty() }.joinToString("/") { ".." }.let { - if (it.isNotEmpty()) "$it/" else it - } - - val contentMap = contentToTemplateMapTranslator.templateMapForPageNode(node, pathToRoot) + val contentMap = contentToTemplateMapTranslator.templateMapForPageNode(node) writeFromTemplate(outputWriter, link, templateForNode(node), contentMap.toList()) node.children.forEach { renderNode(it, link.toNormalized()) } } @@ -99,9 +94,6 @@ class KorteJavadocRenderer(private val outputWriter: OutputWriter, val context: private fun DRI.toLink(context: PageNode? = null) = locationProvider.resolve(this, emptySet(), context) - private fun Path.toNormalized() = this.normalize().toFile().toString() - private fun String.toNormalized() = Paths.get(this).toNormalized() - private suspend fun OutputWriter.writeHtml(path: String, text: String) = write(path, text, ".html") private fun CoroutineScope.writeFromTemplate( writer: OutputWriter, @@ -194,4 +186,4 @@ class KorteJavadocRenderer(private val outputWriter: OutputWriter, val context: ?.joinToString("\n") ?: throw IllegalStateException("Template not found: $basePath/$template") } -}
\ No newline at end of file +} diff --git a/plugins/javadoc/src/main/kotlin/javadoc/utils.kt b/plugins/javadoc/src/main/kotlin/javadoc/utils.kt new file mode 100644 index 00000000..94f7c8b4 --- /dev/null +++ b/plugins/javadoc/src/main/kotlin/javadoc/utils.kt @@ -0,0 +1,8 @@ +package javadoc + +import java.nio.file.Path +import java.nio.file.Paths + +internal fun Path.toNormalized() = this.normalize().toFile().toString() + +internal fun String.toNormalized() = Paths.get(this).toNormalized() diff --git a/plugins/javadoc/src/test/kotlin/javadoc/AbstractJavadocTemplateMapTest.kt b/plugins/javadoc/src/test/kotlin/javadoc/AbstractJavadocTemplateMapTest.kt new file mode 100644 index 00000000..7b31d064 --- /dev/null +++ b/plugins/javadoc/src/test/kotlin/javadoc/AbstractJavadocTemplateMapTest.kt @@ -0,0 +1,69 @@ +package javadoc + +import javadoc.pages.JavadocPageNode +import javadoc.renderer.JavadocContentToTemplateMapTranslator +import org.jetbrains.dokka.DokkaConfigurationImpl +import org.jetbrains.dokka.javadoc.JavadocPlugin +import org.jetbrains.dokka.model.withDescendants +import org.jetbrains.dokka.pages.RootPageNode +import org.jetbrains.dokka.plugability.DokkaContext +import org.jetbrains.dokka.plugability.plugin +import org.jetbrains.dokka.plugability.querySingle +import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest + +internal abstract class AbstractJavadocTemplateMapTest : AbstractCoreTest() { + protected var config: DokkaConfigurationImpl = dokkaConfiguration { + format = "javadoc" + passes { + pass { + sourceRoots = listOf("src") + analysisPlatform = "jvm" + } + } + } + + data class Result( + val rootPageNode: RootPageNode, + val context: DokkaContext + ) { + + val translator: JavadocContentToTemplateMapTranslator by lazy { + val locationProvider = context.plugin<JavadocPlugin>() + .querySingle { locationProviderFactory } + .getLocationProvider(rootPageNode) + + JavadocContentToTemplateMapTranslator(locationProvider, context) + } + + val JavadocPageNode.templateMap: Map<String, Any?> get() = translator.templateMapForPageNode(this) + + inline fun <reified T : JavadocPageNode> allPagesOfType(): List<T> { + return rootPageNode.withDescendants().filterIsInstance<T>().toList() + } + + inline fun <reified T : JavadocPageNode> firstPageOfType(): T { + return rootPageNode.withDescendants().filterIsInstance<T>().first() + } + + inline fun <reified T : JavadocPageNode> firstPageOfTypeOrNull(): T? { + return rootPageNode.withDescendants().filterIsInstance<T>().firstOrNull() + } + + inline fun <reified T : JavadocPageNode> singlePageOfType(): T { + return rootPageNode.withDescendants().filterIsInstance<T>().single() + } + } + + fun testTemplateMapInline( + query: String, + configuration: DokkaConfigurationImpl = config, + assertions: Result.() -> Unit + ) { + testInline(query, configuration) { + renderingStage = { rootPageNode, dokkaContext -> + Result(rootPageNode, dokkaContext).assertions() + } + } + } +} + diff --git a/plugins/javadoc/src/test/kotlin/javadoc/JavadocModuleTemplateMapTest.kt b/plugins/javadoc/src/test/kotlin/javadoc/JavadocModuleTemplateMapTest.kt new file mode 100644 index 00000000..732454f7 --- /dev/null +++ b/plugins/javadoc/src/test/kotlin/javadoc/JavadocModuleTemplateMapTest.kt @@ -0,0 +1,22 @@ +package javadoc + +import javadoc.pages.JavadocModulePageNode +import org.junit.jupiter.api.Test + +internal class JavadocModuleTemplateMapTest : AbstractJavadocTemplateMapTest() { + + @Test + fun simpleKotlinExample() { + testTemplateMapInline( + """ + /src/source.kt + package test + class Test + """.trimIndent(), + config + ) { + val moduleContentMap = singlePageOfType<JavadocModulePageNode>().templateMap + println("module") + } + } +} |