diff options
author | Marcin Aman <maman@virtuslab.com> | 2020-07-06 17:00:13 +0200 |
---|---|---|
committer | Paweł Marks <Kordyjan@users.noreply.github.com> | 2020-07-13 14:48:27 +0200 |
commit | 6377d964819f937bd4a7633488d69edc327542d8 (patch) | |
tree | 5e52cf65cfce31de9a1500d08a9bfe25deb00a90 /plugins/kotlin-as-java/src/main/kotlin/converters | |
parent | d180633e91afd76de788a0bd1bfe75fe09f19aea (diff) | |
download | dokka-6377d964819f937bd4a7633488d69edc327542d8.tar.gz dokka-6377d964819f937bd4a7633488d69edc327542d8.tar.bz2 dokka-6377d964819f937bd4a7633488d69edc327542d8.zip |
Java sources in Kotlin-As-Java plugin should have original property visibilites
Diffstat (limited to 'plugins/kotlin-as-java/src/main/kotlin/converters')
-rw-r--r-- | plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt | 33 |
1 files changed, 17 insertions, 16 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 1ca4ef51..24d99995 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt @@ -67,12 +67,8 @@ internal fun DProperty.asJava(isTopLevel: Boolean = false, relocateToClass: Stri } else { dri.withClass(relocateToClass) }, - modifier = if (setter == null) { - sourceSets.map { it to JavaModifier.Final }.toMap() - } else { - sourceSets.map { it to JavaModifier.Empty }.toMap() - }, - visibility = visibility.mapValues { JavaVisibility.Private }, + modifier = javaModifierFromSetter(), + visibility = visibility.mapValues { it.value.propertyVisibilityAsJava() }, type = type.asJava(), // TODO: check setter = null, getter = null, // Removing getters and setters as they will be available as functions @@ -85,6 +81,15 @@ internal fun DProperty.asJava(isTopLevel: Boolean = false, relocateToClass: Stri else extra ) +internal fun DProperty.javaModifierFromSetter() = + modifier.mapValues { + when { + it.value is JavaModifier -> it.value + setter == null -> JavaModifier.Final + else -> JavaModifier.Empty + } + } + internal fun DProperty.javaAccessors(isTopLevel: Boolean = false, relocateToClass: String? = null): List<DFunction> = listOfNotNull( getter?.copy( @@ -94,11 +99,7 @@ internal fun DProperty.javaAccessors(isTopLevel: Boolean = false, relocateToClas dri.withClass(relocateToClass) }, name = "get" + name.capitalize(), - modifier = if (setter == null) { - sourceSets.map { it to JavaModifier.Final }.toMap() - } else { - sourceSets.map { it to JavaModifier.Empty }.toMap() - }, + modifier = javaModifierFromSetter(), visibility = visibility.mapValues { JavaVisibility.Public }, type = type.asJava(), // TODO: check extra = if (isTopLevel) getter!!.extra + @@ -116,11 +117,7 @@ internal fun DProperty.javaAccessors(isTopLevel: Boolean = false, relocateToClas dri.withClass(relocateToClass) }, name = "set" + name.capitalize(), - modifier = if (setter == null) { - sourceSets.map { it to JavaModifier.Final }.toMap() - } else { - sourceSets.map { it to JavaModifier.Empty }.toMap() - }, + modifier = javaModifierFromSetter(), visibility = visibility.mapValues { JavaVisibility.Public }, type = type.asJava(), // TODO: check extra = if (isTopLevel) setter!!.extra + setter!!.extra.mergeAdditionalModifiers( @@ -249,6 +246,10 @@ internal fun DParameter.asJava(): DParameter = copy( name = if (name.isNullOrBlank()) "\$self" else name ) +internal fun Visibility.propertyVisibilityAsJava(): Visibility = + if(this is JavaVisibility) this + else JavaVisibility.Private + internal fun String.getAsPrimitive(): JvmPrimitiveType? = org.jetbrains.kotlin.builtins.PrimitiveType.values() .find { it.typeFqName.asString() == this } ?.let { JvmPrimitiveType.get(it) } |