diff options
Diffstat (limited to 'plugins/kotlin-as-java')
10 files changed, 44 insertions, 30 deletions
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<DocumentableTransformer, *, *> by extending { CoreExtensions.documentableTransformer with KotlinAsJavaDocumentableTransformer() } - val jvmNameTransformer by extending { + public val jvmNameTransformer: Extension<DocumentableTransformer, *, *> by extending { CoreExtensions.documentableTransformer with JvmNameDocumentableTransformer() order { after(kotlinAsJavaDocumentableTransformer) } } - val javaSignatureProvider by extending { + public val javaSignatureProvider: Extension<SignatureProvider, *, *> by extending { with(plugin<DokkaBase>()) { signatureProvider providing ::JavaSignatureProvider override kotlinSignatureProvider } } - val kotlinAsJavaDocumentableToPageTranslator by extending { + public val kotlinAsJavaDocumentableToPageTranslator: Extension<DocumentableToPageTranslator, *, *> by extending { CoreExtensions.documentableToPageTranslator providing ::KotlinAsJavaDocumentableToPageTranslator override plugin<DokkaBase>().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<DokkaBase>().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 <T : Documentable> WithExtraProperties<T>.modifiers() = - extra[AdditionalModifiers]?.content?.entries?.associate { + 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 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<DFunction> { +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) } } } -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 <T> nameFor(entry: T): String where T : Documentable, T : WithExtraProperties<T> = +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}") - fun <T> nameForSyntheticClass(entry: T): Name where T : WithSources, T : WithExtraProperties<T>, T : Documentable { + 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") } - 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<Annotations.Annotation>.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<DokkaBase, DokkaBaseConfiguration>(context) private val commentsToContentConverter = context.plugin<DokkaBase>().querySingle { commentsToContentConverter } private val signatureProvider = context.plugin<DokkaBase>().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, |