aboutsummaryrefslogtreecommitdiff
path: root/plugins
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 /plugins
parent14e71e40dfab5f18ccd56b0c015383c0dfb5df51 (diff)
downloaddokka-a16e101fad10d024a84aa36069ec6032fcbaf3e6.tar.gz
dokka-a16e101fad10d024a84aa36069ec6032fcbaf3e6.tar.bz2
dokka-a16e101fad10d024a84aa36069ec6032fcbaf3e6.zip
Implement `AbstractJavadocTemplateMapTest` API
Diffstat (limited to 'plugins')
-rw-r--r--plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProvider.kt3
-rw-r--r--plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt7
-rw-r--r--plugins/base/src/test/kotlin/basic/DRITest.kt11
-rw-r--r--plugins/base/src/test/kotlin/content/params/ContentForParamsTest.kt3
-rw-r--r--plugins/base/src/test/kotlin/enums/EnumsTest.kt3
-rw-r--r--plugins/base/src/test/kotlin/model/JavaTest.kt4
-rw-r--r--plugins/javadoc/src/main/kotlin/javadoc/JavadocPageCreator.kt2
-rw-r--r--plugins/javadoc/src/main/kotlin/javadoc/renderer/JavadocContentToTemplateMapTranslator.kt23
-rw-r--r--plugins/javadoc/src/main/kotlin/javadoc/renderer/KorteJavadocRenderer.kt16
-rw-r--r--plugins/javadoc/src/main/kotlin/javadoc/utils.kt8
-rw-r--r--plugins/javadoc/src/test/kotlin/javadoc/AbstractJavadocTemplateMapTest.kt69
-rw-r--r--plugins/javadoc/src/test/kotlin/javadoc/JavadocModuleTemplateMapTest.kt22
12 files changed, 141 insertions, 30 deletions
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")
+ }
+ }
+}