aboutsummaryrefslogtreecommitdiff
path: root/plugins/kotlin-as-java
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/kotlin-as-java')
-rw-r--r--plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt10
-rw-r--r--plugins/kotlin-as-java/src/test/kotlin/JvmFieldTest.kt30
2 files changed, 34 insertions, 6 deletions
diff --git a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt
index 1e3bd800..8ff35781 100644
--- a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt
+++ b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt
@@ -87,7 +87,7 @@ internal fun DProperty.asJava(isTopLevel: Boolean = false, relocateToClass: Stri
visibility = visibility.mapValues {
if (isTopLevel && isConst) {
JavaVisibility.Public
- } else if (jvmField() != null) {
+ } else if (jvmField() != null || (getter == null && setter == null)) {
it.value.asJava()
} else {
it.value.propertyVisibilityAsJava()
@@ -275,7 +275,7 @@ internal fun DClass.functionsInJava(): List<DFunction> =
.flatMap { property -> listOfNotNull(property.getter, property.setter) }
.plus(functions)
.filterNot { it.hasJvmSynthetic() }
- .flatMap { it.asJava(dri.classNames ?: name) }
+ .flatMap { it.asJava(it.dri.classNames ?: it.name) }
private fun DTypeParameter.asJava(): DTypeParameter = copy(
variantTypeParameter = variantTypeParameter.withDri(dri.possiblyAsJava()),
@@ -317,7 +317,7 @@ internal fun DEnum.asJava(): DEnum = copy(
functions = functions
.plus(
properties
- .filterNot { it.hasJvmSynthetic() }
+ .filter { it.jvmField() == null && !it.hasJvmSynthetic() }
.flatMap { listOf(it.getter, it.setter) }
)
.filterNotNull()
@@ -335,7 +335,7 @@ internal fun DObject.asJava(): DObject = copy(
functions = functions
.plus(
properties
- .filterNot { it.hasJvmSynthetic() }
+ .filter { it.jvmField() == null && !it.hasJvmSynthetic() }
.flatMap { listOf(it.getter, it.setter) }
)
.filterNotNull()
@@ -373,7 +373,7 @@ internal fun DInterface.asJava(): DInterface = copy(
functions = functions
.plus(
properties
- .filterNot { it.hasJvmSynthetic() }
+ .filter { it.jvmField() == null && !it.hasJvmSynthetic() }
.flatMap { listOf(it.getter, it.setter) }
)
.filterNotNull()
diff --git a/plugins/kotlin-as-java/src/test/kotlin/JvmFieldTest.kt b/plugins/kotlin-as-java/src/test/kotlin/JvmFieldTest.kt
index 2f490421..99ea017b 100644
--- a/plugins/kotlin-as-java/src/test/kotlin/JvmFieldTest.kt
+++ b/plugins/kotlin-as-java/src/test/kotlin/JvmFieldTest.kt
@@ -5,6 +5,7 @@ import org.jetbrains.dokka.model.JavaVisibility
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
+import kotlin.test.assertNull
class JvmFieldTest : BaseAbstractTest() {
val configuration = dokkaConfiguration {
@@ -78,4 +79,31 @@ class JvmFieldTest : BaseAbstractTest() {
}
}
}
-} \ No newline at end of file
+
+ @Test
+ fun `object jvmfield property should have no getters`(){
+ testInline(
+ """
+ |/src/main/kotlin/kotlinAsJavaPlugin/sample.kt
+ |package kotlinAsJavaPlugin
+ |object MyObject {
+ | @JvmField
+ | val property: String = TODO()
+ |}
+ """.trimMargin(),
+ configuration,
+ ) {
+ documentablesTransformationStage = { module ->
+ val classLike = module.packages.flatMap { it.classlikes }.first()
+ val property = classLike.properties.singleOrNull { it.name == "property" }
+ assertNotNull(property)
+ assertEquals(
+ emptyList(),
+ classLike.functions.map { it.name }
+ )
+ assertNull(property.getter)
+ assertNull(property.setter)
+ }
+ }
+ }
+}