aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZubakov <aleks.zubakov@gmail.com>2018-09-06 19:44:50 +0300
committerZubakov <aleks.zubakov@gmail.com>2018-09-06 19:45:16 +0300
commit0df19264ccae3d294946caf634ee15eea0c4fe4a (patch)
treeaac5889906f49f68c39e1416ea39d4d19bad008e
parente7917d0ca9aee41bbe0cc321ebdb171ee49a8337 (diff)
downloaddokka-0df19264ccae3d294946caf634ee15eea0c4fe4a.tar.gz
dokka-0df19264ccae3d294946caf634ee15eea0c4fe4a.tar.bz2
dokka-0df19264ccae3d294946caf634ee15eea0c4fe4a.zip
Minor refactoring, kotlin-website format change: add platforms to summary signatures, platform evaluating logic change
-rw-r--r--core/src/main/kotlin/Formats/KotlinWebsiteHtmlFormatService.kt7
-rw-r--r--core/src/main/kotlin/Formats/StructuredFormatService.kt123
-rw-r--r--core/src/main/kotlin/Model/DocumentationNode.kt6
3 files changed, 103 insertions, 33 deletions
diff --git a/core/src/main/kotlin/Formats/KotlinWebsiteHtmlFormatService.kt b/core/src/main/kotlin/Formats/KotlinWebsiteHtmlFormatService.kt
index 6ced75b5..16bec5a6 100644
--- a/core/src/main/kotlin/Formats/KotlinWebsiteHtmlFormatService.kt
+++ b/core/src/main/kotlin/Formats/KotlinWebsiteHtmlFormatService.kt
@@ -169,6 +169,13 @@ open class KotlinWebsiteHtmlOutputBuilder(
appendContent(section)
}
}
+
+ override fun appendAsBlockWithPlatforms(platforms: Set<String>, block: () -> Unit) {
+ if (platforms.isNotEmpty())
+ wrap("<div${calculateDataAttributes(platforms)}>", "</div>", block)
+ else
+ block()
+ }
}
class KotlinWebsiteHtmlFormatService @Inject constructor(
diff --git a/core/src/main/kotlin/Formats/StructuredFormatService.kt b/core/src/main/kotlin/Formats/StructuredFormatService.kt
index b57f21be..53172563 100644
--- a/core/src/main/kotlin/Formats/StructuredFormatService.kt
+++ b/core/src/main/kotlin/Formats/StructuredFormatService.kt
@@ -83,6 +83,10 @@ abstract class StructuredOutputBuilder(val to: StringBuilder,
}
}
+ open fun appendAsBlockWithPlatforms(platforms: Set<String>, block: () -> Unit) {
+ block()
+ }
+
open fun appendSymbol(text: String) {
appendText(text)
}
@@ -465,6 +469,18 @@ abstract class StructuredOutputBuilder(val to: StringBuilder,
platformsToShow
+ protected fun mergeVersions(otherKotlinVersion: String, kotlinVersions: List<String>): String {
+ val allKotlinVersions = (kotlinVersions + otherKotlinVersion).distinct()
+
+ val minVersion = allKotlinVersions.min()!!
+ val resultVersion: String = when {
+ allKotlinVersions.size == 1 -> allKotlinVersions.single()
+ minVersion.endsWith("+") -> minVersion
+ else -> "$minVersion+"
+ }
+
+ return resultVersion
+ }
protected fun platformsOfItems(items: List<DocumentationNode>): Set<String> {
val platforms = items.asSequence().map {
@@ -486,19 +502,38 @@ abstract class StructuredOutputBuilder(val to: StringBuilder,
// When no Kotlin version specified, it means that version is 1.0
if (otherKotlinVersion != null && kotlinVersions.isNotEmpty()) {
- val allKotlinVersions = (kotlinVersions + otherKotlinVersion).distinct()
+ result.intersect(platformsOfItem) + mergeVersions(otherKotlinVersion, kotlinVersions)
+ } else {
+ result.intersect(platformsOfItem)
+ }
+ }
+ }
- val minVersion = allKotlinVersions.min()!!
- val resultVersion = when {
- allKotlinVersions.size == 1 -> allKotlinVersions.single()
- minVersion.endsWith("+") -> minVersion
- else -> "$minVersion+"
- }
+ protected fun unionPlatformsOfItems(items: List<DocumentationNode>): Set<String> {
+ val platforms = items.asSequence().map {
+ when (it.kind) {
+ NodeKind.GroupNode -> unionPlatformsOfItems(it.origins)
+ else -> it.platformsToShow.toSet()
+ }
+ }
+
+ fun String.isKotlinVersion() = this.startsWith("Kotlin")
+
+ if (platforms.count() == 0) return emptySet()
+
+ // Calculating common platforms for items
+ return platforms.reduce { result, platformsOfItem ->
+ val otherKotlinVersion = result.find { it.isKotlinVersion() }
+ val (kotlinVersions, otherPlatforms) = platformsOfItem.partition { it.isKotlinVersion() }
- result.intersect(otherPlatforms) + resultVersion
+ // When no Kotlin version specified, it means that version is 1.0
+ if (otherKotlinVersion != null && kotlinVersions.isNotEmpty()) {
+ result.union(otherPlatforms) + mergeVersions(otherKotlinVersion, kotlinVersions)
} else {
- result.intersect(platformsOfItem)
+ result.union(otherPlatforms)
}
+ }.let {
+ if (it.containsAll(impliedPlatforms)) it - impliedPlatforms else it
}
}
@@ -566,6 +601,17 @@ abstract class StructuredOutputBuilder(val to: StringBuilder,
}
}
+ private fun unionPlatformsOfItems(items: List<DocumentationNode>): Set<String> {
+ val platforms = items.flatMapTo(mutableSetOf<String>()) {
+ when (it.kind) {
+ NodeKind.GroupNode -> unionPlatformsOfItems(it.origins)
+ else -> it.platforms
+ }
+ }
+
+ return platforms.let { if (it.containsAll(impliedPlatforms)) it - impliedPlatforms else it }
+ }
+
inner class SectionsBuilder(val node: DocumentationNode): PageBuilder(listOf(node)) {
override fun build() {
@@ -666,12 +712,7 @@ abstract class StructuredOutputBuilder(val to: StringBuilder,
}
}
appendTableCell {
- val nodesToAppend = if (members.all { it.kind == NodeKind.GroupNode }) {
- members.flatMap { it.origins }
- } else {
- members
- }
- appendSummarySignatures(nodesToAppend, platformsBasedOnMembers, omitSamePlatforms)
+ appendSummarySignatures(members, platformsBasedOnMembers, omitSamePlatforms)
}
}
}
@@ -680,6 +721,10 @@ abstract class StructuredOutputBuilder(val to: StringBuilder,
}
private fun platformsOfItems(items: List<DocumentationNode>, omitSamePlatforms: Boolean = true): Set<String> {
+ if (items.all { it.kind != NodeKind.Package && it.kind != NodeKind.Module && it.kind != NodeKind.ExternalClass }) {
+ return unionPlatformsOfItems(items)
+ }
+
val platforms = platformsOfItems(items)
if (platforms.isNotEmpty() && (platforms != node.platformsToShow.toSet() || !omitSamePlatforms)) {
return platforms
@@ -688,35 +733,49 @@ abstract class StructuredOutputBuilder(val to: StringBuilder,
}
private fun appendSummarySignatures(items: List<DocumentationNode>, platformsBasedOnMembers: Boolean, omitSamePlatforms: Boolean) {
- val summarySignature = languageService.summarizeSignatures(items)
- if (summarySignature != null) {
- appendSummarySignature(summarySignature, items, platformsBasedOnMembers, omitSamePlatforms)
- return
- }
+ val groupBySummary = items.groupBy { it.summary }
+ for ((summary, node) in groupBySummary) {
+ val nodesToAppend = if (node.all { it.kind == NodeKind.GroupNode }) {
+ node.flatMap { it.origins }
+ } else {
+ node
+ }
- val groupBySignature = items.groupBy {
- languageService.render(it, RenderMode.SUMMARY)
- }
- for ((sign, node) in groupBySignature) {
- appendSummarySignature(sign, node, platformsBasedOnMembers, omitSamePlatforms)
+ val summarySignature = languageService.summarizeSignatures(nodesToAppend)
+ if (summarySignature != null) {
+ appendSignatures(summarySignature, items, platformsBasedOnMembers, omitSamePlatforms)
+ } else {
+ val groupBySignature = nodesToAppend.groupBy {
+ languageService.render(it, RenderMode.SUMMARY)
+ }
+ for ((sign, members) in groupBySignature) {
+ appendSignatures(sign, members, platformsBasedOnMembers, omitSamePlatforms)
+ }
+ }
+
+ val platforms = platformsOfItems(node)
+ appendAsBlockWithPlatforms(platforms) {
+ appendContent(summary)
+ appendSoftLineBreak()
+ }
}
}
- private fun appendSummarySignature(signature: ContentNode, items: List<DocumentationNode>, platformsBasedOnMembers: Boolean, omitSamePlatforms: Boolean) {
+ private fun appendSignatures(signature: ContentNode, items: List<DocumentationNode>, platformsBasedOnMembers: Boolean, omitSamePlatforms: Boolean) {
val elementPlatforms = platformsOfItems(items, omitSamePlatforms)
val platforms = if (platformsBasedOnMembers)
items.flatMapTo(mutableSetOf()) { platformsOfItems(it.members) } + elementPlatforms
else
elementPlatforms
- appendPlatforms(platforms)
- appendAsSignature(signature) {
- signature.appendSignature()
+ appendAsBlockWithPlatforms(platforms) {
+ appendPlatforms(platforms)
+ appendAsSignature(signature) {
+ signature.appendSignature()
+ }
+ appendSoftLineBreak()
}
-
- appendContent(items.first().summary)
- appendSoftLineBreak()
}
}
diff --git a/core/src/main/kotlin/Model/DocumentationNode.kt b/core/src/main/kotlin/Model/DocumentationNode.kt
index 146c1e99..f2b3a937 100644
--- a/core/src/main/kotlin/Model/DocumentationNode.kt
+++ b/core/src/main/kotlin/Model/DocumentationNode.kt
@@ -76,7 +76,11 @@ open class DocumentationNode(val name: String,
var content: Content = content
private set
- val summary: ContentNode get() = content.summary
+ val summary: ContentNode get() = when (kind) {
+ NodeKind.GroupNode -> this.origins.first().summary
+ else -> content.summary
+ }
+
val owner: DocumentationNode?
get() = references(RefKind.Owner).singleOrNull()?.to