aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Ogorodnik <Simon.Ogorodnik@jetbrains.com>2018-09-28 20:10:45 +0300
committerSimon Ogorodnik <Simon.Ogorodnik@jetbrains.com>2018-09-28 20:10:45 +0300
commit45495ebb61964ce853c4f1b5a4b63f28e18daa57 (patch)
tree28894391be63d24886edcb718e076b3a6d9aa7b5
parent51cb9c12e4db76a552ada7445b346fe1ac3e68ef (diff)
downloaddokka-45495ebb61964ce853c4f1b5a4b63f28e18daa57.tar.gz
dokka-45495ebb61964ce853c4f1b5a4b63f28e18daa57.tar.bz2
dokka-45495ebb61964ce853c4f1b5a4b63f28e18daa57.zip
Support new platform tags style
-rw-r--r--core/src/main/kotlin/Formats/KotlinWebsiteHtmlFormatService.kt38
-rw-r--r--core/src/main/kotlin/Formats/StructuredFormatService.kt148
2 files changed, 126 insertions, 60 deletions
diff --git a/core/src/main/kotlin/Formats/KotlinWebsiteHtmlFormatService.kt b/core/src/main/kotlin/Formats/KotlinWebsiteHtmlFormatService.kt
index 1a674626..5bd346da 100644
--- a/core/src/main/kotlin/Formats/KotlinWebsiteHtmlFormatService.kt
+++ b/core/src/main/kotlin/Formats/KotlinWebsiteHtmlFormatService.kt
@@ -69,27 +69,29 @@ open class KotlinWebsiteHtmlOutputBuilder(
override fun appendLink(href: String, body: () -> Unit) = wrap("<a href=\"$href\">", "</a>", body)
override fun appendTable(vararg columns: String, body: () -> Unit) {
- to.appendln("<table class=\"api-docs-table\">")
- body()
- to.appendln("</table>")
+ //to.appendln("<table class=\"api-docs-table\">")
+ div(to, "api-declarations-list") {
+ body()
+ }
+ //to.appendln("</table>")
}
override fun appendTableBody(body: () -> Unit) {
- to.appendln("<tbody>")
+ //to.appendln("<tbody>")
body()
- to.appendln("</tbody>")
+ //to.appendln("</tbody>")
}
override fun appendTableRow(body: () -> Unit) {
- to.appendln("<tr>")
+ //to.appendln("<tr>")
body()
- to.appendln("</tr>")
+ //to.appendln("</tr>")
}
override fun appendTableCell(body: () -> Unit) {
- to.appendln("<td>")
+// to.appendln("<td>")
body()
- to.appendln("\n</td>")
+// to.appendln("\n</td>")
}
override fun appendSymbol(text: String) {
@@ -125,12 +127,11 @@ open class KotlinWebsiteHtmlOutputBuilder(
private fun calculatePlatforms(platforms: Set<String>): Map<String, List<String>> {
fun String.isKotlinVersion() = this.startsWith("Kotlin")
- fun String.isJREVersion() = this.startsWith("JRE")
+ fun String.isJREVersion() = this.startsWith("JRE", ignoreCase=true)
val kotlinVersion = platforms.singleOrNull(String::isKotlinVersion)?.removePrefix("Kotlin ")
- val jreVersion = platforms.singleOrNull(String::isJREVersion)
+ val jreVersion = platforms.filter(String::isJREVersion).min()?.takeUnless { it.endsWith("6") }
val targetPlatforms = platforms.filterNot { it.isKotlinVersion() || it.isJREVersion() }
-
return mapOf(
"platform" to targetPlatforms,
"kotlin-version" to listOfNotNull(kotlinVersion),
@@ -148,10 +149,13 @@ open class KotlinWebsiteHtmlOutputBuilder(
}
override fun appendIndexRow(platforms: Set<String>, block: () -> Unit) {
- if (platforms.isNotEmpty())
- wrap("<tr${calculateDataAttributes(platforms)}>", "</tr>", block)
- else
- appendTableRow(block)
+// if (platforms.isNotEmpty())
+// wrap("<tr${calculateDataAttributes(platforms)}>", "</tr>", block)
+// else
+// appendTableRow(block)
+ div(to, "declarations", otherAttributes = " ${calculateDataAttributes(platforms)}") {
+ block()
+ }
}
override fun appendPlatforms(platforms: Set<String>) {
@@ -159,7 +163,7 @@ open class KotlinWebsiteHtmlOutputBuilder(
div(to, "tags") {
platformsToKind.entries.forEach { (kind, values) ->
values.forEach { value ->
- div(to, "tags__tag $kind") {
+ div(to, "tags__tag $kind tag-value-$value") {
to.append(value)
}
}
diff --git a/core/src/main/kotlin/Formats/StructuredFormatService.kt b/core/src/main/kotlin/Formats/StructuredFormatService.kt
index 162976a6..dabc0b2b 100644
--- a/core/src/main/kotlin/Formats/StructuredFormatService.kt
+++ b/core/src/main/kotlin/Formats/StructuredFormatService.kt
@@ -5,6 +5,48 @@ import java.util.*
data class FormatLink(val text: String, val href: String)
+private data class Summarized(
+ val data: List<SummarizedBySummary>
+) {
+
+ constructor(data: Map<ContentNode, Map<ContentNode, List<DocumentationNode>>>) : this(
+ data.entries.map { (summary, signatureToMember) ->
+ SummarizedBySummary(
+ summary,
+ signatureToMember.map { (signature, nodes) ->
+ SummarizedNodes(signature, nodes)
+ }
+ )
+ }
+ )
+
+ data class SummarizedNodes(val content: ContentNode, val nodes: List<DocumentationNode>) {
+ val platforms = effectivePlatformAndVersion(nodes)
+ }
+ data class SummarizedBySummary(val content: ContentNode, val signatures: List<SummarizedNodes>) {
+ val platforms = effectivePlatformAndVersion(signatures.flatMap { it.nodes })
+ val platformsOnSignature = !sameVersionAndPlatforms(signatures.map { it.platforms })
+ }
+
+
+ fun computePlatformLevel(): PlatformPlacement {
+ if (data.any { it.platformsOnSignature }) {
+ return PlatformPlacement.Signature
+ }
+ if (sameVersionAndPlatforms(data.map { it.platforms })) {
+ return PlatformPlacement.Row
+ }
+ return PlatformPlacement.Summary
+ }
+ val platformPlacement: PlatformPlacement = computePlatformLevel()
+ val platforms = effectivePlatformAndVersion(data.flatMap { it.signatures.flatMap { it.nodes } })
+
+
+ enum class PlatformPlacement {
+ Row, Summary, Signature
+ }
+}
+
abstract class StructuredOutputBuilder(val to: StringBuilder,
val location: Location,
val generator: NodeLocationAwareGenerator,
@@ -454,7 +496,7 @@ abstract class StructuredOutputBuilder(val to: StringBuilder,
if (platforms.isEmpty()) return
appendParagraph {
- appendStrong { to.append("Platform and version requirements:") }
+ appendStrong { to.append("WTF: Platform and version requirements:") }
to.append(" " + platforms.joinToString())
}
}
@@ -678,20 +720,27 @@ abstract class StructuredOutputBuilder(val to: StringBuilder,
appendTable("Name", "Summary") {
appendTableBody {
for ((memberLocation, members) in membersMap) {
- val platforms = emptySet<String>()
+ val platforms = effectivePlatformAndVersion(members)
// val platforms = if (platformsBasedOnMembers)
// members.flatMapTo(mutableSetOf()) { platformsOfItems(it.members) } + elementPlatforms
// else
// elementPlatforms
+
+ val summarized = computeSummarySignatures(members)
+
+
appendIndexRow(platforms) {
appendTableCell {
+ if (summarized.platformPlacement == Summarized.PlatformPlacement.Row) {
+ appendPlatforms(platforms)
+ }
appendParagraph {
appendLink(memberLocation)
// if (members.singleOrNull()?.kind != NodeKind.ExternalClass) {
// appendPlatforms(platforms)
// }
}
- appendSummarySignatures(members, platformsBasedOnMembers, omitSamePlatforms, platforms)
+ appendSummarySignatures(summarized)
}
}
}
@@ -712,47 +761,52 @@ abstract class StructuredOutputBuilder(val to: StringBuilder,
// return emptySet()
// }
+
+
+ private fun computeSummarySignatures(items: List<DocumentationNode>): Summarized =
+ Summarized(items.groupBy { it.summary }.mapValues { (_, nodes) ->
+ val nodesToAppend = if (nodes.all { it.kind == NodeKind.GroupNode }) {
+ nodes.flatMap { it.origins }
+ } else {
+ nodes
+ }
+ val summarySignature = languageService.summarizeSignatures(nodesToAppend)
+ if (summarySignature != null) {
+ mapOf(summarySignature to nodes)
+ } else {
+ nodesToAppend.groupBy {
+ languageService.render(it, RenderMode.SUMMARY)
+ }
+ }
+ })
+
+
private fun appendSummarySignatures(
- items: List<DocumentationNode>,
- platformsBasedOnMembers: Boolean,
- omitSamePlatforms: Boolean,
- parentPlatforms: Set<String>
+ summarized: Summarized
) {
- val groupBySummary = items.groupBy { it.summary }
+ for(summary in summarized.data) {
- for ((summary, nodes) in groupBySummary) {
- val nodesToAppend = if (nodes.all { it.kind == NodeKind.GroupNode }) {
- nodes.flatMap { it.origins }
- } else {
- nodes
- }
- val platformsToAppend = effectivePlatformAndVersion(nodes)
- appendAsPlatformDependentBlock(platformsToAppend) {
- appendContent(summary)
- appendSoftLineBreak()
- }
- val summarySignature = languageService.summarizeSignatures(nodesToAppend)
- if (summarySignature != null) {
- appendSignatures(summarySignature, nodes, platformsBasedOnMembers, omitSamePlatforms, parentPlatforms)
- } else {
- val groupBySignature = nodesToAppend.groupBy {
- languageService.render(it, RenderMode.SUMMARY)
- }
- for ((sign, members) in groupBySignature) {
- appendSignatures(sign, members, platformsBasedOnMembers, omitSamePlatforms, parentPlatforms)
+ appendAsPlatformDependentBlock(summary.platforms) {
+ if (summarized.platformPlacement == Summarized.PlatformPlacement.Summary) {
+ appendPlatforms(summary.platforms)
}
+ appendContent(summary.content)
+ appendSoftLineBreak()
+ }
+ for (signature in summary.signatures) {
+ appendSignatures(
+ signature,
+ summarized.platformPlacement == Summarized.PlatformPlacement.Signature
+ )
}
}
}
private fun appendSignatures(
- signature: ContentNode,
- items: List<DocumentationNode>,
- platformsBasedOnMembers: Boolean,
- omitSamePlatforms: Boolean,
- parentPlatforms: Set<String>
+ signature: Summarized.SummarizedNodes,
+ withPlatforms: Boolean
) {
// val platforms = if (platformsBasedOnMembers)
@@ -760,14 +814,15 @@ abstract class StructuredOutputBuilder(val to: StringBuilder,
// else
// elementPlatforms
- val platformsToAppend = effectivePlatformAndVersion(items)
- appendAsPlatformDependentBlock(platformsToAppend) {
- appendAsSignature(signature) {
- signature.appendSignature()
+ appendAsPlatformDependentBlock(signature.platforms) {
+ if (withPlatforms) {
+ appendPlatforms(signature.platforms)
+ }
+ appendAsSignature(signature.content) {
+ signature.content.appendSignature()
}
appendSoftLineBreak()
- appendPlatforms(platformsToAppend)
}
}
}
@@ -859,7 +914,7 @@ fun effectivePlatformsForNode(node: DocumentationNode): Set<String> {
}
}
-fun effectivePlatformsForMembers(nodes: List<DocumentationNode>): Set<String> {
+fun effectivePlatformsForMembers(nodes: Collection<DocumentationNode>): Set<String> {
return nodes.map { effectivePlatformsForNode(it) }.reduce { acc, set ->
acc.union(set)
}
@@ -889,18 +944,25 @@ fun effectiveSinceKotlinForNode(node: DocumentationNode, baseVersion: String = "
val nodeVersion = node.sinceKotlin ?: baseVersion
val memberVersion = if (members.isNotEmpty()) effectiveSinceKotlinForNodes(members, nodeVersion) else nodeVersion
- println("${node.path} > $nodeVersion, $memberVersion")
-
return mergeVersions(listOf(memberVersion, nodeVersion))
}
-fun effectiveSinceKotlinForNodes(nodes: List<DocumentationNode>, baseVersion: String = "1.0"): String {
+fun effectiveSinceKotlinForNodes(nodes: Collection<DocumentationNode>, baseVersion: String = "1.0"): String {
return mergeVersions(nodes.map { effectiveSinceKotlinForNode(it, baseVersion) })
}
fun sinceKotlinAsPlatform(version: String): String = "Kotlin $version"
-fun effectivePlatformAndVersion(nodes: List<DocumentationNode>, baseVersion: String = "1.0"): Set<String> {
+fun effectivePlatformAndVersion(nodes: Collection<DocumentationNode>, baseVersion: String = "1.0"): Set<String> {
return effectivePlatformsForMembers(nodes) + sinceKotlinAsPlatform(effectiveSinceKotlinForNodes(nodes, baseVersion))
}
+
+fun effectivePlatformAndVersion(node: DocumentationNode, baseVersion: String = "1.0"): Set<String> {
+ return effectivePlatformsForNode(node) + sinceKotlinAsPlatform(effectiveSinceKotlinForNode(node, baseVersion))
+}
+
+fun sameVersionAndPlatforms(platformsPerNode: Collection<Set<String>>): Boolean {
+ val first = platformsPerNode.firstOrNull() ?: return true
+ return platformsPerNode.all { it == first }
+} \ No newline at end of file