From dd44b839eac1b7b647e97f2cc73dd96bd054713b Mon Sep 17 00:00:00 2001 From: Andrzej Ratajczak Date: Thu, 28 May 2020 21:12:50 +0200 Subject: Refactor of Annotations and ExtraModifiers to be platform depedent --- .../kotlin/converters/KotlinToJavaConverter.kt | 29 ++++++++++++++++++---- .../kotlin/signatures/JavaSignatureProvider.kt | 8 +++--- .../main/kotlin/signatures/JavaSignatureUtils.kt | 4 ++- 3 files changed, 31 insertions(+), 10 deletions(-) (limited to 'plugins/kotlin-as-java/src/main') 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 8f20f942..693fffac 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt @@ -76,7 +76,13 @@ internal fun DProperty.asJava(isTopLevel: Boolean = false, relocateToClass: Stri type = type.asJava(), // TODO: check setter = null, getter = null, // Removing getters and setters as they will be available as functions - extra = if (isTopLevel) extra.plus(extra.mergeAdditionalModifiers(setOf(ExtraModifiers.JavaOnlyModifiers.Static))) else extra + extra = if (isTopLevel) extra + + extra.mergeAdditionalModifiers( + sourceSets.map { + it to setOf(ExtraModifiers.JavaOnlyModifiers.Static) + }.toMap() + ) + else extra ) internal fun DProperty.javaAccessors(isTopLevel: Boolean = false, relocateToClass: String? = null): List = @@ -95,7 +101,13 @@ internal fun DProperty.javaAccessors(isTopLevel: Boolean = false, relocateToClas }, visibility = visibility.mapValues { JavaVisibility.Public }, type = type.asJava(), // TODO: check - extra = if (isTopLevel) getter!!.extra.plus(getter!!.extra.mergeAdditionalModifiers(setOf(ExtraModifiers.JavaOnlyModifiers.Static))) else getter!!.extra + extra = if (isTopLevel) getter!!.extra + + getter!!.extra.mergeAdditionalModifiers( + sourceSets.map { + it to setOf(ExtraModifiers.JavaOnlyModifiers.Static) + }.toMap() + ) + else getter!!.extra ), setter?.copy( dri = if (relocateToClass.isNullOrBlank()) { @@ -111,7 +123,12 @@ internal fun DProperty.javaAccessors(isTopLevel: Boolean = false, relocateToClas }, visibility = visibility.mapValues { JavaVisibility.Public }, type = type.asJava(), // TODO: check - extra = if (isTopLevel) setter!!.extra.plus(setter!!.extra.mergeAdditionalModifiers(setOf(ExtraModifiers.JavaOnlyModifiers.Static))) else setter!!.extra + extra = if (isTopLevel) setter!!.extra + setter!!.extra.mergeAdditionalModifiers( + sourceSets.map { + it to setOf(ExtraModifiers.JavaOnlyModifiers.Static) + }.toMap() + ) + else setter!!.extra ) ) @@ -203,7 +220,9 @@ internal fun DObject.asJava(): DObject = copy( receiver = null, generics = emptyList(), expectPresentInSet = expectPresentInSet, - extra = PropertyContainer.empty() + AdditionalModifiers(setOf(ExtraModifiers.JavaOnlyModifiers.Static)) + 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.possiblyAsJava() } } @@ -248,7 +267,7 @@ internal fun ClassId.toDRI(dri: DRI?): DRI = DRI( target = PointingToDeclaration ) -private fun PropertyContainer.mergeAdditionalModifiers(second: Set) = +private fun PropertyContainer.mergeAdditionalModifiers(second: SourceSetDependent>) = this[AdditionalModifiers]?.squash(AdditionalModifiers(second)) ?: AdditionalModifiers(second) private fun AdditionalModifiers.squash(second: AdditionalModifiers) = 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 a55f9339..5c4985ac 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt @@ -41,7 +41,7 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge if (c is DClass) { platformText(c.modifier) { it.takeIf { it !in ignoredModifiers }?.name.orEmpty() + " " } - text(c.modifiers().toSignatureString()) + platformText(c.modifiers()) { it.toSignatureString() } } when (c) { @@ -71,7 +71,7 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge annotationsBlock(p) platformText(p.visibility) { (it.takeIf { it !in ignoredVisibilities }?.name ?: "") + " " } platformText(p.modifier) { it.name + " " } - text(p.modifiers().toSignatureString()) + platformText(p.modifiers()) { it.toSignatureString() } signatureForProjection(p.type) text(nbsp.toString()) link(p.name, p.dri) @@ -82,7 +82,7 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge group(styles = setOf(TextStyle.Block)) { annotationsBlock(f) platformText(f.modifier) { it.takeIf { it !in ignoredModifiers }?.name.orEmpty() + " " } - text(f.modifiers().toSignatureString()) + platformText(f.modifiers()) { it.toSignatureString() } val returnType = f.type signatureForProjection(returnType) text(nbsp.toString()) @@ -92,7 +92,7 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge } list(f.parameters, "(", ")") { annotationsInline(it) - text(it.modifiers().toSignatureString()) + platformText(it.modifiers()) { it.toSignatureString() } signatureForProjection(it.type) text(nbsp.toString()) link(it.name!!, it.dri) 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 e2f73bf9..b4245834 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureUtils.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureUtils.kt @@ -28,6 +28,8 @@ object JavaSignatureUtils : JvmSignatureUtils { annotationsInlineWithIgnored(d, ignoredAnnotations, strategy, listBrackets, classExtension) override fun WithExtraProperties.modifiers() = - extra[AdditionalModifiers]?.content?.filterIsInstance()?.toSet() ?: emptySet() + extra[AdditionalModifiers]?.content?.entries?.map { + it.key to it.value.filterIsInstance().toSet() + }?.toMap() ?: emptyMap() } \ No newline at end of file -- cgit