From 9af0b307a14253a21d11d340a78dd9061abee359 Mon Sep 17 00:00:00 2001 From: Vsevolod Tolstopyatov Date: Mon, 27 Mar 2023 03:01:34 -0700 Subject: Mark utilities.* API as Dokka-internal (#2937) * Deprecate unused declaration, remove inline declaration (as it's binary compatible), opt-in into internal API at project level * Opt-in into DokkaInternalApi where applicable * Get rid of intermediate test-utils module --- core/src/main/kotlin/utilities/DokkaLogging.kt | 2 +- core/src/main/kotlin/utilities/Html.kt | 4 ++++ core/src/main/kotlin/utilities/ServiceLocator.kt | 7 ++++--- core/src/main/kotlin/utilities/Uri.kt | 6 ++++-- core/src/main/kotlin/utilities/associateWithNotNull.kt | 3 +++ core/src/main/kotlin/utilities/cast.kt | 3 +++ core/src/main/kotlin/utilities/parallelCollectionOperations.kt | 4 ++++ 7 files changed, 23 insertions(+), 6 deletions(-) (limited to 'core/src/main/kotlin/utilities') diff --git a/core/src/main/kotlin/utilities/DokkaLogging.kt b/core/src/main/kotlin/utilities/DokkaLogging.kt index 39529324..5cca6d53 100644 --- a/core/src/main/kotlin/utilities/DokkaLogging.kt +++ b/core/src/main/kotlin/utilities/DokkaLogging.kt @@ -39,7 +39,7 @@ fun interface MessageEmitter : (String) -> Unit { } class DokkaConsoleLogger( - val minLevel: LoggingLevel = LoggingLevel.PROGRESS, + private val minLevel: LoggingLevel = LoggingLevel.PROGRESS, private val emitter: MessageEmitter = MessageEmitter.consoleEmitter ) : DokkaLogger { private val warningsCounter = AtomicInteger() diff --git a/core/src/main/kotlin/utilities/Html.kt b/core/src/main/kotlin/utilities/Html.kt index 874c9fb1..a1d8ecec 100644 --- a/core/src/main/kotlin/utilities/Html.kt +++ b/core/src/main/kotlin/utilities/Html.kt @@ -1,5 +1,6 @@ package org.jetbrains.dokka.utilities +import org.jetbrains.dokka.* import java.net.URLEncoder @@ -7,9 +8,12 @@ import java.net.URLEncoder * Replaces symbols reserved in HTML with their respective entities. * Replaces & with &, < with < and > with > */ +@InternalDokkaApi fun String.htmlEscape(): String = replace("&", "&").replace("<", "<").replace(">", ">").replace("\"", """) +@InternalDokkaApi fun String.urlEncoded(): String = URLEncoder.encode(this, "UTF-8") +@InternalDokkaApi fun String.formatToEndWithHtml() = if (endsWith(".html") || contains(Regex("\\.html#"))) this else "$this.html" diff --git a/core/src/main/kotlin/utilities/ServiceLocator.kt b/core/src/main/kotlin/utilities/ServiceLocator.kt index 3e515348..f86960ec 100644 --- a/core/src/main/kotlin/utilities/ServiceLocator.kt +++ b/core/src/main/kotlin/utilities/ServiceLocator.kt @@ -1,5 +1,6 @@ package org.jetbrains.dokka.utilities +import org.jetbrains.dokka.* import java.io.File import java.net.URISyntaxException import java.net.URL @@ -7,10 +8,13 @@ import java.util.* import java.util.jar.JarFile import java.util.zip.ZipEntry +@InternalDokkaApi data class ServiceDescriptor(val name: String, val category: String, val description: String?, val className: String) +@InternalDokkaApi class ServiceLookupException(message: String) : Exception(message) +@InternalDokkaApi object ServiceLocator { fun lookup(clazz: Class, category: String, implementationName: String): T { val descriptor = lookupDescriptor(category, implementationName) @@ -81,9 +85,6 @@ object ServiceLocator { } } -inline fun ServiceLocator.lookup(category: String, implementationName: String): T = lookup(T::class.java, category, implementationName) -inline fun ServiceLocator.lookup(desc: ServiceDescriptor): T = lookup(T::class.java, desc) - private val ZipEntry.fileName: String get() = name.substringAfterLast("/", name) diff --git a/core/src/main/kotlin/utilities/Uri.kt b/core/src/main/kotlin/utilities/Uri.kt index 089b3cff..67c81d98 100644 --- a/core/src/main/kotlin/utilities/Uri.kt +++ b/core/src/main/kotlin/utilities/Uri.kt @@ -1,8 +1,10 @@ package org.jetbrains.dokka.utilities +import org.jetbrains.dokka.* import java.net.URI - +@InternalDokkaApi +@Deprecated("Deprecated for removal") // Unused in Dokka fun URI.relativeTo(uri: URI): URI { // Normalize paths to remove . and .. segments val base = uri.normalize() @@ -37,4 +39,4 @@ fun URI.relativeTo(uri: URI): URI { append(it) } }) -} \ No newline at end of file +} diff --git a/core/src/main/kotlin/utilities/associateWithNotNull.kt b/core/src/main/kotlin/utilities/associateWithNotNull.kt index ea2e8c3c..6c0bf4d8 100644 --- a/core/src/main/kotlin/utilities/associateWithNotNull.kt +++ b/core/src/main/kotlin/utilities/associateWithNotNull.kt @@ -1,5 +1,8 @@ package org.jetbrains.dokka.utilities +import org.jetbrains.dokka.* + +@InternalDokkaApi inline fun Iterable.associateWithNotNull(valueSelector: (K) -> V?): Map { @Suppress("UNCHECKED_CAST") return associateWith { valueSelector(it) }.filterValues { it != null } as Map diff --git a/core/src/main/kotlin/utilities/cast.kt b/core/src/main/kotlin/utilities/cast.kt index d4a8d73d..784b7e2a 100644 --- a/core/src/main/kotlin/utilities/cast.kt +++ b/core/src/main/kotlin/utilities/cast.kt @@ -1,5 +1,8 @@ package org.jetbrains.dokka.utilities +import org.jetbrains.dokka.* + +@InternalDokkaApi inline fun Any.cast(): T { return this as T } diff --git a/core/src/main/kotlin/utilities/parallelCollectionOperations.kt b/core/src/main/kotlin/utilities/parallelCollectionOperations.kt index 35ad48fd..d24aa7a6 100644 --- a/core/src/main/kotlin/utilities/parallelCollectionOperations.kt +++ b/core/src/main/kotlin/utilities/parallelCollectionOperations.kt @@ -1,15 +1,19 @@ package org.jetbrains.dokka.utilities import kotlinx.coroutines.* +import org.jetbrains.dokka.* +@InternalDokkaApi suspend inline fun Iterable.parallelMap(crossinline f: suspend (A) -> B): List = coroutineScope { map { async { f(it) } }.awaitAll() } +@InternalDokkaApi suspend inline fun Iterable.parallelMapNotNull(crossinline f: suspend (A) -> B?): List = coroutineScope { map { async { f(it) } }.awaitAll().filterNotNull() } +@InternalDokkaApi suspend inline fun Iterable.parallelForEach(crossinline f: suspend (A) -> Unit): Unit = coroutineScope { forEach { launch { f(it) } } } -- cgit