From 8c218ff4dd5f970233c43845c19299fc74256389 Mon Sep 17 00:00:00 2001 From: Ignat Beresnev Date: Fri, 29 Apr 2022 15:03:08 +0300 Subject: Enable warnings as errors and fix all warnings (#2451) * Enable warnings as errors and fix all warnings * Enable skip-metadata-version-check compiler setting --- .../main/kotlin/signatures/JvmSignatureUtils.kt | 27 +++++---- .../kotlin/signatures/KotlinSignatureProvider.kt | 65 ++++++++++++++-------- 2 files changed, 58 insertions(+), 34 deletions(-) (limited to 'plugins/base/src/main/kotlin/signatures') diff --git a/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt b/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt index b6841323..dc5a9543 100644 --- a/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt +++ b/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt @@ -163,16 +163,23 @@ interface JvmSignatureUtils { } } - fun WithExtraProperties.stylesIfDeprecated(sourceSetData: DokkaSourceSet): Set = - if (extra[Annotations]?.directAnnotations?.get(sourceSetData)?.any { - it.dri == DRI("kotlin", "Deprecated") - || it.dri == DRI("java.lang", "Deprecated") - } == true) setOf(TextStyle.Strikethrough) else emptySet() - - infix fun DFunction.uses(t: DTypeParameter): Boolean { - val allDris: List = (listOfNotNull(receiver?.dri, *receiver?.type?.drisOfAllNestedBounds?.toTypedArray() ?: emptyArray()) + - parameters.flatMap { listOf(it.dri) + it.type.drisOfAllNestedBounds }) - return t.dri in allDris + fun WithExtraProperties.stylesIfDeprecated(sourceSetData: DokkaSourceSet): Set { + val directAnnotations = extra[Annotations]?.directAnnotations?.get(sourceSetData) ?: emptyList() + val hasAnyDeprecatedAnnotation = + directAnnotations.any { it.dri == DRI("kotlin", "Deprecated") || it.dri == DRI("java.lang", "Deprecated") } + + return if (hasAnyDeprecatedAnnotation) setOf(TextStyle.Strikethrough) else emptySet() + } + + infix fun DFunction.uses(typeParameter: DTypeParameter): Boolean { + val parameterDris = parameters.flatMap { listOf(it.dri) + it.type.drisOfAllNestedBounds } + val receiverDris = + listOfNotNull( + receiver?.dri, + *receiver?.type?.drisOfAllNestedBounds?.toTypedArray() ?: emptyArray() + ) + val allDris = parameterDris + receiverDris + return typeParameter.dri in allDris } /** diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt index ba4b4131..642c01c3 100644 --- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt +++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt @@ -13,10 +13,7 @@ import org.jetbrains.dokka.model.* import org.jetbrains.dokka.model.Nullable import org.jetbrains.dokka.model.TypeConstructor 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.pages.* import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.plugability.plugin import org.jetbrains.dokka.plugability.querySingle @@ -96,12 +93,16 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog } } - private fun actualTypealiasedSignature(c: DClasslike, sourceSet: DokkaSourceSet, aliasedType: Bound) = - contentBuilder.contentFor( + private fun actualTypealiasedSignature(c: DClasslike, sourceSet: DokkaSourceSet, aliasedType: Bound): ContentGroup { + @Suppress("UNCHECKED_CAST") + val deprecationStyles = (c as? WithExtraProperties) + ?.stylesIfDeprecated(sourceSet) + ?: emptySet() + + return contentBuilder.contentFor( c, ContentKind.Symbol, - setOf(TextStyle.Monospace) + ((c as? WithExtraProperties)?.stylesIfDeprecated(sourceSet) - ?: emptySet()), + setOf(TextStyle.Monospace) + deprecationStyles, sourceSets = setOf(sourceSet) ) { keyword("actual ") @@ -110,15 +111,24 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog operator(" = ") signatureForProjection(aliasedType) } + } - @Suppress("UNCHECKED_CAST") - private fun classlikeSignature(c: T): List = - c.sourceSets.map { sourceSetData -> - (c as? WithExtraProperties)?.extra?.get(ActualTypealias)?.underlyingType?.get(sourceSetData) - ?.let { - actualTypealiasedSignature(c, sourceSetData, it) - } ?: regularSignature(c, sourceSetData) + private fun classlikeSignature(c: T): List { + @Suppress("UNCHECKED_CAST") + val typeAliasUnderlyingType = (c as? WithExtraProperties) + ?.extra + ?.get(ActualTypealias) + ?.underlyingType + + return c.sourceSets.map { sourceSetData -> + val sourceSetType = typeAliasUnderlyingType?.get(sourceSetData) + if (sourceSetType == null) { + regularSignature(c, sourceSetData) + } else { + actualTypealiasedSignature(c, sourceSetData, sourceSetType) + } } + } private fun PageContentBuilder.DocumentableContentBuilder.defaultValueAssign( d: WithExtraProperties, @@ -134,27 +144,33 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog } } - private fun regularSignature(c: DClasslike, sourceSet: DokkaSourceSet) = - contentBuilder.contentFor( + private fun regularSignature(c: DClasslike, sourceSet: DokkaSourceSet): ContentGroup { + @Suppress("UNCHECKED_CAST") + val deprecationStyles = (c as? WithExtraProperties) + ?.stylesIfDeprecated(sourceSet) + ?: emptySet() + + return contentBuilder.contentFor( c, ContentKind.Symbol, - setOf(TextStyle.Monospace) + ((c as? WithExtraProperties)?.stylesIfDeprecated(sourceSet) - ?: emptySet()), + setOf(TextStyle.Monospace) + deprecationStyles, sourceSets = setOf(sourceSet) ) { annotationsBlock(c) c.visibility[sourceSet]?.takeIf { it !in ignoredVisibilities }?.name?.let { keyword("$it ") } if (c.isExpectActual) keyword(if (sourceSet == c.expectPresentInSet) "expect " else "actual ") if (c is DClass) { - val modifier = if (c.modifier[sourceSet] !in ignoredModifiers) + val modifier = + if (c.modifier[sourceSet] !in ignoredModifiers) { when { c.extra[AdditionalModifiers]?.content?.get(sourceSet)?.contains(ExtraModifiers.KotlinOnlyModifiers.Data) == true -> "" c.modifier[sourceSet] is JavaModifier.Empty -> "${KotlinModifier.Open.name} " - else -> c.modifier[sourceSet]?.name?.let { "$it " } ?: "" + else -> c.modifier[sourceSet]?.name?.let { "$it " } } - else - "" - modifier.takeIf { it.isNotEmpty() }?.let { keyword(it) } + } else { + null + } + modifier?.takeIf { it.isNotEmpty() }?.let { keyword(it) } } when (c) { is DClass -> { @@ -232,6 +248,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog } } } + } /** * An example would be a primary constructor `class A(val s: String)`, -- cgit