aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src
diff options
context:
space:
mode:
authorBłażej Kardyś <bkardys@virtuslab.com>2020-09-30 16:33:06 +0200
committerKamil Doległo <9080183+kamildoleglo@users.noreply.github.com>2020-10-06 15:41:04 +0200
commit7c4301a48af55e156538666b6e645d8d13caae9a (patch)
tree47ff8205ff4765aac3caeb5a9552db85e522bb57 /plugins/base/src
parentbe932e200951e5b043f2e04e18b60176ac876156 (diff)
downloaddokka-7c4301a48af55e156538666b6e645d8d13caae9a.tar.gz
dokka-7c4301a48af55e156538666b6e645d8d13caae9a.tar.bz2
dokka-7c4301a48af55e156538666b6e645d8d13caae9a.zip
Fixing clashing properties and functions pages
Diffstat (limited to 'plugins/base/src')
-rw-r--r--plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt41
-rw-r--r--plugins/base/src/test/kotlin/signatures/FunctionalTypeConstructorsSignatureTest.kt18
-rw-r--r--plugins/base/src/test/kotlin/signatures/SignatureTest.kt2
3 files changed, 34 insertions, 27 deletions
diff --git a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt
index e6f92d6b..41881baf 100644
--- a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt
+++ b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt
@@ -36,15 +36,15 @@ open class DefaultPageCreator(
open fun pageForPackage(p: DPackage): PackagePageNode = PackagePageNode(
p.name, contentForPackage(p), setOf(p.dri), p,
- p.classlikes.renameClashingClasslikes().map(::pageForClasslike) +
- p.functions.map(::pageForFunction) + p.properties.mapNotNull(::pageForProperty)
+ p.classlikes.renameClashingDocumentable().map(::pageForClasslike) +
+ p.functions.renameClashingDocumentable().map(::pageForFunction) + p.properties.mapNotNull(::pageForProperty)
)
open fun pageForEnumEntry(e: DEnumEntry): ClasslikePageNode =
ClasslikePageNode(
e.name, contentForEnumEntry(e), setOf(e.dri), e,
- e.classlikes.renameClashingClasslikes().map(::pageForClasslike) +
- e.filteredFunctions.map(::pageForFunction)
+ e.classlikes.renameClashingDocumentable().map(::pageForClasslike) +
+ e.filteredFunctions.renameClashingDocumentable().map(::pageForFunction)
)
open fun pageForClasslike(c: DClasslike): ClasslikePageNode {
@@ -53,24 +53,31 @@ open class DefaultPageCreator(
return ClasslikePageNode(
c.name.orEmpty(), contentForClasslike(c), setOf(c.dri), c,
constructors.map(::pageForFunction) +
- c.classlikes.renameClashingClasslikes().map(::pageForClasslike) +
- c.filteredFunctions.map(::pageForFunction) +
- c.properties.mapNotNull(::pageForProperty) +
+ c.classlikes.renameClashingDocumentable().map(::pageForClasslike) +
+ c.filteredFunctions.renameClashingDocumentable().map(::pageForFunction) +
+ c.properties.renameClashingDocumentable().mapNotNull(::pageForProperty) +
if (c is DEnum) c.entries.map(::pageForEnumEntry) else emptyList()
)
}
- private fun List<DClasslike>.renameClashingClasslikes(): List<DClasslike> = groupBy { it.dri }.values.flatMap { classlikes ->
- if (classlikes.size == 1) classlikes else classlikes.map { classlike ->
- fun ClashingDriIdentifier?.toName() = this?.value?.joinToString(", ", "(", ")") { it.displayName } ?: ""
- when(classlike) {
- is DClass -> classlike.copy(name = classlike.name + classlike.extra[ClashingDriIdentifier]?.toName())
- is DObject -> classlike.copy(name = classlike.name.orEmpty() + classlike.extra[ClashingDriIdentifier]?.toName())
- is DAnnotation -> classlike.copy(name = classlike.name + classlike.extra[ClashingDriIdentifier]?.toName())
- is DInterface -> classlike.copy(name = classlike.name + classlike.extra[ClashingDriIdentifier]?.toName())
- is DEnum -> classlike.copy(name = classlike.name + classlike.extra[ClashingDriIdentifier]?.toName())
- }
+ private fun <T> T.toClashedName() where T: Documentable, T: WithExtraProperties<T> =
+ name.orEmpty() + (extra[ClashingDriIdentifier]?.value?.joinToString(", ", "(", ")") { it.displayName } ?: "")
+
+ private fun <T> List<T>.renameClashingDocumentable(): List<T> where T: Documentable =
+ groupBy { it.dri }.values.flatMap { elements ->
+ if (elements.size == 1) elements else elements.mapNotNull { element ->
+ when(element) {
+ is DClass -> element.copy(name = element.toClashedName())
+ is DObject -> element.copy(name = element.toClashedName())
+ is DAnnotation -> element.copy(name = element.toClashedName())
+ is DInterface -> element.copy(name = element.toClashedName())
+ is DEnum -> element.copy(name = element.toClashedName())
+ is DFunction -> element.copy(name = element.toClashedName())
+ is DProperty -> element.copy(name = element.toClashedName())
+ is DTypeAlias -> element.copy(name = element.toClashedName())
+ else -> null
+ } as? T?
}
}
diff --git a/plugins/base/src/test/kotlin/signatures/FunctionalTypeConstructorsSignatureTest.kt b/plugins/base/src/test/kotlin/signatures/FunctionalTypeConstructorsSignatureTest.kt
index bac3ced2..93d53df4 100644
--- a/plugins/base/src/test/kotlin/signatures/FunctionalTypeConstructorsSignatureTest.kt
+++ b/plugins/base/src/test/kotlin/signatures/FunctionalTypeConstructorsSignatureTest.kt
@@ -43,7 +43,7 @@ class FunctionalTypeConstructorsSignatureTest : AbstractCoreTest() {
pluginOverrides = listOf(writerPlugin)
) {
renderingStage = { _, _ ->
- writerPlugin.writer.renderedContent("root/example.html").firstSignature().match(
+ writerPlugin.writer.renderedContent("root/example/index.html").firstSignature().match(
"val ", A("nF"), ": (", A("Int"), ") -> ", A("String"), Span()
)
}
@@ -61,7 +61,7 @@ class FunctionalTypeConstructorsSignatureTest : AbstractCoreTest() {
pluginOverrides = listOf(writerPlugin)
) {
renderingStage = { _, _ ->
- writerPlugin.writer.renderedContent("root/example.html").firstSignature().match(
+ writerPlugin.writer.renderedContent("root/example/index.html").firstSignature().match(
"val ", A("nF"), ": (", A("Int"), ") -> ", A("String"), Span()
)
}
@@ -79,7 +79,7 @@ class FunctionalTypeConstructorsSignatureTest : AbstractCoreTest() {
pluginOverrides = listOf(writerPlugin)
) {
renderingStage = { _, _ ->
- writerPlugin.writer.renderedContent("root/example.html").firstSignature().match(
+ writerPlugin.writer.renderedContent("root/example/index.html").firstSignature().match(
"val ", A("nF"), ": ", A("Boolean"), ".(", A("Int"), ") -> ", A("String"), Span()
)
}
@@ -97,7 +97,7 @@ class FunctionalTypeConstructorsSignatureTest : AbstractCoreTest() {
pluginOverrides = listOf(writerPlugin)
) {
renderingStage = { _, _ ->
- writerPlugin.writer.renderedContent("root/example.html").firstSignature().match(
+ writerPlugin.writer.renderedContent("root/example/index.html").firstSignature().match(
"val ", A("nF"), ": (param: ", A("Int"), ") -> ", A("String"), Span()
)
}
@@ -116,7 +116,7 @@ class FunctionalTypeConstructorsSignatureTest : AbstractCoreTest() {
pluginOverrides = listOf(writerPlugin)
) {
renderingStage = { _, _ ->
- writerPlugin.writer.renderedContent("root/example.html").firstSignature().match(
+ writerPlugin.writer.renderedContent("root/example/index.html").firstSignature().match(
"val ", A("nF"), ": suspend (", A("Int"), ") -> ", A("String"), Span()
)
}
@@ -134,7 +134,7 @@ class FunctionalTypeConstructorsSignatureTest : AbstractCoreTest() {
pluginOverrides = listOf(writerPlugin)
) {
renderingStage = { _, _ ->
- writerPlugin.writer.renderedContent("root/example.html").firstSignature().match(
+ writerPlugin.writer.renderedContent("root/example/index.html").firstSignature().match(
"val ", A("nF"), ": suspend (", A("Int"), ") -> ", A("String"), Span()
)
}
@@ -152,7 +152,7 @@ class FunctionalTypeConstructorsSignatureTest : AbstractCoreTest() {
pluginOverrides = listOf(writerPlugin)
) {
renderingStage = { _, _ ->
- writerPlugin.writer.renderedContent("root/example.html").firstSignature().match(
+ writerPlugin.writer.renderedContent("root/example/index.html").firstSignature().match(
"val ", A("nF"), ": suspend ", A("Boolean"), ".(", A("Int"), ") -> ", A("String"), Span()
)
}
@@ -170,7 +170,7 @@ class FunctionalTypeConstructorsSignatureTest : AbstractCoreTest() {
pluginOverrides = listOf(writerPlugin)
) {
renderingStage = { _, _ ->
- writerPlugin.writer.renderedContent("root/example.html").firstSignature().match(
+ writerPlugin.writer.renderedContent("root/example/index.html").firstSignature().match(
"val ", A("nF"), ": suspend (param: ", A("Int"), ") -> ", A("String"), Span()
)
}
@@ -189,7 +189,7 @@ class FunctionalTypeConstructorsSignatureTest : AbstractCoreTest() {
pluginOverrides = listOf(writerPlugin)
) {
renderingStage = { _, _ ->
- writerPlugin.writer.renderedContent("root/example.html").firstSignature().match(
+ writerPlugin.writer.renderedContent("root/example/index.html").firstSignature().match(
"val ",
A("nF"),
": suspend (param1: suspend",
diff --git a/plugins/base/src/test/kotlin/signatures/SignatureTest.kt b/plugins/base/src/test/kotlin/signatures/SignatureTest.kt
index f8c17794..35a11cda 100644
--- a/plugins/base/src/test/kotlin/signatures/SignatureTest.kt
+++ b/plugins/base/src/test/kotlin/signatures/SignatureTest.kt
@@ -606,7 +606,7 @@ class SignatureTest : AbstractCoreTest() {
pluginOverrides = listOf(writerPlugin)
) {
renderingStage = { _, _ ->
- writerPlugin.writer.renderedContent("root/example.html").firstSignature().match(
+ writerPlugin.writer.renderedContent("root/example/index.html").firstSignature().match(
"const val ", A("simpleVal"), ": ", A("Int"), " = 1", Span()
)
}