Skip to content

Commit

Permalink
Enable warnings as errors and fix all warnings (#2451)
Browse files Browse the repository at this point in the history
* Enable warnings as errors and fix all warnings

* Enable skip-metadata-version-check compiler setting
  • Loading branch information
IgnatBeresnev committed Apr 29, 2022
1 parent 84aacad commit 8c218ff
Show file tree
Hide file tree
Showing 75 changed files with 368 additions and 333 deletions.
9 changes: 6 additions & 3 deletions build.gradle.kts
Expand Up @@ -4,7 +4,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") apply false
id("java")
id("org.jetbrains.dokka") version "1.5.0"
id("org.jetbrains.dokka") version "1.6.20"
id("io.github.gradle-nexus.publish-plugin")
}

Expand All @@ -21,10 +21,13 @@ allprojects {
tasks.withType(KotlinCompile::class).all {
kotlinOptions {
freeCompilerArgs = freeCompilerArgs + listOf(
"-Xopt-in=kotlin.RequiresOptIn",
"-opt-in=kotlin.RequiresOptIn",
"-Xjsr305=strict",
"-Xskip-metadata-version-check",
"-Xjsr305=strict"
// need 1.4 support, otherwise there might be problems with Gradle 6.x (it's bundling Kotlin 1.4)
"-Xsuppress-version-warnings"
)
allWarningsAsErrors = true
languageVersion = language_version
apiVersion = language_version
jvmTarget = "1.8"
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/kotlin/configuration.kt
Expand Up @@ -235,7 +235,7 @@ interface DokkaConfiguration : Serializable {

interface PackageOptions : Serializable {
val matchingRegex: String
@Deprecated(message = "Use [documentedVisibilities] property for a more flexible control over documented visibilities")
@Deprecated("Use [documentedVisibilities] property for a more flexible control over documented visibilities")
val includeNonPublic: Boolean
val reportUndocumented: Boolean?
val skipDeprecated: Boolean
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/kotlin/defaultConfiguration.kt
Expand Up @@ -37,6 +37,7 @@ data class DokkaSourceSetImpl(
override val dependentSourceSets: Set<DokkaSourceSetID> = emptySet(),
override val samples: Set<File> = emptySet(),
override val includes: Set<File> = emptySet(),
@Deprecated("Use [documentedVisibilities] property for a more flexible control over documented visibilities")
override val includeNonPublic: Boolean = DokkaDefaults.includeNonPublic,
override val reportUndocumented: Boolean = DokkaDefaults.reportUndocumented,
override val skipEmptyPackages: Boolean = DokkaDefaults.skipEmptyPackages,
Expand Down Expand Up @@ -79,6 +80,7 @@ data class SourceLinkDefinitionImpl(

data class PackageOptionsImpl(
override val matchingRegex: String,
@Deprecated("Use [documentedVisibilities] property for a more flexible control over documented visibilities")
override val includeNonPublic: Boolean,
override val reportUndocumented: Boolean?,
override val skipDeprecated: Boolean,
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/kotlin/pages/PageNodes.kt
Expand Up @@ -21,7 +21,7 @@ interface ContentPage : PageNode {
val embeddedResources: List<String>

@Deprecated("Deprecated. Remove its usages from your code.",
ReplaceWith("documentables.firstOrNull()")
ReplaceWith("this.documentables.firstOrNull()")
)
val documentable: Documentable?
get() = if (this is WithDocumentables) this.documentables.firstOrNull() else null
Expand Down
Expand Up @@ -106,6 +106,7 @@ class DokkaSourceSetBuilder(
var externalDocumentationLinks: List<ExternalDocumentationLinkImpl> = emptyList(),
var sourceLinks: List<SourceLinkDefinitionImpl> = emptyList()
) {
@Suppress("DEPRECATION")
fun build() = DokkaSourceSetImpl(
displayName = displayName,
sourceSetID = DokkaSourceSetID(moduleName, name),
Expand Down
17 changes: 17 additions & 0 deletions integration-tests/gradle/projects/it-basic-groovy/build.gradle
Expand Up @@ -19,6 +19,23 @@ dokkaHtml {
displayName.set("custom")
reportUndocumented.set(true)
}

configureEach {
perPackageOption { // testing closures
matchingRegex.set(".*internal.*")
suppress.set(true)
}

sourceLink { // testing closures
localDirectory.set(file("src/main"))
remoteUrl.set(
new URL(
"https://github.com/Kotlin/dokka/tree/master/" +
"integration-tests/gradle/projects/it-basic-groovy/src/main"
)
)
}
}
}

}
Expand Down
Expand Up @@ -114,8 +114,11 @@ class AnalysisEnvironment(val messageCollector: MessageCollector, val analysisPl
JavadocTagInfo.EP_NAME, JavadocTagInfo::class.java
)

@Suppress("DEPRECATION")
val extensionArea = Extensions.getRootArea()

CoreApplicationEnvironment.registerExtensionPoint(
Extensions.getRootArea(),
extensionArea,
CustomJavadocTagProvider.EP_NAME, CustomJavadocTagProvider::class.java
)

Expand Down Expand Up @@ -588,8 +591,12 @@ class AnalysisEnvironment(val messageCollector: MessageCollector, val analysisPl
instances: List<T>,
disposable: Disposable
) {
if (Extensions.getRootArea().hasExtensionPoint(appExtension.extensionPointName))
@Suppress("DEPRECATION")
val extensionArea = Extensions.getRootArea()

if (extensionArea.hasExtensionPoint(appExtension.extensionPointName)) {
return
}

appExtension.registerExtensionPoint()
instances.forEach { extension -> appExtension.registerExtension(extension, disposable) }
Expand Down
Expand Up @@ -75,6 +75,7 @@ class DokkaResolutionFacade(
if (key != element) {
throw UnsupportedOperationException()
}
@Suppress("UNCHECKED_CAST")
return when {
slice == BindingContext.DECLARATION_TO_DESCRIPTOR -> descriptor as V
slice == BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER && (element as KtParameter).hasValOrVar() -> descriptor as V
Expand Down
Expand Up @@ -20,7 +20,7 @@ import com.intellij.ide.highlighter.JavaClassFileType
import com.intellij.ide.highlighter.JavaFileType
import com.intellij.openapi.vfs.VfsUtilCore
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.util.containers.IntArrayList
import it.unimi.dsi.fastutil.ints.IntArrayList
import gnu.trove.THashMap
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
Expand Down Expand Up @@ -54,7 +54,7 @@ class JvmDependenciesIndexImpl(_roots: List<JavaRoot>) : JvmDependenciesIndex {
Cache().apply {
roots.indices.forEach(rootIndices::add)
rootIndices.add(maxIndex)
rootIndices.trimToSize()
rootIndices.trim()
}
}

Expand Down Expand Up @@ -121,8 +121,8 @@ class JvmDependenciesIndexImpl(_roots: List<JavaRoot>) : JvmDependenciesIndex {
// NOTE: indices manipulation instead of using caches.reversed() is here for performance reasons
for (cacheIndex in caches.lastIndex downTo 0) {
val cacheRootIndices = caches[cacheIndex].rootIndices
for (i in 0 until cacheRootIndices.size()) {
val rootIndex = cacheRootIndices[i]
for (i in 0 until cacheRootIndices.size) {
val rootIndex = cacheRootIndices.getInt(i)
if (rootIndex <= processedRootsUpTo) continue // roots with those indices have been processed by now

val directoryInRoot =
Expand All @@ -138,7 +138,12 @@ class JvmDependenciesIndexImpl(_roots: List<JavaRoot>) : JvmDependenciesIndex {
}
}
}
processedRootsUpTo = if (cacheRootIndices.isEmpty) processedRootsUpTo else cacheRootIndices.get(cacheRootIndices.size() - 1)
processedRootsUpTo =
if (cacheRootIndices.isEmpty) {
processedRootsUpTo
} else {
cacheRootIndices.getInt(cacheRootIndices.size - 1)
}
}

if (request is FindClassRequest) {
Expand All @@ -160,7 +165,7 @@ class JvmDependenciesIndexImpl(_roots: List<JavaRoot>) : JvmDependenciesIndex {
for (i in (fillCachesAfter + 1) until cachesPath.size) {
// we all know roots that contain this package by now
cachesPath[i].rootIndices.add(maxIndex)
cachesPath[i].rootIndices.trimToSize()
cachesPath[i].rootIndices.trim()
}
return null
}
Expand Down
Expand Up @@ -23,7 +23,7 @@ fun TypeReference.Companion.from(d: ReceiverParameterDescriptor): TypeReference?
fun TypeReference.Companion.from(d: ValueParameterDescriptor): TypeReference =
fromPossiblyNullable(d.type, emptyList())

fun TypeReference.Companion.from(p: PsiClass) = TypeReference
fun TypeReference.Companion.from(@Suppress("UNUSED_PARAMETER") p: PsiClass) = TypeReference

private fun TypeReference.Companion.fromPossiblyNullable(t: KotlinType, paramTrace: List<KotlinType>): TypeReference =
fromPossiblyRecursive(t, paramTrace).let { if (t.isMarkedNullable) Nullable(it) else it }
Expand Down
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions plugins/base/src/main/kotlin/parsers/MarkdownParser.kt
Expand Up @@ -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) =
Expand Down Expand Up @@ -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,
Expand Down
Expand Up @@ -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)
Expand Down
22 changes: 8 additions & 14 deletions plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
Expand Up @@ -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")
Expand All @@ -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)
}
}
}
Expand All @@ -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") {
Expand All @@ -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") {
Expand All @@ -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") {
Expand Down Expand Up @@ -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)
}
}
}
Expand Down
27 changes: 17 additions & 10 deletions plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt
Expand Up @@ -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
}

/**
Expand Down

0 comments on commit 8c218ff

Please sign in to comment.