aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/utilities
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/main/kotlin/utilities')
-rw-r--r--core/src/main/kotlin/utilities/Collections.kt29
-rw-r--r--core/src/main/kotlin/utilities/DokkaLogging.kt90
-rw-r--r--core/src/main/kotlin/utilities/Html.kt23
-rw-r--r--core/src/main/kotlin/utilities/SelfRepresentingSingletonSet.kt27
-rw-r--r--core/src/main/kotlin/utilities/ServiceLocator.kt99
-rw-r--r--core/src/main/kotlin/utilities/Uri.kt46
-rw-r--r--core/src/main/kotlin/utilities/associateWithNotNull.kt13
-rw-r--r--core/src/main/kotlin/utilities/cast.kt12
-rw-r--r--core/src/main/kotlin/utilities/json.kt65
-rw-r--r--core/src/main/kotlin/utilities/parallelCollectionOperations.kt26
10 files changed, 0 insertions, 430 deletions
diff --git a/core/src/main/kotlin/utilities/Collections.kt b/core/src/main/kotlin/utilities/Collections.kt
deleted file mode 100644
index e0b84a28..00000000
--- a/core/src/main/kotlin/utilities/Collections.kt
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.utilities
-
-import org.jetbrains.dokka.InternalDokkaApi
-
-/**
- * This utility method was previously imported from `org.jetbrains.kotlin.utils.addToStdlib`,
- * and there were a lot of usages. Since no replacement exists in stdlib, it was implemented
- * locally for convenience.
- */
-@InternalDokkaApi
-public inline fun <reified T : Any> Iterable<*>.firstIsInstanceOrNull(): T? {
- for (element in this) if (element is T) return element
- return null
-}
-
-/**
- * This utility method was previously imported from `org.jetbrains.kotlin.utils.addToStdlib`,
- * and there were a lot of usages. Since no replacement exists in stdlib, it was implemented
- * locally for convenience.
- */
-@InternalDokkaApi
-public inline fun <reified T : Any> Sequence<*>.firstIsInstanceOrNull(): T? {
- for (element in this) if (element is T) return element
- return null
-}
diff --git a/core/src/main/kotlin/utilities/DokkaLogging.kt b/core/src/main/kotlin/utilities/DokkaLogging.kt
deleted file mode 100644
index 7855c9c1..00000000
--- a/core/src/main/kotlin/utilities/DokkaLogging.kt
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.utilities
-
-import java.util.concurrent.atomic.AtomicInteger
-
-public interface DokkaLogger {
- public var warningsCount: Int
- public var errorsCount: Int
-
- public fun debug(message: String)
- public fun info(message: String)
- public fun progress(message: String)
- public fun warn(message: String)
- public fun error(message: String)
-}
-
-public fun DokkaLogger.report() {
- if (warningsCount > 0 || errorsCount > 0) {
- info(
- "Generation completed with $warningsCount warning" +
- (if (warningsCount == 1) "" else "s") +
- " and $errorsCount error" +
- if (errorsCount == 1) "" else "s"
- )
- } else {
- info("Generation completed successfully")
- }
-}
-
-public enum class LoggingLevel(
- public val index: Int
-) {
- DEBUG(0), PROGRESS(1), INFO(2), WARN(3), ERROR(4);
-}
-
-/**
- * Used to decouple the transport layer from logger and make it convenient for testing
- */
-public fun interface MessageEmitter : (String) -> Unit {
- public companion object {
- public val consoleEmitter: MessageEmitter = MessageEmitter { message -> println(message) }
- }
-}
-
-public class DokkaConsoleLogger(
- private val minLevel: LoggingLevel = LoggingLevel.PROGRESS,
- private val emitter: MessageEmitter = MessageEmitter.consoleEmitter
-) : DokkaLogger {
- private val warningsCounter = AtomicInteger()
- private val errorsCounter = AtomicInteger()
-
- override var warningsCount: Int
- get() = warningsCounter.get()
- set(value) = warningsCounter.set(value)
-
- override var errorsCount: Int
- get() = errorsCounter.get()
- set(value) = errorsCounter.set(value)
-
- override fun debug(message: String) {
- if (shouldBeDisplayed(LoggingLevel.DEBUG)) emitter(message)
- }
-
- override fun progress(message: String) {
- if (shouldBeDisplayed(LoggingLevel.PROGRESS)) emitter("PROGRESS: $message")
- }
-
- override fun info(message: String) {
- if (shouldBeDisplayed(LoggingLevel.INFO)) emitter(message)
- }
-
- override fun warn(message: String) {
- if (shouldBeDisplayed(LoggingLevel.WARN)) {
- emitter("WARN: $message")
- }
- warningsCounter.incrementAndGet()
- }
-
- override fun error(message: String) {
- if (shouldBeDisplayed(LoggingLevel.ERROR)) {
- emitter("ERROR: $message")
- }
- errorsCounter.incrementAndGet()
- }
-
- private fun shouldBeDisplayed(messageLevel: LoggingLevel): Boolean = messageLevel.index >= minLevel.index
-}
diff --git a/core/src/main/kotlin/utilities/Html.kt b/core/src/main/kotlin/utilities/Html.kt
deleted file mode 100644
index fc2330d2..00000000
--- a/core/src/main/kotlin/utilities/Html.kt
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.utilities
-
-import org.jetbrains.dokka.InternalDokkaApi
-import java.net.URLEncoder
-
-
-/**
- * Replaces symbols reserved in HTML with their respective entities.
- * Replaces & with &amp;, < with &lt; and > with &gt;
- */
-@InternalDokkaApi
-public fun String.htmlEscape(): String = replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;").replace("\"", "&quot;")
-
-@InternalDokkaApi
-public fun String.urlEncoded(): String = URLEncoder.encode(this, "UTF-8")
-
-@InternalDokkaApi
-public fun String.formatToEndWithHtml(): String =
- if (endsWith(".html") || contains(Regex("\\.html#"))) this else "$this.html"
diff --git a/core/src/main/kotlin/utilities/SelfRepresentingSingletonSet.kt b/core/src/main/kotlin/utilities/SelfRepresentingSingletonSet.kt
deleted file mode 100644
index 57d3b1e1..00000000
--- a/core/src/main/kotlin/utilities/SelfRepresentingSingletonSet.kt
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.utilities
-
-import org.jetbrains.dokka.InternalDokkaApi
-
-@InternalDokkaApi
-@Suppress("DEPRECATION_ERROR")
-@Deprecated(message = "SelfRepresentingSingletonSet is an incorrect set implementation that breaks set invariants", level = DeprecationLevel.ERROR)
-public interface SelfRepresentingSingletonSet<T : SelfRepresentingSingletonSet<T>> : Set<T> {
- override val size: Int get() = 1
-
- override fun contains(element: T): Boolean = this == element
-
- override fun containsAll(elements: Collection<T>): Boolean =
- if (elements.isEmpty()) true
- else elements.all { this == it }
-
- override fun isEmpty(): Boolean = false
-
- override fun iterator(): Iterator<T> = iterator {
- @Suppress("UNCHECKED_CAST")
- yield(this@SelfRepresentingSingletonSet as T)
- }
-}
diff --git a/core/src/main/kotlin/utilities/ServiceLocator.kt b/core/src/main/kotlin/utilities/ServiceLocator.kt
deleted file mode 100644
index c8b8a837..00000000
--- a/core/src/main/kotlin/utilities/ServiceLocator.kt
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.utilities
-
-import org.jetbrains.dokka.InternalDokkaApi
-import java.io.File
-import java.net.URISyntaxException
-import java.net.URL
-import java.util.*
-import java.util.jar.JarFile
-import java.util.zip.ZipEntry
-
-@InternalDokkaApi
-public data class ServiceDescriptor(val name: String, val category: String, val description: String?, val className: String)
-
-@InternalDokkaApi
-public class ServiceLookupException(message: String) : Exception(message)
-
-@InternalDokkaApi
-public object ServiceLocator {
- public fun <T : Any> lookup(clazz: Class<T>, category: String, implementationName: String): T {
- val descriptor = lookupDescriptor(category, implementationName)
- return lookup(clazz, descriptor)
- }
-
- public fun <T : Any> lookup(
- clazz: Class<T>,
- descriptor: ServiceDescriptor
- ): T {
- val loadedClass = javaClass.classLoader.loadClass(descriptor.className)
- val constructor = loadedClass.constructors.firstOrNull { it.parameterTypes.isEmpty() } ?: throw ServiceLookupException("Class ${descriptor.className} has no corresponding constructor")
-
- val implementationRawType: Any =
- if (constructor.parameterTypes.isEmpty()) constructor.newInstance() else constructor.newInstance(constructor)
-
- if (!clazz.isInstance(implementationRawType)) {
- throw ServiceLookupException("Class ${descriptor.className} is not a subtype of ${clazz.name}")
- }
-
- @Suppress("UNCHECKED_CAST")
- return implementationRawType as T
- }
-
- private fun lookupDescriptor(category: String, implementationName: String): ServiceDescriptor {
- val properties = javaClass.classLoader.getResourceAsStream("dokka/$category/$implementationName.properties")?.use { stream ->
- Properties().let { properties ->
- properties.load(stream)
- properties
- }
- } ?: throw ServiceLookupException("No implementation with name $implementationName found in category $category")
-
- val className = properties["class"]?.toString() ?: throw ServiceLookupException("Implementation $implementationName has no class configured")
-
- return ServiceDescriptor(implementationName, category, properties["description"]?.toString(), className)
- }
-
- public fun URL.toFile(): File {
- assert(protocol == "file")
-
- return try {
- File(toURI())
- } catch (e: URISyntaxException) { //Try to handle broken URLs, with unescaped spaces
- File(path)
- }
- }
-
- public fun allServices(category: String): List<ServiceDescriptor> {
- val entries = this.javaClass.classLoader.getResources("dokka/$category")?.toList() ?: emptyList()
-
- return entries.flatMap {
- when (it.protocol) {
- "file" -> it.toFile().listFiles()?.filter { it.extension == "properties" }?.map { lookupDescriptor(category, it.nameWithoutExtension) } ?: emptyList()
- "jar" -> {
- JarFile(URL(it.file.substringBefore("!")).toFile()).use { file ->
- val jarPath = it.file.substringAfterLast("!").removePrefix("/").removeSuffix("/")
- file.entries()
- .asSequence()
- .filter { entry -> !entry.isDirectory && entry.path == jarPath && entry.extension == "properties" }
- .map { entry ->
- lookupDescriptor(category, entry.fileName.substringBeforeLast("."))
- }.toList()
- }
- }
- else -> emptyList()
- }
- }
- }
-}
-
-private val ZipEntry.fileName: String
- get() = name.substringAfterLast("/", name)
-
-private val ZipEntry.path: String
- get() = name.substringBeforeLast("/", "").removePrefix("/")
-
-private val ZipEntry.extension: String?
- get() = fileName.let { fn -> if ("." in fn) fn.substringAfterLast(".") else null }
diff --git a/core/src/main/kotlin/utilities/Uri.kt b/core/src/main/kotlin/utilities/Uri.kt
deleted file mode 100644
index 7e6b3fbe..00000000
--- a/core/src/main/kotlin/utilities/Uri.kt
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.utilities
-
-import org.jetbrains.dokka.InternalDokkaApi
-import java.net.URI
-
-@InternalDokkaApi
-@Deprecated("Deprecated for removal") // Unused in Dokka
-public fun URI.relativeTo(uri: URI): URI {
- // Normalize paths to remove . and .. segments
- val base = uri.normalize()
- val child = this.normalize()
-
- fun StringBuilder.appendRelativePath() {
- // Split paths into segments
- var bParts = base.path.split('/').dropLastWhile { it.isEmpty() }
- val cParts = child.path.split('/').dropLastWhile { it.isEmpty() }
-
- // Discard trailing segment of base path
- if (bParts.isNotEmpty() && !base.path.endsWith("/")) {
- bParts = bParts.dropLast(1)
- }
-
- // Compute common prefix
- val commonPartsSize = bParts.zip(cParts).takeWhile { (basePart, childPart) -> basePart == childPart }.count()
- bParts.drop(commonPartsSize).joinTo(this, separator = "") { "../" }
- cParts.drop(commonPartsSize).joinTo(this, separator = "/")
- }
-
- return URI.create(buildString {
- if (base.path != child.path) {
- appendRelativePath()
- }
- child.rawQuery?.let {
- append("?")
- append(it)
- }
- child.rawFragment?.let {
- append("#")
- append(it)
- }
- })
-}
diff --git a/core/src/main/kotlin/utilities/associateWithNotNull.kt b/core/src/main/kotlin/utilities/associateWithNotNull.kt
deleted file mode 100644
index 29e37d13..00000000
--- a/core/src/main/kotlin/utilities/associateWithNotNull.kt
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.utilities
-
-import org.jetbrains.dokka.InternalDokkaApi
-
-@InternalDokkaApi
-public inline fun <K, V : Any> Iterable<K>.associateWithNotNull(valueSelector: (K) -> V?): Map<K, V> {
- @Suppress("UNCHECKED_CAST")
- return associateWith { valueSelector(it) }.filterValues { it != null } as Map<K, V>
-}
diff --git a/core/src/main/kotlin/utilities/cast.kt b/core/src/main/kotlin/utilities/cast.kt
deleted file mode 100644
index c2598a33..00000000
--- a/core/src/main/kotlin/utilities/cast.kt
+++ /dev/null
@@ -1,12 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.utilities
-
-import org.jetbrains.dokka.InternalDokkaApi
-
-@InternalDokkaApi
-public inline fun <reified T> Any.cast(): T {
- return this as T
-}
diff --git a/core/src/main/kotlin/utilities/json.kt b/core/src/main/kotlin/utilities/json.kt
deleted file mode 100644
index a8325161..00000000
--- a/core/src/main/kotlin/utilities/json.kt
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.utilities
-
-import com.fasterxml.jackson.core.JsonGenerator
-import com.fasterxml.jackson.databind.DeserializationFeature
-import com.fasterxml.jackson.databind.SerializerProvider
-import com.fasterxml.jackson.databind.module.SimpleModule
-import com.fasterxml.jackson.databind.ser.std.StdScalarSerializer
-import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
-import com.fasterxml.jackson.module.kotlin.jacksonTypeRef
-import java.io.File
-import com.fasterxml.jackson.core.type.TypeReference as JacksonTypeReference
-
-private val objectMapper = run {
- val module = SimpleModule().apply {
- addSerializer(FileSerializer)
- addAbstractTypeMapping(Set::class.java, LinkedHashSet::class.java)
- }
- jacksonObjectMapper()
- .registerModule(module)
- .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
-}
-
-@PublishedApi
-internal class TypeReference<T> @PublishedApi internal constructor(
- internal val jackson: JacksonTypeReference<T>
-) {
- companion object {
- @PublishedApi
- internal inline operator fun <reified T> invoke(): TypeReference<T> = TypeReference(jacksonTypeRef())
- }
-}
-
-// not used anywhere since at least 1.7.20, but might still be referenced in previously compiled
-// inline functions. should be safe to remove after a few major releases.
-@PublishedApi
-@Deprecated(
- "Left for previously compiled public inline classes, not for use",
- ReplaceWith("serializeAsCompactJson(value)"),
- level = DeprecationLevel.ERROR
-)
-internal fun toJsonString(value: Any): String = serializeAsCompactJson(value)
-
-internal fun serializeAsCompactJson(value: Any): String =
- objectMapper.writeValueAsString(value)
-
-internal fun serializeAsPrettyJson(value: Any): String =
- objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(value)
-
-@PublishedApi
-internal inline fun <reified T : Any> parseJson(json: String): T = parseJson(json, TypeReference())
-
-@PublishedApi
-internal fun <T : Any> parseJson(json: String, typeReference: TypeReference<T>): T =
- objectMapper.readValue(json, typeReference.jackson)
-
-
-private object FileSerializer : StdScalarSerializer<File>(File::class.java) {
- override fun serialize(value: File, g: JsonGenerator, provider: SerializerProvider) {
- g.writeString(value.path)
- }
-}
diff --git a/core/src/main/kotlin/utilities/parallelCollectionOperations.kt b/core/src/main/kotlin/utilities/parallelCollectionOperations.kt
deleted file mode 100644
index 001fca0b..00000000
--- a/core/src/main/kotlin/utilities/parallelCollectionOperations.kt
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.utilities
-
-import kotlinx.coroutines.async
-import kotlinx.coroutines.awaitAll
-import kotlinx.coroutines.coroutineScope
-import kotlinx.coroutines.launch
-import org.jetbrains.dokka.InternalDokkaApi
-
-@InternalDokkaApi
-public suspend inline fun <A, B> Iterable<A>.parallelMap(crossinline f: suspend (A) -> B): List<B> = coroutineScope {
- map { async { f(it) } }.awaitAll()
-}
-
-@InternalDokkaApi
-public suspend inline fun <A, B> Iterable<A>.parallelMapNotNull(crossinline f: suspend (A) -> B?): List<B> = coroutineScope {
- map { async { f(it) } }.awaitAll().filterNotNull()
-}
-
-@InternalDokkaApi
-public suspend inline fun <A> Iterable<A>.parallelForEach(crossinline f: suspend (A) -> Unit): Unit = coroutineScope {
- forEach { launch { f(it) } }
-}