aboutsummaryrefslogtreecommitdiff
path: root/plugins/kotlin-as-java/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/kotlin-as-java/src/main')
-rw-r--r--plugins/kotlin-as-java/src/main/kotlin/transformToJava.kt29
-rw-r--r--plugins/kotlin-as-java/src/main/kotlin/transformers/JvmNameDocumentableTransformer.kt54
2 files changed, 55 insertions, 28 deletions
diff --git a/plugins/kotlin-as-java/src/main/kotlin/transformToJava.kt b/plugins/kotlin-as-java/src/main/kotlin/transformToJava.kt
new file mode 100644
index 00000000..69df21ee
--- /dev/null
+++ b/plugins/kotlin-as-java/src/main/kotlin/transformToJava.kt
@@ -0,0 +1,29 @@
+package org.jetbrains.dokka.kotlinAsJava
+
+import org.jetbrains.dokka.kotlinAsJava.converters.asJava
+import org.jetbrains.dokka.kotlinAsJava.transformers.JvmNameDocumentableTransformer
+import org.jetbrains.dokka.model.DClasslike
+import org.jetbrains.dokka.model.DFunction
+import org.jetbrains.dokka.model.DPackage
+import org.jetbrains.dokka.model.DProperty
+import org.jetbrains.dokka.plugability.DokkaContext
+
+private val JVM_NAME_DOCUMENTABLE_TRANSFORMER by lazy {
+ JvmNameDocumentableTransformer()
+}
+
+fun DPackage.transformToJava(context: DokkaContext): DPackage {
+ return JVM_NAME_DOCUMENTABLE_TRANSFORMER.transform(this.asJava(), context)
+}
+
+fun DClasslike.transformToJava(context: DokkaContext): DClasslike {
+ return JVM_NAME_DOCUMENTABLE_TRANSFORMER.transform(this.asJava(), context)
+}
+
+fun DFunction.transformToJava(context: DokkaContext, containingClassName: String, isTopLevel: Boolean = false): List<DFunction> {
+ return this.asJava(containingClassName, isTopLevel).map { JVM_NAME_DOCUMENTABLE_TRANSFORMER.transform(it, context) }
+}
+
+fun DProperty.transformToJava(context: DokkaContext, isTopLevel: Boolean = false, relocateToClass: String? = null): DProperty {
+ return JVM_NAME_DOCUMENTABLE_TRANSFORMER.transform(this.asJava(isTopLevel, relocateToClass), context)
+}
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 c49e08f0..28cb3453 100644
--- a/plugins/kotlin-as-java/src/main/kotlin/transformers/JvmNameDocumentableTransformer.kt
+++ b/plugins/kotlin-as-java/src/main/kotlin/transformers/JvmNameDocumentableTransformer.kt
@@ -7,20 +7,18 @@ import org.jetbrains.dokka.transformers.documentation.DocumentableTransformer
class JvmNameDocumentableTransformer : DocumentableTransformer {
private val jvmNameProvider = JvmNameProvider()
- private lateinit var context: DokkaContext
override fun invoke(original: DModule, context: DokkaContext): DModule {
- this.context = context
- return original.copy(packages = original.packages.map { transform(it) })
+ return original.copy(packages = original.packages.map { transform(it, context) })
}
- private fun <T : Documentable> transform(documentable: T): T =
+ internal fun <T : Documentable> transform(documentable: T, context: DokkaContext): T =
with(documentable) {
when (this) {
is DPackage -> copy(
- functions = functions.map { transform(it) },
- properties = properties.map { transform(it) },
- classlikes = classlikes.map { transform(it) },
+ functions = functions.map { transform(it, context) },
+ properties = properties.map { transform(it, context) },
+ classlikes = classlikes.map { transform(it, context) },
)
is DFunction -> {
val name = jvmNameProvider.nameFor(this)
@@ -31,11 +29,11 @@ class JvmNameDocumentableTransformer : DocumentableTransformer {
)
}
is DProperty -> transformGetterAndSetter(this)
- is DClasslike -> transformClassLike(this)
+ is DClasslike -> transformClassLike(this, context)
is DEnumEntry -> copy(
- functions = functions.map { transform(it) },
- properties = properties.map { transform(it) },
- classlikes = classlikes.map { transform(it) },
+ functions = functions.map { transform(it, context) },
+ properties = properties.map { transform(it, context) },
+ classlikes = classlikes.map { transform(it, context) },
)
else -> {
context.logger.warn("Failed to translate a JvmName for ${this.javaClass.canonicalName}")
@@ -55,33 +53,33 @@ class JvmNameDocumentableTransformer : DocumentableTransformer {
return extraWithoutAnnotations.addAll(listOfNotNull(annotationsWithoutJvmName))
}
- private fun transformClassLike(documentable: DClasslike): DClasslike =
+ private fun transformClassLike(documentable: DClasslike, context: DokkaContext): DClasslike =
with(documentable) {
when (this) {
is DClass -> copy(
- functions = functions.map { transform(it) },
- properties = properties.map { transform(it) },
- classlikes = classlikes.map { transform(it) },
+ functions = functions.map { transform(it, context) },
+ properties = properties.map { transform(it, context) },
+ classlikes = classlikes.map { transform(it, context) },
)
is DAnnotation -> copy(
- functions = functions.map { transform(it) },
- properties = properties.map { transform(it) },
- classlikes = classlikes.map { transform(it) },
+ functions = functions.map { transform(it, context) },
+ properties = properties.map { transform(it, context) },
+ classlikes = classlikes.map { transform(it, context) },
)
is DObject -> copy(
- functions = functions.map { transform(it) },
- properties = properties.map { transform(it) },
- classlikes = classlikes.map { transform(it) },
+ functions = functions.map { transform(it, context) },
+ properties = properties.map { transform(it, context) },
+ classlikes = classlikes.map { transform(it, context) },
)
is DEnum -> copy(
- functions = functions.map { transform(it) },
- properties = properties.map { transform(it) },
- classlikes = classlikes.map { transform(it) },
+ functions = functions.map { transform(it, context) },
+ properties = properties.map { transform(it, context) },
+ classlikes = classlikes.map { transform(it, context) },
)
is DInterface -> copy(
- functions = functions.map { transform(it) },
- properties = properties.map { transform(it) },
- classlikes = classlikes.map { transform(it) },
+ functions = functions.map { transform(it, context) },
+ properties = properties.map { transform(it, context) },
+ classlikes = classlikes.map { transform(it, context) },
)
}
}
@@ -108,4 +106,4 @@ class JvmNameDocumentableTransformer : DocumentableTransformer {
}
})
}
-} \ No newline at end of file
+}