From 02f30b142aa467d3a24cc52a1fe3f2fed7ea1e33 Mon Sep 17 00:00:00 2001 From: Ignat Beresnev Date: Thu, 31 Aug 2023 20:16:01 +0200 Subject: Enable explicit API mode (#3139) --- .../kotlin-as-java/src/main/kotlin/KotlinAsJavaPlugin.kt | 14 +++++++++----- .../src/main/kotlin/converters/KotlinToJavaConverter.kt | 4 ++-- .../src/main/kotlin/signatures/JavaSignatureProvider.kt | 10 +++++++--- .../src/main/kotlin/signatures/JavaSignatureUtils.kt | 14 +++++++++----- plugins/kotlin-as-java/src/main/kotlin/transformToJava.kt | 8 ++++---- .../kotlin/transformers/JvmNameDocumentableTransformer.kt | 2 +- .../src/main/kotlin/transformers/JvmNameProvider.kt | 14 +++++++------- .../transformers/KotlinAsJavaDocumentableTransformer.kt | 2 +- .../KotlinAsJavaDocumentableToPageTranslator.kt | 4 +++- .../src/main/kotlin/translators/KotlinAsJavaPageCreator.kt | 2 +- 10 files changed, 44 insertions(+), 30 deletions(-) (limited to 'plugins/kotlin-as-java/src') diff --git a/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPlugin.kt b/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPlugin.kt index 2ed021fb..36da34dc 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPlugin.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPlugin.kt @@ -6,33 +6,37 @@ 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 -class KotlinAsJavaPlugin : DokkaPlugin() { - val kotlinAsJavaDocumentableTransformer by extending { +public class KotlinAsJavaPlugin : DokkaPlugin() { + public val kotlinAsJavaDocumentableTransformer: Extension by extending { CoreExtensions.documentableTransformer with KotlinAsJavaDocumentableTransformer() } - val jvmNameTransformer by extending { + public val jvmNameTransformer: Extension by extending { CoreExtensions.documentableTransformer with JvmNameDocumentableTransformer() order { after(kotlinAsJavaDocumentableTransformer) } } - val javaSignatureProvider by extending { + public val javaSignatureProvider: Extension by extending { with(plugin()) { signatureProvider providing ::JavaSignatureProvider override kotlinSignatureProvider } } - val kotlinAsJavaDocumentableToPageTranslator by extending { + public val kotlinAsJavaDocumentableToPageTranslator: Extension by extending { CoreExtensions.documentableToPageTranslator providing ::KotlinAsJavaDocumentableToPageTranslator override plugin().documentableToPageTranslator } 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 4a8979b0..a8b3a86c 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt @@ -17,7 +17,7 @@ import org.jetbrains.dokka.plugability.plugin import org.jetbrains.dokka.plugability.querySingle import org.jetbrains.dokka.analysis.kotlin.internal.InternalKotlinAnalysisPlugin -val jvmNameProvider = JvmNameProvider() +public val jvmNameProvider: JvmNameProvider = JvmNameProvider() internal const val OBJECT_INSTANCE_NAME = "INSTANCE" internal val DProperty.isConst: Boolean @@ -37,7 +37,7 @@ private fun DProperty.hasModifier(modifier: ExtraModifiers.KotlinOnlyModifiers): ?.content ?.any { (_, modifiers) -> modifier in modifiers } == true -class KotlinToJavaConverter( +public class KotlinToJavaConverter( private val context: DokkaContext ) { private val kotlinToJavaMapper by lazy { diff --git a/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt b/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt index 20f7e941..e4c9d5dd 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt @@ -22,12 +22,16 @@ import org.jetbrains.dokka.plugability.querySingle import org.jetbrains.dokka.utilities.DokkaLogger import kotlin.text.Typography.nbsp -class JavaSignatureProvider internal constructor(ctcc: CommentsToContentConverter, logger: DokkaLogger) : SignatureProvider, - JvmSignatureUtils by JavaSignatureUtils { - constructor(context: DokkaContext) : this( +public class JavaSignatureProvider internal constructor( + ctcc: CommentsToContentConverter, + logger: DokkaLogger +) : SignatureProvider, JvmSignatureUtils by JavaSignatureUtils { + + public constructor(context: DokkaContext) : this( context.plugin().querySingle { commentsToContentConverter }, context.logger ) + private val contentBuilder = PageContentBuilder(ctcc, this, logger) private val ignoredVisibilities = setOf(JavaVisibility.Default) diff --git a/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureUtils.kt b/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureUtils.kt index 864e4db8..1738d40d 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureUtils.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureUtils.kt @@ -4,6 +4,7 @@ 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 @@ -12,7 +13,7 @@ import org.jetbrains.dokka.model.* import org.jetbrains.dokka.model.AnnotationTarget import org.jetbrains.dokka.model.properties.WithExtraProperties -object JavaSignatureUtils : JvmSignatureUtils { +public object JavaSignatureUtils : JvmSignatureUtils { private val ignoredAnnotations = setOf( Annotations.Annotation(DRI("kotlin.jvm", "Transient"), emptyMap()), @@ -26,15 +27,18 @@ object JavaSignatureUtils : JvmSignatureUtils { private val listBrackets = Pair('{', '}') private val classExtension = ".class" - override fun PageContentBuilder.DocumentableContentBuilder.annotationsBlock(d: AnnotationTarget) = + override fun PageContentBuilder.DocumentableContentBuilder.annotationsBlock(d: AnnotationTarget) { annotationsBlockWithIgnored(d, ignoredAnnotations, strategy, listBrackets, classExtension) + } - override fun PageContentBuilder.DocumentableContentBuilder.annotationsInline(d: AnnotationTarget) = + override fun PageContentBuilder.DocumentableContentBuilder.annotationsInline(d: AnnotationTarget) { annotationsInlineWithIgnored(d, ignoredAnnotations, strategy, listBrackets, classExtension) + } - override fun WithExtraProperties.modifiers() = - extra[AdditionalModifiers]?.content?.entries?.associate { + override fun WithExtraProperties.modifiers(): Map> { + return extra[AdditionalModifiers]?.content?.entries?.associate { it.key to it.value.filterIsInstance().toSet() } ?: emptyMap() + } } diff --git a/plugins/kotlin-as-java/src/main/kotlin/transformToJava.kt b/plugins/kotlin-as-java/src/main/kotlin/transformToJava.kt index 477a3a6d..32344dd9 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/transformToJava.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/transformToJava.kt @@ -16,26 +16,26 @@ private val JVM_NAME_DOCUMENTABLE_TRANSFORMER by lazy { JvmNameDocumentableTransformer() } -fun DPackage.transformToJava(context: DokkaContext): DPackage { +public fun DPackage.transformToJava(context: DokkaContext): DPackage { with(KotlinToJavaConverter(context)) { return JVM_NAME_DOCUMENTABLE_TRANSFORMER.transform(this@transformToJava.asJava(), context) } } -fun DClasslike.transformToJava(context: DokkaContext): DClasslike { +public fun DClasslike.transformToJava(context: DokkaContext): DClasslike { with(KotlinToJavaConverter(context)) { return JVM_NAME_DOCUMENTABLE_TRANSFORMER.transform(this@transformToJava.asJava(), context) } } -fun DFunction.transformToJava(context: DokkaContext, containingClassName: String, isTopLevel: Boolean = false): List { +public fun DFunction.transformToJava(context: DokkaContext, containingClassName: String, isTopLevel: Boolean = false): List { with(KotlinToJavaConverter(context)) { return this@transformToJava.asJava(containingClassName, isTopLevel) .map { JVM_NAME_DOCUMENTABLE_TRANSFORMER.transform(it, context) } } } -fun DProperty.transformToJava(context: DokkaContext, isTopLevel: Boolean = false, relocateToClass: String? = null): DProperty { +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 index dbfbf8ae..fe625e1c 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/transformers/JvmNameDocumentableTransformer.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/transformers/JvmNameDocumentableTransformer.kt @@ -9,7 +9,7 @@ import org.jetbrains.dokka.model.properties.PropertyContainer import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.transformers.documentation.DocumentableTransformer -class JvmNameDocumentableTransformer : DocumentableTransformer { +public class JvmNameDocumentableTransformer : DocumentableTransformer { private val jvmNameProvider = JvmNameProvider() override fun invoke(original: DModule, context: DokkaContext): DModule { diff --git a/plugins/kotlin-as-java/src/main/kotlin/transformers/JvmNameProvider.kt b/plugins/kotlin-as-java/src/main/kotlin/transformers/JvmNameProvider.kt index 83576278..caf76b68 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/transformers/JvmNameProvider.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/transformers/JvmNameProvider.kt @@ -10,26 +10,26 @@ import org.jetbrains.dokka.kotlinAsJava.jvmNameAsString import org.jetbrains.dokka.model.* import org.jetbrains.dokka.model.properties.WithExtraProperties -data class Name(val fqName: String) { - val name = fqName.substringAfterLast(".") +public data class Name(val fqName: String) { + val name: String = fqName.substringAfterLast(".") } -class JvmNameProvider { - fun nameFor(entry: T): String where T : Documentable, T : WithExtraProperties = +public class JvmNameProvider { + public fun nameFor(entry: T): String where T : Documentable, T : WithExtraProperties = entry.directlyAnnotatedJvmName()?.jvmNameAsString() ?: entry.name ?: throw IllegalStateException("Failed to provide a name for ${entry.javaClass.canonicalName}") - fun nameForSyntheticClass(entry: T): Name where T : WithSources, T : WithExtraProperties, T : Documentable { + public fun nameForSyntheticClass(entry: T): Name where T : WithSources, T : WithExtraProperties, 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") } - fun nameForGetter(entry: DProperty): String? = + public fun nameForGetter(entry: DProperty): String? = entry.getter?.directlyAnnotatedJvmName()?.jvmNameAsString() - fun nameForSetter(entry: DProperty): String? = + public fun nameForSetter(entry: DProperty): String? = entry.setter?.directlyAnnotatedJvmName()?.jvmNameAsString() private fun List.jvmNameAnnotation(): Annotations.Annotation? = diff --git a/plugins/kotlin-as-java/src/main/kotlin/transformers/KotlinAsJavaDocumentableTransformer.kt b/plugins/kotlin-as-java/src/main/kotlin/transformers/KotlinAsJavaDocumentableTransformer.kt index 11dfae9b..45682ea4 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/transformers/KotlinAsJavaDocumentableTransformer.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/transformers/KotlinAsJavaDocumentableTransformer.kt @@ -9,7 +9,7 @@ import org.jetbrains.dokka.model.DModule import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.transformers.documentation.DocumentableTransformer -class KotlinAsJavaDocumentableTransformer : DocumentableTransformer { +public class KotlinAsJavaDocumentableTransformer : DocumentableTransformer { override fun invoke(original: DModule, context: DokkaContext): DModule = original.copy(packages = original.packages.map { with(KotlinToJavaConverter(context)) { diff --git a/plugins/kotlin-as-java/src/main/kotlin/translators/KotlinAsJavaDocumentableToPageTranslator.kt b/plugins/kotlin-as-java/src/main/kotlin/translators/KotlinAsJavaDocumentableToPageTranslator.kt index 6b8249d9..a0ed24d4 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/translators/KotlinAsJavaDocumentableToPageTranslator.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/translators/KotlinAsJavaDocumentableToPageTranslator.kt @@ -13,7 +13,9 @@ import org.jetbrains.dokka.transformers.documentation.DocumentableToPageTranslat import org.jetbrains.dokka.utilities.DokkaLogger import org.jetbrains.dokka.analysis.kotlin.internal.InternalKotlinAnalysisPlugin -class KotlinAsJavaDocumentableToPageTranslator(context: DokkaContext) : DocumentableToPageTranslator { +public class KotlinAsJavaDocumentableToPageTranslator( + context: DokkaContext +) : DocumentableToPageTranslator { private val configuration = configuration(context) private val commentsToContentConverter = context.plugin().querySingle { commentsToContentConverter } private val signatureProvider = context.plugin().querySingle { signatureProvider } diff --git a/plugins/kotlin-as-java/src/main/kotlin/translators/KotlinAsJavaPageCreator.kt b/plugins/kotlin-as-java/src/main/kotlin/translators/KotlinAsJavaPageCreator.kt index af6670a3..fcdc1d83 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/translators/KotlinAsJavaPageCreator.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/translators/KotlinAsJavaPageCreator.kt @@ -14,7 +14,7 @@ import org.jetbrains.dokka.pages.MemberPageNode import org.jetbrains.dokka.utilities.DokkaLogger import org.jetbrains.dokka.analysis.kotlin.internal.DocumentableSourceLanguageParser -class KotlinAsJavaPageCreator( +public class KotlinAsJavaPageCreator( configuration: DokkaBaseConfiguration?, commentsToContentConverter: CommentsToContentConverter, signatureProvider: SignatureProvider, -- cgit