aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorvmishenev <vad-mishenev@yandex.ru>2021-10-14 18:54:56 +0300
committerGitHub <noreply@github.com>2021-10-14 18:54:56 +0300
commitde5b8cb414023e36fa3c660b292bcc5835634b34 (patch)
tree94c0e486c678b134c63cc4aca4c78263f38ef554 /plugins
parentbc68cbfb1e2644498559016889b838a7b2836e41 (diff)
downloaddokka-de5b8cb414023e36fa3c660b292bcc5835634b34.tar.gz
dokka-de5b8cb414023e36fa3c660b292bcc5835634b34.tar.bz2
dokka-de5b8cb414023e36fa3c660b292bcc5835634b34.zip
Add keywords `expect` and `actual` in signatures (#2182)
Diffstat (limited to 'plugins')
-rw-r--r--plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt4
-rw-r--r--plugins/base/src/test/kotlin/signatures/SignatureTest.kt67
2 files changed, 69 insertions, 2 deletions
diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
index 8db37012..47e16e69 100644
--- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
+++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
@@ -101,6 +101,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
?: emptySet()),
sourceSets = setOf(sourceSet)
) {
+ keyword("actual ")
keyword("typealias ")
link(c.name.orEmpty(), c.dri)
operator(" = ")
@@ -127,6 +128,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
) {
annotationsBlock(c)
c.visibility[sourceSet]?.takeIf { it !in ignoredVisibilities }?.name?.let { keyword("$it ") }
+ if (c.isExpectActual) keyword(if (sourceSet == c.expectPresentInSet) "expect " else "actual ")
if (c is DClass) {
val modifier = if (c.modifier[sourceSet] !in ignoredModifiers)
when {
@@ -217,6 +219,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
) {
annotationsBlock(p)
p.visibility[it].takeIf { it !in ignoredVisibilities }?.name?.let { keyword("$it ") }
+ if (p.isExpectActual) keyword(if (it == p.expectPresentInSet) "expect " else "actual ")
p.modifier[it].takeIf { it !in ignoredModifiers }?.let {
if (it is JavaModifier.Empty) KotlinModifier.Open else it
}?.name?.let { keyword("$it ") }
@@ -262,6 +265,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
) {
annotationsBlock(f)
f.visibility[it]?.takeIf { it !in ignoredVisibilities }?.name?.let { keyword("$it ") }
+ if (f.isExpectActual) keyword(if (it == f.expectPresentInSet) "expect " else "actual ")
f.modifier[it]?.takeIf { it !in ignoredModifiers }?.let {
if (it is JavaModifier.Empty) KotlinModifier.Open else it
}?.name?.let { keyword("$it ") }
diff --git a/plugins/base/src/test/kotlin/signatures/SignatureTest.kt b/plugins/base/src/test/kotlin/signatures/SignatureTest.kt
index d8b23d77..9ca6a5db 100644
--- a/plugins/base/src/test/kotlin/signatures/SignatureTest.kt
+++ b/plugins/base/src/test/kotlin/signatures/SignatureTest.kt
@@ -410,6 +410,63 @@ class SignatureTest : BaseAbstractTest() {
}
@Test
+ fun `actual fun`() {
+
+ val configuration = dokkaConfiguration {
+ moduleName = "test"
+ sourceSets {
+ sourceSet {
+ name = "common"
+ sourceRoots = listOf("src/main/kotlin/common/Test.kt")
+ classpath = listOf(commonStdlibPath!!)
+ externalDocumentationLinks = listOf(stdlibExternalDocumentationLink)
+ }
+ sourceSet {
+ name = "jvm"
+ dependentSourceSets = setOf(DokkaSourceSetID("test", "common"))
+ sourceRoots = listOf("src/main/kotlin/jvm/Test.kt")
+ classpath = listOf(commonStdlibPath!!)
+ externalDocumentationLinks = listOf(stdlibExternalDocumentationLink)
+ }
+ }
+ }
+
+ val writerPlugin = TestOutputWriterPlugin()
+
+ testInline(
+ """
+ |/src/main/kotlin/common/Test.kt
+ |package example
+ |
+ |expect fun simpleFun(): String
+ |
+ |/src/main/kotlin/jvm/Test.kt
+ |package example
+ |
+ |actual fun simpleFun(): String = "Celebrimbor"
+ |
+ """.trimMargin(),
+ configuration,
+ pluginOverrides = listOf(writerPlugin)
+ ) {
+ renderingStage = { _, _ ->
+ val signatures = writerPlugin.writer.renderedContent("test/example/simple-fun.html").signature().toList()
+
+ signatures[0].match(
+ "expect fun ", A("simpleFun"),
+ "(): ", A("String"), Span(),
+ ignoreSpanWithTokenStyle = true
+ )
+ signatures[1].match(
+ "actual fun ", A("simpleFun"),
+ "(): ", A("String"), Span(),
+ ignoreSpanWithTokenStyle = true
+ )
+ }
+ }
+ }
+
+ @Test
fun `type with an actual typealias`() {
val configuration = dokkaConfiguration {
@@ -451,8 +508,14 @@ class SignatureTest : BaseAbstractTest() {
pluginOverrides = listOf(writerPlugin)
) {
renderingStage = { _, _ ->
- writerPlugin.writer.renderedContent("test/example/-foo/index.html").signature().toList()[1].match(
- "typealias ", A("Foo"), " = ", A("Bar"), Span(),
+ val signatures = writerPlugin.writer.renderedContent("test/example/-foo/index.html").signature().toList()
+
+ signatures[0].match(
+ "expect class ", A("Foo"), Span(),
+ ignoreSpanWithTokenStyle = true
+ )
+ signatures[1].match(
+ "actual typealias ", A("Foo"), " = ", A("Bar"), Span(),
ignoreSpanWithTokenStyle = true
)
}