aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaweł Marks <pmarks@virtuslab.com>2020-03-04 14:07:57 +0100
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-03-04 14:28:14 +0100
commit1ed877e8b51ec586a2976e8088e34d17de82fc52 (patch)
treea1cfe422a3cd659a35fa5dea924d9da99afb7c71
parentad8d1e01a8d4f1f6066c74f89466f3b33c948f87 (diff)
downloaddokka-1ed877e8b51ec586a2976e8088e34d17de82fc52.tar.gz
dokka-1ed877e8b51ec586a2976e8088e34d17de82fc52.tar.bz2
dokka-1ed877e8b51ec586a2976e8088e34d17de82fc52.zip
Now signature provider uses new visibility model
-rw-r--r--core/src/main/kotlin/model/Documentable.kt22
-rw-r--r--plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt13
-rw-r--r--plugins/base/src/test/resources/expect/test/out/root/fn.html2
-rw-r--r--plugins/base/src/test/resources/expect/test/out/root/index.html2
4 files changed, 20 insertions, 19 deletions
diff --git a/core/src/main/kotlin/model/Documentable.kt b/core/src/main/kotlin/model/Documentable.kt
index aeb10bee..9116b6e6 100644
--- a/core/src/main/kotlin/model/Documentable.kt
+++ b/core/src/main/kotlin/model/Documentable.kt
@@ -351,19 +351,19 @@ fun Documentable.dfs(predicate: (Documentable) -> Boolean): Documentable? =
this.children.asSequence().mapNotNull { it.dfs(predicate) }.firstOrNull()
}
-sealed class Visibility
-sealed class KotlinVisibility : Visibility() {
- object Public : KotlinVisibility()
- object Private : KotlinVisibility()
- object Protected : KotlinVisibility()
- object Internal : KotlinVisibility()
+sealed class Visibility(val name: String)
+sealed class KotlinVisibility(name: String) : Visibility(name) {
+ object Public : KotlinVisibility("public")
+ object Private : KotlinVisibility("private")
+ object Protected : KotlinVisibility("protected")
+ object Internal : KotlinVisibility("internal")
}
-sealed class JavaVisibility : Visibility() {
- object Public : JavaVisibility()
- object Private : JavaVisibility()
- object Protected : JavaVisibility()
- object Default : JavaVisibility()
+sealed class JavaVisibility(name: String) : Visibility(name) {
+ object Public : JavaVisibility("public")
+ object Private : JavaVisibility("private")
+ object Protected : JavaVisibility("protected")
+ object Default : JavaVisibility("")
}
fun <T> PlatformDependent<T>?.orEmpty(): PlatformDependent<T> = this ?: PlatformDependent.empty()
diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
index 3e06dc20..cfca20b0 100644
--- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
+++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
@@ -15,6 +15,8 @@ import org.jetbrains.dokka.utilities.DokkaLogger
class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogger) : SignatureProvider {
private val contentBuilder = PageContentBuilder(ctcc, this, logger)
+ private val ignoredVisibilities = setOf(JavaVisibility.Default, KotlinVisibility.Public)
+
override fun signature(documentable: Documentable): ContentNode = when (documentable) {
is Function -> signature(documentable)
is Classlike -> signature(documentable)
@@ -25,7 +27,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
}
private fun signature(c: Classlike) = contentBuilder.contentFor(c, ContentKind.Symbol) {
- platformText(c.visibility) { it.externalDisplayName + " " }
+ platformText(c.visibility) { (it.takeIf { it !in ignoredVisibilities }?.name ?: "") + " " }
if (c is Class) {
text(c.modifier.toString() + " ")
}
@@ -47,7 +49,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
}
private fun signature(f: Function) = contentBuilder.contentFor(f, ContentKind.Symbol) {
- platformText(f.visibility) { it.externalDisplayName + " " }
+ platformText(f.visibility) { (it.takeIf { it !in ignoredVisibilities }?.name ?: "") + " " }
text(f.modifier.toString().toLowerCase() + " ")
text("fun ")
f.receiver?.also {
@@ -101,12 +103,11 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
text("?")
}
}
-
- private fun <T : Documentable> Collection<T>.filterOnPlatform(platformData: PlatformData) =
- this.filter { it.platformData.contains(platformData) }
}
private fun <T> PageContentBuilder.DocumentableContentBuilder.platformText(
value: PlatformDependent<T>,
transform: (T) -> String
-) = value.entries.forEach { (p, v) -> text(transform(v), platformData = setOf(p)) } \ No newline at end of file
+) = value.entries.forEach { (p, v) ->
+ transform(v).takeIf { it.isNotBlank() }?.also { text(it, platformData = setOf(p)) }
+} \ No newline at end of file
diff --git a/plugins/base/src/test/resources/expect/test/out/root/fn.html b/plugins/base/src/test/resources/expect/test/out/root/fn.html
index cc0ae002..e87d7bc4 100644
--- a/plugins/base/src/test/resources/expect/test/out/root/fn.html
+++ b/plugins/base/src/test/resources/expect/test/out/root/fn.html
@@ -14,7 +14,7 @@
</div>
<div id="content">//<a href="../index.html">root</a>/<a href="index.html"></a>/<a href="fn.html">fn</a>
<h1>fn</h1>
-public final fun <a href="fn.html">fn</a>()
+final fun <a href="fn.html">fn</a>()
<h3>Description</h3>
Function fn
</div>
diff --git a/plugins/base/src/test/resources/expect/test/out/root/index.html b/plugins/base/src/test/resources/expect/test/out/root/index.html
index 81f2bcc2..25c65b11 100644
--- a/plugins/base/src/test/resources/expect/test/out/root/index.html
+++ b/plugins/base/src/test/resources/expect/test/out/root/index.html
@@ -20,7 +20,7 @@
<tbody>
<tr>
<td><a href="fn.html">fn</a></td>
- <td>public final fun <a href="fn.html">fn</a>()</td>
+ <td>final fun <a href="fn.html">fn</a>()</td>
<td>Function fn</td>
</tr>
</tbody>