aboutsummaryrefslogtreecommitdiff
path: root/plugins/kotlin-as-java/src/main
diff options
context:
space:
mode:
authorIgnat Beresnev <ignat.beresnev@jetbrains.com>2023-11-10 11:46:54 +0100
committerGitHub <noreply@github.com>2023-11-10 11:46:54 +0100
commit8e5c63d035ef44a269b8c43430f43f5c8eebfb63 (patch)
tree1b915207b2b9f61951ddbf0ff2e687efd053d555 /plugins/kotlin-as-java/src/main
parenta44efd4ba0c2e4ab921ff75e0f53fc9335aa79db (diff)
downloaddokka-8e5c63d035ef44a269b8c43430f43f5c8eebfb63.tar.gz
dokka-8e5c63d035ef44a269b8c43430f43f5c8eebfb63.tar.bz2
dokka-8e5c63d035ef44a269b8c43430f43f5c8eebfb63.zip
Restructure the project to utilize included builds (#3174)
* Refactor and simplify artifact publishing * Update Gradle to 8.4 * Refactor and simplify convention plugins and build scripts Fixes #3132 --------- Co-authored-by: Adam <897017+aSemy@users.noreply.github.com> Co-authored-by: Oleg Yukhnevich <whyoleg@gmail.com>
Diffstat (limited to 'plugins/kotlin-as-java/src/main')
-rw-r--r--plugins/kotlin-as-java/src/main/kotlin/CollectionExtensions.kt16
-rw-r--r--plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPlugin.kt55
-rw-r--r--plugins/kotlin-as-java/src/main/kotlin/converters/KotlinCompanion.kt65
-rw-r--r--plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt508
-rw-r--r--plugins/kotlin-as-java/src/main/kotlin/jvmField.kt16
-rw-r--r--plugins/kotlin-as-java/src/main/kotlin/jvmName.kt23
-rw-r--r--plugins/kotlin-as-java/src/main/kotlin/jvmOverloads.kt18
-rw-r--r--plugins/kotlin-as-java/src/main/kotlin/jvmStatic.kt16
-rw-r--r--plugins/kotlin-as-java/src/main/kotlin/jvmSynthetic.kt17
-rw-r--r--plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt227
-rw-r--r--plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureUtils.kt44
-rw-r--r--plugins/kotlin-as-java/src/main/kotlin/transformToJava.kt42
-rw-r--r--plugins/kotlin-as-java/src/main/kotlin/transformers/JvmNameDocumentableTransformer.kt116
-rw-r--r--plugins/kotlin-as-java/src/main/kotlin/transformers/JvmNameProvider.kt37
-rw-r--r--plugins/kotlin-as-java/src/main/kotlin/transformers/KotlinAsJavaDocumentableTransformer.kt19
-rw-r--r--plugins/kotlin-as-java/src/main/kotlin/transformers/withCallableName.kt9
-rw-r--r--plugins/kotlin-as-java/src/main/kotlin/translators/KotlinAsJavaDocumentableToPageTranslator.kt35
-rw-r--r--plugins/kotlin-as-java/src/main/kotlin/translators/KotlinAsJavaPageCreator.kt33
-rw-r--r--plugins/kotlin-as-java/src/main/resources/META-INF/services/org.jetbrains.dokka.plugability.DokkaPlugin5
19 files changed, 0 insertions, 1301 deletions
diff --git a/plugins/kotlin-as-java/src/main/kotlin/CollectionExtensions.kt b/plugins/kotlin-as-java/src/main/kotlin/CollectionExtensions.kt
deleted file mode 100644
index 3eab0aeb..00000000
--- a/plugins/kotlin-as-java/src/main/kotlin/CollectionExtensions.kt
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.kotlinAsJava
-
-// TODO [beresnev] remove this copy-paste and use the same method from stdlib instead after updating to 1.5
-internal inline fun <T, R : Any> Iterable<T>.firstNotNullOfOrNull(transform: (T) -> R?): R? {
- for (element in this) {
- val result = transform(element)
- if (result != null) {
- return result
- }
- }
- return null
-}
diff --git a/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPlugin.kt b/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPlugin.kt
deleted file mode 100644
index 36da34dc..00000000
--- a/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPlugin.kt
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.kotlinAsJava
-
-import org.jetbrains.dokka.CoreExtensions
-import org.jetbrains.dokka.base.DokkaBase
-import org.jetbrains.dokka.base.signatures.SignatureProvider
-import org.jetbrains.dokka.kotlinAsJava.signatures.JavaSignatureProvider
-import org.jetbrains.dokka.kotlinAsJava.transformers.JvmNameDocumentableTransformer
-import org.jetbrains.dokka.kotlinAsJava.transformers.KotlinAsJavaDocumentableTransformer
-import org.jetbrains.dokka.kotlinAsJava.translators.KotlinAsJavaDocumentableToPageTranslator
-import org.jetbrains.dokka.plugability.DokkaPlugin
-import org.jetbrains.dokka.plugability.DokkaPluginApiPreview
-import org.jetbrains.dokka.plugability.Extension
-import org.jetbrains.dokka.plugability.PluginApiPreviewAcknowledgement
-import org.jetbrains.dokka.renderers.PostAction
-import org.jetbrains.dokka.transformers.documentation.DocumentableToPageTranslator
-import org.jetbrains.dokka.transformers.documentation.DocumentableTransformer
-
-public class KotlinAsJavaPlugin : DokkaPlugin() {
- public val kotlinAsJavaDocumentableTransformer: Extension<DocumentableTransformer, *, *> by extending {
- CoreExtensions.documentableTransformer with KotlinAsJavaDocumentableTransformer()
- }
-
- public val jvmNameTransformer: Extension<DocumentableTransformer, *, *> by extending {
- CoreExtensions.documentableTransformer with JvmNameDocumentableTransformer() order {
- after(kotlinAsJavaDocumentableTransformer)
- }
- }
-
- public val javaSignatureProvider: Extension<SignatureProvider, *, *> by extending {
- with(plugin<DokkaBase>()) {
- signatureProvider providing ::JavaSignatureProvider override kotlinSignatureProvider
- }
- }
-
- public val kotlinAsJavaDocumentableToPageTranslator: Extension<DocumentableToPageTranslator, *, *> by extending {
- CoreExtensions.documentableToPageTranslator providing ::KotlinAsJavaDocumentableToPageTranslator override
- plugin<DokkaBase>().documentableToPageTranslator
- }
-
- internal val alphaVersionNotifier by extending {
- CoreExtensions.postActions providing { ctx ->
- PostAction {
- ctx.logger.info("KotlinAsJava plugin is in Alpha version, use at your own risk, expect bugs and migration issues")
- }
- }
- }
-
- @OptIn(DokkaPluginApiPreview::class)
- override fun pluginApiPreviewAcknowledgement(): PluginApiPreviewAcknowledgement =
- PluginApiPreviewAcknowledgement
-}
diff --git a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinCompanion.kt b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinCompanion.kt
deleted file mode 100644
index 260fc25d..00000000
--- a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinCompanion.kt
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.kotlinAsJava.converters
-
-import org.jetbrains.dokka.links.Callable
-import org.jetbrains.dokka.model.*
-import org.jetbrains.dokka.model.properties.PropertyContainer
-
-private const val DEFAULT_COMPANION_NAME = "Companion"
-
-internal fun DObject?.staticFunctionsForJava(): List<DFunction> {
- if (this == null) return emptyList()
- return functions.filter { it.isJvmStatic }
-}
-
-/**
- * @return properties that will be visible as static for java.
- * See [Static fields](https://kotlinlang.org/docs/java-to-kotlin-interop.html#static-fields)
- */
-internal fun DObject?.staticPropertiesForJava(): List<DProperty> {
- if (this == null) return emptyList()
- return properties.filter { it.isJvmField || it.isConst || it.isLateInit }
-}
-
-internal fun DObject.companionInstancePropertyForJava(): DProperty? {
- if (hasNothingToRender()) return null // do not show if companion not rendered
-
- return DProperty(
- name = name ?: DEFAULT_COMPANION_NAME,
- modifier = sourceSets.associateWith { JavaModifier.Final },
- dri = dri.copy(callable = Callable(name ?: DEFAULT_COMPANION_NAME, null, emptyList())),
- documentation = emptyMap(),
- sources = emptyMap(),
- visibility = sourceSets.associateWith {
- JavaVisibility.Public
- },
- type = GenericTypeConstructor(dri, emptyList()),
- setter = null,
- getter = null,
- sourceSets = sourceSets,
- receiver = null,
- generics = emptyList(),
- expectPresentInSet = expectPresentInSet,
- isExpectActual = false,
- extra = PropertyContainer.withAll(sourceSets.map {
- mapOf(it to setOf(ExtraModifiers.JavaOnlyModifiers.Static)).toAdditionalModifiers()
- })
- )
-}
-
-/**
- * Hide companion object if there isn't members of parents.
- * Properties and functions that are moved to outer class are not counted as members.
- */
-internal fun DObject.hasNothingToRender(): Boolean {
- val nonStaticPropsCount = properties.size - staticPropertiesForJava().size
- val nonStaticFunctionsCount = functions.size - staticFunctionsForJava().size
- val classLikesCount = classlikes.size
- val superTypesCount = supertypes.values.firstOrNull()?.size ?: 0
-
- return nonStaticFunctionsCount + nonStaticPropsCount +
- classLikesCount + superTypesCount == 0
-}
diff --git a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt
deleted file mode 100644
index a8b3a86c..00000000
--- a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt
+++ /dev/null
@@ -1,508 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.kotlinAsJava.converters
-
-import org.jetbrains.dokka.kotlinAsJava.*
-import org.jetbrains.dokka.kotlinAsJava.transformers.JvmNameProvider
-import org.jetbrains.dokka.kotlinAsJava.transformers.withCallableName
-import org.jetbrains.dokka.links.Callable
-import org.jetbrains.dokka.links.DRI
-import org.jetbrains.dokka.links.withClass
-import org.jetbrains.dokka.model.*
-import org.jetbrains.dokka.model.properties.PropertyContainer
-import org.jetbrains.dokka.plugability.DokkaContext
-import org.jetbrains.dokka.plugability.plugin
-import org.jetbrains.dokka.plugability.querySingle
-import org.jetbrains.dokka.analysis.kotlin.internal.InternalKotlinAnalysisPlugin
-
-public val jvmNameProvider: JvmNameProvider = JvmNameProvider()
-internal const val OBJECT_INSTANCE_NAME = "INSTANCE"
-
-internal val DProperty.isConst: Boolean
- get() = hasModifier(ExtraModifiers.KotlinOnlyModifiers.Const)
-
-internal val DProperty.isLateInit: Boolean
- get() = hasModifier(ExtraModifiers.KotlinOnlyModifiers.LateInit)
-
-internal val DProperty.isJvmField: Boolean
- get() = jvmField() != null
-
-internal val DFunction.isJvmStatic: Boolean
- get() = jvmStatic() != null
-
-private fun DProperty.hasModifier(modifier: ExtraModifiers.KotlinOnlyModifiers): Boolean =
- extra[AdditionalModifiers]
- ?.content
- ?.any { (_, modifiers) -> modifier in modifiers } == true
-
-public class KotlinToJavaConverter(
- private val context: DokkaContext
-) {
- private val kotlinToJavaMapper by lazy {
- context.plugin<InternalKotlinAnalysisPlugin>().querySingle { kotlinToJavaService }
- }
-
- internal fun DPackage.asJava(): DPackage {
- val syntheticClasses =
- (properties.map { jvmNameProvider.nameForSyntheticClass(it) to it }
- + functions.map { jvmNameProvider.nameForSyntheticClass(it) to it })
- .groupBy({ it.first }) { it.second }
- .map { (syntheticClassName, nodes) ->
- DClass(
- dri = dri.withClass(syntheticClassName.name),
- name = syntheticClassName.name,
- properties = nodes
- .filterIsInstance<DProperty>()
- .filterNot { it.hasJvmSynthetic() }
- .map { it.asJava(true) },
- constructors = emptyList(),
- functions = (
- nodes
- .filterIsInstance<DProperty>()
- .filterNot { it.isConst || it.isJvmField || it.hasJvmSynthetic() }
- .flatMap { it.javaAccessors(relocateToClass = syntheticClassName.name) } +
- nodes
- .filterIsInstance<DFunction>()
- .flatMap { it.asJava(syntheticClassName.name, true) })
- .filterNot { it.hasJvmSynthetic() },
- classlikes = emptyList(),
- sources = emptyMap(),
- expectPresentInSet = null,
- visibility = sourceSets.associateWith {
- JavaVisibility.Public
- },
- companion = null,
- generics = emptyList(),
- supertypes = emptyMap(),
- documentation = emptyMap(),
- modifier = sourceSets.associateWith { JavaModifier.Final },
- sourceSets = sourceSets,
- isExpectActual = false,
- extra = PropertyContainer.empty()
- )
- }
-
- return copy(
- functions = emptyList(),
- properties = emptyList(),
- classlikes = classlikes.map { it.asJava() } + syntheticClasses,
- typealiases = emptyList()
- )
- }
-
- internal fun DProperty.asJava(
- isTopLevel: Boolean = false,
- relocateToClass: String? = null,
- isFromObjectOrCompanion: Boolean = false
- ) =
- copy(
- dri = if (relocateToClass.isNullOrBlank()) {
- dri
- } else {
- dri.withClass(relocateToClass)
- },
- modifier = javaModifierFromSetter(),
- visibility = visibility.mapValues {
- if (isConst || isJvmField || (getter == null && setter == null) || (isFromObjectOrCompanion && isLateInit)) {
- it.value.asJava()
- } else {
- it.value.propertyVisibilityAsJava()
- }
- },
- type = type.asJava(), // TODO: check
- setter = null,
- getter = null, // Removing getters and setters as they will be available as functions
- extra = if (isTopLevel || isConst || (isFromObjectOrCompanion && isJvmField) || (isFromObjectOrCompanion && isLateInit))
- extra + extra.mergeAdditionalModifiers(
- sourceSets.associateWith {
- setOf(ExtraModifiers.JavaOnlyModifiers.Static)
- }
- )
- else extra
- )
-
- internal fun Visibility.asJava() =
- when (this) {
- is JavaVisibility -> this
- is KotlinVisibility.Public, KotlinVisibility.Internal -> JavaVisibility.Public
- is KotlinVisibility.Private -> JavaVisibility.Private
- is KotlinVisibility.Protected -> JavaVisibility.Protected
- }
-
- 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?.let { getter ->
- val name = "get" + name.capitalize()
- getter.copy(
- dri = if (relocateToClass.isNullOrBlank()) {
- getter.dri
- } else {
- getter.dri.withClass(relocateToClass)
- }.withCallableName(name),
- name = name,
- modifier = javaModifierFromSetter(),
- visibility = visibility.mapValues { JavaVisibility.Public },
- type = getter.type.asJava(),
- extra = if (isTopLevel) getter.extra +
- getter.extra.mergeAdditionalModifiers(
- sourceSets.associateWith {
- setOf(ExtraModifiers.JavaOnlyModifiers.Static)
- }
- )
- else getter.extra
- )
- },
- setter?.let { setter ->
- val name = "set" + name.capitalize()
- val baseDRI = (if (relocateToClass.isNullOrBlank()) {
- setter.dri
- } else {
- setter.dri.withClass(relocateToClass)
- }).withCallableName(name)
- setter.copy(
- dri = baseDRI,
- name = name,
- parameters = setter.parameters.map {
- it.copy(
- dri = baseDRI.copy(
- target = it.dri.target,
- extra = it.dri.extra
- ), type = it.type.asJava()
- )
- },
- modifier = javaModifierFromSetter(),
- visibility = visibility.mapValues { JavaVisibility.Public },
- type = Void,
- extra = if (isTopLevel) setter.extra + setter.extra.mergeAdditionalModifiers(
- sourceSets.associateWith {
- setOf(ExtraModifiers.JavaOnlyModifiers.Static)
- }
- )
- else setter.extra
- )
- }
- )
-
- private fun DFunction.asJava(
- containingClassName: String,
- newName: String,
- parameters: List<DParameter>,
- isTopLevel: Boolean = false
- ): DFunction {
- return copy(
- dri = dri.copy(classNames = containingClassName, callable = dri.callable?.copy(name = newName)),
- name = newName,
- type = type.asJava(),
- modifier = if (modifier.all { (_, v) -> v is KotlinModifier.Final } && isConstructor)
- sourceSets.associateWith { JavaModifier.Empty }
- else sourceSets.associateWith { modifier.values.first() },
- parameters = listOfNotNull(receiver?.asJava()) + parameters.map { it.asJava() },
- visibility = visibility.map { (sourceSet, visibility) -> Pair(sourceSet, visibility.asJava()) }.toMap(),
- receiver = null,
- extra = if (isTopLevel || isJvmStatic) {
- extra + extra.mergeAdditionalModifiers(
- sourceSets.associateWith {
- setOf(ExtraModifiers.JavaOnlyModifiers.Static)
- }
- )
- } else {
- extra
- }
- )
- }
-
- private fun DFunction.withJvmOverloads(
- containingClassName: String,
- newName: String,
- isTopLevel: Boolean = false
- ): List<DFunction>? {
- val (paramsWithDefaults, paramsWithoutDefaults) = parameters
- .withIndex()
- .partition { (_, p) -> p.extra[DefaultValue] != null }
- return paramsWithDefaults
- .runningFold(paramsWithoutDefaults) { acc, param -> (acc + param) }
- .map { params ->
- asJava(
- containingClassName,
- newName,
- params
- .sortedBy(IndexedValue<DParameter>::index)
- .map { it.value },
- isTopLevel
- )
- }
- .reversed()
- .takeIf { it.isNotEmpty() }
- }
-
- internal fun DFunction.asJava(containingClassName: String, isTopLevel: Boolean = false): List<DFunction> {
- val newName = when {
- isConstructor -> containingClassName
- else -> name
- }
- val baseFunction = asJava(containingClassName, newName, parameters, isTopLevel)
- return if (hasJvmOverloads()) {
- withJvmOverloads(containingClassName, newName, isTopLevel) ?: listOf(baseFunction)
- } else {
- listOf(baseFunction)
- }
- }
-
- internal fun DClasslike.asJava(): DClasslike = when (this) {
- is DClass -> asJava()
- is DEnum -> asJava()
- is DAnnotation -> asJava()
- is DObject -> asJava()
- is DInterface -> asJava()
- else -> throw IllegalArgumentException("$this shouldn't be here")
- }
-
- internal fun DClass.asJava(): DClass = copy(
- constructors = constructors
- .filterNot { it.hasJvmSynthetic() }
- .flatMap {
- it.asJava(
- dri.classNames ?: name
- )
- }, // name may not always be valid here, however classNames should always be not null
- functions = functionsInJava(),
- properties = propertiesInJava(),
- classlikes = classlikesInJava(),
- generics = generics.map { it.asJava() },
- companion = companion?.companionAsJava(),
- supertypes = supertypes.mapValues { it.value.map { it.asJava() } },
- modifier = if (modifier.all { (_, v) -> v is KotlinModifier.Empty }) sourceSets.associateWith { JavaModifier.Final }
- else sourceSets.associateWith { modifier.values.first() }
- )
-
- /**
- * Companion objects requires some custom logic for rendering as Java.
- * They are excluded from usual classlikes rendering and added after.
- */
- internal fun DClass.classlikesInJava(): List<DClasslike> {
- val classlikes = classlikes
- .filter { it.name != companion?.name }
- .map { it.asJava() }
-
- val companionAsJava = companion?.companionAsJava()
- return if (companionAsJava != null) classlikes.plus(companionAsJava) else classlikes
- }
-
-
- internal fun DClass.functionsInJava(): List<DFunction> =
- properties
- .filter { !it.isJvmField && !it.hasJvmSynthetic() }
- .flatMap { property -> listOfNotNull(property.getter, property.setter) }
- .plus(functions)
- .plus(companion.staticFunctionsForJava())
- .filterNot { it.hasJvmSynthetic() }
- .flatMap { it.asJava(it.dri.classNames ?: it.name) }
-
- internal fun DClass.propertiesInJava(): List<DProperty> {
- val propertiesFromCompanion = companion
- .staticPropertiesForJava()
- .filterNot { it.hasJvmSynthetic() }
- .map { it.asJava(isFromObjectOrCompanion = true) }
- val companionInstanceProperty = companion?.companionInstancePropertyForJava()
- val ownProperties = properties
- .filterNot { it.hasJvmSynthetic() }
- .map { it.asJava() }
-
- return propertiesFromCompanion + ownProperties + listOfNotNull(companionInstanceProperty)
- }
-
- private fun DTypeParameter.asJava(): DTypeParameter = copy(
- variantTypeParameter = variantTypeParameter.withDri(dri.possiblyAsJava()),
- bounds = bounds.map { it.asJava() }
- )
-
- private fun Projection.asJava(): Projection = when (this) {
- is Star -> Star
- is Covariance<*> -> copy(inner.asJava())
- is Contravariance<*> -> copy(inner.asJava())
- is Invariance<*> -> copy(inner.asJava())
- is Bound -> asJava()
- }
-
- private fun Bound.asJava(): Bound = when (this) {
- is TypeParameter -> copy(dri.possiblyAsJava())
- is GenericTypeConstructor -> copy(
- dri = dri.possiblyAsJava(),
- projections = projections.map { it.asJava() }
- )
-
- is FunctionalTypeConstructor -> copy(
- dri = dri.possiblyAsJava(),
- projections = projections.map { it.asJava() }
- )
-
- is TypeAliased -> copy(
- typeAlias = typeAlias.asJava(),
- inner = inner.asJava()
- )
-
- is Nullable -> copy(inner.asJava())
- is DefinitelyNonNullable -> copy(inner.asJava())
- is PrimitiveJavaType -> this
- is Void -> this
- is JavaObject -> this
- is Dynamic -> this
- is UnresolvedBound -> this
- }
-
- internal fun DEnum.asJava(): DEnum = copy(
- constructors = constructors.flatMap { it.asJava(dri.classNames ?: name) },
- functions = functions
- .plus(
- properties
- .filter { !it.isJvmField && !it.hasJvmSynthetic() }
- .flatMap { listOf(it.getter, it.setter) }
- )
- .filterNotNull()
- .filterNot { it.hasJvmSynthetic() }
- .flatMap { it.asJava(dri.classNames ?: name) },
- properties = properties
- .filterNot { it.hasJvmSynthetic() }
- .map { it.asJava() },
- classlikes = classlikes.map { it.asJava() },
- supertypes = supertypes.mapValues { it.value.map { it.asJava() } }
-// , entries = entries.map { it.asJava() }
- )
-
- /**
- * Parameters [excludedProps] and [excludedFunctions] used for rendering companion objects
- * where some members (that lifted to outer class) are not rendered
- */
- internal fun DObject.asJava(
- excludedProps: List<DProperty> = emptyList(),
- excludedFunctions: List<DFunction> = emptyList()
- ): DObject = copy(
- functions = functions
- .plus(
- properties
- .filterNot { it in excludedProps }
- .filter { !it.isJvmField && !it.isConst && !it.isLateInit && !it.hasJvmSynthetic() }
- .flatMap { listOf(it.getter, it.setter) }
- )
- .filterNotNull()
- .filterNot { it in excludedFunctions }
- .filterNot { it.hasJvmSynthetic() }
- .flatMap { it.asJava(dri.classNames ?: name.orEmpty()) },
- properties = properties
- .filterNot { it.hasJvmSynthetic() }
- .filterNot { it in excludedProps }
- .map { it.asJava(isFromObjectOrCompanion = true) } +
- DProperty(
- name = OBJECT_INSTANCE_NAME,
- modifier = sourceSets.associateWith { JavaModifier.Final },
- dri = dri.copy(callable = Callable(OBJECT_INSTANCE_NAME, null, emptyList())),
- documentation = emptyMap(),
- sources = emptyMap(),
- visibility = sourceSets.associateWith {
- JavaVisibility.Public
- },
- type = GenericTypeConstructor(dri, emptyList()),
- setter = null,
- getter = null,
- sourceSets = sourceSets,
- receiver = null,
- generics = emptyList(),
- expectPresentInSet = expectPresentInSet,
- isExpectActual = false,
- extra = PropertyContainer.withAll(sourceSets.map {
- mapOf(it to setOf(ExtraModifiers.JavaOnlyModifiers.Static)).toAdditionalModifiers()
- })
- ),
- classlikes = classlikes.map { it.asJava() },
- supertypes = supertypes.mapValues { it.value.map { it.asJava() } }
- )
-
- internal fun DInterface.asJava(): DInterface = copy(
- functions = functions
- .plus(
- properties
- .filter { it.jvmField() == null && !it.hasJvmSynthetic() }
- .flatMap { listOf(it.getter, it.setter) }
- )
- .filterNotNull()
- .filterNot { it.hasJvmSynthetic() }
- .flatMap { it.asJava(dri.classNames ?: name) },
- properties = emptyList(),
- classlikes = classlikes.map { it.asJava() }, // TODO: public static final class DefaultImpls with impls for methods
- generics = generics.map { it.asJava() },
- supertypes = supertypes.mapValues { it.value.map { it.asJava() } }
- )
-
- internal fun DAnnotation.asJava(): DAnnotation = copy(
- properties = properties.map { it.asJava() },
- constructors = emptyList(),
- classlikes = classlikes.map { it.asJava() }
- ) // TODO investigate if annotation class can have methods and properties not from constructor
-
- internal fun DParameter.asJava(): DParameter = copy(
- type = type.asJava(),
- name = if (name.isNullOrBlank()) "\$self" else name
- )
-
- internal fun Visibility.propertyVisibilityAsJava(): Visibility =
- if (this is JavaVisibility) this
- else JavaVisibility.Private
-
- private fun TypeConstructor.possiblyAsJava(): TypeConstructor = when (this) {
- is GenericTypeConstructor -> copy(dri = this.dri.possiblyAsJava())
- is FunctionalTypeConstructor -> copy(dri = this.dri.possiblyAsJava())
- }
-
-
- internal fun TypeConstructorWithKind.asJava(): TypeConstructorWithKind =
- TypeConstructorWithKind(
- typeConstructor = typeConstructor.possiblyAsJava(),
- kind = kind.asJava()
- )
-
- internal fun ClassKind.asJava(): ClassKind {
- return when (this) {
- is JavaClassKindTypes -> this
- KotlinClassKindTypes.CLASS -> JavaClassKindTypes.CLASS
- KotlinClassKindTypes.INTERFACE -> JavaClassKindTypes.INTERFACE
- KotlinClassKindTypes.ENUM_CLASS -> JavaClassKindTypes.ENUM_CLASS
- KotlinClassKindTypes.ENUM_ENTRY -> JavaClassKindTypes.ENUM_ENTRY
- KotlinClassKindTypes.ANNOTATION_CLASS -> JavaClassKindTypes.ANNOTATION_CLASS
- KotlinClassKindTypes.OBJECT -> JavaClassKindTypes.CLASS
- else -> throw IllegalStateException("Non exchaustive match while trying to convert $this to Java")
- }
- }
-
- private fun <T : Documentable> PropertyContainer<T>.mergeAdditionalModifiers(second: SourceSetDependent<Set<ExtraModifiers>>) =
- this[AdditionalModifiers]?.squash(AdditionalModifiers(second)) ?: AdditionalModifiers(second)
-
- private fun AdditionalModifiers.squash(second: AdditionalModifiers) =
- AdditionalModifiers(content + second.content)
-
- internal fun DObject.companionAsJava(): DObject? {
- if (hasNothingToRender()) return null
-
- return asJava(
- excludedProps = staticPropertiesForJava(),
- excludedFunctions = staticFunctionsForJava()
- )
- }
-
- private fun DRI.possiblyAsJava(): DRI {
- return kotlinToJavaMapper.findAsJava(this) ?: this
- }
-}
diff --git a/plugins/kotlin-as-java/src/main/kotlin/jvmField.kt b/plugins/kotlin-as-java/src/main/kotlin/jvmField.kt
deleted file mode 100644
index 3cf9b8fa..00000000
--- a/plugins/kotlin-as-java/src/main/kotlin/jvmField.kt
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.kotlinAsJava
-
-import org.jetbrains.dokka.model.Annotations
-import org.jetbrains.dokka.model.Documentable
-import org.jetbrains.dokka.model.properties.WithExtraProperties
-
-internal fun <T : Documentable> WithExtraProperties<T>.jvmField(): Annotations.Annotation? =
- extra[Annotations]?.directAnnotations?.entries?.firstNotNullOfOrNull { (_, annotations) -> annotations.jvmFieldAnnotation() }
-
-internal fun List<Annotations.Annotation>.jvmFieldAnnotation(): Annotations.Annotation? =
- firstOrNull { it.dri.packageName == "kotlin.jvm" && it.dri.classNames == "JvmField" }
-
diff --git a/plugins/kotlin-as-java/src/main/kotlin/jvmName.kt b/plugins/kotlin-as-java/src/main/kotlin/jvmName.kt
deleted file mode 100644
index 6561f079..00000000
--- a/plugins/kotlin-as-java/src/main/kotlin/jvmName.kt
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.kotlinAsJava
-
-import org.jetbrains.dokka.model.Annotations
-import org.jetbrains.dokka.model.Documentable
-import org.jetbrains.dokka.model.StringValue
-import org.jetbrains.dokka.model.isJvmName
-import org.jetbrains.dokka.model.properties.WithExtraProperties
-
-internal fun <T : Documentable> WithExtraProperties<T>.directlyAnnotatedJvmName(): Annotations.Annotation? =
- extra[Annotations]?.directAnnotations?.entries?.firstNotNullOfOrNull { (_, annotations)-> annotations.jvmNameAnnotation() }
-
-internal fun <T : Documentable> WithExtraProperties<T>.fileLevelJvmName(): Annotations.Annotation? =
- extra[Annotations]?.fileLevelAnnotations?.entries?.firstNotNullOfOrNull { (_, annotations) -> annotations.jvmNameAnnotation() }
-
-internal fun List<Annotations.Annotation>.jvmNameAnnotation(): Annotations.Annotation? =
- firstOrNull { it.isJvmName() }
-
-internal fun Annotations.Annotation.jvmNameAsString(): String? = (params["name"] as? StringValue)?.value
-
diff --git a/plugins/kotlin-as-java/src/main/kotlin/jvmOverloads.kt b/plugins/kotlin-as-java/src/main/kotlin/jvmOverloads.kt
deleted file mode 100644
index 08fbca07..00000000
--- a/plugins/kotlin-as-java/src/main/kotlin/jvmOverloads.kt
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.kotlinAsJava
-
-import org.jetbrains.dokka.model.Annotations
-import org.jetbrains.dokka.model.Documentable
-import org.jetbrains.dokka.model.properties.WithExtraProperties
-
-internal fun <T : Documentable> WithExtraProperties<T>.hasJvmOverloads(): Boolean {
- return extra[Annotations]
- ?.directAnnotations
- ?.entries
- ?.any { (_, annotations) ->
- annotations.any { it.dri.packageName == "kotlin.jvm" && it.dri.classNames == "JvmOverloads" }
- } == true
-}
diff --git a/plugins/kotlin-as-java/src/main/kotlin/jvmStatic.kt b/plugins/kotlin-as-java/src/main/kotlin/jvmStatic.kt
deleted file mode 100644
index a253dc83..00000000
--- a/plugins/kotlin-as-java/src/main/kotlin/jvmStatic.kt
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.kotlinAsJava
-
-import org.jetbrains.dokka.model.Annotations
-import org.jetbrains.dokka.model.Documentable
-import org.jetbrains.dokka.model.properties.WithExtraProperties
-
-internal fun <T : Documentable> WithExtraProperties<T>.jvmStatic(): Annotations.Annotation? =
- extra[Annotations]?.directAnnotations?.entries?.firstNotNullOfOrNull { (_, annotations) -> annotations.jvmStaticAnnotation() }
-
-internal fun List<Annotations.Annotation>.jvmStaticAnnotation(): Annotations.Annotation? =
- firstOrNull { it.dri.packageName == "kotlin.jvm" && it.dri.classNames == "JvmStatic" }
-
diff --git a/plugins/kotlin-as-java/src/main/kotlin/jvmSynthetic.kt b/plugins/kotlin-as-java/src/main/kotlin/jvmSynthetic.kt
deleted file mode 100644
index bf2a9ad1..00000000
--- a/plugins/kotlin-as-java/src/main/kotlin/jvmSynthetic.kt
+++ /dev/null
@@ -1,17 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.kotlinAsJava
-
-import org.jetbrains.dokka.model.Annotations
-import org.jetbrains.dokka.model.properties.WithExtraProperties
-
-internal fun <T : org.jetbrains.dokka.model.AnnotationTarget> WithExtraProperties<T>.hasJvmSynthetic(): Boolean {
- return extra[Annotations]
- ?.directAnnotations
- ?.entries
- ?.any { (_, annotations) ->
- annotations.any { it.dri.packageName == "kotlin.jvm" && it.dri.classNames == "JvmSynthetic" }
- } == true
-}
diff --git a/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt b/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt
deleted file mode 100644
index e4c9d5dd..00000000
--- a/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt
+++ /dev/null
@@ -1,227 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.kotlinAsJava.signatures
-
-import org.jetbrains.dokka.base.DokkaBase
-import org.jetbrains.dokka.base.signatures.JvmSignatureUtils
-import org.jetbrains.dokka.base.signatures.SignatureProvider
-import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter
-import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder
-import org.jetbrains.dokka.links.DRI
-import org.jetbrains.dokka.model.*
-import org.jetbrains.dokka.model.properties.WithExtraProperties
-import org.jetbrains.dokka.pages.ContentKind
-import org.jetbrains.dokka.pages.ContentNode
-import org.jetbrains.dokka.pages.TextStyle
-import org.jetbrains.dokka.pages.TokenStyle
-import org.jetbrains.dokka.plugability.DokkaContext
-import org.jetbrains.dokka.plugability.plugin
-import org.jetbrains.dokka.plugability.querySingle
-import org.jetbrains.dokka.utilities.DokkaLogger
-import kotlin.text.Typography.nbsp
-
-public class JavaSignatureProvider internal constructor(
- ctcc: CommentsToContentConverter,
- logger: DokkaLogger
-) : SignatureProvider, JvmSignatureUtils by JavaSignatureUtils {
-
- public constructor(context: DokkaContext) : this(
- context.plugin<DokkaBase>().querySingle { commentsToContentConverter },
- context.logger
- )
-
- private val contentBuilder = PageContentBuilder(ctcc, this, logger)
-
- private val ignoredVisibilities = setOf(JavaVisibility.Default)
-
- private val ignoredModifiers =
- setOf(KotlinModifier.Open, JavaModifier.Empty, KotlinModifier.Empty, KotlinModifier.Sealed)
-
- override fun signature(documentable: Documentable): List<ContentNode> = when (documentable) {
- is DFunction -> signature(documentable)
- is DProperty -> signature(documentable)
- is DClasslike -> signature(documentable)
- is DEnumEntry -> signature(documentable)
- is DTypeParameter -> signature(documentable)
- else -> throw NotImplementedError(
- "Cannot generate signature for ${documentable::class.qualifiedName} ${documentable.name}"
- )
- }
-
- private fun signature(e: DEnumEntry) =
- e.sourceSets.map {
- contentBuilder.contentFor(
- e,
- ContentKind.Symbol,
- setOf(TextStyle.Monospace),
- sourceSets = setOf(it)
- ) {
- link(e.name, e.dri, styles = mainStyles + e.stylesIfDeprecated(it))
- }
- }
-
- private fun signature(c: DClasslike) =
- c.sourceSets.map { sourceSet ->
- @Suppress("UNCHECKED_CAST")
- val deprecationStyles = (c as? WithExtraProperties<out Documentable>)
- ?.stylesIfDeprecated(sourceSet)
- ?: emptySet()
-
- contentBuilder.contentFor(
- c,
- ContentKind.Symbol,
- setOf(TextStyle.Monospace),
- sourceSets = setOf(sourceSet)
- ) {
- annotationsBlock(c)
- c.visibility[sourceSet]?.takeIf { it !in ignoredVisibilities }?.name?.plus(" ")?.let { keyword(it) }
-
- if (c is DClass) {
- c.modifier[sourceSet]?.takeIf { it !in ignoredModifiers }?.name?.plus(" ")?.let { keyword(it) }
- c.modifiers()[sourceSet]?.toSignatureString()?.let { keyword(it) }
- }
-
- when (c) {
- is DClass -> keyword("class ")
- is DInterface -> keyword("interface ")
- is DEnum -> keyword("enum ")
- is DObject -> keyword("class ")
- is DAnnotation -> keyword("@interface ")
- }
- link(c.name!!, c.dri, styles = mainStyles + deprecationStyles)
- if (c is WithGenerics) {
- list(c.generics, prefix = "<", suffix = ">",
- separatorStyles = mainStyles + TokenStyle.Punctuation,
- surroundingCharactersStyle = mainStyles + TokenStyle.Operator) {
- +buildSignature(it)
- }
- }
- if (c is WithSupertypes) {
- c.supertypes.map { (p, dris) ->
- val (classes, interfaces) = dris.partition { it.kind == JavaClassKindTypes.CLASS }
- list(classes, prefix = " extends ", sourceSets = setOf(p),
- separatorStyles = mainStyles + TokenStyle.Punctuation,
- surroundingCharactersStyle = mainStyles + TokenStyle.Keyword) {
- signatureForProjection(it.typeConstructor)
- }
- list(interfaces, prefix = " implements ", sourceSets = setOf(p),
- separatorStyles = mainStyles + TokenStyle.Punctuation,
- surroundingCharactersStyle = mainStyles + TokenStyle.Keyword) {
- signatureForProjection(it.typeConstructor)
- }
- }
- }
- }
- }
-
- private fun signature(p: DProperty) =
- p.sourceSets.map {
- contentBuilder.contentFor(
- p,
- ContentKind.Symbol,
- setOf(TextStyle.Monospace, TextStyle.Block),
- sourceSets = setOf(it)
- ) {
- annotationsBlock(p)
- p.visibility[it]?.takeIf { it !in ignoredVisibilities }?.name?.let { keyword("$it ") }
- p.modifier[it]?.takeIf { it !in ignoredModifiers }?.name?.let { keyword("$it ") }
- p.modifiers()[it]?.toSignatureString()?.let { keyword(it) }
- signatureForProjection(p.type)
- text(nbsp.toString())
- link(p.name, p.dri, styles = mainStyles + p.stylesIfDeprecated(it))
- }
- }
-
- private fun signature(f: DFunction) =
- f.sourceSets.map { sourceSet ->
- contentBuilder.contentFor(
- f,
- ContentKind.Symbol,
- setOf(TextStyle.Monospace, TextStyle.Block),
- sourceSets = setOf(sourceSet)
- ) {
- annotationsBlock(f)
- f.visibility[sourceSet]?.takeIf { it !in ignoredVisibilities }?.name?.let { keyword("$it ") }
- f.modifier[sourceSet]?.takeIf { it !in ignoredModifiers }?.name?.plus(" ")?.let { keyword(it) }
- f.modifiers()[sourceSet]?.toSignatureString()?.let { keyword(it) }
- val returnType = f.type
- signatureForProjection(returnType)
- text(nbsp.toString())
- link(f.name, f.dri, styles = mainStyles + TokenStyle.Function + f.stylesIfDeprecated(sourceSet))
- val usedGenerics = if (f.isConstructor) f.generics.filter { f uses it } else f.generics
- list(usedGenerics, prefix = "<", suffix = ">",
- separatorStyles = mainStyles + TokenStyle.Punctuation,
- surroundingCharactersStyle = mainStyles + TokenStyle.Operator) {
- +buildSignature(it)
- }
- punctuation("(")
- if (f.parameters.isNotEmpty()) {
- parametersBlock(f) {
- annotationsInline(it)
- text(it.modifiers()[sourceSet]?.toSignatureString() ?: "", styles = mainStyles + TokenStyle.Keyword)
- signatureForProjection(it.type)
- text(nbsp.toString())
- text(it.name!!)
- }
- }
- punctuation(")")
- }
- }
-
- private fun signature(t: DTypeParameter) =
- t.sourceSets.map {
- contentBuilder.contentFor(t, sourceSets = setOf(it)) {
- annotationsInline(t)
- text(t.name.substringAfterLast("."), styles = mainStyles + t.stylesIfDeprecated(it))
- list(
- elements = t.bounds,
- prefix = " extends ",
- separatorStyles = mainStyles + TokenStyle.Punctuation,
- surroundingCharactersStyle = mainStyles + TokenStyle.Keyword
- ) {
- signatureForProjection(it)
- }
- }
-
- }
-
- private fun PageContentBuilder.DocumentableContentBuilder.signatureForProjection(p: Projection): Unit = when (p) {
- is TypeParameter -> {
- annotationsInline(p)
- link(p.name, p.dri)
- }
-
- is TypeConstructor -> group(styles = emptySet()) {
- annotationsInline(p)
- link(p.dri.classNames.orEmpty(), p.dri)
- list(p.projections, prefix = "<", suffix = ">",
- separatorStyles = mainStyles + TokenStyle.Punctuation,
- surroundingCharactersStyle = mainStyles + TokenStyle.Operator) {
- signatureForProjection(it)
- }
- }
-
- is Variance<*> -> group(styles = emptySet()) {
- val variance = when(p) {
- is Covariance<*> -> "? extends "
- is Contravariance<*> -> "? super "
- is Invariance<*> -> ""
- }
- keyword(variance)
- signatureForProjection(p.inner)
- }
-
- is Star -> operator("?")
-
- is Nullable -> signatureForProjection(p.inner)
- is DefinitelyNonNullable -> signatureForProjection(p.inner)
-
- is JavaObject, is Dynamic -> link("Object", DRI("java.lang", "Object"))
- is Void -> text("void")
- is PrimitiveJavaType -> text(p.name)
- is UnresolvedBound -> text(p.name)
- is TypeAliased -> signatureForProjection(p.inner)
- }
-}
diff --git a/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureUtils.kt b/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureUtils.kt
deleted file mode 100644
index 1738d40d..00000000
--- a/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureUtils.kt
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.kotlinAsJava.signatures
-
-import org.jetbrains.dokka.DokkaConfiguration
-import org.jetbrains.dokka.base.signatures.All
-import org.jetbrains.dokka.base.signatures.JvmSignatureUtils
-import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder
-import org.jetbrains.dokka.links.DRI
-import org.jetbrains.dokka.model.*
-import org.jetbrains.dokka.model.AnnotationTarget
-import org.jetbrains.dokka.model.properties.WithExtraProperties
-
-public object JavaSignatureUtils : JvmSignatureUtils {
-
- private val ignoredAnnotations = setOf(
- Annotations.Annotation(DRI("kotlin.jvm", "Transient"), emptyMap()),
- Annotations.Annotation(DRI("kotlin.jvm", "Volatile"), emptyMap()),
- Annotations.Annotation(DRI("kotlin.jvm", "Transitive"), emptyMap()),
- Annotations.Annotation(DRI("kotlin.jvm", "Strictfp"), emptyMap()),
- Annotations.Annotation(DRI("kotlin.jvm", "JvmStatic"), emptyMap())
- )
-
- private val strategy = All
- private val listBrackets = Pair('{', '}')
- private val classExtension = ".class"
-
- override fun PageContentBuilder.DocumentableContentBuilder.annotationsBlock(d: AnnotationTarget) {
- annotationsBlockWithIgnored(d, ignoredAnnotations, strategy, listBrackets, classExtension)
- }
-
- override fun PageContentBuilder.DocumentableContentBuilder.annotationsInline(d: AnnotationTarget) {
- annotationsInlineWithIgnored(d, ignoredAnnotations, strategy, listBrackets, classExtension)
- }
-
- override fun <T : Documentable> WithExtraProperties<T>.modifiers(): Map<DokkaConfiguration.DokkaSourceSet, Set<ExtraModifiers.JavaOnlyModifiers>> {
- return extra[AdditionalModifiers]?.content?.entries?.associate {
- it.key to it.value.filterIsInstance<ExtraModifiers.JavaOnlyModifiers>().toSet()
- } ?: emptyMap()
- }
-
-}
diff --git a/plugins/kotlin-as-java/src/main/kotlin/transformToJava.kt b/plugins/kotlin-as-java/src/main/kotlin/transformToJava.kt
deleted file mode 100644
index 32344dd9..00000000
--- a/plugins/kotlin-as-java/src/main/kotlin/transformToJava.kt
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.kotlinAsJava
-
-import org.jetbrains.dokka.kotlinAsJava.converters.KotlinToJavaConverter
-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()
-}
-
-public fun DPackage.transformToJava(context: DokkaContext): DPackage {
- with(KotlinToJavaConverter(context)) {
- return JVM_NAME_DOCUMENTABLE_TRANSFORMER.transform(this@transformToJava.asJava(), context)
- }
-}
-
-public fun DClasslike.transformToJava(context: DokkaContext): DClasslike {
- with(KotlinToJavaConverter(context)) {
- return JVM_NAME_DOCUMENTABLE_TRANSFORMER.transform(this@transformToJava.asJava(), context)
- }
-}
-
-public fun DFunction.transformToJava(context: DokkaContext, containingClassName: String, isTopLevel: Boolean = false): List<DFunction> {
- with(KotlinToJavaConverter(context)) {
- return this@transformToJava.asJava(containingClassName, isTopLevel)
- .map { JVM_NAME_DOCUMENTABLE_TRANSFORMER.transform(it, context) }
- }
-}
-
-public fun DProperty.transformToJava(context: DokkaContext, isTopLevel: Boolean = false, relocateToClass: String? = null): DProperty {
- with(KotlinToJavaConverter(context)) {
- return JVM_NAME_DOCUMENTABLE_TRANSFORMER.transform(this@transformToJava.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
deleted file mode 100644
index fe625e1c..00000000
--- a/plugins/kotlin-as-java/src/main/kotlin/transformers/JvmNameDocumentableTransformer.kt
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.kotlinAsJava.transformers
-
-import org.jetbrains.dokka.model.*
-import org.jetbrains.dokka.model.properties.PropertyContainer
-import org.jetbrains.dokka.plugability.DokkaContext
-import org.jetbrains.dokka.transformers.documentation.DocumentableTransformer
-
-public class JvmNameDocumentableTransformer : DocumentableTransformer {
- private val jvmNameProvider = JvmNameProvider()
-
- override fun invoke(original: DModule, context: DokkaContext): DModule {
- return original.copy(packages = original.packages.map { transform(it, context) })
- }
-
- internal fun <T : Documentable> transform(documentable: T, context: DokkaContext): T {
- val transformResult = with(documentable) {
- when (this) {
- is DPackage -> copy(
- 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)
- copy(
- dri = documentable.dri.withCallableName(name),
- name = name,
- extra = extra.withoutJvmName()
- )
- }
- is DProperty -> transformGetterAndSetter(this)
- is DClasslike -> transformClassLike(this, context)
- is DEnumEntry -> copy(
- 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}")
- this
- }
- }
- }
- @Suppress("UNCHECKED_CAST")
- return transformResult as T
- }
-
- private fun PropertyContainer<DFunction>.withoutJvmName(): PropertyContainer<DFunction> {
- val annotationsWithoutJvmName = get(Annotations)?.let { annotations ->
- annotations.copy((annotations.directAnnotations).map { (sourceset, annotations) ->
- sourceset to annotations.filterNot { it.isJvmName() }
- }.toMap() + annotations.fileLevelAnnotations)
- }
- val extraWithoutAnnotations: PropertyContainer<DFunction> = minus(Annotations)
-
- return extraWithoutAnnotations.addAll(listOfNotNull(annotationsWithoutJvmName))
- }
-
- private fun transformClassLike(documentable: DClasslike, context: DokkaContext): DClasslike =
- with(documentable) {
- when (this) {
- is DClass -> copy(
- 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, context) },
- properties = properties.map { transform(it, context) },
- classlikes = classlikes.map { transform(it, context) },
- )
- is DObject -> copy(
- 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, context) },
- properties = properties.map { transform(it, context) },
- classlikes = classlikes.map { transform(it, context) },
- )
- is DInterface -> copy(
- functions = functions.map { transform(it, context) },
- properties = properties.map { transform(it, context) },
- classlikes = classlikes.map { transform(it, context) },
- )
- }
- }
-
- private fun transformGetterAndSetter(entry: DProperty): DProperty =
- with(entry) {
- copy(
- setter = jvmNameProvider.nameForSetter(this)?.let { setterName ->
- setter?.let { setter ->
- setter.copy(
- dri = setter.dri.withCallableName(setterName),
- name = setterName,
- extra = setter.extra.withoutJvmName()
- )
- }
- },
- getter = jvmNameProvider.nameForGetter(this)?.let { getterName ->
- getter?.let { getter ->
- getter.copy(
- dri = getter.dri.withCallableName(getterName),
- name = getterName,
- extra = getter.extra.withoutJvmName()
- )
- }
- })
- }
-}
diff --git a/plugins/kotlin-as-java/src/main/kotlin/transformers/JvmNameProvider.kt b/plugins/kotlin-as-java/src/main/kotlin/transformers/JvmNameProvider.kt
deleted file mode 100644
index caf76b68..00000000
--- a/plugins/kotlin-as-java/src/main/kotlin/transformers/JvmNameProvider.kt
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.kotlinAsJava.transformers
-
-import org.jetbrains.dokka.kotlinAsJava.directlyAnnotatedJvmName
-import org.jetbrains.dokka.kotlinAsJava.fileLevelJvmName
-import org.jetbrains.dokka.kotlinAsJava.jvmNameAsString
-import org.jetbrains.dokka.model.*
-import org.jetbrains.dokka.model.properties.WithExtraProperties
-
-public data class Name(val fqName: String) {
- val name: String = fqName.substringAfterLast(".")
-}
-
-public class JvmNameProvider {
- public fun <T> nameFor(entry: T): String where T : Documentable, T : WithExtraProperties<T> =
- entry.directlyAnnotatedJvmName()?.jvmNameAsString()
- ?: entry.name
- ?: throw IllegalStateException("Failed to provide a name for ${entry.javaClass.canonicalName}")
-
- public fun <T> nameForSyntheticClass(entry: T): Name where T : WithSources, T : WithExtraProperties<T>, T : Documentable {
- val name: String = (entry.fileLevelJvmName()?.params?.get("name") as? StringValue)?.value
- ?: (entry.sources.entries.first().value.path.split("/").last().split(".").first().capitalize() + "Kt")
- return Name("${entry.dri.packageName}.$name")
- }
-
- public fun nameForGetter(entry: DProperty): String? =
- entry.getter?.directlyAnnotatedJvmName()?.jvmNameAsString()
-
- public fun nameForSetter(entry: DProperty): String? =
- entry.setter?.directlyAnnotatedJvmName()?.jvmNameAsString()
-
- private fun List<Annotations.Annotation>.jvmNameAnnotation(): Annotations.Annotation? =
- firstOrNull { it.isJvmName() }
-}
diff --git a/plugins/kotlin-as-java/src/main/kotlin/transformers/KotlinAsJavaDocumentableTransformer.kt b/plugins/kotlin-as-java/src/main/kotlin/transformers/KotlinAsJavaDocumentableTransformer.kt
deleted file mode 100644
index 45682ea4..00000000
--- a/plugins/kotlin-as-java/src/main/kotlin/transformers/KotlinAsJavaDocumentableTransformer.kt
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.kotlinAsJava.transformers
-
-import org.jetbrains.dokka.kotlinAsJava.converters.KotlinToJavaConverter
-import org.jetbrains.dokka.model.DModule
-import org.jetbrains.dokka.plugability.DokkaContext
-import org.jetbrains.dokka.transformers.documentation.DocumentableTransformer
-
-public class KotlinAsJavaDocumentableTransformer : DocumentableTransformer {
- override fun invoke(original: DModule, context: DokkaContext): DModule =
- original.copy(packages = original.packages.map {
- with(KotlinToJavaConverter(context)) {
- it.asJava()
- }
- })
-}
diff --git a/plugins/kotlin-as-java/src/main/kotlin/transformers/withCallableName.kt b/plugins/kotlin-as-java/src/main/kotlin/transformers/withCallableName.kt
deleted file mode 100644
index d2f5a9cf..00000000
--- a/plugins/kotlin-as-java/src/main/kotlin/transformers/withCallableName.kt
+++ /dev/null
@@ -1,9 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.kotlinAsJava.transformers
-
-import org.jetbrains.dokka.links.DRI
-
-internal fun DRI.withCallableName(newName: String): DRI = copy(callable = callable?.copy(name = newName))
diff --git a/plugins/kotlin-as-java/src/main/kotlin/translators/KotlinAsJavaDocumentableToPageTranslator.kt b/plugins/kotlin-as-java/src/main/kotlin/translators/KotlinAsJavaDocumentableToPageTranslator.kt
deleted file mode 100644
index a0ed24d4..00000000
--- a/plugins/kotlin-as-java/src/main/kotlin/translators/KotlinAsJavaDocumentableToPageTranslator.kt
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.kotlinAsJava.translators
-
-import org.jetbrains.dokka.base.DokkaBase
-import org.jetbrains.dokka.base.DokkaBaseConfiguration
-import org.jetbrains.dokka.model.DModule
-import org.jetbrains.dokka.pages.ModulePageNode
-import org.jetbrains.dokka.plugability.*
-import org.jetbrains.dokka.transformers.documentation.DocumentableToPageTranslator
-import org.jetbrains.dokka.utilities.DokkaLogger
-import org.jetbrains.dokka.analysis.kotlin.internal.InternalKotlinAnalysisPlugin
-
-public class KotlinAsJavaDocumentableToPageTranslator(
- context: DokkaContext
-) : DocumentableToPageTranslator {
- private val configuration = configuration<DokkaBase, DokkaBaseConfiguration>(context)
- private val commentsToContentConverter = context.plugin<DokkaBase>().querySingle { commentsToContentConverter }
- private val signatureProvider = context.plugin<DokkaBase>().querySingle { signatureProvider }
- private val customTagContentProviders = context.plugin<DokkaBase>().query { customTagContentProvider }
- private val documentableSourceLanguageParser = context.plugin<InternalKotlinAnalysisPlugin>().querySingle { documentableSourceLanguageParser }
- private val logger: DokkaLogger = context.logger
-
- override fun invoke(module: DModule): ModulePageNode =
- KotlinAsJavaPageCreator(
- configuration,
- commentsToContentConverter,
- signatureProvider,
- logger,
- customTagContentProviders,
- documentableSourceLanguageParser
- ).pageForModule(module)
-}
diff --git a/plugins/kotlin-as-java/src/main/kotlin/translators/KotlinAsJavaPageCreator.kt b/plugins/kotlin-as-java/src/main/kotlin/translators/KotlinAsJavaPageCreator.kt
deleted file mode 100644
index fcdc1d83..00000000
--- a/plugins/kotlin-as-java/src/main/kotlin/translators/KotlinAsJavaPageCreator.kt
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.kotlinAsJava.translators
-
-import org.jetbrains.dokka.base.DokkaBaseConfiguration
-import org.jetbrains.dokka.base.signatures.SignatureProvider
-import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter
-import org.jetbrains.dokka.base.transformers.pages.tags.CustomTagContentProvider
-import org.jetbrains.dokka.base.translators.documentables.DefaultPageCreator
-import org.jetbrains.dokka.model.DProperty
-import org.jetbrains.dokka.pages.MemberPageNode
-import org.jetbrains.dokka.utilities.DokkaLogger
-import org.jetbrains.dokka.analysis.kotlin.internal.DocumentableSourceLanguageParser
-
-public class KotlinAsJavaPageCreator(
- configuration: DokkaBaseConfiguration?,
- commentsToContentConverter: CommentsToContentConverter,
- signatureProvider: SignatureProvider,
- logger: DokkaLogger,
- customTagContentProviders: List<CustomTagContentProvider>,
- documentableAnalyzer: DocumentableSourceLanguageParser
-) : DefaultPageCreator(
- configuration,
- commentsToContentConverter,
- signatureProvider,
- logger,
- customTagContentProviders = customTagContentProviders,
- documentableAnalyzer = documentableAnalyzer
-) {
- override fun pageForProperty(p: DProperty): MemberPageNode? = null
-}
diff --git a/plugins/kotlin-as-java/src/main/resources/META-INF/services/org.jetbrains.dokka.plugability.DokkaPlugin b/plugins/kotlin-as-java/src/main/resources/META-INF/services/org.jetbrains.dokka.plugability.DokkaPlugin
deleted file mode 100644
index 4b6619b1..00000000
--- a/plugins/kotlin-as-java/src/main/resources/META-INF/services/org.jetbrains.dokka.plugability.DokkaPlugin
+++ /dev/null
@@ -1,5 +0,0 @@
-#
-# Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
-#
-
-org.jetbrains.dokka.kotlinAsJava.KotlinAsJavaPlugin