aboutsummaryrefslogtreecommitdiff
path: root/plugins/kotlin-as-java/src/main/kotlin
diff options
context:
space:
mode:
authorValentin Rocher <bishiboosh@gmail.com>2020-12-03 10:33:23 +0100
committerGitHub <noreply@github.com>2020-12-03 10:33:23 +0100
commit207a66a54f65fc2bd40baff4b144e0df6bb2eb15 (patch)
tree861ba7da33f0aa02902c071368688ab65b221669 /plugins/kotlin-as-java/src/main/kotlin
parent254f319aadf9327261da7c623fb22a632ce9bab8 (diff)
downloaddokka-207a66a54f65fc2bd40baff4b144e0df6bb2eb15.tar.gz
dokka-207a66a54f65fc2bd40baff4b144e0df6bb2eb15.tar.bz2
dokka-207a66a54f65fc2bd40baff4b144e0df6bb2eb15.zip
exclude top-level const val from getter generation and show them as public and static (#1636)
Diffstat (limited to 'plugins/kotlin-as-java/src/main/kotlin')
-rw-r--r--plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt21
1 files changed, 18 insertions, 3 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 5112ae0b..0f7d5c7a 100644
--- a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt
+++ b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt
@@ -23,6 +23,13 @@ private fun <T : WithSources> List<T>.groupedByLocation() =
} // TODO: first() does not look reasonable
}) { it.second }
+private val DProperty.isConst: Boolean
+ get() = extra[AdditionalModifiers]
+ ?.content
+ ?.any { (_, modifiers) ->
+ ExtraModifiers.KotlinOnlyModifiers.Const in modifiers
+ } == true
+
internal fun DPackage.asJava(): DPackage {
@Suppress("UNCHECKED_CAST")
val syntheticClasses = ((properties + functions) as List<WithSources>)
@@ -31,10 +38,12 @@ internal fun DPackage.asJava(): DPackage {
DClass(
dri = dri.withClass(syntheticClassName),
name = syntheticClassName,
- properties = nodes.filterIsInstance<DProperty>().map { it.asJava() },
+ properties = nodes.filterIsInstance<DProperty>().map { it.asJava(true) },
constructors = emptyList(),
functions = (
- nodes.filterIsInstance<DProperty>()
+ nodes
+ .filterIsInstance<DProperty>()
+ .filterNot { it.isConst }
.flatMap { it.javaAccessors() } +
nodes.filterIsInstance<DFunction>()
.map { it.asJava(syntheticClassName) }), // TODO: methods are static and receiver is a param
@@ -71,7 +80,13 @@ internal fun DProperty.asJava(isTopLevel: Boolean = false, relocateToClass: Stri
dri.withClass(relocateToClass)
},
modifier = javaModifierFromSetter(),
- visibility = visibility.mapValues { it.value.propertyVisibilityAsJava() },
+ visibility = visibility.mapValues {
+ if (isTopLevel && isConst) {
+ JavaVisibility.Public
+ } else {
+ it.value.propertyVisibilityAsJava()
+ }
+ },
type = type.asJava(), // TODO: check
setter = null,
getter = null, // Removing getters and setters as they will be available as functions