diff options
author | Marcin Aman <marcin.aman@gmail.com> | 2021-01-20 10:30:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-20 10:30:50 +0100 |
commit | 93520158b4be59f98015d07e8fecaa7e5a49fd99 (patch) | |
tree | 24c57c752bb7f3125f6248ebae232a69bec8efb6 /plugins/kotlin-as-java/src | |
parent | 9f7dc9cc0183c74fc77c63297eb73f936715d77d (diff) | |
download | dokka-93520158b4be59f98015d07e8fecaa7e5a49fd99.tar.gz dokka-93520158b4be59f98015d07e8fecaa7e5a49fd99.tar.bz2 dokka-93520158b4be59f98015d07e8fecaa7e5a49fd99.zip |
Bring back displaying jvm name when KaJ is not present (#1702)
Diffstat (limited to 'plugins/kotlin-as-java/src')
-rw-r--r-- | plugins/kotlin-as-java/src/main/kotlin/transformers/JvmNameDocumentableTransformer.kt | 21 | ||||
-rw-r--r-- | plugins/kotlin-as-java/src/test/kotlin/JvmNameTest.kt | 32 |
2 files changed, 48 insertions, 5 deletions
diff --git a/plugins/kotlin-as-java/src/main/kotlin/transformers/JvmNameDocumentableTransformer.kt b/plugins/kotlin-as-java/src/main/kotlin/transformers/JvmNameDocumentableTransformer.kt index 3fb26034..c49e08f0 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/transformers/JvmNameDocumentableTransformer.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/transformers/JvmNameDocumentableTransformer.kt @@ -1,6 +1,7 @@ package org.jetbrains.dokka.kotlinAsJava.transformers import org.jetbrains.dokka.model.* +import org.jetbrains.dokka.model.properties.PropertyContainer import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.transformers.documentation.DocumentableTransformer @@ -25,7 +26,8 @@ class JvmNameDocumentableTransformer : DocumentableTransformer { val name = jvmNameProvider.nameFor(this) copy( dri = documentable.dri.withCallableName(name), - name = name + name = name, + extra = extra.withoutJvmName() ) } is DProperty -> transformGetterAndSetter(this) @@ -42,6 +44,17 @@ class JvmNameDocumentableTransformer : DocumentableTransformer { } } as T + private fun PropertyContainer<DFunction>.withoutJvmName(): PropertyContainer<DFunction> { + val annotationsWithoutJvmName = get(Annotations)?.let { annotations -> + annotations.copy((annotations.directAnnotations).map { (sourceset, annotations) -> + sourceset to annotations.filterNot { it.isJvmName() } + }.toMap() + annotations.fileLevelAnnotations) + } + val extraWithoutAnnotations: PropertyContainer<DFunction> = minus(Annotations) + + return extraWithoutAnnotations.addAll(listOfNotNull(annotationsWithoutJvmName)) + } + private fun transformClassLike(documentable: DClasslike): DClasslike = with(documentable) { when (this) { @@ -80,7 +93,8 @@ class JvmNameDocumentableTransformer : DocumentableTransformer { setter?.let { setter -> setter.copy( dri = setter.dri.withCallableName(setterName), - name = setterName + name = setterName, + extra = setter.extra.withoutJvmName() ) } }, @@ -88,7 +102,8 @@ class JvmNameDocumentableTransformer : DocumentableTransformer { getter?.let { getter -> getter.copy( dri = getter.dri.withCallableName(getterName), - name = getterName + name = getterName, + extra = getter.extra.withoutJvmName() ) } }) diff --git a/plugins/kotlin-as-java/src/test/kotlin/JvmNameTest.kt b/plugins/kotlin-as-java/src/test/kotlin/JvmNameTest.kt index 4c7e2445..1da2316c 100644 --- a/plugins/kotlin-as-java/src/test/kotlin/JvmNameTest.kt +++ b/plugins/kotlin-as-java/src/test/kotlin/JvmNameTest.kt @@ -4,8 +4,12 @@ import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest import org.jetbrains.dokka.links.Callable import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.links.TypeConstructor +import org.jetbrains.dokka.model.Annotations +import org.jetbrains.dokka.model.DClass +import org.jetbrains.dokka.model.isJvmName import org.junit.jupiter.api.Test import kotlin.test.assertEquals +import kotlin.test.assertNull class JvmNameTest : BaseAbstractTest() { val configuration = dokkaConfiguration { @@ -95,7 +99,8 @@ class JvmNameTest : BaseAbstractTest() { params = listOf(TypeConstructor("kotlin.String", emptyList())) ) ) - val function = module.packages.flatMap { it.classlikes }.flatMap { it.functions }.first { it.name == "asd"} + val function = + module.packages.flatMap { it.classlikes }.flatMap { it.functions }.first { it.name == "asd" } assertEquals(expectedSetterDri, function.dri) assertEquals("asd", function.name) } @@ -127,7 +132,8 @@ class JvmNameTest : BaseAbstractTest() { params = emptyList() ) ) - val function = module.packages.flatMap { it.classlikes }.flatMap { it.functions }.first { it.name == "xd"} + val function = + module.packages.flatMap { it.classlikes }.flatMap { it.functions }.first { it.name == "xd" } assertEquals(expectedGetterDri, function.dri) assertEquals("xd", function.name) } @@ -155,4 +161,26 @@ class JvmNameTest : BaseAbstractTest() { } } } + + @Test + fun `jvmName extra should be removed after the name swap`() { + testInline( + """ + |/src/main/kotlin/kotlinAsJavaPlugin/sample.kt + |package kotlinAsJavaPlugin + |@JvmName("CustomJvmName") + |fun sample(): String = "" + """.trimMargin(), + configuration, + ) { + documentablesTransformationStage = { module -> + val classLike = module.packages.flatMap { it.classlikes }.first() as DClass + assertNull( + classLike.extra[Annotations]?.directAnnotations?.flatMap { it.value } + ?.map { it.dri } + ?.firstOrNull { it.isJvmName() } + ) + } + } + } }
\ No newline at end of file |