aboutsummaryrefslogtreecommitdiff
path: root/plugins/kotlin-as-java/src/main/kotlin
diff options
context:
space:
mode:
authorGoooler <wangzongler@gmail.com>2022-02-21 22:01:06 +0800
committerGitHub <noreply@github.com>2022-02-21 17:01:06 +0300
commitf5b7797255576e5f1c230e2ca3fcb5f4e602387c (patch)
tree25fd98250066c4ed6c2fff1104be533604bbf1b9 /plugins/kotlin-as-java/src/main/kotlin
parentdf4780c31026aaa626746f49f0e6fa3fa0278a05 (diff)
downloaddokka-f5b7797255576e5f1c230e2ca3fcb5f4e602387c.tar.gz
dokka-f5b7797255576e5f1c230e2ca3fcb5f4e602387c.tar.bz2
dokka-f5b7797255576e5f1c230e2ca3fcb5f4e602387c.zip
Code cleanups (#2165)
Diffstat (limited to 'plugins/kotlin-as-java/src/main/kotlin')
-rw-r--r--plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPlugin.kt2
-rw-r--r--plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt55
-rw-r--r--plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureUtils.kt4
-rw-r--r--plugins/kotlin-as-java/src/main/kotlin/transformers/JvmNameProvider.kt2
-rw-r--r--plugins/kotlin-as-java/src/main/kotlin/translators/KotlinAsJavaDocumentableToPageTranslator.kt11
-rw-r--r--plugins/kotlin-as-java/src/main/kotlin/translators/KotlinAsJavaPageCreator.kt1
6 files changed, 38 insertions, 37 deletions
diff --git a/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPlugin.kt b/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPlugin.kt
index 531ff59f..aae6f570 100644
--- a/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPlugin.kt
+++ b/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPlugin.kt
@@ -2,13 +2,11 @@ package org.jetbrains.dokka.kotlinAsJava
import org.jetbrains.dokka.CoreExtensions
import org.jetbrains.dokka.base.DokkaBase
-import org.jetbrains.dokka.base.DokkaBaseConfiguration
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.configuration
class KotlinAsJavaPlugin : DokkaPlugin() {
val kotlinAsJavaDocumentableTransformer by extending {
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 2a0762ba..1e3bd800 100644
--- a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt
+++ b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt
@@ -54,14 +54,14 @@ internal fun DPackage.asJava(): DPackage {
classlikes = emptyList(),
sources = emptyMap(),
expectPresentInSet = null,
- visibility = sourceSets.map {
- it to JavaVisibility.Public
- }.toMap(),
+ visibility = sourceSets.associateWith {
+ JavaVisibility.Public
+ },
companion = null,
generics = emptyList(),
supertypes = emptyMap(),
documentation = emptyMap(),
- modifier = sourceSets.map { it to JavaModifier.Final }.toMap(),
+ modifier = sourceSets.associateWith { JavaModifier.Final },
sourceSets = sourceSets,
isExpectActual = false,
extra = PropertyContainer.empty()
@@ -98,9 +98,9 @@ internal fun DProperty.asJava(isTopLevel: Boolean = false, relocateToClass: Stri
getter = null, // Removing getters and setters as they will be available as functions
extra = if (isTopLevel) extra +
extra.mergeAdditionalModifiers(
- sourceSets.map {
- it to setOf(ExtraModifiers.JavaOnlyModifiers.Static)
- }.toMap()
+ sourceSets.associateWith {
+ setOf(ExtraModifiers.JavaOnlyModifiers.Static)
+ }
)
else extra
)
@@ -138,9 +138,9 @@ internal fun DProperty.javaAccessors(isTopLevel: Boolean = false, relocateToClas
type = getter.type.asJava(),
extra = if (isTopLevel) getter.extra +
getter.extra.mergeAdditionalModifiers(
- sourceSets.map {
- it to setOf(ExtraModifiers.JavaOnlyModifiers.Static)
- }.toMap()
+ sourceSets.associateWith {
+ setOf(ExtraModifiers.JavaOnlyModifiers.Static)
+ }
)
else getter.extra
)
@@ -167,9 +167,9 @@ internal fun DProperty.javaAccessors(isTopLevel: Boolean = false, relocateToClas
visibility = visibility.mapValues { JavaVisibility.Public },
type = Void,
extra = if (isTopLevel) setter.extra + setter.extra.mergeAdditionalModifiers(
- sourceSets.map {
- it to setOf(ExtraModifiers.JavaOnlyModifiers.Static)
- }.toMap()
+ sourceSets.associateWith {
+ setOf(ExtraModifiers.JavaOnlyModifiers.Static)
+ }
)
else setter.extra
)
@@ -187,16 +187,16 @@ private fun DFunction.asJava(
name = newName,
type = type.asJava(),
modifier = if (modifier.all { (_, v) -> v is KotlinModifier.Final } && isConstructor)
- sourceSets.map { it to JavaModifier.Empty }.toMap()
- else sourceSets.map { it to modifier.values.first() }.toMap(),
+ 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) {
extra + extra.mergeAdditionalModifiers(
- sourceSets.map {
- it to setOf(ExtraModifiers.JavaOnlyModifiers.Static)
- }.toMap()
+ sourceSets.associateWith {
+ setOf(ExtraModifiers.JavaOnlyModifiers.Static)
+ }
)
} else {
extra
@@ -253,7 +253,11 @@ internal fun DClasslike.asJava(): DClasslike = when (this) {
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
+ .flatMap {
+ it.asJava(
+ dri.classNames ?: name
+ )
+ }, // name may not always be valid here, however classNames should always be not null
functions = functionsInJava(),
properties = properties
.filterNot { it.hasJvmSynthetic() }
@@ -261,9 +265,8 @@ internal fun DClass.asJava(): DClass = copy(
classlikes = classlikes.map { it.asJava() },
generics = generics.map { it.asJava() },
supertypes = supertypes.mapValues { it.value.map { it.asJava() } },
- modifier = if (modifier.all { (_, v) -> v is KotlinModifier.Empty }) sourceSets.map { it to JavaModifier.Final }
- .toMap()
- else sourceSets.map { it to modifier.values.first() }.toMap()
+ modifier = if (modifier.all { (_, v) -> v is KotlinModifier.Empty }) sourceSets.associateWith { JavaModifier.Final }
+ else sourceSets.associateWith { modifier.values.first() }
)
internal fun DClass.functionsInJava(): List<DFunction> =
@@ -343,13 +346,13 @@ internal fun DObject.asJava(): DObject = copy(
.map { it.asJava() } +
DProperty(
name = "INSTANCE",
- modifier = sourceSets.map { it to JavaModifier.Final }.toMap(),
+ modifier = sourceSets.associateWith { JavaModifier.Final },
dri = dri.copy(callable = Callable("INSTANCE", null, emptyList())),
documentation = emptyMap(),
sources = emptyMap(),
- visibility = sourceSets.map {
- it to JavaVisibility.Public
- }.toMap(),
+ visibility = sourceSets.associateWith {
+ JavaVisibility.Public
+ },
type = GenericTypeConstructor(dri, emptyList()),
setter = null,
getter = null,
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 a50fdf68..61a31627 100644
--- a/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureUtils.kt
+++ b/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureUtils.kt
@@ -29,8 +29,8 @@ object JavaSignatureUtils : JvmSignatureUtils {
annotationsInlineWithIgnored(d, ignoredAnnotations, strategy, listBrackets, classExtension)
override fun <T : Documentable> WithExtraProperties<T>.modifiers() =
- extra[AdditionalModifiers]?.content?.entries?.map {
+ extra[AdditionalModifiers]?.content?.entries?.associate {
it.key to it.value.filterIsInstance<ExtraModifiers.JavaOnlyModifiers>().toSet()
- }?.toMap() ?: emptyMap()
+ } ?: emptyMap()
} \ No newline at end of file
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 31252ae0..c928ea67 100644
--- a/plugins/kotlin-as-java/src/main/kotlin/transformers/JvmNameProvider.kt
+++ b/plugins/kotlin-as-java/src/main/kotlin/transformers/JvmNameProvider.kt
@@ -18,7 +18,7 @@ class JvmNameProvider {
fun <T> nameForSyntheticClass(entry: T): Name where T : WithSources, T : WithExtraProperties<out Documentable>, 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"
+ ?: (entry.sources.entries.first().value.path.split("/").last().split(".").first().capitalize() + "Kt")
return Name("${entry.dri.packageName}.$name")
}
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 f1aae2dc..80c3a3de 100644
--- a/plugins/kotlin-as-java/src/main/kotlin/translators/KotlinAsJavaDocumentableToPageTranslator.kt
+++ b/plugins/kotlin-as-java/src/main/kotlin/translators/KotlinAsJavaDocumentableToPageTranslator.kt
@@ -2,13 +2,14 @@ package org.jetbrains.dokka.kotlinAsJava.translators
import org.jetbrains.dokka.base.DokkaBase
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.DokkaConfiguration
-import org.jetbrains.dokka.transformers.documentation.DocumentableToPageTranslator
import org.jetbrains.dokka.model.DModule
import org.jetbrains.dokka.pages.ModulePageNode
-import org.jetbrains.dokka.plugability.*
+import org.jetbrains.dokka.plugability.DokkaContext
+import org.jetbrains.dokka.plugability.configuration
+import org.jetbrains.dokka.plugability.plugin
+import org.jetbrains.dokka.plugability.query
+import org.jetbrains.dokka.plugability.querySingle
+import org.jetbrains.dokka.transformers.documentation.DocumentableToPageTranslator
import org.jetbrains.dokka.utilities.DokkaLogger
class KotlinAsJavaDocumentableToPageTranslator(context: DokkaContext) : DocumentableToPageTranslator {
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 ef075153..ad3c8b0e 100644
--- a/plugins/kotlin-as-java/src/main/kotlin/translators/KotlinAsJavaPageCreator.kt
+++ b/plugins/kotlin-as-java/src/main/kotlin/translators/KotlinAsJavaPageCreator.kt
@@ -4,7 +4,6 @@ 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.translators.documentables.DefaultPageCreator
-import org.jetbrains.dokka.DokkaConfiguration
import org.jetbrains.dokka.base.transformers.pages.tags.CustomTagContentProvider
import org.jetbrains.dokka.model.DProperty
import org.jetbrains.dokka.pages.MemberPageNode