diff options
author | Marcin Aman <marcin.aman@gmail.com> | 2021-01-04 10:27:10 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-04 10:27:10 +0100 |
commit | 6b0cdf3102b1f1dd213ca0c2e2c333f8756be6b4 (patch) | |
tree | 173db191f3f48b93574ff5d1052c99f98469e0f4 /plugins/kotlin-as-java/src/test/kotlin | |
parent | 1bf2cda23362ccab60fb866e07e9b8f073254d2c (diff) | |
download | dokka-6b0cdf3102b1f1dd213ca0c2e2c333f8756be6b4.tar.gz dokka-6b0cdf3102b1f1dd213ca0c2e2c333f8756be6b4.tar.bz2 dokka-6b0cdf3102b1f1dd213ca0c2e2c333f8756be6b4.zip |
JvmField annotation (#1678)
Diffstat (limited to 'plugins/kotlin-as-java/src/test/kotlin')
-rw-r--r-- | plugins/kotlin-as-java/src/test/kotlin/JvmFieldTest.kt | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/plugins/kotlin-as-java/src/test/kotlin/JvmFieldTest.kt b/plugins/kotlin-as-java/src/test/kotlin/JvmFieldTest.kt new file mode 100644 index 00000000..154083d7 --- /dev/null +++ b/plugins/kotlin-as-java/src/test/kotlin/JvmFieldTest.kt @@ -0,0 +1,81 @@ +package kotlinAsJavaPlugin + +import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest +import org.jetbrains.dokka.model.JavaVisibility +import org.junit.jupiter.api.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotNull + +class JvmFieldTest : BaseAbstractTest() { + val configuration = dokkaConfiguration { + sourceSets { + sourceSet { + sourceRoots = listOf("src/") + classpath += jvmStdlibPath!! + } + } + } + + @Test + fun `should keep properties annotated with JvmField as properties`() { + testInline( + """ + |/src/main/kotlin/kotlinAsJavaPlugin/sample.kt + |package kotlinAsJavaPlugin + |class SampleClass(@JvmField val property: String, val otherProperty: String) + """.trimMargin(), + configuration, + ) { + documentablesTransformationStage = { module -> + val classLike = module.packages.flatMap { it.classlikes }.first() + assertNotNull(classLike.properties.firstOrNull { it.name == "property" }) + assertEquals( + listOf("getOtherProperty", "equals", "hashCode", "toString"), + classLike.functions.map { it.name }) + } + } + } + + @Test + fun `should work for top-level property`(){ + testInline( + """ + |/src/main/kotlin/kotlinAsJavaPlugin/sample.kt + |package kotlinAsJavaPlugin + |@JvmField + |val property: String = TODO() + """.trimMargin(), + configuration, + ) { + documentablesTransformationStage = { module -> + val classLike = module.packages.flatMap { it.classlikes }.first() + assertNotNull(classLike.properties.firstOrNull { it.name == "property" }) + assertEquals( + emptyList(), + classLike.functions.map { it.name }) + } + } + } + + @Test + fun `properties without JvmName should be kept private`() { + testInline( + """ + |/src/main/kotlin/kotlinAsJavaPlugin/sample.kt + |package kotlinAsJavaPlugin + |class SampleClass(val property: String) + """.trimMargin(), + configuration, + ) { + documentablesTransformationStage = { module -> + val classLike = module.packages.flatMap { it.classlikes }.first() + assertEquals(JavaVisibility.Private, classLike.properties.firstOrNull()?.visibility?.values?.first()) + assertNotNull(classLike.functions.firstOrNull { it.name.startsWith("get") }) + assertEquals( + JavaVisibility.Public, + classLike.functions.first { it.name.startsWith("get") }.visibility.values.first() + ) + } + } + } +}
\ No newline at end of file |