diff options
| author | Ignat Beresnev <ignat.beresnev@jetbrains.com> | 2022-04-29 15:03:08 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-29 15:03:08 +0300 |
| commit | 8c218ff4dd5f970233c43845c19299fc74256389 (patch) | |
| tree | b6818183ce8faa2c58d6571ca1c86aa28d4f0431 /plugins | |
| parent | 84aacad29982240ae367b21e9d283d38dab672ae (diff) | |
| download | dokka-8c218ff4dd5f970233c43845c19299fc74256389.tar.gz dokka-8c218ff4dd5f970233c43845c19299fc74256389.tar.bz2 dokka-8c218ff4dd5f970233c43845c19299fc74256389.zip | |
Enable warnings as errors and fix all warnings (#2451)
* Enable warnings as errors and fix all warnings
* Enable skip-metadata-version-check compiler setting
Diffstat (limited to 'plugins')
59 files changed, 305 insertions, 314 deletions
diff --git a/plugins/base/base-test-utils/src/main/kotlin/utils/assertHtmlEqualsIgnoringWhitespace.kt b/plugins/base/base-test-utils/src/main/kotlin/utils/assertHtmlEqualsIgnoringWhitespace.kt index 95dcae4e..eeeea265 100644 --- a/plugins/base/base-test-utils/src/main/kotlin/utils/assertHtmlEqualsIgnoringWhitespace.kt +++ b/plugins/base/base-test-utils/src/main/kotlin/utils/assertHtmlEqualsIgnoringWhitespace.kt @@ -1,8 +1,8 @@ package utils -import junit.framework.Assert.assertEquals import org.jsoup.Jsoup import org.jsoup.nodes.Document +import kotlin.test.assertEquals /** * Parses it using JSOUP, trims whitespace at the end of the line and asserts if they are equal diff --git a/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt b/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt index 75617e0c..d3006f33 100644 --- a/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt +++ b/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt @@ -74,7 +74,7 @@ open class MarkdownParser( ).flatMap { it.children } ) - private fun horizontalRulesHandler(node: ASTNode) = + private fun horizontalRulesHandler() = DocTagsFromIElementFactory.getInstance(MarkdownTokenTypes.HORIZONTAL_RULE) private fun emphasisHandler(node: ASTNode) = @@ -353,7 +353,7 @@ open class MarkdownParser( MarkdownElementTypes.ATX_5, MarkdownElementTypes.ATX_6, -> headersHandler(node) - MarkdownTokenTypes.HORIZONTAL_RULE -> horizontalRulesHandler(node) + MarkdownTokenTypes.HORIZONTAL_RULE -> horizontalRulesHandler() MarkdownElementTypes.STRONG -> strongHandler(node) MarkdownElementTypes.EMPH -> emphasisHandler(node) MarkdownElementTypes.FULL_REFERENCE_LINK, diff --git a/plugins/base/src/main/kotlin/parsers/factories/DocTagsFromIElementFactory.kt b/plugins/base/src/main/kotlin/parsers/factories/DocTagsFromIElementFactory.kt index a3cbcc2e..ea87dce8 100644 --- a/plugins/base/src/main/kotlin/parsers/factories/DocTagsFromIElementFactory.kt +++ b/plugins/base/src/main/kotlin/parsers/factories/DocTagsFromIElementFactory.kt @@ -54,6 +54,7 @@ object DocTagsFromIElementFactory { MarkdownTokenTypes.HTML_BLOCK_CONTENT -> Text(body.orEmpty(), params = params + contentTypeParam("html")) else -> CustomDocTag(children, params, type.name) }.let { + @Suppress("UNCHECKED_CAST") when (it) { is List<*> -> it as List<DocTag> else -> listOf(it as DocTag) diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt index 05559469..7ce41866 100644 --- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt @@ -367,8 +367,6 @@ open class HtmlRenderer( pageContext: ContentPage ) = // TODO: extension point there if (node.isImage()) { - //TODO: add imgAttrs parsing - val imgAttrs = node.extra.allOfType<SimpleAttr>().joinAttr() img(src = node.address, alt = node.altText) } else { println("Unrecognized resource type: $node") @@ -377,17 +375,16 @@ open class HtmlRenderer( private fun FlowContent.buildRow( node: ContentGroup, pageContext: ContentPage, - sourceSetRestriction: Set<DisplaySourceSet>?, - style: Set<Style> + sourceSetRestriction: Set<DisplaySourceSet>? ) { node.children .filter { sourceSetRestriction == null || it.sourceSets.any { s -> s in sourceSetRestriction } } .takeIf { it.isNotEmpty() } ?.let { when (pageContext) { - is MultimoduleRootPage -> buildRowForMultiModule(node, it, pageContext, sourceSetRestriction, style) - is ModulePage -> buildRowForModule(node, it, pageContext, sourceSetRestriction, style) - else -> buildRowForContent(node, it, pageContext, sourceSetRestriction, style) + is MultimoduleRootPage -> buildRowForMultiModule(node, it, pageContext, sourceSetRestriction) + is ModulePage -> buildRowForModule(node, it, pageContext, sourceSetRestriction) + else -> buildRowForContent(node, it, pageContext, sourceSetRestriction) } } } @@ -396,8 +393,7 @@ open class HtmlRenderer( contextNode: ContentGroup, toRender: List<ContentNode>, pageContext: ContentPage, - sourceSetRestriction: Set<DisplaySourceSet>?, - style: Set<Style> + sourceSetRestriction: Set<DisplaySourceSet>? ) { buildAnchor(contextNode) div(classes = "table-row") { @@ -414,8 +410,7 @@ open class HtmlRenderer( contextNode: ContentGroup, toRender: List<ContentNode>, pageContext: ContentPage, - sourceSetRestriction: Set<DisplaySourceSet>?, - style: Set<Style> + sourceSetRestriction: Set<DisplaySourceSet>? ) { buildAnchor(contextNode) div(classes = "table-row") { @@ -440,8 +435,7 @@ open class HtmlRenderer( contextNode: ContentGroup, toRender: List<ContentNode>, pageContext: ContentPage, - sourceSetRestriction: Set<DisplaySourceSet>?, - style: Set<Style> + sourceSetRestriction: Set<DisplaySourceSet>? ) { buildAnchor(contextNode) div(classes = "table-row") { @@ -551,7 +545,7 @@ open class HtmlRenderer( else -> div(classes = "table") { node.extra.extraHtmlAttributes().forEach { attributes[it.extraKey] = it.extraValue } node.children.forEach { - buildRow(it, pageContext, sourceSetRestriction, node.style) + buildRow(it, pageContext, sourceSetRestriction) } } } 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 <T : Documentable> WithExtraProperties<T>.stylesIfDeprecated(sourceSetData: DokkaSourceSet): Set<TextStyle> = - 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<DRI> = (listOfNotNull(receiver?.dri, *receiver?.type?.drisOfAllNestedBounds?.toTypedArray() ?: emptyArray()) + - parameters.flatMap { listOf(it.dri) + it.type.drisOfAllNestedBounds }) - return t.dri in allDris + fun <T : Documentable> WithExtraProperties<T>.stylesIfDeprecated(sourceSetData: DokkaSourceSet): Set<TextStyle> { + 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<out Documentable>) + ?.stylesIfDeprecated(sourceSet) + ?: emptySet() + + return contentBuilder.contentFor( c, ContentKind.Symbol, - setOf(TextStyle.Monospace) + ((c as? WithExtraProperties<out Documentable>)?.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 <T : DClasslike> classlikeSignature(c: T): List<ContentNode> = - c.sourceSets.map { sourceSetData -> - (c as? WithExtraProperties<out DClasslike>)?.extra?.get(ActualTypealias)?.underlyingType?.get(sourceSetData) - ?.let { - actualTypealiasedSignature(c, sourceSetData, it) - } ?: regularSignature(c, sourceSetData) + private fun <T : DClasslike> classlikeSignature(c: T): List<ContentNode> { + @Suppress("UNCHECKED_CAST") + val typeAliasUnderlyingType = (c as? WithExtraProperties<out DClasslike>) + ?.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 <T : Documentable> PageContentBuilder.DocumentableContentBuilder.defaultValueAssign( d: WithExtraProperties<T>, @@ -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<out Documentable>) + ?.stylesIfDeprecated(sourceSet) + ?: emptySet() + + return contentBuilder.contentFor( c, ContentKind.Symbol, - setOf(TextStyle.Monospace) + ((c as? WithExtraProperties<out Documentable>)?.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)`, diff --git a/plugins/base/src/main/kotlin/templating/jsonMapperForPlugins.kt b/plugins/base/src/main/kotlin/templating/jsonMapperForPlugins.kt index 71245778..98cabd72 100644 --- a/plugins/base/src/main/kotlin/templating/jsonMapperForPlugins.kt +++ b/plugins/base/src/main/kotlin/templating/jsonMapperForPlugins.kt @@ -49,6 +49,7 @@ private object FileSerializer : StdScalarSerializer<File>(File::class.java) { } } +@Suppress("DEPRECATION") // for TypeFactory constructor, no way to use non-deprecated one, it's essentially identical private class PluginTypeFactory: TypeFactory(null) { override fun findClass(className: String): Class<out Any>? = Class.forName(className, true, DokkaBase::class.java.classLoader) ?: super.findClass(className) diff --git a/plugins/base/src/main/kotlin/transformers/documentables/ActualTypealiasAdder.kt b/plugins/base/src/main/kotlin/transformers/documentables/ActualTypealiasAdder.kt index a9b99840..58c601bc 100644 --- a/plugins/base/src/main/kotlin/transformers/documentables/ActualTypealiasAdder.kt +++ b/plugins/base/src/main/kotlin/transformers/documentables/ActualTypealiasAdder.kt @@ -66,7 +66,7 @@ class ActualTypealiasAdder : DocumentableTransformer { elements.map { element -> if (element.expectPresentInSet != null) { typealiases[element.dri]?.let { ta -> - element.withNewExtras(element.extra + ActualTypealias(ta.underlyingType)).let { + val merged = element.withNewExtras(element.extra + ActualTypealias(ta.underlyingType)).let { when(it) { is DClass -> it.copy(sourceSets = element.sourceSets + ta.sourceSets) is DEnum -> it.copy(sourceSets = element.sourceSets + ta.sourceSets) @@ -75,7 +75,9 @@ class ActualTypealiasAdder : DocumentableTransformer { is DAnnotation -> it.copy(sourceSets = element.sourceSets + ta.sourceSets) else -> throw IllegalStateException("${it::class.qualifiedName} ${it.name} cannot have copy its sourceSets") } - } as T + } + @Suppress("UNCHECKED_CAST") + merged as T } ?: element } else { element diff --git a/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt b/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt index 6239ad6b..17e3cbcd 100644 --- a/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt +++ b/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt @@ -49,7 +49,7 @@ internal class DefaultDocumentableMerger(val context: DokkaContext) : Documentab fun mergeClashingElements(elements: List<Pair<T, Set<DokkaConfiguration.DokkaSourceSet>>>): List<T> = elements.groupBy { it.first.name }.values.flatMap { listOfDocumentableToSSIds -> - listOfDocumentableToSSIds.map { (documentable, sourceSets |
