diff options
Diffstat (limited to 'core/src/main/kotlin')
65 files changed, 0 insertions, 4869 deletions
diff --git a/core/src/main/kotlin/ConfigurationJsonUtils.kt b/core/src/main/kotlin/ConfigurationJsonUtils.kt deleted file mode 100644 index e693f4ef..00000000 --- a/core/src/main/kotlin/ConfigurationJsonUtils.kt +++ /dev/null @@ -1,54 +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 - -import org.jetbrains.dokka.plugability.ConfigurableBlock -import org.jetbrains.dokka.utilities.parseJson -import org.jetbrains.dokka.utilities.serializeAsCompactJson -import org.jetbrains.dokka.utilities.serializeAsPrettyJson - -public fun DokkaConfigurationImpl(json: String): DokkaConfigurationImpl = parseJson(json) - -public fun GlobalDokkaConfiguration(json: String): GlobalDokkaConfiguration = parseJson(json) - -@Deprecated("Renamed to better distinguish between compact/pretty prints", ReplaceWith("this.toCompactJsonString()")) -public fun DokkaConfiguration.toJsonString(): String = this.toCompactJsonString() - -@Deprecated("Renamed to better distinguish between compact/pretty prints", ReplaceWith("this.toCompactJsonString()")) -public fun <T : ConfigurableBlock> T.toJsonString(): String = this.toCompactJsonString() - -/** - * Serializes [DokkaConfiguration] as a machine-readable and compact JSON string. - * - * The returned string is not very human friendly as it will be difficult to parse by eyes due to it - * being compact and in one line. If you want to show the output to a human being, see [toPrettyJsonString]. - */ -public fun DokkaConfiguration.toCompactJsonString(): String = serializeAsCompactJson(this) - -/** - * Serializes [DokkaConfiguration] as a human-readable (pretty printed) JSON string. - * - * The returned string will have excessive line breaks and indents, which might not be - * desirable when passing this value between API consumers/producers. If you want - * a machine-readable and compact json string, see [toCompactJsonString]. - */ -public fun DokkaConfiguration.toPrettyJsonString(): String = serializeAsPrettyJson(this) - -/** - * Serializes a [ConfigurableBlock] as a machine-readable and compact JSON string. - * - * The returned string is not very human friendly as it will be difficult to parse by eyes due to it - * being compact and in one line. If you want to show the output to a human being, see [toPrettyJsonString]. - */ -public fun <T : ConfigurableBlock> T.toCompactJsonString(): String = serializeAsCompactJson(this) - -/** - * Serializes a [ConfigurableBlock] as a human-readable (pretty printed) JSON string. - * - * The returned string will have excessive line breaks and indents, which might not be - * desirable when passing this value between API consumers/producers. If you want - * a machine-readable and compact json string, see [toCompactJsonString]. - */ -public fun <T : ConfigurableBlock> T.toPrettyJsonString(): String = serializeAsCompactJson(this) diff --git a/core/src/main/kotlin/CoreExtensions.kt b/core/src/main/kotlin/CoreExtensions.kt deleted file mode 100644 index ca2504e2..00000000 --- a/core/src/main/kotlin/CoreExtensions.kt +++ /dev/null @@ -1,43 +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 - -import org.jetbrains.dokka.generation.Generation -import org.jetbrains.dokka.plugability.ExtensionPoint -import org.jetbrains.dokka.renderers.PostAction -import org.jetbrains.dokka.renderers.Renderer -import org.jetbrains.dokka.transformers.documentation.DocumentableMerger -import org.jetbrains.dokka.transformers.documentation.DocumentableToPageTranslator -import org.jetbrains.dokka.transformers.documentation.DocumentableTransformer -import org.jetbrains.dokka.transformers.pages.PageTransformer -import org.jetbrains.dokka.transformers.sources.SourceToDocumentableTranslator -import org.jetbrains.dokka.validity.PreGenerationChecker -import kotlin.reflect.KProperty - -public object CoreExtensions { - - public val preGenerationCheck: ExtensionPoint<PreGenerationChecker> by coreExtensionPoint<PreGenerationChecker>() - - public val generation: ExtensionPoint<Generation> by coreExtensionPoint<Generation>() - - public val sourceToDocumentableTranslator: ExtensionPoint<SourceToDocumentableTranslator> by coreExtensionPoint<SourceToDocumentableTranslator>() - - public val documentableMerger: ExtensionPoint<DocumentableMerger> by coreExtensionPoint<DocumentableMerger>() - - public val documentableTransformer: ExtensionPoint<DocumentableTransformer> by coreExtensionPoint<DocumentableTransformer>() - - public val documentableToPageTranslator: ExtensionPoint<DocumentableToPageTranslator> by coreExtensionPoint<DocumentableToPageTranslator>() - - public val pageTransformer: ExtensionPoint<PageTransformer> by coreExtensionPoint<PageTransformer>() - - public val renderer: ExtensionPoint<Renderer> by coreExtensionPoint<Renderer>() - - public val postActions: ExtensionPoint<PostAction> by coreExtensionPoint<PostAction>() - - private fun <T : Any> coreExtensionPoint() = object { - operator fun provideDelegate(thisRef: CoreExtensions, property: KProperty<*>): Lazy<ExtensionPoint<T>> = - lazy { ExtensionPoint(thisRef::class.qualifiedName!!, property.name) } - } -} diff --git a/core/src/main/kotlin/DokkaBootstrap.kt b/core/src/main/kotlin/DokkaBootstrap.kt deleted file mode 100644 index d3d82e39..00000000 --- a/core/src/main/kotlin/DokkaBootstrap.kt +++ /dev/null @@ -1,15 +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 - -import java.util.function.BiConsumer - -public interface DokkaBootstrap { - @Throws(Throwable::class) - public fun configure(serializedConfigurationJSON: String, logger: BiConsumer<String, String>) - - @Throws(Throwable::class) - public fun generate() -} diff --git a/core/src/main/kotlin/DokkaBootstrapImpl.kt b/core/src/main/kotlin/DokkaBootstrapImpl.kt deleted file mode 100644 index 65f0ef72..00000000 --- a/core/src/main/kotlin/DokkaBootstrapImpl.kt +++ /dev/null @@ -1,69 +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 - -import org.jetbrains.dokka.utilities.DokkaLogger -import java.util.concurrent.atomic.AtomicInteger - -import java.util.function.BiConsumer - -/** - * Accessed with reflection - */ -@Suppress("unused") -public class DokkaBootstrapImpl : DokkaBootstrap { - - public class DokkaProxyLogger( - public val consumer: BiConsumer<String, String> - ) : 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) { - consumer.accept("debug", message) - } - - override fun info(message: String) { - consumer.accept("info", message) - } - - override fun progress(message: String) { - consumer.accept("progress", message) - } - - override fun warn(message: String) { - consumer.accept("warn", message).also { warningsCounter.incrementAndGet() } - } - - override fun error(message: String) { - consumer.accept("error", message).also { errorsCounter.incrementAndGet() } - } - } - - private lateinit var generator: DokkaGenerator - - public fun configure(logger: DokkaLogger, configuration: DokkaConfigurationImpl) { - generator = DokkaGenerator(configuration, logger) - } - - override fun configure(serializedConfigurationJSON: String, logger: BiConsumer<String, String>) { - configure( - DokkaProxyLogger(logger), - DokkaConfigurationImpl(serializedConfigurationJSON) - ) - } - - override fun generate() { - generator.generate() - } -} diff --git a/core/src/main/kotlin/DokkaException.kt b/core/src/main/kotlin/DokkaException.kt deleted file mode 100644 index f16a2649..00000000 --- a/core/src/main/kotlin/DokkaException.kt +++ /dev/null @@ -1,7 +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 - -public open class DokkaException(message: String) : RuntimeException(message) diff --git a/core/src/main/kotlin/DokkaGenerator.kt b/core/src/main/kotlin/DokkaGenerator.kt deleted file mode 100644 index 9ae3adb4..00000000 --- a/core/src/main/kotlin/DokkaGenerator.kt +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -@file:Suppress("SameParameterValue") - -package org.jetbrains.dokka - -import kotlinx.coroutines.DelicateCoroutinesApi -import kotlinx.coroutines.Dispatchers -import org.jetbrains.dokka.generation.GracefulGenerationExit -import org.jetbrains.dokka.plugability.DokkaContext -import org.jetbrains.dokka.plugability.DokkaPlugin -import org.jetbrains.dokka.utilities.DokkaLogger - -/** - * DokkaGenerator is the main entry point for generating documentation - * - * [generate] method has been split into submethods for test reasons - */ -public class DokkaGenerator( - private val configuration: DokkaConfiguration, - private val logger: DokkaLogger -) { - - public fun generate() { - timed(logger) { - report("Initializing plugins") - val context = initializePlugins(configuration, logger) - - runCatching { - context.single(CoreExtensions.generation).run { - logger.progress("Dokka is performing: $generationName") - generate() - } - }.exceptionOrNull()?.let { e -> - finalizeCoroutines() - throw e - } - - finalizeCoroutines() - }.dump("\n\n === TIME MEASUREMENT ===\n") - } - - public fun initializePlugins( - configuration: DokkaConfiguration, - logger: DokkaLogger, - additionalPlugins: List<DokkaPlugin> = emptyList() - ): DokkaContext = DokkaContext.create(configuration, logger, additionalPlugins) - - @OptIn(DelicateCoroutinesApi::class) - private fun finalizeCoroutines() { - if (configuration.finalizeCoroutines) { - Dispatchers.shutdown() - } - } -} - -public class Timer internal constructor(startTime: Long, private val logger: DokkaLogger?) { - private val steps = mutableListOf("" to startTime) - - public fun report(name: String) { - logger?.progress(name) - steps += (name to System.currentTimeMillis()) - } - - public fun dump(prefix: String = "") { - logger?.info(prefix) - val namePad = steps.map { it.first.length }.maxOrNull() ?: 0 - val timePad = steps.windowed(2).map { (p1, p2) -> p2.second - p1.second }.maxOrNull()?.toString()?.length ?: 0 - steps.windowed(2).forEach { (p1, p2) -> - if (p1.first.isNotBlank()) { - logger?.info("${p1.first.padStart(namePad)}: ${(p2.second - p1.second).toString().padStart(timePad)}") - } - } - } -} - -private fun timed(logger: DokkaLogger? = null, block: Timer.() -> Unit): Timer = - Timer(System.currentTimeMillis(), logger).apply { - try { - block() - } catch (exit: GracefulGenerationExit) { - report("Exiting Generation: ${exit.reason}") - } finally { - report("") - } - } - diff --git a/core/src/main/kotlin/DokkaVersion.kt b/core/src/main/kotlin/DokkaVersion.kt deleted file mode 100644 index d846988b..00000000 --- a/core/src/main/kotlin/DokkaVersion.kt +++ /dev/null @@ -1,15 +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 - -import java.util.* - -public object DokkaVersion { - public val version: String by lazy { - javaClass.getResourceAsStream("/META-INF/dokka/dokka-version.properties").use { stream -> - Properties().apply { load(stream) }.getProperty("dokka-version") - } - } -} diff --git a/core/src/main/kotlin/InternalDokkaApi.kt b/core/src/main/kotlin/InternalDokkaApi.kt deleted file mode 100644 index 65c0427c..00000000 --- a/core/src/main/kotlin/InternalDokkaApi.kt +++ /dev/null @@ -1,28 +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 - - -/** - * Marks declarations that are **internal** to Dokka core artifact. - * It means that this API is marked as **public** either for historical or technical reasons. - * It is not intended to be used outside of the Dokka project, has no behaviour guarantees, - * and may lack clear semantics, documentation and backward compatibility. - * - * If you are using such API, it is strongly suggested to migrate from it in order - * to keep backwards compatibility with future Dokka versions. - * Typically, the easiest way to do so is to copy-paste the corresponding utility into - * your own project. - */ -@RequiresOptIn( - level = RequiresOptIn.Level.ERROR, - message = "This is an internal Dokka API not intended for public use" -) -@Target( - AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.FIELD, - AnnotationTarget.PROPERTY, AnnotationTarget.TYPEALIAS -) -@Retention(AnnotationRetention.BINARY) -public annotation class InternalDokkaApi() diff --git a/core/src/main/kotlin/configuration.kt b/core/src/main/kotlin/configuration.kt deleted file mode 100644 index 65035d04..00000000 --- a/core/src/main/kotlin/configuration.kt +++ /dev/null @@ -1,280 +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 - -import org.jetbrains.dokka.utilities.cast -import java.io.File -import java.io.Serializable -import java.net.URL - -public object DokkaDefaults { - public val moduleName: String = "root" - public val moduleVersion: String? = null - public val outputDir: File = File("./dokka") - public const val failOnWarning: Boolean = false - public const val suppressObviousFunctions: Boolean = true - public const val suppressInheritedMembers: Boolean = false - public const val offlineMode: Boolean = false - - public const val sourceSetDisplayName: String = "JVM" - public const val sourceSetName: String = "main" - public val analysisPlatform: Platform = Platform.DEFAULT - - public const val suppress: Boolean = false - public const val suppressGeneratedFiles: Boolean = true - - public const val skipEmptyPackages: Boolean = true - public const val skipDeprecated: Boolean = false - - public const val reportUndocumented: Boolean = false - - public const val noStdlibLink: Boolean = false - public const val noAndroidSdkLink: Boolean = false - public const val noJdkLink: Boolean = false - public const val jdkVersion: Int = 8 - - public const val includeNonPublic: Boolean = false - public val documentedVisibilities: Set<DokkaConfiguration.Visibility> = setOf(DokkaConfiguration.Visibility.PUBLIC) - - public val pluginsConfiguration: List<PluginConfigurationImpl> = mutableListOf() - - public const val delayTemplateSubstitution: Boolean = false - - public val cacheRoot: File? = null -} - -public enum class Platform( - public val key: String -) { - jvm("jvm"), - js("js"), - wasm("wasm"), - native("native"), - common("common"); - - public companion object { - public val DEFAULT: Platform = jvm - - public fun fromString(key: String): Platform { - return when (key.toLowerCase()) { - jvm.key -> jvm - js.key -> js - wasm.key -> wasm - native.key -> native - common.key -> common - "androidjvm", "android" -> jvm - "metadata" -> common - else -> throw IllegalArgumentException("Unrecognized platform: $key") - } - } - } -} - -public fun interface DokkaConfigurationBuilder<T : Any> { - public fun build(): T -} - -public fun <T : Any> Iterable<DokkaConfigurationBuilder<T>>.build(): List<T> = this.map { it.build() } - -public data class DokkaSourceSetID( - /** - * Unique identifier of the scope that this source set is placed in. - * Each scope provide only unique source set names. - * - * E.g. One DokkaTask inside the Gradle plugin represents one source set scope, since there cannot be multiple - * source sets with the same name. However, a Gradle project will not be a proper scope, since there can be - * multple DokkaTasks that contain source sets with the same name (but different configuration) - */ - val scopeId: String, - val sourceSetName: String -) : Serializable { - override fun toString(): String { - return "$scopeId/$sourceSetName" - } -} - -/** - * Global options can be configured and applied to all packages and modules at once, overwriting package configuration. - * - * These are handy if we have multiple source sets sharing the same global options as it reduces the size of the - * boilerplate. Otherwise, the user would be forced to repeat all these options for each source set. - * - * @see [apply] to learn how to apply global configuration - */ -public data class GlobalDokkaConfiguration( - val perPackageOptions: List<PackageOptionsImpl>?, - val externalDocumentationLinks: List<ExternalDocumentationLinkImpl>?, - val sourceLinks: List<SourceLinkDefinitionImpl>? -) - -public fun DokkaConfiguration.apply(globals: GlobalDokkaConfiguration): DokkaConfiguration = this.apply { - sourceSets.forEach { - it.perPackageOptions.cast<MutableList<DokkaConfiguration.PackageOptions>>() - .addAll(globals.perPackageOptions ?: emptyList()) - } - - sourceSets.forEach { - it.externalDocumentationLinks.cast<MutableSet<DokkaConfiguration.ExternalDocumentationLink>>() - .addAll(globals.externalDocumentationLinks ?: emptyList()) - } - - sourceSets.forEach { - it.sourceLinks.cast<MutableSet<SourceLinkDefinitionImpl>>().addAll(globals.sourceLinks ?: emptyList()) - } -} - -public interface DokkaConfiguration : Serializable { - public val moduleName: String - public val moduleVersion: String? - public val outputDir: File - public val cacheRoot: File? - public val offlineMode: Boolean - public val failOnWarning: Boolean - public val sourceSets: List<DokkaSourceSet> - public val modules: List<DokkaModuleDescription> - public val pluginsClasspath: List<File> - public val pluginsConfiguration: List<PluginConfiguration> - public val delayTemplateSubstitution: Boolean - public val suppressObviousFunctions: Boolean - public val includes: Set<File> - public val suppressInheritedMembers: Boolean - - /** - * Whether coroutines dispatchers should be shutdown after - * generating documentation via [DokkaGenerator.generate]. - * - * It effectively stops all background threads associated with - * coroutines in order to make classes unloadable by the JVM, - * and rejects all new tasks with [RejectedExecutionException] - * - * This is primarily useful for multi-module builds where coroutines - * can be shut down after each module's partial task to avoid - * possible memory leaks. - * - * However, this can lead to problems in specific lifecycles where - * coroutines are shared and will be reused after documentation generation, - * and closing it down will leave the build in an inoperable state. - * One such example is unit tests, for which finalization should be disabled. - */ - public val finalizeCoroutines: Boolean - - public enum class SerializationFormat : Serializable { - JSON, XML - } - - public interface PluginConfiguration : Serializable { - public val fqPluginName: String - public val serializationFormat: SerializationFormat - public val values: String - } - - public interface DokkaSourceSet : Serializable { - public val sourceSetID: DokkaSourceSetID - public val displayName: String - public val classpath: List<File> - public val sourceRoots: Set<File> - public val dependentSourceSets: Set<DokkaSourceSetID> - public val samples: Set<File> - public val includes: Set<File> - - @Deprecated(message = "Use [documentedVisibilities] property for a more flexible control over documented visibilities") - public val includeNonPublic: Boolean - public val reportUndocumented: Boolean - public val skipEmptyPackages: Boolean - public val skipDeprecated: Boolean - public val jdkVersion: Int - public val sourceLinks: Set<SourceLinkDefinition> - public val perPackageOptions: List<PackageOptions> - public val externalDocumentationLinks: Set<ExternalDocumentationLink> - public val languageVersion: String? - public val apiVersion: String? - public val noStdlibLink: Boolean - public val noJdkLink: Boolean - public val suppressedFiles: Set<File> - public val analysisPlatform: Platform - public val documentedVisibilities: Set<Visibility> - } - - public enum class Visibility { - /** - * `public` modifier for Java, default visibility for Kotlin - */ - PUBLIC, - - /** - * `private` modifier for both Kotlin and Java - */ - PRIVATE, - - /** - * `protected` modifier for both Kotlin and Java - */ - PROTECTED, - - /** - * Kotlin-specific `internal` modifier - */ - INTERNAL, - - /** - * Java-specific package-private visibility (no modifier) - */ - PACKAGE; - - public companion object { - public fun fromString(value: String): Visibility = valueOf(value.toUpperCase()) - } - } - - public interface SourceLinkDefinition : Serializable { - public val localDirectory: String - public val remoteUrl: URL - public val remoteLineSuffix: String? - } - - public interface DokkaModuleDescription : Serializable { - public val name: String - public val relativePathToOutputDirectory: File - public val sourceOutputDirectory: File - public val includes: Set<File> - } - - public interface PackageOptions : Serializable { - public val matchingRegex: String - - @Deprecated("Use [documentedVisibilities] property for a more flexible control over documented visibilities") - public val includeNonPublic: Boolean - public val reportUndocumented: Boolean? - public val skipDeprecated: Boolean - public val suppress: Boolean - public val documentedVisibilities: Set<Visibility> - } - - public interface ExternalDocumentationLink : Serializable { - public val url: URL - public val packageListUrl: URL - - public companion object - } -} - -@Suppress("FunctionName") -public fun ExternalDocumentationLink( - url: URL? = null, - packageListUrl: URL? = null -): ExternalDocumentationLinkImpl { - return if (packageListUrl != null && url != null) - ExternalDocumentationLinkImpl(url, packageListUrl) - else if (url != null) - ExternalDocumentationLinkImpl(url, URL(url, "package-list")) - else - throw IllegalArgumentException("url or url && packageListUrl must not be null for external documentation link") -} - -@Suppress("FunctionName") -public fun ExternalDocumentationLink( - url: String, packageListUrl: String? = null -): ExternalDocumentationLinkImpl = - ExternalDocumentationLink(url.let(::URL), packageListUrl?.let(::URL)) diff --git a/core/src/main/kotlin/defaultConfiguration.kt b/core/src/main/kotlin/defaultConfiguration.kt deleted file mode 100644 index f858d8c0..00000000 --- a/core/src/main/kotlin/defaultConfiguration.kt +++ /dev/null @@ -1,100 +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 - -import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet -import java.io.File -import java.net.URL - -public data class DokkaConfigurationImpl( - override val moduleName: String = DokkaDefaults.moduleName, - override val moduleVersion: String? = DokkaDefaults.moduleVersion, - override val outputDir: File = DokkaDefaults.outputDir, - override val cacheRoot: File? = DokkaDefaults.cacheRoot, - override val offlineMode: Boolean = DokkaDefaults.offlineMode, - override val sourceSets: List<DokkaSourceSetImpl> = emptyList(), - override val pluginsClasspath: List<File> = emptyList(), - override val pluginsConfiguration: List<PluginConfigurationImpl> = DokkaDefaults.pluginsConfiguration, - override val modules: List<DokkaModuleDescriptionImpl> = emptyList(), - override val failOnWarning: Boolean = DokkaDefaults.failOnWarning, - override val delayTemplateSubstitution: Boolean = false, - override val suppressObviousFunctions: Boolean = DokkaDefaults.suppressObviousFunctions, - override val includes: Set<File> = emptySet(), - override val suppressInheritedMembers: Boolean = DokkaDefaults.suppressInheritedMembers, - override val finalizeCoroutines: Boolean = true, -) : DokkaConfiguration - -public data class PluginConfigurationImpl( - override val fqPluginName: String, - override val serializationFormat: DokkaConfiguration.SerializationFormat, - override val values: String -) : DokkaConfiguration.PluginConfiguration - - -public data class DokkaSourceSetImpl( - override val displayName: String = DokkaDefaults.sourceSetDisplayName, - override val sourceSetID: DokkaSourceSetID, - override val classpath: List<File> = emptyList(), - override val sourceRoots: Set<File> = emptySet(), - 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, - override val skipDeprecated: Boolean = DokkaDefaults.skipDeprecated, - override val jdkVersion: Int = DokkaDefaults.jdkVersion, - override val sourceLinks: Set<SourceLinkDefinitionImpl> = mutableSetOf(), - override val perPackageOptions: List<PackageOptionsImpl> = mutableListOf(), - override val externalDocumentationLinks: Set<ExternalDocumentationLinkImpl> = mutableSetOf(), - override val languageVersion: String? = null, - override val apiVersion: String? = null, - override val noStdlibLink: Boolean = DokkaDefaults.noStdlibLink, - override val noJdkLink: Boolean = DokkaDefaults.noJdkLink, - override val suppressedFiles: Set<File> = emptySet(), - override val analysisPlatform: Platform = DokkaDefaults.analysisPlatform, - override val documentedVisibilities: Set<DokkaConfiguration.Visibility> = DokkaDefaults.documentedVisibilities, -) : DokkaSourceSet - -public data class DokkaModuleDescriptionImpl( - override val name: String, - override val relativePathToOutputDirectory: File, - override val includes: Set<File>, - override val sourceOutputDirectory: File -) : DokkaConfiguration.DokkaModuleDescription - -public data class SourceLinkDefinitionImpl( - override val localDirectory: String, - override val remoteUrl: URL, - override val remoteLineSuffix: String?, -) : DokkaConfiguration.SourceLinkDefinition { - - public companion object { - public fun parseSourceLinkDefinition(srcLink: String): SourceLinkDefinitionImpl { - val (path, urlAndLine) = srcLink.split('=') - return SourceLinkDefinitionImpl( - localDirectory = File(path).canonicalPath, - remoteUrl = URL(urlAndLine.substringBefore("#")), - remoteLineSuffix = urlAndLine.substringAfter("#", "").let { if (it.isEmpty()) null else "#$it" }) - } - } -} - -public 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, - override val suppress: Boolean, - override val documentedVisibilities: Set<DokkaConfiguration.Visibility>, // TODO add default to DokkaDefaults.documentedVisibilities -) : DokkaConfiguration.PackageOptions - - -public data class ExternalDocumentationLinkImpl( - override val url: URL, - override val packageListUrl: URL, -) : DokkaConfiguration.ExternalDocumentationLink diff --git a/core/src/main/kotlin/defaultExternalLinks.kt b/core/src/main/kotlin/defaultExternalLinks.kt deleted file mode 100644 index 26e3e0ae..00000000 --- a/core/src/main/kotlin/defaultExternalLinks.kt +++ /dev/null @@ -1,33 +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 - -import org.jetbrains.dokka.DokkaConfiguration.ExternalDocumentationLink -import java.net.URL - - -public fun ExternalDocumentationLink.Companion.jdk(jdkVersion: Int): ExternalDocumentationLinkImpl = - ExternalDocumentationLink( - url = - if (jdkVersion < 11) "https://docs.oracle.com/javase/${jdkVersion}/docs/api/" - else "https://docs.oracle.com/en/java/javase/${jdkVersion}/docs/api/", - packageListUrl = - if (jdkVersion < 11) "https://docs.oracle.com/javase/${jdkVersion}/docs/api/package-list" - else "https://docs.oracle.com/en/java/javase/${jdkVersion}/docs/api/element-list" - ) - - -public fun ExternalDocumentationLink.Companion.kotlinStdlib(): ExternalDocumentationLinkImpl = - ExternalDocumentationLink("https://kotlinlang.org/api/latest/jvm/stdlib/") - - -public fun ExternalDocumentationLink.Companion.androidSdk(): ExternalDocumentationLinkImpl = - ExternalDocumentationLink("https://developer.android.com/reference/kotlin/") - - -public fun ExternalDocumentationLink.Companion.androidX(): ExternalDocumentationLinkImpl = ExternalDocumentationLink( - url = URL("https://developer.android.com/reference/kotlin/"), - packageListUrl = URL("https://developer.android.com/reference/kotlin/androidx/package-list") -) diff --git a/core/src/main/kotlin/generation/Generation.kt b/core/src/main/kotlin/generation/Generation.kt deleted file mode 100644 index 9f14912f..00000000 --- a/core/src/main/kotlin/generation/Generation.kt +++ /dev/null @@ -1,19 +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.generation - -import org.jetbrains.dokka.Timer - -public interface Generation { - public fun Timer.generate() - public val generationName: String -} - -// This needs to be public for now but in the future it should be replaced with system of checks provided by EP -public fun exitGenerationGracefully(reason: String): Nothing { - throw GracefulGenerationExit(reason) -} - -public class GracefulGenerationExit(public val reason: String) : Throwable() diff --git a/core/src/main/kotlin/links/DRI.kt b/core/src/main/kotlin/links/DRI.kt deleted file mode 100644 index 180d9eb8..00000000 --- a/core/src/main/kotlin/links/DRI.kt +++ /dev/null @@ -1,146 +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.links - -import com.fasterxml.jackson.annotation.JsonTypeInfo -import com.fasterxml.jackson.annotation.JsonTypeInfo.Id.CLASS -import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.module.kotlin.readValue - -/** - * [DRI] stands for DokkaResourceIdentifier - */ -public data class DRI( - val packageName: String? = null, - val classNames: String? = null, - val callable: Callable? = null, - val target: DriTarget = PointingToDeclaration, - val extra: String? = null -) { - override fun toString(): String = - "${packageName.orEmpty()}/${classNames.orEmpty()}/${callable?.name.orEmpty()}/${callable?.signature() - .orEmpty()}/$target/${extra.orEmpty()}" - - public companion object { - public val topLevel: DRI = DRI() - } -} - -public object EnumEntryDRIExtra: DRIExtraProperty<EnumEntryDRIExtra>() - -public abstract class DRIExtraProperty<T> { - public val key: String = this::class.qualifiedName - ?: (this.javaClass.let { it.`package`.name + "." + it.simpleName.ifEmpty { "anonymous" } }) -} - - -public class DRIExtraContainer(public val data: String? = null) { - public val map: MutableMap<String, Any> = if (data != null) OBJECT_MAPPER.readValue(data) else mutableMapOf() - public inline operator fun <reified T> get(prop: DRIExtraProperty<T>): T? = - map[prop.key]?.let { prop as? T } - - public inline operator fun <reified T> set(prop: DRIExtraProperty<T>, value: T) { - map[prop.key] = value as Any - } - - public fun encode(): String = OBJECT_MAPPER.writeValueAsString(map) - - private companion object { - private val OBJECT_MAPPER = ObjectMapper() - } -} - -public val DriOfUnit: DRI = DRI("kotlin", "Unit") -public val DriOfAny: DRI = DRI("kotlin", "Any") - -public fun DRI.withClass(name: String): DRI = copy(classNames = if (classNames.isNullOrBlank()) name else "$classNames.$name") - -public fun DRI.withTargetToDeclaration(): DRI = copy(target = PointingToDeclaration) - -public fun DRI.withEnumEntryExtra(): DRI = copy( - extra = DRIExtraContainer(this.extra).also { it[EnumEntryDRIExtra] = EnumEntryDRIExtra }.encode() -) - -public val DRI.parent: DRI - get() = when { - extra != null -> when { - DRIExtraContainer(extra)[EnumEntryDRIExtra] != null -> copy( - classNames = classNames?.substringBeforeLast(".", "")?.takeIf { it.isNotBlank() }, - extra = null - ) - else -> copy(extra = null) - } - target != PointingToDeclaration -> copy(target = PointingToDeclaration) - callable != null -> copy(callable = null) - classNames != null -> copy(classNames = classNames.substringBeforeLast(".", "").takeIf { it.isNotBlank() }) - else -> DRI.topLevel - } - -public val DRI.sureClassNames: String - get() = classNames ?: throw IllegalStateException("Malformed DRI. It requires classNames in this context.") - -public data class Callable( - val name: String, - val receiver: TypeReference? = null, - val params: List<TypeReference> -) { - public fun signature(): String = "${receiver?.toString().orEmpty()}#${params.joinToString("#")}" - - public companion object -} - -@JsonTypeInfo(use = CLASS) -public sealed class TypeReference { - public companion object -} - -public data class JavaClassReference(val name: String) : TypeReference() { - override fun toString(): String = name -} - -public data class TypeParam(val bounds: List<TypeReference>) : TypeReference() - -public data class TypeConstructor( - val fullyQualifiedName: String, - val params: List<TypeReference> -) : TypeReference() { - override fun toString(): String = fullyQualifiedName + - (if (params.isNotEmpty()) "[${params.joinToString(",")}]" else "") -} - -public data class RecursiveType(val rank: Int): TypeReference() { - override fun toString(): String = "^".repeat(rank + 1) -} - -public data class Nullable(val wrapped: TypeReference) : TypeReference() { - override fun toString(): String = "$wrapped?" -} - -public object StarProjection : TypeReference() { - override fun toString(): String = "*" -} - -@JsonTypeInfo(use = CLASS) -public sealed class DriTarget { - override fun toString(): String = this.javaClass.simpleName - - public companion object -} - -public data class PointingToGenericParameters(val parameterIndex: Int) : DriTarget() { - override fun toString(): String = "PointingToGenericParameters($parameterIndex)" -} - -public object PointingToDeclaration : DriTarget() - -public data class PointingToCallableParameters(val parameterIndex: Int) : DriTarget() { - override fun toString(): String = "PointingToCallableParameters($parameterIndex)" -} - -public fun DriTarget.nextTarget(): DriTarget = when (this) { - is PointingToGenericParameters -> PointingToGenericParameters(this.parameterIndex + 1) - is PointingToCallableParameters -> PointingToCallableParameters(this.parameterIndex + 1) - else -> this -} diff --git a/core/src/main/kotlin/model/CompositeSourceSetID.kt b/core/src/main/kotlin/model/CompositeSourceSetID.kt deleted file mode 100644 index af7d1a5d..00000000 --- a/core/src/main/kotlin/model/CompositeSourceSetID.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.model - -import org.jetbrains.dokka.DokkaConfiguration -import org.jetbrains.dokka.DokkaSourceSetID - -/** - * A unique composite key of multiple [DokkaSourceSetID] that identifies [DisplaySourceSet]. - * Consists of multiple (non-zero) [DokkaSourceSetID] that the corresponding [DisplaySourceSet] was built from. - * - * Should not be constructed or copied outside of [DisplaySourceSet] instantiation. - */ -public data class CompositeSourceSetID( - private val children: Set<DokkaSourceSetID> -) { - public constructor(sourceSetIDs: Iterable<DokkaSourceSetID>) : this(sourceSetIDs.toSet()) - public constructor(sourceSetId: DokkaSourceSetID) : this(setOf(sourceSetId)) - - init { - require(children.isNotEmpty()) { "Expected at least one source set id" } - } - - public val merged: DokkaSourceSetID = children.sortedBy { it.scopeId + it.sourceSetName }.let { sortedChildren -> - DokkaSourceSetID( - scopeId = sortedChildren.joinToString(separator = "+") { it.scopeId }, - sourceSetName = sortedChildren.joinToString(separator = "+") { it.sourceSetName } - ) - } - - public val all: Set<DokkaSourceSetID> = setOf(merged, *children.toTypedArray()) - - public operator fun contains(sourceSetId: DokkaSourceSetID): Boolean { - return sourceSetId in all - } - - public operator fun contains(sourceSet: DokkaConfiguration.DokkaSourceSet): Boolean { - return sourceSet.sourceSetID in this - } - - public operator fun plus(other: DokkaSourceSetID): CompositeSourceSetID { - return copy(children = children + other) - } -} diff --git a/core/src/main/kotlin/model/DisplaySourceSet.kt b/core/src/main/kotlin/model/DisplaySourceSet.kt deleted file mode 100644 index 9d637048..00000000 --- a/core/src/main/kotlin/model/DisplaySourceSet.kt +++ /dev/null @@ -1,61 +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.model - -import org.jetbrains.dokka.* -import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet - -/** - * Represents a final user-visible source set in the documentable model that is - * used to specify under which source sets/targets current signatures are available, - * can be used to filter in and out all available signatures under the specified source set, - * and, depending on the format, are rendered as "platform" selectors. - * - * E.g. HTML format renders display source sets as "bubbles" that later are used for filtering - * and informational purposes. - * - * [DisplaySourceSet]s typically have a one-to-one correspondence to the build system source sets, - * are created by the base plugin from [DokkaSourceSet] and never tweaked manually. - * [DisplaySourceSet] is uniquely identified by the corresponding [CompositeSourceSetID]. - * - * @property sourceSetIDs unique stable id of the display source set. - * It is composite by definition, as it uniquely defines the source set and all nested source sets. - * Apart from names, it also contains a substitute to a full source set path in order to differentiate - * source sets with the same name in a stable manner. - * @property name corresponds to the name of the original [DokkaSourceSet] - * @property platform the platform of the source set. If the source set is a mix of multiple source sets - * that correspond to multiple KMP platforms, then it is [Platform.common] - */ -public data class DisplaySourceSet( - val sourceSetIDs: CompositeSourceSetID, - val name: String, - val platform: Platform -) { - public constructor(sourceSet: DokkaSourceSet) : this( - sourceSetIDs = CompositeSourceSetID(sourceSet.sourceSetID), - name = sourceSet.displayName, - platform = sourceSet.analysisPlatform - ) -} - -/** - * Transforms the current [DokkaSourceSet] into [DisplaySourceSet], - * matching the corresponding subset of its properties to [DisplaySourceSet] properties. - */ -public fun DokkaSourceSet.toDisplaySourceSet(): DisplaySourceSet = DisplaySourceSet(this) - -/** - * Transforms all the given [DokkaSourceSet]s into [DisplaySourceSet]s. - */ -public fun Iterable<DokkaSourceSet>.toDisplaySourceSets(): Set<DisplaySourceSet> = - map { it.toDisplaySourceSet() }.toSet() - -@InternalDokkaApi -@Deprecated("Use computeSourceSetIds() and cache its results instead", replaceWith = ReplaceWith("computeSourceSetIds()")) -public val Iterable<DisplaySourceSet>.sourceSetIDs: List<DokkaSourceSetID> get() = this.flatMap { it.sourceSetIDs.all } - -@InternalDokkaApi -public fun Iterable<DisplaySourceSet>.computeSourceSetIds(): Set<DokkaSourceSetID> = - fold(hashSetOf()) { acc, set -> acc.addAll(set.sourceSetIDs.all); acc } diff --git a/core/src/main/kotlin/model/Documentable.kt b/core/src/main/kotlin/model/Documentable.kt deleted file mode 100644 index c6109f47..00000000 --- a/core/src/main/kotlin/model/Documentable.kt +++ /dev/null @@ -1,540 +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.model - -import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet -import org.jetbrains.dokka.links.DRI -import org.jetbrains.dokka.model.doc.DocumentationNode -import org.jetbrains.dokka.model.properties.PropertyContainer -import org.jetbrains.dokka.model.properties.WithExtraProperties - -public interface AnnotationTarget - -public abstract class Documentable : WithChildren<Documentable>, - AnnotationTarget { - public abstract val name: String? - public abstract val dri: DRI - public abstract val documentation: SourceSetDependent<DocumentationNode> - public abstract val sourceSets: Set<DokkaSourceSet> - public abstract val expectPresentInSet: DokkaSourceSet? - abstract override val children: List<Documentable> - - override fun toString(): String = - "${javaClass.simpleName}($dri)" - - override fun equals(other: Any?): Boolean = - other is Documentable && this.dri == other.dri // TODO: https://github.com/Kotlin/dokka/pull/667#discussion_r382555806 - - override fun hashCode(): Int = dri.hashCode() -} - -public typealias SourceSetDependent<T> = Map<DokkaSourceSet, T> - -public interface WithSources { - public val sources: SourceSetDependent<DocumentableSource> -} - -public interface WithScope { - public val functions: List<DFunction> - public val properties: List<DProperty> - public val classlikes: List<DClasslike> -} - -public interface WithVisibility { - public val visibility: SourceSetDependent<Visibility> -} - -public interface WithType { - public val type: Bound -} - -public interface WithAbstraction { - public val modifier: SourceSetDependent<Modifier> -} - -public sealed class Modifier( - public val name: String -) - -public sealed class KotlinModifier(name: String) : Modifier(name) { - public object Abstract : KotlinModifier("abstract") - public object Open : KotlinModifier("open") - public object Final : KotlinModifier("final") - public object Sealed : KotlinModifier("sealed") - public object Empty : KotlinModifier("") -} - -public sealed class JavaModifier(name: String) : Modifier(name) { - public object Abstract : JavaModifier("abstract") - public object Final : JavaModifier("final") - public object Empty : JavaModifier("") -} - -public interface WithCompanion { - public val companion: DObject? -} - -public interface WithConstructors { - public val constructors: List<DFunction> -} - -public interface WithGenerics { - public val generics: List<DTypeParameter> -} - -public interface WithSupertypes { - public val supertypes: SourceSetDependent<List<TypeConstructorWithKind>> -} - -public interface WithIsExpectActual { - public val isExpectActual: Boolean -} - -public interface Callable : WithVisibility, WithType, WithAbstraction, WithSources, WithIsExpectActual { - public val receiver: DParameter? -} - -public sealed class DClasslike : Documentable(), WithScope, WithVisibility, WithSources, WithIsExpectActual - -public data class DModule( - override val name: String, - val packages: List<DPackage>, - override val documentation: SourceSetDependent<DocumentationNode>, - override val expectPresentInSet: DokkaSourceSet? = null, - override val sourceSets: Set<DokkaSourceSet>, - override val extra: PropertyContainer<DModule> = PropertyContainer.empty() -) : Documentable(), WithExtraProperties<DModule> { - override val dri: DRI = DRI.topLevel - override val children: List<Documentable> - get() = packages - - override fun withNewExtras(newExtras: PropertyContainer<DModule>): DModule = copy(extra = newExtras) -} - -public data class DPackage( - override val dri: DRI, - override val functions: List<DFunction>, - override val properties: List<DProperty>, - override val classlikes: List<DClasslike>, - val typealiases: List<DTypeAlias>, - override val documentation: SourceSetDependent<DocumentationNode>, - override val expectPresentInSet: DokkaSourceSet? = null, - override val sourceSets: Set<DokkaSourceSet>, - override val extra: PropertyContainer<DPackage> = PropertyContainer.empty() -) : Documentable(), WithScope, WithExtraProperties<DPackage> { - - val packageName: String = dri.packageName.orEmpty() - - /** - * !!! WARNING !!! - * This name is not guaranteed to be a be a canonical/real package name. - * e.g. this will return a human readable version for root packages. - * Use [packageName] or `dri.packageName` instead to obtain the real packageName - */ - override val name: String = packageName.ifBlank { "[root]" } - - override val children: List<Documentable> = properties + functions + classlikes + typealiases - - override fun withNewExtras(newExtras: PropertyContainer<DPackage>): DPackage = copy(extra = newExtras) -} - -public data class DClass( - override val dri: DRI, - override val name: String, - override val constructors: List<DFunction>, - override val functions: List<DFunction>, - override val properties: List<DProperty>, - override val classlikes: List<DClasslike>, - override val sources: SourceSetDependent<DocumentableSource>, - override val visibility: SourceSetDependent<Visibility>, - override val companion: DObject?, - override val generics: List<DTypeParameter>, - override val supertypes: SourceSetDependent<List<TypeConstructorWithKind>>, - override val documentation: SourceSetDependent<DocumentationNode>, - override val expectPresentInSet: DokkaSourceSet?, - override val modifier: SourceSetDependent<Modifier>, - override val sourceSets: Set<DokkaSourceSet>, - override val isExpectActual: Boolean, - override val extra: PropertyContainer<DClass> = PropertyContainer.empty() -) : DClasslike(), WithAbstraction, WithCompanion, WithConstructors, WithGenerics, WithSupertypes, - WithExtraProperties<DClass> { - - override val children: List<Documentable> - get() = (functions + properties + classlikes + constructors) - - override fun withNewExtras(newExtras: PropertyContainer<DClass>): DClass = copy(extra = newExtras) -} - -public data class DEnum( - override val dri: DRI, - override val name: String, - val entries: List<DEnumEntry>, - override val documentation: SourceSetDependent<DocumentationNode>, - override val expectPresentInSet: DokkaSourceSet?, - override val sources: SourceSetDependent<DocumentableSource>, - override val functions: List<DFunction>, - override val properties: List<DProperty>, - override val classlikes: List<DClasslike>, - override val visibility: SourceSetDependent<Visibility>, - override val companion: DObject?, - override val constructors: List<DFunction>, - override val supertypes: SourceSetDependent<List<TypeConstructorWithKind>>, - override val sourceSets: Set<DokkaSourceSet>, - override val isExpectActual: Boolean, - override val extra: PropertyContainer<DEnum> = PropertyContainer.empty() -) : DClasslike(), WithCompanion, WithConstructors, WithSupertypes, WithExtraProperties<DEnum> { - override val children: List<Documentable> - get() = (entries + functions + properties + classlikes + constructors) - - override fun withNewExtras(newExtras: PropertyContainer<DEnum>): DEnum = copy(extra = newExtras) -} - -public data class DEnumEntry( - override val dri: DRI, - override val name: String, - override val documentation: SourceSetDependent<DocumentationNode>, - override val expectPresentInSet: DokkaSourceSet?, - override val functions: List<DFunction>, - override val properties: List<DProperty>, - override val classlikes: List<DClasslike>, - override val sourceSets: Set<DokkaSourceSet>, - override val extra: PropertyContainer<DEnumEntry> = PropertyContainer.empty() -) : Documentable(), WithScope, WithExtraProperties<DEnumEntry> { - override val children: List<Documentable> - get() = (functions + properties + classlikes) - - override fun withNewExtras(newExtras: PropertyContainer<DEnumEntry>): DEnumEntry = copy(extra = newExtras) -} - -public data class DFunction( - override val dri: DRI, - override val name: String, - val isConstructor: Boolean, - val parameters: List<DParameter>, - override val documentation: SourceSetDependent<DocumentationNode>, - override val expectPresentInSet: DokkaSourceSet?, - override val sources: SourceSetDependent<DocumentableSource>, - override val visibility: SourceSetDependent<Visibility>, - override val type: Bound, - override val generics: List<DTypeParameter>, - override val receiver: DParameter?, - override val modifier: SourceSetDependent<Modifier>, - override val sourceSets: Set<DokkaSourceSet>, - override val isExpectActual: Boolean, - override val extra: PropertyContainer<DFunction> = PropertyContainer.empty() -) : Documentable(), Callable, WithGenerics, WithExtraProperties<DFunction> { - override val children: List<Documentable> - get() = parameters - - override fun withNewExtras(newExtras: PropertyContainer<DFunction>): DFunction = copy(extra = newExtras) -} - -public data class DInterface( - override val dri: DRI, - override val name: String, - override val documentation: SourceSetDependent<DocumentationNode>, - override val expectPresentInSet: DokkaSourceSet?, - override val sources: SourceSetDependent<DocumentableSource>, - override val functions: List<DFunction>, - override val properties: List<DProperty>, - override val classlikes: List<DClasslike>, - override val visibility: SourceSetDependent<Visibility>, - override val companion: DObject?, - override val generics: List<DTypeParameter>, - override val supertypes: SourceSetDependent<List<TypeConstructorWithKind>>, - override val sourceSets: Set<DokkaSourceSet>, - override val isExpectActual: Boolean, - override val extra: PropertyContainer<DInterface> = PropertyContainer.empty() -) : DClasslike(), WithCompanion, WithGenerics, WithSupertypes, WithExtraProperties<DInterface> { - override val children: List<Documentable> - get() = (functions + properties + classlikes) - - override fun withNewExtras(newExtras: PropertyContainer<DInterface>): DInterface = copy(extra = newExtras) -} - -public data class DObject( - override val name: String?, - override val dri: DRI, - override val documentation: SourceSetDependent<DocumentationNode>, - override val expectPresentInSet: DokkaSourceSet?, - override val sources: SourceSetDependent<DocumentableSource>, - override val functions: List<DFunction>, - override val properties: List<DProperty>, - override val classlikes: List<DClasslike>, - override val visibility: SourceSetDependent<Visibility>, - override val supertypes: SourceSetDependent<List<TypeConstructorWithKind>>, - override val sourceSets: Set<DokkaSourceSet>, - override val isExpectActual: Boolean, - override val extra: PropertyContainer<DObject> = PropertyContainer.empty() -) : DClasslike(), WithSupertypes, WithExtraProperties<DObject> { - override val children: List<Documentable> - get() = (functions + properties + classlikes) - - override fun withNewExtras(newExtras: PropertyContainer<DObject>): DObject = copy(extra = newExtras) -} - -public data class DAnnotation( - override val name: String, - override val dri: DRI, - override val documentation: SourceSetDependent<DocumentationNode>, - override val expectPresentInSet: DokkaSourceSet?, - override val sources: SourceSetDependent<DocumentableSource>, - override val functions: List<DFunction>, - override val properties: List<DProperty>, - override val classlikes: List<DClasslike>, - override val visibility: SourceSetDependent<Visibility>, - override val companion: DObject?, - override val constructors: List<DFunction>, - override val generics: List<DTypeParameter>, - override val sourceSets: Set<DokkaSourceSet>, - override val isExpectActual: Boolean, - override val extra: PropertyContainer<DAnnotation> = PropertyContainer.empty() -) : DClasslike(), WithCompanion, WithConstructors, WithExtraProperties<DAnnotation>, WithGenerics { - override val children: List<Documentable> - get() = (functions + properties + classlikes + constructors) - - override fun withNewExtras(newExtras: PropertyContainer<DAnnotation>): DAnnotation = copy(extra = newExtras) -} - -public data class DProperty( - override val dri: DRI, - override val name: String, - override val documentation: SourceSetDependent<DocumentationNode>, - override val expectPresentInSet: DokkaSourceSet?, - override val sources: SourceSetDependent<DocumentableSource>, - override val visibility: SourceSetDependent<Visibility>, - override val type: Bound, - override val receiver: DParameter?, - val setter: DFunction?, - val getter: DFunction?, - override val modifier: SourceSetDependent<Modifier>, - override val sourceSets: Set<DokkaSourceSet>, - override val generics: List<DTypeParameter>, - override val isExpectActual: Boolean, - override val extra: PropertyContainer<DProperty> = PropertyContainer.empty() -) : Documentable(), Callable, WithExtraProperties<DProperty>, WithGenerics { - override val children: List<Nothing> - get() = emptyList() - - override fun withNewExtras(newExtras: PropertyContainer<DProperty>): DProperty = copy(extra = newExtras) -} - -// TODO: treat named Parameters and receivers differently -public data class DParameter( - override val dri: DRI, - override val name: String?, - override val documentation: SourceSetDependent<DocumentationNode>, - override val expectPresentInSet: DokkaSourceSet?, - override val type: Bound, - override val sourceSets: Set<DokkaSourceSet>, - override val extra: PropertyContainer<DParameter> = PropertyContainer.empty() -) : Documentable(), WithExtraProperties<DParameter>, WithType { - override val children: List<Nothing> - get() = emptyList() - - override fun withNewExtras(newExtras: PropertyContainer<DParameter>): DParameter = copy(extra = newExtras) -} - -public data class DTypeParameter( - val variantTypeParameter: Variance<TypeParameter>, - override val documentation: SourceSetDependent<DocumentationNode>, - override val expectPresentInSet: DokkaSourceSet?, - val bounds: List<Bound>, - override val sourceSets: Set<DokkaSourceSet>, - override val extra: PropertyContainer<DTypeParameter> = PropertyContainer.empty() -) : Documentable(), WithExtraProperties<DTypeParameter> { - - public constructor( - dri: DRI, - name: String, - presentableName: String?, - documentation: SourceSetDependent<DocumentationNode>, - expectPresentInSet: DokkaSourceSet?, - bounds: List<Bound>, - sourceSets: Set<DokkaSourceSet>, - extra: PropertyContainer<DTypeParameter> = PropertyContainer.empty() - ) : this( - Invariance(TypeParameter(dri, name, presentableName)), - documentation, - expectPresentInSet, - bounds, - sourceSets, - extra - ) - - override val dri: DRI by variantTypeParameter.inner::dri - override val name: String by variantTypeParameter.inner::name - - override val children: List<Nothing> - get() = emptyList() - - override fun withNewExtras(newExtras: PropertyContainer<DTypeParameter>): DTypeParameter = copy(extra = newExtras) -} - -public data class DTypeAlias( - override val dri: DRI, - override val name: String, - override val type: Bound, - val underlyingType: SourceSetDependent<Bound>, - override val visibility: SourceSetDependent<Visibility>, - override val documentation: SourceSetDependent<DocumentationNode>, - override val expectPresentInSet: DokkaSourceSet?, - override val sourceSets: Set<DokkaSourceSet>, - override val generics: List<DTypeParameter>, - override val sources: SourceSetDependent<DocumentableSource>, - override val extra: PropertyContainer<DTypeAlias> = PropertyContainer.empty() -) : Documentable(), WithType, WithVisibility, WithExtraProperties<DTypeAlias>, WithGenerics, WithSources { - override val children: List<Nothing> - get() = emptyList() - - override fun withNewExtras(newExtras: PropertyContainer<DTypeAlias>): DTypeAlias = copy(extra = newExtras) -} - -public sealed class Projection -public sealed class Bound : Projection() -public data class TypeParameter( - val dri: DRI, - val name: String, - val presentableName: String? = null, - override val extra: PropertyContainer<TypeParameter> = PropertyContainer.empty() -) : Bound(), AnnotationTarget, WithExtraProperties<TypeParameter> { - override fun withNewExtras(newExtras: PropertyContainer<TypeParameter>): TypeParameter = - copy(extra = extra) -} - -public sealed class TypeConstructor : Bound(), AnnotationTarget { - public abstract val dri: DRI - public abstract val projections: List<Projection> - public abstract val presentableName: String? -} - -public data class GenericTypeConstructor( - override val dri: DRI, - override val projections: List<Projection>, - override val presentableName: String? = null, - override val extra: PropertyContainer<GenericTypeConstructor> = PropertyContainer.empty() -) : TypeConstructor(), WithExtraProperties<GenericTypeConstructor> { - override fun withNewExtras(newExtras: PropertyContainer<GenericTypeConstructor>): GenericTypeConstructor = - copy(extra = newExtras) -} - -public data class FunctionalTypeConstructor( - override val dri: DRI, - override val projections: List<Projection>, - val isExtensionFunction: Boolean = false, - val isSuspendable: Boolean = false, - override val presentableName: String? = null, - override val extra: PropertyContainer<FunctionalTypeConstructor> = PropertyContainer.empty(), -) : TypeConstructor(), WithExtraProperties<FunctionalTypeConstructor> { - override fun withNewExtras(newExtras: PropertyContainer<FunctionalTypeConstructor>): FunctionalTypeConstructor = - copy(extra = newExtras) -} - -// kotlin.annotation.AnnotationTarget.TYPEALIAS -public data class TypeAliased( - val typeAlias: Bound, - val inner: Bound, - override val extra: PropertyContainer<TypeAliased> = PropertyContainer.empty() -) : Bound(), AnnotationTarget, WithExtraProperties<TypeAliased> { - override fun withNewExtras(newExtras: PropertyContainer<TypeAliased>): TypeAliased = - copy(extra = newExtras) -} - -public data class PrimitiveJavaType( - val name: String, - override val extra: PropertyContainer<PrimitiveJavaType> = PropertyContainer.empty() -) : Bound(), AnnotationTarget, WithExtraProperties<PrimitiveJavaType> { - override fun withNewExtras(newExtras: PropertyContainer<PrimitiveJavaType>): PrimitiveJavaType = - copy(extra = newExtras) -} - -public data class JavaObject(override val extra: PropertyContainer<JavaObject> = PropertyContainer.empty()) : - Bound(), AnnotationTarget, WithExtraProperties<JavaObject> { - override fun withNewExtras(newExtras: PropertyContainer<JavaObject>): JavaObject = - copy(extra = newExtras) -} - -public data class UnresolvedBound( - val name: String, - override val extra: PropertyContainer<UnresolvedBound> = PropertyContainer.empty() -) : Bound(), AnnotationTarget, WithExtraProperties<UnresolvedBound> { - override fun withNewExtras(newExtras: PropertyContainer<UnresolvedBound>): UnresolvedBound = - copy(extra = newExtras) -} - -// The following Projections are not AnnotationTargets; they cannot be annotated. -public data class Nullable(val inner: Bound) : Bound() - -/** - * It introduces [definitely non-nullable types](https://github.com/Kotlin/KEEP/blob/c72601cf35c1e95a541bb4b230edb474a6d1d1a8/proposals/definitely-non-nullable-types.md) - */ -public data class DefinitelyNonNullable(val inner: Bound) : Bound() - -public sealed class Variance<out T : Bound> : Projection() { - public abstract val inner: T -} - -public data class Covariance<out T : Bound>(override val inner: T) : Variance<T>() { - override fun toString(): String = "out" -} - -public data class Contravariance<out T : Bound>(override val inner: T) : Variance<T>() { - override fun toString(): String = "in" -} - -public data class Invariance<out T : Bound>(override val inner: T) : Variance<T>() { - override fun toString(): String = "" -} - -public object Star : Projection() - -public object Void : Bound() -public object Dynamic : Bound() - -public fun Variance<TypeParameter>.withDri(dri: DRI): Variance<TypeParameter> = when (this) { - is Contravariance -> Contravariance(TypeParameter(dri, inner.name, inner.presentableName)) - is Covariance -> Covariance(TypeParameter(dri, inner.name, inner.presentableName)) - is Invariance -> Invariance(TypeParameter(dri, inner.name, inner.presentableName)) -} - -public fun Documentable.dfs(predicate: (Documentable) -> Boolean): Documentable? = - if (predicate(this)) { - this - } else { - this.children.asSequence().mapNotNull { it.dfs(predicate) }.firstOrNull() - } - -public sealed class Visibility(public val name: String) - -public sealed class KotlinVisibility(name: String) : Visibility(name) { - public object Public : KotlinVisibility("public") - public object Private : KotlinVisibility("private") - public object Protected : KotlinVisibility("protected") - public object Internal : KotlinVisibility("internal") -} - -public sealed class JavaVisibility(name: String) : Visibility(name) { - public object Public : JavaVisibility("public") - public object Private : JavaVisibility("private") - public object Protected : JavaVisibility("protected") - public object Default : JavaVisibility("") -} - -public fun <T> SourceSetDependent<T>?.orEmpty(): SourceSetDependent<T> = this ?: emptyMap() - -public interface DocumentableSource { - public val path: String - - /** - * Computes the first line number of the documentable's declaration/signature/identifier. - * - * Numbering is always 1-based. - * - * May return null if the sources could not be found - for example, for synthetic/generated declarations. - */ - public fun computeLineNumber(): Int? -} - -public data class TypeConstructorWithKind(val typeConstructor: TypeConstructor, val kind: ClassKind) diff --git a/core/src/main/kotlin/model/JvmField.kt b/core/src/main/kotlin/model/JvmField.kt deleted file mode 100644 index a2b641c9..00000000 --- a/core/src/main/kotlin/model/JvmField.kt +++ /dev/null @@ -1,14 +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.model - -import org.jetbrains.dokka.links.DRI - -public const val JVM_FIELD_PACKAGE_NAME: String = "kotlin.jvm" -public const val JVM_FIELD_CLASS_NAMES: String = "JvmField" - -public fun DRI.isJvmField(): Boolean = packageName == JVM_FIELD_PACKAGE_NAME && classNames == JVM_FIELD_CLASS_NAMES - -public fun Annotations.Annotation.isJvmField(): Boolean = dri.isJvmField() diff --git a/core/src/main/kotlin/model/WithChildren.kt b/core/src/main/kotlin/model/WithChildren.kt deleted file mode 100644 index f73a5aa0..00000000 --- a/core/src/main/kotlin/model/WithChildren.kt +++ /dev/null @@ -1,98 +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.model - -public interface WithChildren<out T> { - public val children: List<T> -} - -public inline fun <reified T> WithChildren<*>.firstChildOfTypeOrNull(): T? = - children.filterIsInstance<T>().firstOrNull() - -public inline fun <reified T> WithChildren<*>.firstChildOfTypeOrNull(predicate: (T) -> Boolean): T? = - children.filterIsInstance<T>().firstOrNull(predicate) - -public inline fun <reified T> WithChildren<*>.firstChildOfType(): T = - children.filterIsInstance<T>().first() - -public inline fun <reified T> WithChildren<*>.childrenOfType(): List<T> = - children.filterIsInstance<T>() - -public inline fun <reified T> WithChildren<*>.firstChildOfType(predicate: (T) -> Boolean): T = - children.filterIsInstance<T>().first(predicate) - -public inline fun <reified T> WithChildren<WithChildren<*>>.firstMemberOfType(): T where T : WithChildren<*> { - return withDescendants().filterIsInstance<T>().first() -} - -public inline fun <reified T> WithChildren<WithChildren<*>>.firstMemberOfType( - predicate: (T) -> Boolean -): T where T : WithChildren<*> = withDescendants().filterIsInstance<T>().first(predicate) - - -public inline fun <reified T> WithChildren<WithChildren<*>>.firstMemberOfTypeOrNull(): T? where T : WithChildren<*> { - return withDescendants().filterIsInstance<T>().firstOrNull() -} - -public fun <T> T.withDescendants(): Sequence<T> where T : WithChildren<T> { - return sequence { - yield(this@withDescendants) - children.forEach { child -> - yieldAll(child.withDescendants()) - } - } -} - -@JvmName("withDescendantsProjection") -public fun WithChildren<*>.withDescendants(): Sequence<Any?> { - return sequence { - yield(this@withDescendants) - children.forEach { child -> - if (child is WithChildren<*>) { - yieldAll(child.withDescendants()) - } - } - } -} - -@JvmName("withDescendantsAny") -public fun WithChildren<Any>.withDescendants(): Sequence<Any> { - return sequence { - yield(this@withDescendants) - children.forEach { child -> - if (child is WithChildren<*>) { - yieldAll(child.withDescendants().filterNotNull()) - } - } - } -} - -public fun <T> T.dfs(predicate: (T) -> Boolean): T? where T : WithChildren<T> = if (predicate(this)) { - this -} else { - children.asSequence().mapNotNull { it.dfs(predicate) }.firstOrNull() -} - -public fun <T : WithChildren<T>> T.asPrintableTree( - nodeNameBuilder: Appendable.(T) -> Unit = { append(it.toString()) } -): String { - fun Appendable.append(element: T, ownPrefix: String, childPrefix: String) { - append(ownPrefix) - nodeNameBuilder(element) - appendLine() - element.children.takeIf(Collection<*>::isNotEmpty)?.also { children -> - val newOwnPrefix = "$childPrefix├─ " - val lastOwnPrefix = "$childPrefix└─ " - val newChildPrefix = "$childPrefix│ " - val lastChildPrefix = "$childPrefix " - children.forEachIndexed { n, e -> - if (n != children.lastIndex) append(e, newOwnPrefix, newChildPrefix) - else append(e, lastOwnPrefix, lastChildPrefix) - } - } - } - - return buildString { append(this@asPrintableTree, "", "") } -} diff --git a/core/src/main/kotlin/model/additionalExtras.kt b/core/src/main/kotlin/model/additionalExtras.kt deleted file mode 100644 index 1db8e59d..00000000 --- a/core/src/main/kotlin/model/additionalExtras.kt +++ /dev/null @@ -1,142 +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.model - -import org.jetbrains.dokka.links.DRI -import org.jetbrains.dokka.model.properties.ExtraProperty -import org.jetbrains.dokka.model.properties.MergeStrategy - -public class AdditionalModifiers( - public val content: SourceSetDependent<Set<ExtraModifiers>> -) : ExtraProperty<Documentable> { - - public companion object : ExtraProperty.Key<Documentable, AdditionalModifiers> { - override fun mergeStrategyFor( - left: AdditionalModifiers, - right: AdditionalModifiers - ): MergeStrategy<Documentable> = MergeStrategy.Replace(AdditionalModifiers(left.content + right.content)) - } - - override fun equals(other: Any?): Boolean = - if (other is AdditionalModifiers) other.content == content else false - - override fun hashCode(): Int = content.hashCode() - override val key: ExtraProperty.Key<Documentable, *> = AdditionalModifiers -} - -public fun SourceSetDependent<Set<ExtraModifiers>>.toAdditionalModifiers(): AdditionalModifiers = AdditionalModifiers(this) - -public data class Annotations( - private val myContent: SourceSetDependent<List<Annotation>> -) : ExtraProperty<AnnotationTarget> { - public companion object : ExtraProperty.Key<AnnotationTarget, Annotations> { - override fun mergeStrategyFor(left: Annotations, right: Annotations): MergeStrategy<AnnotationTarget> = - MergeStrategy.Replace(Annotations(left.myContent + right.myContent)) - } - - override val key: ExtraProperty.Key<AnnotationTarget, *> = Annotations - - public data class Annotation( - val dri: DRI, - val params: Map<String, AnnotationParameterValue>, - val mustBeDocumented: Boolean = false, - val scope: AnnotationScope = AnnotationScope.DIRECT - ) { - override fun equals(other: Any?): Boolean = when (other) { - is Annotation -> dri == other.dri - else -> false - } - - override fun hashCode(): Int = dri.hashCode() - } - - @Deprecated("Use directAnnotations or fileLevelAnnotations") - val content: SourceSetDependent<List<Annotation>> - get() = myContent - - val directAnnotations: SourceSetDependent<List<Annotation>> = annotationsByScope(AnnotationScope.DIRECT) - - val fileLevelAnnotations: SourceSetDependent<List<Annotation>> = annotationsByScope(AnnotationScope.FILE) - - private fun annotationsByScope(scope: AnnotationScope): SourceSetDependent<List<Annotation>> = - myContent.entries.mapNotNull { (key, value) -> - val withoutFileLevel = value.filter { it.scope == scope } - if (withoutFileLevel.isEmpty()) null - else Pair(key, withoutFileLevel) - }.toMap() - - public enum class AnnotationScope { - DIRECT, FILE, GETTER, SETTER - } -} - -public fun SourceSetDependent<List<Annotations.Annotation>>.toAnnotations(): Annotations = Annotations(this) - -public sealed class AnnotationParameterValue - -public data class AnnotationValue(val annotation: Annotations.Annotation) : AnnotationParameterValue() - -public data class ArrayValue(val value: List<AnnotationParameterValue>) : AnnotationParameterValue() - -public data class EnumValue(val enumName: String, val enumDri: DRI) : AnnotationParameterValue() - -public data class ClassValue(val className: String, val classDRI: DRI) : AnnotationParameterValue() - -public abstract class LiteralValue : AnnotationParameterValue() { - public abstract fun text() : String -} -public data class IntValue(val value: Int) : LiteralValue() { - override fun text(): String = value.toString() -} - -public data class LongValue(val value: Long) : LiteralValue() { - override fun text(): String = value.toString() -} - -public data class FloatValue(val value: Float) : LiteralValue() { - override fun text(): String = value.toString() -} - -public data class DoubleValue(val value: Double) : LiteralValue() { - override fun text(): String = value.toString() -} - -public object NullValue : LiteralValue() { - override fun text(): String = "null" -} - -public data class BooleanValue(val value: Boolean) : LiteralValue() { - override fun text(): String = value.toString() -} - -public data class StringValue(val value: String) : LiteralValue() { - override fun text(): String = value - override fun toString(): String = value -} - -public object PrimaryConstructorExtra : ExtraProperty<DFunction>, ExtraProperty.Key<DFunction, PrimaryConstructorExtra> { - override val key: ExtraProperty.Key<DFunction, *> = this -} - -public data class ActualTypealias( - val typeAlias: DTypeAlias -) : ExtraProperty<DClasslike> { - - @Suppress("unused") - @Deprecated(message = "It can be removed soon. Use [typeAlias.underlyingType]", ReplaceWith("this.typeAlias.underlyingType")) - val underlyingType: SourceSetDependent<Bound> - get() = typeAlias.underlyingType - - public companion object : ExtraProperty.Key<DClasslike, ActualTypealias> { - override fun mergeStrategyFor( - left: ActualTypealias, - right: ActualTypealias - ): MergeStrategy<DClasslike> = MergeStrategy.Fail { - throw IllegalStateException("Adding [ActualTypealias] should be after merging all documentables") - } - } - - override val key: ExtraProperty.Key<DClasslike, ActualTypealias> = ActualTypealias -} diff --git a/core/src/main/kotlin/model/ancestryNode.kt b/core/src/main/kotlin/model/ancestryNode.kt deleted file mode 100644 index 7203ab18..00000000 --- a/core/src/main/kotlin/model/ancestryNode.kt +++ /dev/null @@ -1,18 +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.model - -public data class AncestryNode( - val typeConstructor: TypeConstructor, - val superclass: AncestryNode?, - val interfaces: List<AncestryNode>, -) { - public fun allImplementedInterfaces(): List<TypeConstructor> { - fun traverseInterfaces(ancestry: AncestryNode): List<TypeConstructor> = - ancestry.interfaces.flatMap { listOf(it.typeConstructor) + traverseInterfaces(it) } + - (ancestry.superclass?.let(::traverseInterfaces) ?: emptyList()) - return traverseInterfaces(this).distinct() - } -} diff --git a/core/src/main/kotlin/model/classKinds.kt b/core/src/main/kotlin/model/classKinds.kt deleted file mode 100644 index 25256022..00000000 --- a/core/src/main/kotlin/model/classKinds.kt +++ /dev/null @@ -1,24 +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.model - -public interface ClassKind - -public enum class KotlinClassKindTypes : ClassKind { - CLASS, - INTERFACE, - ENUM_CLASS, - ENUM_ENTRY, - ANNOTATION_CLASS, - OBJECT; -} - -public enum class JavaClassKindTypes : ClassKind { - CLASS, - INTERFACE, - ENUM_CLASS, - ENUM_ENTRY, - ANNOTATION_CLASS; -} diff --git a/core/src/main/kotlin/model/defaultValues.kt b/core/src/main/kotlin/model/defaultValues.kt deleted file mode 100644 index 426954fb..00000000 --- a/core/src/main/kotlin/model/defaultValues.kt +++ /dev/null @@ -1,34 +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.model - -import org.jetbrains.dokka.model.properties.ExtraProperty -import org.jetbrains.dokka.model.properties.MergeStrategy - -public class DefaultValue( - public val expression: SourceSetDependent<Expression> -): ExtraProperty<Documentable> { - - @Deprecated("Use `expression` property that depends on source set", ReplaceWith("this.expression.values.first()")) - public val value: Expression - get() = expression.values.first() - - public companion object : ExtraProperty.Key<Documentable, DefaultValue> { - override fun mergeStrategyFor(left: DefaultValue, right: DefaultValue): MergeStrategy<Documentable> = - MergeStrategy.Replace(DefaultValue(left.expression + right.expression)) - - } - - override val key: ExtraProperty.Key<Documentable, *> - get() = Companion -} - -public interface Expression -public data class ComplexExpression(val value: String) : Expression -public data class IntegerConstant(val value: Long) : Expression -public data class StringConstant(val value: String) : Expression -public data class DoubleConstant(val value: Double) : Expression -public data class FloatConstant(val value: Float) : Expression -public data class BooleanConstant(val value: Boolean) : Expression diff --git a/core/src/main/kotlin/model/doc/DocTag.kt b/core/src/main/kotlin/model/doc/DocTag.kt deleted file mode 100644 index f4cb9b33..00000000 --- a/core/src/main/kotlin/model/doc/DocTag.kt +++ /dev/null @@ -1,372 +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.model.doc - -import org.jetbrains.dokka.links.DRI -import org.jetbrains.dokka.model.WithChildren - -public sealed class DocTag : WithChildren<DocTag> { - public abstract val params: Map<String, String> - - public companion object { - public fun contentTypeParam(type: String): Map<String, String> = mapOf("content-type" to type) - } -} - -public data class A( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Big( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class B( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class BlockQuote( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public object Br : DocTag() { - override val children: List<DocTag> = emptyList() - override val params: Map<String, String> = emptyMap() -} - -public data class Cite( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public sealed class Code : DocTag() - -public data class CodeInline( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : Code() - -public data class CodeBlock( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : Code() - -public data class CustomDocTag( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap(), - val name: String -) : DocTag() - -public data class Dd( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Dfn( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Dir( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Div( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Dl( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class DocumentationLink( - val dri: DRI, - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Dt( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Em( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Font( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Footer( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Frame( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class FrameSet( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class H1( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class H2( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class H3( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class H4( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class H5( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class H6( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Head( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Header( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public object HorizontalRule : DocTag() { - override val children: List<DocTag> = emptyList() - override val params: Map<String, String> = emptyMap() -} - -public data class Html( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class I( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class IFrame( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Img( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Index( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Input( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Li( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Link( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Listing( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Main( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Menu( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Meta( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Nav( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class NoFrames( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class NoScript( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Ol( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class P( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Pre( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Script( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Section( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Small( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Span( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Strikethrough( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Strong( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Sub( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Sup( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Table( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Text( - val body: String = "", - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class TBody( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Td( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class TFoot( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Th( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class THead( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Title( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Tr( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Tt( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class U( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Ul( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Var( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - -public data class Caption( - override val children: List<DocTag> = emptyList(), - override val params: Map<String, String> = emptyMap() -) : DocTag() - diff --git a/core/src/main/kotlin/model/doc/DocumentationNode.kt b/core/src/main/kotlin/model/doc/DocumentationNode.kt deleted file mode 100644 index 9c270f79..00000000 --- a/core/src/main/kotlin/model/doc/DocumentationNode.kt +++ /dev/null @@ -1,9 +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.model.doc - -import org.jetbrains.dokka.model.WithChildren - -public data class DocumentationNode(override val children: List<TagWrapper>): WithChildren<TagWrapper> diff --git a/core/src/main/kotlin/model/doc/TagWrapper.kt b/core/src/main/kotlin/model/doc/TagWrapper.kt deleted file mode 100644 index e3eaffb7..00000000 --- a/core/src/main/kotlin/model/doc/TagWrapper.kt +++ /dev/null @@ -1,36 +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.model.doc - -import org.jetbrains.dokka.links.DRI -import org.jetbrains.dokka.model.WithChildren - -public sealed class TagWrapper : WithChildren<DocTag> { - public abstract val root: DocTag - - override val children: List<DocTag> - get() = root.children -} - -public sealed class NamedTagWrapper : TagWrapper() { - public abstract val name: String -} - -public data class Description(override val root: DocTag) : TagWrapper() -public data class Author(override val root: DocTag) : TagWrapper() -public data class Version(override val root: DocTag) : TagWrapper() -public data class Since(override val root: DocTag) : TagWrapper() -public data class See(override val root: DocTag, override val name: String, val address: DRI?) : NamedTagWrapper() -public data class Param(override val root: DocTag, override val name: String) : NamedTagWrapper() -public data class Return(override val root: DocTag) : TagWrapper() -public data class Receiver(override val root: DocTag) : TagWrapper() -public data class Constructor(override val root: DocTag) : TagWrapper() -//TODO this naming is confusing since kotlin has Throws annotation -public data class Throws(override val root: DocTag, override val name: String, val exceptionAddress: DRI?) : NamedTagWrapper() -public data class Sample(override val root: DocTag, override val name: String) : NamedTagWrapper() -public data class Deprecated(override val root: DocTag) : TagWrapper() -public data class Property(override val root: DocTag, override val name: String) : NamedTagWrapper() -public data class Suppress(override val root: DocTag) : TagWrapper() -public data class CustomTagWrapper(override val root: DocTag, override val name: String) : NamedTagWrapper() diff --git a/core/src/main/kotlin/model/documentableProperties.kt b/core/src/main/kotlin/model/documentableProperties.kt deleted file mode 100644 index b0ebb6ef..00000000 --- a/core/src/main/kotlin/model/documentableProperties.kt +++ /dev/null @@ -1,71 +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.model - -import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet -import org.jetbrains.dokka.links.DRI -import org.jetbrains.dokka.model.properties.ExtraProperty -import org.jetbrains.dokka.model.properties.MergeStrategy - -public data class InheritedMember(val inheritedFrom: SourceSetDependent<DRI?>) : ExtraProperty<Documentable> { - public companion object : ExtraProperty.Key<Documentable, InheritedMember> { - override fun mergeStrategyFor(left: InheritedMember, right: InheritedMember): MergeStrategy<Documentable> = MergeStrategy.Replace( - InheritedMember(left.inheritedFrom + right.inheritedFrom) - ) - } - - public fun isInherited(sourceSetDependent: DokkaSourceSet): Boolean = inheritedFrom[sourceSetDependent] != null - - override val key: ExtraProperty.Key<Documentable, *> = InheritedMember -} - -public data class ImplementedInterfaces(val interfaces: SourceSetDependent<List<TypeConstructor>>) : ExtraProperty<Documentable> { - public companion object : ExtraProperty.Key<Documentable, ImplementedInterfaces> { - override fun mergeStrategyFor(left: ImplementedInterfaces, right: ImplementedInterfaces): MergeStrategy<Documentable> = - MergeStrategy.Replace(ImplementedInterfaces(left.interfaces + right.interfaces)) - } - - override val key: ExtraProperty.Key<Documentable, *> = ImplementedInterfaces -} - -public data class ExceptionInSupertypes(val exceptions: SourceSetDependent<List<TypeConstructor>>): ExtraProperty<Documentable> { - public companion object : ExtraProperty.Key<Documentable, ExceptionInSupertypes> { - override fun mergeStrategyFor(left: ExceptionInSupertypes, right: ExceptionInSupertypes): MergeStrategy<Documentable> = - MergeStrategy.Replace(ExceptionInSupertypes(left.exceptions + right.exceptions)) - } - - override val key: ExtraProperty.Key<Documentable, *> = ExceptionInSupertypes -} - -public object ObviousMember : ExtraProperty<Documentable>, ExtraProperty.Key<Documentable, ObviousMember> { - override val key: ExtraProperty.Key<Documentable, *> = this -} - -/** - * Whether this [DProperty] is `var` or `val`, should be present both in Kotlin and in Java properties - * - * In case of properties that came from `Java`, [IsVar] is added if - * the java field has no accessors at all (plain field) or has a setter - */ -public object IsVar : ExtraProperty<DProperty>, ExtraProperty.Key<DProperty, IsVar> { - override val key: ExtraProperty.Key<DProperty, *> = this -} - -public data class IsAlsoParameter(val inSourceSets: List<DokkaSourceSet>) : ExtraProperty<DProperty> { - public companion object : ExtraProperty.Key<DProperty, IsAlsoParameter> { - override fun mergeStrategyFor(left: IsAlsoParameter, right: IsAlsoParameter): MergeStrategy<DProperty> = - MergeStrategy.Replace(IsAlsoParameter(left.inSourceSets + right.inSourceSets)) - } - - override val key: ExtraProperty.Key<DProperty, *> = IsAlsoParameter -} - -public data class CheckedExceptions(val exceptions: SourceSetDependent<List<DRI>>) : ExtraProperty<Documentable>, ExtraProperty.Key<Documentable, ObviousMember> { - public companion object : ExtraProperty.Key<Documentable, CheckedExceptions> { - override fun mergeStrategyFor(left: CheckedExceptions, right: CheckedExceptions): MergeStrategy<Documentable> = - MergeStrategy.Replace(CheckedExceptions(left.exceptions + right.exceptions)) - } - override val key: ExtraProperty.Key<Documentable, *> = CheckedExceptions -} diff --git a/core/src/main/kotlin/model/documentableUtils.kt b/core/src/main/kotlin/model/documentableUtils.kt deleted file mode 100644 index c9d75bf4..00000000 --- a/core/src/main/kotlin/model/documentableUtils.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.model - -import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet - -public fun <T> SourceSetDependent<T>.filtered(sourceSets: Set<DokkaSourceSet>): SourceSetDependent<T> = filter { it.key in sourceSets } -public fun DokkaSourceSet?.filtered(sourceSets: Set<DokkaSourceSet>): DokkaSourceSet? = takeIf { this in sourceSets } - -public fun DTypeParameter.filter(filteredSet: Set<DokkaSourceSet>): DTypeParameter? = - if (filteredSet.containsAll(sourceSets)) this - else { - val intersection = filteredSet.intersect(sourceSets) - if (intersection.isEmpty()) null - else DTypeParameter( - variantTypeParameter, - documentation.filtered(intersection), - expectPresentInSet?.takeIf { intersection.contains(expectPresentInSet) }, - bounds, - intersection, - extra - ) - } - -public fun Documentable.isExtension(): Boolean = this is Callable && receiver != null diff --git a/core/src/main/kotlin/model/extraModifiers.kt b/core/src/main/kotlin/model/extraModifiers.kt deleted file mode 100644 index f1193070..00000000 --- a/core/src/main/kotlin/model/extraModifiers.kt +++ /dev/null @@ -1,68 +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.model - -public sealed class ExtraModifiers(public val name: String) { - - public sealed class KotlinOnlyModifiers(name: String) : ExtraModifiers(name) { - public object Inline : KotlinOnlyModifiers("inline") - public object Value : KotlinOnlyModifiers("value") - public object Infix : KotlinOnlyModifiers("infix") - public object External : KotlinOnlyModifiers("external") - public object Suspend : KotlinOnlyModifiers("suspend") - public object Reified : KotlinOnlyModifiers("reified") - public object CrossInline : KotlinOnlyModifiers("crossinline") - public object NoInline : KotlinOnlyModifiers("noinline") - public object Override : KotlinOnlyModifiers("override") - public object Data : KotlinOnlyModifiers("data") - public object Const : KotlinOnlyModifiers("const") - public object Inner : KotlinOnlyModifiers("inner") - public object LateInit : KotlinOnlyModifiers("lateinit") - public object Operator : KotlinOnlyModifiers("operator") - public object TailRec : KotlinOnlyModifiers("tailrec") - public object VarArg : KotlinOnlyModifiers("vararg") - public object Fun : KotlinOnlyModifiers("fun") - } - - public sealed class JavaOnlyModifiers(name: String) : ExtraModifiers(name) { - public object Static : JavaOnlyModifiers("static") - public object Native : JavaOnlyModifiers("native") - public object Synchronized : JavaOnlyModifiers("synchronized") - public object StrictFP : JavaOnlyModifiers("strictfp") - public object Transient : JavaOnlyModifiers("transient") - public object Volatile : JavaOnlyModifiers("volatile") - public object Transitive : JavaOnlyModifiers("transitive") - } - - public companion object { - public fun valueOf(str: String): ExtraModifiers = when (str) { - "inline" -> KotlinOnlyModifiers.Inline - "value" -> KotlinOnlyModifiers.Value - "infix" -> KotlinOnlyModifiers.Infix - "external" -> KotlinOnlyModifiers.External - "suspend" -> KotlinOnlyModifiers.Suspend - "reified" -> KotlinOnlyModifiers.Reified - "crossinline" -> KotlinOnlyModifiers.CrossInline - "noinline" -> KotlinOnlyModifiers.NoInline - "override" -> KotlinOnlyModifiers.Override - "data" -> KotlinOnlyModifiers.Data - "const" -> KotlinOnlyModifiers.Const - "inner" -> KotlinOnlyModifiers.Inner - "lateinit" -> KotlinOnlyModifiers.LateInit - "operator" -> KotlinOnlyModifiers.Operator - "tailrec" -> KotlinOnlyModifiers.TailRec - "vararg" -> KotlinOnlyModifiers.VarArg - "static" -> JavaOnlyModifiers.Static - "native" -> JavaOnlyModifiers.Native - "synchronized" -> JavaOnlyModifiers.Synchronized - "strictfp" -> JavaOnlyModifiers.StrictFP - "transient" -> JavaOnlyModifiers.Transient - "volatile" -> JavaOnlyModifiers.Volatile - "transitive" -> JavaOnlyModifiers.Transitive - "fun" -> KotlinOnlyModifiers.Fun - else -> throw IllegalArgumentException("There is no Extra Modifier for given name $str") - } - } -} diff --git a/core/src/main/kotlin/model/jvmName.kt b/core/src/main/kotlin/model/jvmName.kt deleted file mode 100644 index 8fd7ccd9..00000000 --- a/core/src/main/kotlin/model/jvmName.kt +++ /dev/null @@ -1,11 +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.model - -import org.jetbrains.dokka.links.DRI - -public fun DRI.isJvmName(): Boolean = packageName == "kotlin.jvm" && classNames == "JvmName" - -public fun Annotations.Annotation.isJvmName(): Boolean = dri.isJvmName() diff --git a/core/src/main/kotlin/model/properties/PropertyContainer.kt b/core/src/main/kotlin/model/properties/PropertyContainer.kt deleted file mode 100644 index 7f5bb2f0..00000000 --- a/core/src/main/kotlin/model/properties/PropertyContainer.kt +++ /dev/null @@ -1,69 +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.model.properties - -public data class PropertyContainer<C : Any> internal constructor( - @PublishedApi internal val map: Map<ExtraProperty.Key<C, *>, ExtraProperty<C>> -) { - public operator fun <D : C> plus(prop: ExtraProperty<D>): PropertyContainer<D> = - PropertyContainer(map + (prop.key to prop)) - - // TODO: Add logic for caching calculated properties - public inline operator fun <reified T : Any> get(key: ExtraProperty.Key<C, T>): T? = when (val prop = map[key]) { - is T? -> prop - else -> throw ClassCastException("Property for $key stored under not matching key type.") - } - - public inline fun <reified T : Any> allOfType(): List<T> = map.values.filterIsInstance<T>() - - public fun <D : C> addAll(extras: Collection<ExtraProperty<D>>): PropertyContainer<D> = - PropertyContainer(map + extras.map { p -> p.key to p }) - - public operator fun <D : C> minus(prop: ExtraProperty.Key<C, *>): PropertyContainer<D> = - PropertyContainer(map.filterNot { it.key == prop }) - - public companion object { - public fun <T : Any> empty(): PropertyContainer<T> = PropertyContainer(emptyMap()) - public fun <T : Any> withAll(vararg extras: ExtraProperty<T>?): PropertyContainer<T> = empty<T>().addAll(extras.filterNotNull()) - public fun <T : Any> withAll(extras: Collection<ExtraProperty<T>>): PropertyContainer<T> = empty<T>().addAll(extras) - } -} - -public operator fun <D: Any> PropertyContainer<D>.plus(prop: ExtraProperty<D>?): PropertyContainer<D> = - if (prop == null) this else PropertyContainer(map + (prop.key to prop)) - - -public interface WithExtraProperties<C : Any> { - public val extra: PropertyContainer<C> - - public fun withNewExtras(newExtras: PropertyContainer<C>): C -} - -public fun <C> C.mergeExtras(left: C, right: C): C where C : Any, C : WithExtraProperties<C> { - val aggregatedExtras: List<List<ExtraProperty<C>>> = - (left.extra.map.values + right.extra.map.values) - .groupBy { it.key } - .values - .map { it.distinct() } - - val (unambiguous, toMerge) = aggregatedExtras.partition { it.size == 1 } - - @Suppress("UNCHECKED_CAST") - val strategies: List<MergeStrategy<C>> = toMerge.map { (l, r) -> - (l.key as ExtraProperty.Key<C, ExtraProperty<C>>).mergeStrategyFor(l, r) - } - - strategies.filterIsInstance<MergeStrategy.Fail>().firstOrNull()?.error?.invoke() - - val replaces: List<ExtraProperty<C>> = - strategies.filterIsInstance<MergeStrategy.Replace<C>>().map { it.newProperty } - - val needingFullMerge: List<(preMerged: C, left: C, right: C) -> C> = - strategies.filterIsInstance<MergeStrategy.Full<C>>().map { it.merger } - - val newExtras = PropertyContainer((unambiguous.flatten() + replaces).associateBy { it.key }) - - return needingFullMerge.fold(withNewExtras(newExtras)) { acc, merger -> merger(acc, left, right) } -} diff --git a/core/src/main/kotlin/model/properties/properties.kt b/core/src/main/kotlin/model/properties/properties.kt deleted file mode 100644 index ea76dc72..00000000 --- a/core/src/main/kotlin/model/properties/properties.kt +++ /dev/null @@ -1,36 +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.model.properties - -public interface ExtraProperty<in C : Any> { - public interface Key<in C : Any, T : Any> { - public fun mergeStrategyFor(left: T, right: T): MergeStrategy<C> = MergeStrategy.Fail { - throw NotImplementedError("Property merging for $this is not implemented") - } - } - - public val key: Key<C, *> -} - -public interface CalculatedProperty<in C : Any, T : Any> : ExtraProperty.Key<C, T> { - public fun calculate(subject: C): T -} - -public sealed class MergeStrategy<in C> { - - public class Replace<in C : Any>( - public val newProperty: ExtraProperty<C> - ) : MergeStrategy<C>() - - public object Remove : MergeStrategy<Any>() - - public class Full<C : Any>( - public val merger: (preMerged: C, left: C, right: C) -> C - ) : MergeStrategy<C>() - - public class Fail( - public val error: () -> Nothing - ) : MergeStrategy<Any>() -} diff --git a/core/src/main/kotlin/pages/ContentNodes.kt b/core/src/main/kotlin/pages/ContentNodes.kt deleted file mode 100644 index 96f43205..00000000 --- a/core/src/main/kotlin/pages/ContentNodes.kt +++ /dev/null @@ -1,436 +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.pages - -import org.jetbrains.dokka.links.DRI -import org.jetbrains.dokka.model.DisplaySourceSet -import org.jetbrains.dokka.model.WithChildren -import org.jetbrains.dokka.model.properties.PropertyContainer -import org.jetbrains.dokka.model.properties.WithExtraProperties - -public data class DCI(val dri: Set<DRI>, val kind: Kind) { - override fun toString(): String = "$dri[$kind]" -} - -public interface ContentNode : WithExtraProperties<ContentNode>, WithChildren<ContentNode> { - public val dci: DCI - public val sourceSets: Set<DisplaySourceSet> - public val style: Set<Style> - - public fun hasAnyContent(): Boolean - - public fun withSourceSets(sourceSets: Set<DisplaySourceSet>): ContentNode - - override val children: List<ContentNode> - get() = emptyList() -} - -/** Simple text */ -public data class ContentText( - val text: String, - override val dci: DCI, - override val sourceSets: Set<DisplaySourceSet>, - override val style: Set<Style> = emptySet(), - override val extra: PropertyContainer<ContentNode> = PropertyContainer.empty() -) : ContentNode { - override fun withNewExtras(newExtras: PropertyContainer<ContentNode>): ContentText = copy(extra = newExtras) - override fun withSourceSets(sourceSets: Set<DisplaySourceSet>): ContentText = copy(sourceSets = sourceSets) - override fun hasAnyContent(): Boolean = text.isNotBlank() -} - -public data class ContentBreakLine( - override val sourceSets: Set<DisplaySourceSet>, - override val dci: DCI = DCI(emptySet(), ContentKind.Empty), - override val style: Set<Style> = emptySet(), - override val extra: PropertyContainer<ContentNode> = PropertyContainer.empty() -) : ContentNode { - override fun withNewExtras(newExtras: PropertyContainer<ContentNode>): ContentBreakLine = copy(extra = newExtras) - override fun withSourceSets(sourceSets: Set<DisplaySourceSet>): ContentBreakLine = copy(sourceSets = sourceSets) - override fun hasAnyContent(): Boolean = true -} - -/** Headers */ -public data class ContentHeader( - override val children: List<ContentNode>, - val level: Int, - override val dci: DCI, - override val sourceSets: Set<DisplaySourceSet>, - override val style: Set<Style>, - override val extra: PropertyContainer<ContentNode> = PropertyContainer.empty() -) : ContentComposite { - public constructor(level: Int, c: ContentComposite) : this(c.children, level, c.dci, c.sourceSets, c.style, c.extra) - - override fun withNewExtras(newExtras: PropertyContainer<ContentNode>): ContentHeader = copy(extra = newExtras) - - override fun transformChildren(transformer: (ContentNode) -> ContentNode): ContentHeader = - copy(children = children.map(transformer)) - - override fun withSourceSets(sourceSets: Set<DisplaySourceSet>): ContentHeader = - copy(sourceSets = sourceSets) -} - -public interface ContentCode : ContentComposite - -/** Code blocks */ -public data class ContentCodeBlock( - override val children: List<ContentNode>, - val language: String, - override val dci: DCI, - override val sourceSets: Set<DisplaySourceSet>, - override val style: Set<Style>, - override val extra: PropertyContainer<ContentNode> = PropertyContainer.empty() -) : ContentCode { - override fun withNewExtras(newExtras: PropertyContainer<ContentNode>): ContentCodeBlock = copy(extra = newExtras) - - override fun transformChildren(transformer: (ContentNode) -> ContentNode): ContentCodeBlock = - copy(children = children.map(transformer)) - - override fun withSourceSets(sourceSets: Set<DisplaySourceSet>): ContentCodeBlock = - copy(sourceSets = sourceSets) - -} - -public data class ContentCodeInline( - override val children: List<ContentNode>, - val language: String, - override val dci: DCI, - override val sourceSets: Set<DisplaySourceSet>, - override val style: Set<Style>, - override val extra: PropertyContainer<ContentNode> = PropertyContainer.empty() -) : ContentCode { - override fun withNewExtras(newExtras: PropertyContainer<ContentNode>): ContentCodeInline = copy(extra = newExtras) - - override fun transformChildren(transformer: (ContentNode) -> ContentNode): ContentCodeInline = - copy(children = children.map(transformer)) - - override fun withSourceSets(sourceSets: Set<DisplaySourceSet>): ContentCodeInline = - copy(sourceSets = sourceSets) - -} - -/** Union type replacement */ -public interface ContentLink : ContentComposite - -/** All links to classes, packages, etc. that have te be resolved */ -public data class ContentDRILink( - override val children: List<ContentNode>, - val address: DRI, - override val dci: DCI, - override val sourceSets: Set<DisplaySourceSet>, - override val style: Set<Style> = emptySet(), - override val extra: PropertyContainer<ContentNode> = PropertyContainer.empty() -) : ContentLink { - override fun withNewExtras(newExtras: PropertyContainer<ContentNode>): ContentDRILink = copy(extra = newExtras) - - override fun transformChildren(transformer: (ContentNode) -> ContentNode): ContentDRILink = - copy(children = children.map(transformer)) - - override fun withSourceSets(sourceSets: Set<DisplaySourceSet>): ContentDRILink = - copy(sourceSets = sourceSets) - -} - -/** All links that do not need to be resolved */ -public data class ContentResolvedLink( - override val children: List<ContentNode>, - val address: String, - override val dci: DCI, - override val sourceSets: Set<DisplaySourceSet>, - override val style: Set<Style> = emptySet(), - override val extra: PropertyContainer<ContentNode> = PropertyContainer.empty() -) : ContentLink { - override fun withNewExtras(newExtras: PropertyContainer<ContentNode>): ContentResolvedLink = - copy(extra = newExtras) - - override fun transformChildren(transformer: (ContentNode) -> ContentNode): ContentResolvedLink = - copy(children = children.map(transformer)) - - override fun withSourceSets(sourceSets: Set<DisplaySourceSet>): ContentResolvedLink = - copy(sourceSets = sourceSets) -} - -/** Embedded resources like images */ -public data class ContentEmbeddedResource( - override val children: List<ContentNode> = emptyList(), - val address: String, - val altText: String?, - override val dci: DCI, - override val sourceSets: Set<DisplaySourceSet>, - override val style: Set<Style> = emptySet(), - override val extra: PropertyContainer<ContentNode> = PropertyContainer.empty() -) : ContentLink { - override fun withNewExtras(newExtras: PropertyContainer<ContentNode>): ContentEmbeddedResource = - copy(extra = newExtras) - - override fun transformChildren(transformer: (ContentNode) -> ContentNode): ContentEmbeddedResource = - copy(children = children.map(transformer)) - - override fun withSourceSets(sourceSets: Set<DisplaySourceSet>): ContentEmbeddedResource = - copy(sourceSets = sourceSets) -} - -/** Logical grouping of [ContentNode]s */ -public interface ContentComposite : ContentNode { - override val children: List<ContentNode> // overwrite to make it abstract once again - - override val sourceSets: Set<DisplaySourceSet> get() = children.flatMap { it.sourceSets }.toSet() - - public fun transformChildren(transformer: (ContentNode) -> ContentNode): ContentComposite - - override fun hasAnyContent(): Boolean = children.any { it.hasAnyContent() } -} - -/** Tables */ -public data class ContentTable( - val header: List<ContentGroup>, - val caption: ContentGroup? = null, - override val children: List<ContentGroup>, - override val dci: DCI, - override val sourceSets: Set<DisplaySourceSet>, - override val style: Set<Style>, - override val extra: PropertyContainer<ContentNode> = PropertyContainer.empty() -) : ContentComposite { - override fun withNewExtras(newExtras: PropertyContainer<ContentNode>): ContentTable = copy(extra = newExtras) - - override fun transformChildren(transformer: (ContentNode) -> ContentNode): ContentTable = - copy(children = children.map(transformer).map { it as ContentGroup }) - - override fun withSourceSets(sourceSets: Set<DisplaySourceSet>): ContentTable = - copy(sourceSets = sourceSets) - -} - -/** Lists */ -public data class ContentList( - override val children: List<ContentNode>, - val ordered: Boolean, - override val dci: DCI, - override val sourceSets: Set<DisplaySourceSet>, - override val style: Set<Style>, - override val extra: PropertyContainer<ContentNode> = PropertyContainer.empty() -) : ContentComposite { - override fun withNewExtras(newExtras: PropertyContainer<ContentNode>): ContentList = copy(extra = newExtras) - - override fun transformChildren(transformer: (ContentNode) -> ContentNode): ContentList = - copy(children = children.map(transformer)) - - override fun withSourceSets(sourceSets: Set<DisplaySourceSet>): ContentList = - copy(sourceSets = sourceSets) -} - -/** Default group, eg. for blocks of Functions, Properties, etc. **/ -public data class ContentGroup( - override val children: List<ContentNode>, - override val dci: DCI, - override val sourceSets: Set<DisplaySourceSet>, - override val style: Set<Style>, - override val extra: PropertyContainer<ContentNode> = PropertyContainer.empty() -) : ContentComposite { - override fun withNewExtras(newExtras: PropertyContainer<ContentNode>): ContentGroup = copy(extra = newExtras) - - override fun transformChildren(transformer: (ContentNode) -> ContentNode): ContentGroup = - copy(children = children.map(transformer)) - - override fun withSourceSets(sourceSets: Set<DisplaySourceSet>): ContentGroup = - copy(sourceSets = sourceSets) -} - -/** - * @property groupID is used for finding and copying [ContentDivergentInstance]s when merging [ContentPage]s - */ -public data class ContentDivergentGroup( - override val children: List<ContentDivergentInstance>, - override val dci: DCI, - override val style: Set<Style>, - override val extra: PropertyContainer<ContentNode>, - val groupID: GroupID, - val implicitlySourceSetHinted: Boolean = true -) : ContentComposite { - public data class GroupID(val name: String) - - override val sourceSets: Set<DisplaySourceSet> - get() = children.flatMap { it.sourceSets }.distinct().toSet() - - override fun withNewExtras(newExtras: PropertyContainer<ContentNode>): ContentDivergentGroup = - copy(extra = newExtras) - - override fun transformChildren(transformer: (ContentNode) -> ContentNode): ContentDivergentGroup = - copy(children = children.map(transformer).map { it as ContentDivergentInstance }) - - override fun withSourceSets(sourceSets: Set<DisplaySourceSet>): ContentDivergentGroup = this -} - -/** Instance of a divergent content */ -public data class ContentDivergentInstance( - val before: ContentNode?, - val divergent: ContentNode, - val after: ContentNode?, - override val dci: DCI, - override val sourceSets: Set<DisplaySourceSet>, - override val style: Set<Style>, - override val extra: PropertyContainer<ContentNode> = PropertyContainer.empty() -) : ContentComposite { - override val children: List<ContentNode> - get() = listOfNotNull(before, divergent, after) - - override fun withNewExtras(newExtras: PropertyContainer<ContentNode>): ContentDivergentInstance = - copy(extra = newExtras) - - override fun transformChildren(transformer: (ContentNode) -> ContentNode): ContentDivergentInstance = - copy( - before = before?.let(transformer), - divergent = divergent.let(transformer), - after = after?.let(transformer) - ) - - override fun withSourceSets(sourceSets: Set<DisplaySourceSet>): ContentDivergentInstance = - copy(sourceSets = sourceSets) - -} - -public data class PlatformHintedContent( - val inner: ContentNode, - override val sourceSets: Set<DisplaySourceSet> -) : ContentComposite { - override val children: List<ContentNode> = listOf(inner) - - override val dci: DCI - get() = inner.dci - - override val extra: PropertyContainer<ContentNode> - get() = inner.extra - - override val style: Set<Style> - get() = inner.style - - override fun withNewExtras(newExtras: PropertyContainer<ContentNode>): ContentNode = - throw UnsupportedOperationException("This method should not be called on this PlatformHintedContent") - - override fun transformChildren(transformer: (ContentNode) -> ContentNode): PlatformHintedContent = - copy(inner = transformer(inner)) - - override fun withSourceSets(sourceSets: Set<DisplaySourceSet>): PlatformHintedContent = - copy(sourceSets = sourceSets) - -} - -public interface Style -public interface Kind - -/** - * [ContentKind] represents a grouping of content of one kind that can can be rendered - * as part of a composite page (one tab/block within a class's page, for instance). - */ -public enum class ContentKind : Kind { - - /** - * Marks all sorts of signatures. Can contain sub-kinds marked as [SymbolContentKind] - * - * Some examples: - * - primary constructor: `data class CoroutineName(name: String) : AbstractCoroutineContextElement` - * - constructor: `fun CoroutineName(name: String)` - * - function: `open override fun toString(): String` - * - property: `val name: String` - */ - Symbol, - - Comment, Constructors, Functions, Parameters, Properties, Classlikes, Packages, Sample, Main, BriefComment, - Empty, Source, TypeAliases, Cover, Inheritors, SourceSetDependentHint, Extensions, Annotations, - - /** - * Deprecation details block with related information such as message/replaceWith/level. - */ - Deprecation; - - public companion object { - private val platformTagged = - setOf( - Constructors, - Functions, - Properties, - Classlikes, - Packages, - Source, - TypeAliases, - Inheritors, - Extensions - ) - - public fun shouldBePlatformTagged(kind: Kind): Boolean = kind in platformTagged - } -} - -/** - * Content kind for [ContentKind.Symbol] content, which is essentially about signatures - */ -public enum class SymbolContentKind : Kind { - /** - * Marks constructor/function parameters, everything in-between parentheses. - * - * For function `fun foo(bar: String, baz: Int, qux: Boolean)`, - * the parameters would be the whole of `bar: String, baz: Int, qux: Boolean` - */ - Parameters, - - /** - * Marks a single parameter in a function. Most likely to be a child of [Parameters]. - * - * In function `fun foo(bar: String, baz: Int, qux: Boolean)` there would be 3 [Parameter] instances: - * - `bar: String, ` - * - `baz: Int, ` - * - `qux: Boolean` - */ - Parameter, -} - -public enum class TokenStyle : Style { - Keyword, Punctuation, Function, Operator, Annotation, Number, String, Boolean, Constant -} - -public enum class TextStyle : Style { - Bold, Italic, Strong, Strikethrough, Paragraph, - Block, Span, Monospace, Indented, Cover, UnderCoverText, BreakableAfter, Breakable, InlineComment, Quotation, - FloatingRight, Var, Underlined -} - -public enum class ContentStyle : Style { - RowTitle, - /** - * The style is used only for HTML. It is applied only for [ContentGroup]. - * Creating and rendering tabs is a part of a renderer. - */ - TabbedContent, - - WithExtraAttributes, RunnableSample, InDocumentationAnchor, Caption, - Wrapped, Indented, KDocTag, Footnote -} - -public enum class ListStyle : Style { - /** - * Represents a list of groups of [DescriptionTerm] and [DescriptionDetails]. - * Common uses for this element are to implement a glossary or to display - * metadata (a list of key-value pairs). Formatting example: see `<dl>` html tag. - */ - DescriptionList, - - /** - * If used within [DescriptionList] context, specifies a term in a description - * or definition list, usually followed by [DescriptionDetails] for one or more - * terms. Formatting example: see `<dt>` html tag - */ - DescriptionTerm, - - /** - * If used within [DescriptionList] context, provides the definition or other - * related text associated with [DescriptionTerm]. Formatting example: see `<dd>` html tag - */ - DescriptionDetails -} - -public object CommentTable : Style - -public object MultimoduleTable : Style - -public fun ContentNode.hasStyle(style: Style): Boolean = this.style.contains(style) diff --git a/core/src/main/kotlin/pages/PageNodes.kt b/core/src/main/kotlin/pages/PageNodes.kt deleted file mode 100644 index cfaf2347..00000000 --- a/core/src/main/kotlin/pages/PageNodes.kt +++ /dev/null @@ -1,200 +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.pages - -import org.jetbrains.dokka.links.DRI -import org.jetbrains.dokka.model.Documentable -import org.jetbrains.dokka.model.WithChildren -import java.util.* - -public interface PageNode : WithChildren<PageNode> { - public val name: String - override val children: List<PageNode> - - public fun modified( - name: String = this.name, - children: List<PageNode> = this.children - ): PageNode -} - -public interface ContentPage : PageNode { - public val content: ContentNode - public val dri: Set<DRI> - public val embeddedResources: List<String> - - @Deprecated("Deprecated. Remove its usages from your code.", - ReplaceWith("this.documentables.firstOrNull()") - ) - public val documentable: Documentable? - get() = if (this is WithDocumentables) this.documentables.firstOrNull() else null - - public fun modified( - name: String = this.name, - content: ContentNode = this.content, - dri: Set<DRI> = this.dri, - embeddedResources: List<String> = this.embeddedResources, - children: List<PageNode> = this.children - ): ContentPage -} - -public interface WithDocumentables { - public val documentables: List<Documentable> -} - -public abstract class RootPageNode( - public val forceTopLevelName: Boolean = false -) : PageNode { - public val parentMap: Map<PageNode, PageNode> by lazy { - IdentityHashMap<PageNode, PageNode>().apply { - fun process(parent: PageNode) { - parent.children.forEach { child -> - put(child, parent) - process(child) - } - } - process(this@RootPageNode) - } - } - - public fun transformPageNodeTree(operation: (PageNode) -> PageNode): RootPageNode = - this.transformNode(operation) as RootPageNode - - public fun transformContentPagesTree(operation: (ContentPage) -> ContentPage): RootPageNode = transformPageNodeTree { - if (it is ContentPage) operation(it) else it - } - - private fun PageNode.transformNode(operation: (PageNode) -> PageNode): PageNode = - operation(this).let { newNode -> - newNode.modified(children = newNode.children.map { it.transformNode(operation) }) - } - - abstract override fun modified( - name: String, - children: List<PageNode> - ): RootPageNode -} - -public class ModulePageNode( - override val name: String, - override val content: ContentNode, - override val documentables: List<Documentable> = listOf(), - override val children: List<PageNode>, - override val embeddedResources: List<String> = listOf() -) : RootPageNode(), ModulePage { - override val dri: Set<DRI> = setOf(DRI.topLevel) - - override fun modified(name: String, children: List<PageNode>): ModulePageNode = - modified(name = name, content = this.content, dri = dri, children = children) - - override fun modified( - name: String, - content: ContentNode, - dri: Set<DRI>, - embeddedResources: List<String>, - children: List<PageNode> - ): ModulePageNode = - if (name == this.name && content === this.content && embeddedResources === this.embeddedResources && children shallowEq this.children) this - else ModulePageNode(name, content, documentables, children, embeddedResources) -} - -public class PackagePageNode( - override val name: String, - override val content: ContentNode, - override val dri: Set<DRI>, - override val documentables: List<Documentable> = listOf(), - override val children: List<PageNode>, - override val embeddedResources: List<String> = listOf() -) : PackagePage { - - init { - require(name.isNotBlank()) { "PackagePageNode.name cannot be blank" } - } - - override fun modified(name: String, children: List<PageNode>): PackagePageNode = - modified(name = name, content = this.content, children = children) - - override fun modified( - name: String, - content: ContentNode, - dri: Set<DRI>, - embeddedResources: List<String>, - children: List<PageNode> - ): PackagePageNode = - if (name == this.name && content === this.content && embeddedResources === this.embeddedResources && children shallowEq this.children) this - else PackagePageNode(name, content, dri, documentables, children, embeddedResources) -} - -public class ClasslikePageNode( - override val name: String, - override val content: ContentNode, - override val dri: Set<DRI>, - override val documentables: List<Documentable> = listOf(), - override val children: List<PageNode>, - override val embeddedResources: List<String> = listOf() -) : ClasslikePage { - override fun modified(name: String, children: List<PageNode>): ClasslikePageNode = - modified(name = name, content = this.content, children = children) - - override fun modified( - name: String, - content: ContentNode, - dri: Set<DRI>, - embeddedResources: List<String>, - children: List<PageNode> - ): ClasslikePageNode = - if (name == this.name && content === this.content && embeddedResources === this.embeddedResources && children shallowEq this.children) this - else ClasslikePageNode(name, content, dri, documentables, children, embeddedResources) -} - -public class MemberPageNode( - override val name: String, - override val content: ContentNode, - override val dri: Set<DRI>, - override val documentables: List<Documentable> = listOf(), - override val children: List<PageNode> = emptyList(), - override val embeddedResources: List<String> = listOf() -) : MemberPage { - override fun modified(name: String, children: List<PageNode>): MemberPageNode = - modified(name = name, content = this.content, children = children) - - override fun modified( - name: String, - content: ContentNode, - dri: Set<DRI>, - embeddedResources: List<String>, - children: List<PageNode> - ): MemberPageNode = - if (name == this.name && content === this.content && embeddedResources === this.embeddedResources && children shallowEq this.children) this - else MemberPageNode(name, content, dri, documentables, children, embeddedResources) -} - - -public class MultimoduleRootPageNode( - override val dri: Set<DRI>, - override val content: ContentNode, - override val embeddedResources: List<String> = emptyList() -) : RootPageNode(forceTopLevelName = true), MultimoduleRootPage { - override val name: String = "All modules" - - override val children: List<PageNode> = emptyList() - - override fun modified(name: String, children: List<PageNode>): RootPageNode = - MultimoduleRootPageNode(dri, content, embeddedResources) - - override fun modified( - name: String, - content: ContentNode, - dri: Set<DRI>, - embeddedResources: List<String>, - children: List<PageNode> - ): ContentPage = - if (name == this.name && content === this.content && embeddedResources === this.embeddedResources && children shallowEq this.children) this - else MultimoduleRootPageNode(dri, content, embeddedResources) -} - -public inline fun <reified T : PageNode> PageNode.children(): List<T> = children.filterIsInstance<T>() - -private infix fun <T> List<T>.shallowEq(other: List<T>) = - this === other || (this.size == other.size && (this zip other).all { (a, b) -> a === b }) diff --git a/core/src/main/kotlin/pages/Pages.kt b/core/src/main/kotlin/pages/Pages.kt deleted file mode 100644 index 0bf225c9..00000000 --- a/core/src/main/kotlin/pages/Pages.kt +++ /dev/null @@ -1,15 +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.pages - -public interface MultimoduleRootPage : ContentPage - -public interface ModulePage : ContentPage, WithDocumentables - -public interface PackagePage : ContentPage, WithDocumentables - -public interface ClasslikePage : ContentPage, WithDocumentables - -public interface MemberPage : ContentPage, WithDocumentables diff --git a/core/src/main/kotlin/pages/RendererSpecificPage.kt b/core/src/main/kotlin/pages/RendererSpecificPage.kt deleted file mode 100644 index 701886b7..00000000 --- a/core/src/main/kotlin/pages/RendererSpecificPage.kt +++ /dev/null @@ -1,52 +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.pages - -import org.jetbrains.dokka.links.DRI -import org.jetbrains.dokka.model.DisplaySourceSet -import org.jetbrains.dokka.renderers.Renderer -import kotlin.reflect.KClass - -public fun interface DriResolver: (DRI, Set<DisplaySourceSet>) -> String? -public fun interface PageResolver: (PageNode, PageNode?) -> String? - -public interface RendererSpecificPage : PageNode { - public val strategy: RenderingStrategy -} - -public class RendererSpecificRootPage( - override val name: String, - override val children: List<PageNode>, - override val strategy: RenderingStrategy -) : RootPageNode(), RendererSpecificPage { - override fun modified(name: String, children: List<PageNode>): RendererSpecificRootPage = - RendererSpecificRootPage(name, children, strategy) -} - -public class RendererSpecificResourcePage( - override val name: String, - override val children: List<PageNode>, - override val strategy: RenderingStrategy -): RendererSpecificPage { - override fun modified(name: String, children: List<PageNode>): RendererSpecificResourcePage = - RendererSpecificResourcePage(name, children, strategy) -} - -public sealed class RenderingStrategy { - public class Callback(public val instructions: Renderer.(PageNode) -> String): RenderingStrategy() - public data class Copy(val from: String) : RenderingStrategy() - public data class Write(val text: String) : RenderingStrategy() - public data class DriLocationResolvableWrite(val contentToResolve: (DriResolver) -> String) : RenderingStrategy() - public data class PageLocationResolvableWrite(val contentToResolve: (PageResolver) -> String) : RenderingStrategy() - public object DoNothing : RenderingStrategy() - - public companion object { - public inline operator fun <reified T: Renderer> invoke(crossinline instructions: T.(PageNode) -> String): RenderingStrategy { - return Callback { if (this is T) instructions(it) else throw WrongRendererTypeException(T::class) } - } - } -} - -public data class WrongRendererTypeException(val expectedType: KClass<*>): Exception() diff --git a/core/src/main/kotlin/pages/contentNodeProperties.kt b/core/src/main/kotlin/pages/contentNodeProperties.kt deleted file mode 100644 index 64f19572..00000000 --- a/core/src/main/kotlin/pages/contentNodeProperties.kt +++ /dev/null @@ -1,37 +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.pages - -import org.jetbrains.dokka.model.properties.ExtraProperty - -public class SimpleAttr( - public val extraKey: String, - public val extraValue: String -) : ExtraProperty<ContentNode> { - public data class SimpleAttrKey(val key: String) : ExtraProperty.Key<ContentNode, SimpleAttr> - override val key: ExtraProperty.Key<ContentNode, SimpleAttr> = SimpleAttrKey(extraKey) - -} - -public enum class BasicTabbedContentType : TabbedContentType { - TYPE, CONSTRUCTOR, FUNCTION, PROPERTY, ENTRY, EXTENSION_PROPERTY, EXTENSION_FUNCTION -} - -/** - * It is used only to mark content for tabs in HTML format - */ -public interface TabbedContentType - -/** - * @see TabbedContentType - */ -public class TabbedContentTypeExtra(public val value: TabbedContentType) : ExtraProperty<ContentNode> { - public companion object : ExtraProperty.Key<ContentNode, TabbedContentTypeExtra> - override val key: ExtraProperty.Key<ContentNode, TabbedContentTypeExtra> = TabbedContentTypeExtra -} - -public object HtmlContent : ExtraProperty<ContentNode>, ExtraProperty.Key<ContentNode, HtmlContent> { - override val key: ExtraProperty.Key<ContentNode, *> = this -} diff --git a/core/src/main/kotlin/pages/utils.kt b/core/src/main/kotlin/pages/utils.kt deleted file mode 100644 index 6c416e24..00000000 --- a/core/src/main/kotlin/pages/utils.kt +++ /dev/null @@ -1,63 +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.pages - -import kotlin.reflect.KClass - -public inline fun <reified T : ContentNode, R : ContentNode> R.mapTransform(noinline operation: (T) -> T): R = - mapTransform(T::class, operation) - -public inline fun <reified T : ContentNode, R : ContentNode> R.recursiveMapTransform(noinline operation: (T) -> T): R = - recursiveMapTransform(T::class, operation) - -@PublishedApi -@Suppress("UNCHECKED_CAST") -internal fun <T : ContentNode, R : ContentNode> R.mapTransform(type: KClass<T>, operation: (T) -> T): R { - if (this::class == type) { - return operation(this as T) as R - } - val new = when (this) { - is ContentGroup -> copy(children = children.map { it.mapTransform(type, operation) }) - is ContentHeader -> copy(children = children.map { it.mapTransform(type, operation) }) - is ContentCodeBlock -> copy(children = children.map { it.mapTransform(type, operation) }) - is ContentCodeInline -> copy(children = children.map { it.mapTransform(type, operation) }) - is ContentTable -> copy(header = header.map { it.recursiveMapTransform(type, operation) }, children = children.map { it.recursiveMapTransform(type, operation) }) - is ContentList -> copy(children = children.map { it.mapTransform(type, operation) }) - is ContentDivergentGroup -> copy(children = children.map { it.mapTransform(type, operation) }) - is ContentDivergentInstance -> copy( - before = before?.mapTransform(type, operation), - divergent = divergent.mapTransform(type, operation), - after = after?.mapTransform(type, operation) - ) - is PlatformHintedContent -> copy(inner = inner.mapTransform(type, operation)) - else -> this - } - return new as R -} - -@PublishedApi -@Suppress("UNCHECKED_CAST") -internal fun <T : ContentNode, R : ContentNode> R.recursiveMapTransform(type: KClass<T>, operation: (T) -> T): R { - val new = when (this) { - is ContentGroup -> copy(children = children.map { it.recursiveMapTransform(type, operation) }) - is ContentHeader -> copy(children = children.map { it.recursiveMapTransform(type, operation) }) - is ContentCodeBlock -> copy(children = children.map { it.recursiveMapTransform(type, operation) }) - is ContentCodeInline -> copy(children = children.map { it.recursiveMapTransform(type, operation) }) - is ContentTable -> copy(header = header.map { it.recursiveMapTransform(type, operation) }, children = children.map { it.recursiveMapTransform(type, operation) }) - is ContentList -> copy(children = children.map { it.recursiveMapTransform(type, operation) }) - is ContentDivergentGroup -> copy(children = children.map { it.recursiveMapTransform(type, operation) }) - is ContentDivergentInstance -> copy( - before = before?.recursiveMapTransform(type, operation), - divergent = divergent.recursiveMapTransform(type, operation), - after = after?.recursiveMapTransform(type, operation) - ) - is PlatformHintedContent -> copy(inner = inner.recursiveMapTransform(type, operation)) - else -> this - } - if (new::class == type) { - return operation(new as T) as R - } - return new as R -} diff --git a/core/src/main/kotlin/plugability/DokkaContext.kt b/core/src/main/kotlin/plugability/DokkaContext.kt deleted file mode 100644 index 1287e58b..00000000 --- a/core/src/main/kotlin/plugability/DokkaContext.kt +++ /dev/null @@ -1,235 +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.plugability - -import org.jetbrains.dokka.DokkaConfiguration -import org.jetbrains.dokka.utilities.DokkaLogger -import java.io.File -import java.net.URLClassLoader -import java.util.* -import kotlin.reflect.KClass -import kotlin.reflect.full.createInstance - -public interface DokkaContext { - public fun <T : DokkaPlugin> plugin(kclass: KClass<T>): T? - - public operator fun <T, E> get(point: E): List<T> - where T : Any, E : ExtensionPoint<T> - - public fun <T, E> single(point: E): T where T : Any, E : ExtensionPoint<T> - - public val logger: DokkaLogger - public val configuration: DokkaConfiguration - public val unusedPoints: Collection<ExtensionPoint<*>> - - public companion object { - public fun create( - configuration: DokkaConfiguration, - logger: DokkaLogger, - pluginOverrides: List<DokkaPlugin> - ): DokkaContext = - DokkaContextConfigurationImpl(logger, configuration).apply { - // File(it.path) is a workaround for an incorrect filesystem in a File instance returned by Gradle. - configuration.pluginsClasspath.map { File(it.path).toURI().toURL() } - .toTypedArray() - .let { URLClassLoader(it, this.javaClass.classLoader) } - .also { checkClasspath(it) } - .let { ServiceLoader.load(DokkaPlugin::class.java, it) } - .let { it + pluginOverrides } - .forEach { install(it) } - topologicallySortAndPrune() - }.also { it.logInitialisationInfo() } - } -} - -public inline fun <reified T : DokkaPlugin> DokkaContext.plugin(): T = plugin(T::class) - ?: throw java.lang.IllegalStateException("Plugin ${T::class.qualifiedName} is not present in context.") - -public fun interface DokkaContextConfiguration { - public fun installExtension(extension: Extension<*, *, *>) -} - -private class DokkaContextConfigurationImpl( - override val logger: DokkaLogger, - override val configuration: DokkaConfiguration -) : DokkaContext, DokkaContextConfiguration { - private val plugins = mutableMapOf<KClass<*>, DokkaPlugin>() - private val pluginStubs = mutableMapOf<KClass<*>, DokkaPlugin>() - val extensions = mutableMapOf<ExtensionPoint<*>, MutableList<Extension<*, *, *>>>() - val pointsUsed: MutableSet<ExtensionPoint<*>> = mutableSetOf() - val pointsPopulated: MutableSet<ExtensionPoint<*>> = mutableSetOf() - override val unusedPoints: Set<ExtensionPoint<*>> - get() = pointsPopulated - pointsUsed - - private enum class State { - UNVISITED, - VISITING, - VISITED; - } - - private sealed class Suppression { - data class ByExtension(val extension: Extension<*, *, *>) : Suppression() { - override fun toString() = extension.toString() - } - - data class ByPlugin(val plugin: DokkaPlugin) : Suppression() { - override fun toString() = "Plugin ${plugin::class.qualifiedName}" - } - } - - private val rawExtensions = mutableListOf<Extension<*, *, *>>() - private val rawAdjacencyList = mutableMapOf<Extension<*, *, *>, MutableList<Extension<*, *, *>>>() - private val suppressedExtensions = mutableMapOf<Extension<*, *, *>, MutableList<Suppression>>() - - fun topologicallySortAndPrune() { - pointsPopulated.clear() - extensions.clear() - - val overridesInfo = processOverrides() - val extensionsToSort = overridesInfo.keys - val adjacencyList = translateAdjacencyList(overridesInfo) - - val verticesWithState = extensionsToSort.associateWithTo(mutableMapOf()) { State.UNVISITED } - val result: MutableList<Extension<*, *, *>> = mutableListOf() - - fun visit(n: Extension<*, *, *>) { - val state = verticesWithState[n] - if (state == State.VISITED) - return - if (state == State.VISITING) - throw Error("Detected cycle in plugins graph") - verticesWithState[n] = State.VISITING - adjacencyList[n]?.forEach { visit(it) } - verticesWithState[n] = State.VISITED - result += n - } - - extensionsToSort.forEach(::visit) - - val filteredResult = result.asReversed().filterNot { it in suppressedExtensions } - - filteredResult.mapTo(pointsPopulated) { it.extensionPoint } - filteredResult.groupByTo(extensions) { it.extensionPoint } - } - - private fun processOverrides(): Map<Extension<*, *, *>, Set<Extension<*, *, *>>> { - val buckets = rawExtensions.associateWithTo(mutableMapOf()) { setOf(it) } - suppressedExtensions.forEach { (extension, suppressions) -> - val mergedBucket = suppressions.filterIsInstance<Suppression.ByExtension>() - .map { it.extension } - .plus(extension) - .flatMap { buckets[it].orEmpty() } - .toSet() - mergedBucket.forEach { buckets[it] = mergedBucket } - } - return buckets.values.distinct().associateBy(::findNotOverridden) - } - - private fun findNotOverridden(bucket: Set<Extension<*, *, *>>): Extension<*, *, *> { - // Let's filter out all suppressedExtensions that are not only overrides. - // suppressedExtensions can be polluted by suppressions that completely disables the extension, and would break dokka behaviour - // if not filtered out - val suppressedExtensionsByOverrides = suppressedExtensions.filterNot { it.value.any { it !is Suppression.ByExtension } } - val filtered = bucket.filterNot { it in suppressedExtensionsByOverrides } - return filtered.singleOrNull() - ?: throw IllegalStateException("Conflicting overrides: $filtered") - } - - private fun translateAdjacencyList( - overridesInfo: Map<Extension<*, *, *>, Set<Extension<*, *, *>>> - ): Map<Extension<*, *, *>, List<Extension<*, *, *>>> { - val reverseOverrideInfo = overridesInfo.flatMap { (ext, set) -> set.map { it to ext } }.toMap() - return rawAdjacencyList.mapNotNull { (ext, list) -> - reverseOverrideInfo[ext]?.to(list.mapNotNull { reverseOverrideInfo[it] }) - }.toMap() - } - - @Suppress("UNCHECKED_CAST") - override operator fun <T, E> get(point: E) where T : Any, E : ExtensionPoint<T> = - actions(point).also { pointsUsed += point }.orEmpty() as List<T> - - @Suppress("UNCHECKED_CAST") - override fun <T, E> single(point: E): T where T : Any, E : ExtensionPoint<T> { - fun throwBadArity(substitution: String): Nothing = throw IllegalStateException( - "$point was expected to have exactly one extension registered, but $substitution found." - ) - pointsUsed += point - - val extensions = extensions[point].orEmpty() as List<Extension<T, *, *>> - return when (extensions.size) { - 0 -> throwBadArity("none was") - 1 -> extensions.single().action.get(this) - else -> throwBadArity("many were") - } - } - - private fun <E : ExtensionPoint<*>> actions(point: E) = extensions[point]?.map { it.action.get(this) } - - @Suppress("UNCHECKED_CAST") - override fun <T : DokkaPlugin> plugin(kclass: KClass<T>) = (plugins[kclass] ?: pluginStubFor(kclass)) as T - - private fun <T : DokkaPlugin> pluginStubFor(kclass: KClass<T>): DokkaPlugin = - pluginStubs.getOrPut(kclass) { kclass.createInstance().also { it.context = this } } - - fun install(plugin: DokkaPlugin) { - plugins[plugin::class] = plugin - plugin.context = this - plugin.internalInstall(this, this.configuration) - - if (plugin is WithUnsafeExtensionSuppression) { - plugin.extensionsSuppressed.forEach { - suppressedExtensions.listFor(it) += Suppression.ByPlugin(plugin) - } - } - } - - override fun installExtension(extension: Extension<*, *, *>) { - rawExtensions += extension - - if (extension.ordering is OrderingKind.ByDsl) { - val orderDsl = OrderDsl() - orderDsl.(extension.ordering.block)() - - rawAdjacencyList.listFor(extension) += orderDsl.following.toList() - orderDsl.previous.forEach { rawAdjacencyList.listFor(it) += extension } - } - - if (extension.override is OverrideKind.Present) { - fun root(ext: Extension<*, *, *>): List<Extension<*, *, *>> = if (ext.override is OverrideKind.Present) ext.override.overriden.flatMap(::root) else listOf(ext) - if (extension.override.overriden.size > 1 && root(extension).distinct().size > 1) - throw IllegalStateException("Extension $extension overrides extensions without common root") - extension.override.overriden.forEach { overriden -> - suppressedExtensions.listFor(overriden) += Suppression.ByExtension(extension) - } - } - } - - fun logInitialisationInfo() { - val pluginNames = plugins.values.map { it::class.qualifiedName.toString() } - - val loadedListForDebug = extensions.run { keys + values.flatten() }.toList() - .joinToString(prefix = "[\n", separator = ",\n", postfix = "\n]") { "\t$it" } - - val suppressedList = suppressedExtensions.asSequence() - .joinToString(prefix = "[\n", separator = ",\n", postfix = "\n]") { - "\t${it.key} by " + (it.value.singleOrNull() ?: it.value) - } - - logger.info("Loaded plugins: $pluginNames") - logger.info("Loaded: $loadedListForDebug") - logger.info("Suppressed: $suppressedList") - } -} - -private fun checkClasspath(classLoader: URLClassLoader) { - classLoader.findResource(DokkaContext::class.java.name.replace('.', '/') + ".class")?.also { - throw AssertionError( - "Dokka API found on plugins classpath. This will lead to subtle bugs. " + - "Please fix your plugins dependencies or exclude dokka api artifact from plugin classpath" - ) - } -} - -private fun <K, V> MutableMap<K, MutableList<V>>.listFor(key: K) = getOrPut(key, ::mutableListOf) diff --git a/core/src/main/kotlin/plugability/DokkaJavaPlugin.kt b/core/src/main/kotlin/plugability/DokkaJavaPlugin.kt deleted file mode 100644 index 3c2f5e65..00000000 --- a/core/src/main/kotlin/plugability/DokkaJavaPlugin.kt +++ /dev/null @@ -1,78 +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.plugability - -import org.jetbrains.dokka.DokkaConfiguration - -public class ExtensionBuilderStart internal constructor(){ - public fun <T: Any> extensionPoint(ext: ExtensionPoint<T>): ProvidedExtension<T> = ProvidedExtension(ext) -} - -public class ProvidedExtension<T: Any> internal constructor( - public val ext: ExtensionPoint<T> -) { - public fun fromInstance(inst: T): ExtensionBuilder<T> = createBuilder( - LazyEvaluated.fromInstance( - inst - ) - ) - public fun fromRecipe(recipe: (DokkaContext) -> T): ExtensionBuilder<T> = createBuilder( - LazyEvaluated.fromRecipe(recipe) - ) - - private val defaultName = "${ext.pointName}/in/${javaClass.simpleName}" - - private fun createBuilder(action: LazyEvaluated<T>) = - ExtensionBuilder(defaultName, ext, action, - emptyList(), emptyList(), - OverrideKind.None, emptyList()) -} - -public data class ExtensionBuilder<T: Any> internal constructor( - private val name: String, - private val ext: ExtensionPoint<T>, - private val action: LazyEvaluated<T>, - private val before: List<Extension<*, *, *>>, - private val after: List<Extension<*, *, *>>, - private val override: OverrideKind = OverrideKind.None, - private val conditions: List<(DokkaConfiguration) -> Boolean> -){ - public fun build(): Extension<T, *, *> = Extension( - ext, - javaClass.name, - name, - action, - OrderingKind.ByDsl { - before(*before.toTypedArray()) - after(*after.toTypedArray()) - }, - override, - conditions - ) - - public fun overrideExtension(extension: Extension<T, *, *>): ExtensionBuilder<T> = copy(override = OverrideKind.Present(listOf(extension))) - - public fun newOrdering(before: Array<out Extension<*, *, *>>, after: Array<out Extension<*, *, *>>): ExtensionBuilder<T> = - copy(before = this.before + before, after = this.after + after) - - public fun before(vararg exts: Extension<*, *, *>): ExtensionBuilder<T> = copy(before = this.before + exts) - - public fun after(vararg exts: Extension<*, *, *>): ExtensionBuilder<T> = copy(after = this.after + exts) - - public fun addCondition(c: (DokkaConfiguration) -> Boolean): ExtensionBuilder<T> = copy(conditions = conditions + c) - - public fun name(name: String): ExtensionBuilder<T> = copy(name = name) -} - -public abstract class DokkaJavaPlugin: DokkaPlugin() { - - public fun <T: DokkaPlugin> plugin(clazz: Class<T>): T = - context?.plugin(clazz.kotlin) ?: throwIllegalQuery() - - - public fun <T: Any> extend(func: (ExtensionBuilderStart) -> ExtensionBuilder<T>): Lazy<Extension<T, *, *>> = - lazy { func(ExtensionBuilderStart()).build() }.also { unsafeInstall(it) } - -} diff --git a/core/src/main/kotlin/plugability/DokkaPlugin.kt b/core/src/main/kotlin/plugability/DokkaPlugin.kt deleted file mode 100644 index 7e15c325..00000000 --- a/core/src/main/kotlin/plugability/DokkaPlugin.kt +++ /dev/null @@ -1,114 +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.plugability - -import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule -import com.fasterxml.jackson.dataformat.xml.XmlMapper -import com.fasterxml.jackson.module.kotlin.readValue -import org.jetbrains.dokka.DokkaConfiguration -import org.jetbrains.dokka.utilities.DokkaLogger -import org.jetbrains.dokka.utilities.parseJson -import kotlin.properties.ReadOnlyProperty -import kotlin.reflect.KProperty -import kotlin.reflect.KProperty1 - -@RequiresOptIn( - level = RequiresOptIn.Level.WARNING, - message = "All of Dokka's plugin API is in preview and it can be changed " + - "in a backwards-incompatible manner with a best-effort migration. " + - "By opting in, you acknowledge the risks of relying on preview API." -) -@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.FIELD) -@Retention(AnnotationRetention.BINARY) -public annotation class DokkaPluginApiPreview - -/** - * Acknowledgement for empty methods that inform users about [DokkaPluginApiPreview] - * Also, it allows to not propagates the annotation in IDE by default when a user autogenerate methods. - */ -@DokkaPluginApiPreview -public object PluginApiPreviewAcknowledgement - -public abstract class DokkaPlugin { - private val extensionDelegates = mutableListOf<KProperty<*>>() - private val unsafePlugins = mutableListOf<Lazy<Extension<*, *, *>>>() - - @PublishedApi - internal var context: DokkaContext? = null - - protected val logger: DokkaLogger get() = context?.logger ?: throw IllegalStateException("No logger found") - - /** - * @see PluginApiPreviewAcknowledgement - */ - @OptIn(DokkaPluginApiPreview::class) - protected abstract fun pluginApiPreviewAcknowledgement(): PluginApiPreviewAcknowledgement - protected inline fun <reified T : DokkaPlugin> plugin(): T = context?.plugin(T::class) ?: throwIllegalQuery() - - protected fun <T : Any> extensionPoint(): ReadOnlyProperty<DokkaPlugin, ExtensionPoint<T>> { - return ReadOnlyProperty { thisRef, property -> - ExtensionPoint( - thisRef::class.qualifiedName ?: throw AssertionError("Plugin must be named class"), - property.name - ) - } - } - protected fun <T : Any> extending(definition: ExtendingDSL.() -> Extension<T, *, *>): ExtensionProvider<T> { - return ExtensionProvider(definition) - } - - protected class ExtensionProvider<T : Any> internal constructor( - private val definition: ExtendingDSL.() -> Extension<T, *, *> - ) { - public operator fun provideDelegate(thisRef: DokkaPlugin, property: KProperty<*>): Lazy<Extension<T, *, *>> { - return lazy { - ExtendingDSL( - thisRef::class.qualifiedName ?: throw AssertionError("Plugin must be named class"), - property.name - ).definition() - }.also { thisRef.extensionDelegates += property } - } - } - - internal fun internalInstall(ctx: DokkaContextConfiguration, configuration: DokkaConfiguration) { - val extensionsToInstall = extensionDelegates.asSequence() - .filterIsInstance<KProperty1<DokkaPlugin, Extension<*, *, *>>>() // should be always true - .map { it.get(this) } + unsafePlugins.map { it.value } - - extensionsToInstall.forEach { if (configuration.(it.condition)()) ctx.installExtension(it) } - } - - protected fun <T : Any> unsafeInstall(ext: Lazy<Extension<T, *, *>>) { - unsafePlugins.add(ext) - } -} - -public interface WithUnsafeExtensionSuppression { - public val extensionsSuppressed: List<Extension<*, *, *>> -} - -public interface ConfigurableBlock - -public inline fun <reified P : DokkaPlugin, reified E : Any> P.query(extension: P.() -> ExtensionPoint<E>): List<E> = - context?.let { it[extension()] } ?: throwIllegalQuery() - -public inline fun <reified P : DokkaPlugin, reified E : Any> P.querySingle(extension: P.() -> ExtensionPoint<E>): E = - context?.single(extension()) ?: throwIllegalQuery() - -public fun throwIllegalQuery(): Nothing = - throw IllegalStateException("Querying about plugins is only possible with dokka context initialised") - -public inline fun <reified T : DokkaPlugin, reified R : ConfigurableBlock> configuration(context: DokkaContext): R? = - context.configuration.pluginsConfiguration.firstOrNull { it.fqPluginName == T::class.qualifiedName } - ?.let { configuration -> - when (configuration.serializationFormat) { - DokkaConfiguration.SerializationFormat.JSON -> parseJson(configuration.values) - DokkaConfiguration.SerializationFormat.XML -> XmlMapper(JacksonXmlModule().apply { - setDefaultUseWrapper( - true - ) - }).readValue<R>(configuration.values) - } - } diff --git a/core/src/main/kotlin/plugability/LazyEvaluated.kt b/core/src/main/kotlin/plugability/LazyEvaluated.kt deleted file mode 100644 index 46f15b17..00000000 --- a/core/src/main/kotlin/plugability/LazyEvaluated.kt +++ /dev/null @@ -1,21 +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.plugability - -internal class LazyEvaluated<T : Any> private constructor(private val recipe: ((DokkaContext) -> T)? = null, private var value: T? = null) { - - @Synchronized - internal fun get(context: DokkaContext): T { - if(value == null) { - value = recipe?.invoke(context) - } - return value ?: throw AssertionError("Incorrect initialized LazyEvaluated instance") - } - - companion object { - fun <T : Any> fromInstance(value: T) = LazyEvaluated(value = value) - fun <T : Any> fromRecipe(recipe: (DokkaContext) -> T) = LazyEvaluated(recipe = recipe) - } -} diff --git a/core/src/main/kotlin/plugability/extensions.kt b/core/src/main/kotlin/plugability/extensions.kt deleted file mode 100644 index 04212d1a..00000000 --- a/core/src/main/kotlin/plugability/extensions.kt +++ /dev/null @@ -1,110 +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.plugability - -import org.jetbrains.dokka.DokkaConfiguration - -public data class ExtensionPoint<T : Any> internal constructor( - internal val pluginClass: String, - internal val pointName: String -) { - override fun toString(): String = "ExtensionPoint: $pluginClass/$pointName" -} - -public sealed class OrderingKind { - public object None : OrderingKind() - - public class ByDsl( - public val block: (OrderDsl.() -> Unit) - ) : OrderingKind() -} - -public sealed class OverrideKind { - public object None : OverrideKind() - public class Present( - public val overriden: List<Extension<*, *, *>> - ) : OverrideKind() -} - -public class Extension<T : Any, Ordering : OrderingKind, Override : OverrideKind> internal constructor( - internal val extensionPoint: ExtensionPoint<T>, - internal val pluginClass: String, - internal val extensionName: String, - internal val action: LazyEvaluated<T>, - internal val ordering: Ordering, - internal val override: Override, - internal val conditions: List<DokkaConfiguration.() -> Boolean> -) { - override fun toString(): String = "Extension: $pluginClass/$extensionName" - - override fun equals(other: Any?): Boolean = - if (other is Extension<*, *, *>) this.pluginClass == other.pluginClass && this.extensionName == other.extensionName - else false - - override fun hashCode(): Int = listOf(pluginClass, extensionName).hashCode() - - public val condition: DokkaConfiguration.() -> Boolean - get() = { conditions.all { it(this) } } -} - -internal fun <T : Any> Extension( - extensionPoint: ExtensionPoint<T>, - pluginClass: String, - extensionName: String, - action: LazyEvaluated<T> -) = Extension(extensionPoint, pluginClass, extensionName, action, OrderingKind.None, OverrideKind.None, emptyList()) - -@DslMarker -public annotation class ExtensionsDsl - -@ExtensionsDsl -public class ExtendingDSL(private val pluginClass: String, private val extensionName: String) { - - public infix fun <T : Any> ExtensionPoint<T>.with(action: T): Extension<T, OrderingKind.None, OverrideKind.None> { - return Extension(this, this@ExtendingDSL.pluginClass, extensionName, LazyEvaluated.fromInstance(action)) - } - - public infix fun <T : Any> ExtensionPoint<T>.providing(action: (DokkaContext) -> T): Extension<T, OrderingKind.None, OverrideKind.None> { - return Extension(this, this@ExtendingDSL.pluginClass, extensionName, LazyEvaluated.fromRecipe(action)) - } - - public infix fun <T : Any, Override : OverrideKind> Extension<T, OrderingKind.None, Override>.order( - block: OrderDsl.() -> Unit - ): Extension<T, OrderingKind.ByDsl, Override> { - return Extension(extensionPoint, pluginClass, extensionName, action, OrderingKind.ByDsl(block), override, conditions) - } - - public infix fun <T : Any, Override : OverrideKind, Ordering: OrderingKind> Extension<T, Ordering, Override>.applyIf( - condition: DokkaConfiguration.() -> Boolean - ): Extension<T, Ordering, Override> { - return Extension(extensionPoint, pluginClass, extensionName, action, ordering, override, conditions + condition) - } - - public infix fun <T : Any, Override : OverrideKind, Ordering: OrderingKind> Extension<T, Ordering, Override>.override( - overriden: List<Extension<T, *, *>> - ): Extension<T, Ordering, OverrideKind.Present> { - return Extension(extensionPoint, pluginClass, extensionName, action, ordering, OverrideKind.Present(overriden), conditions) - } - - public infix fun <T : Any, Override : OverrideKind, Ordering: OrderingKind> Extension<T, Ordering, Override>.override( - overriden: Extension<T, *, *> - ): Extension<T, Ordering, OverrideKind.Present> { - return this.override(listOf(overriden)) - } -} - -@ExtensionsDsl -public class OrderDsl { - internal val previous = mutableSetOf<Extension<*, *, *>>() - internal val following = mutableSetOf<Extension<*, *, *>>() - - public fun after(vararg extensions: Extension<*, *, *>) { - previous += extensions - } - - public fun before(vararg extensions: Extension<*, *, *>) { - following += extensions - } -} diff --git a/core/src/main/kotlin/renderers/PostAction.kt b/core/src/main/kotlin/renderers/PostAction.kt deleted file mode 100644 index 191a77b3..00000000 --- a/core/src/main/kotlin/renderers/PostAction.kt +++ /dev/null @@ -1,7 +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.renderers - -public fun interface PostAction : () -> Unit diff --git a/core/src/main/kotlin/renderers/Renderer.kt b/core/src/main/kotlin/renderers/Renderer.kt deleted file mode 100644 index f1583506..00000000 --- a/core/src/main/kotlin/renderers/Renderer.kt +++ /dev/null @@ -1,11 +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.renderers - -import org.jetbrains.dokka.pages.RootPageNode - -public fun interface Renderer { - public fun render(root: RootPageNode) -} diff --git a/core/src/main/kotlin/transformers/documentation/DefaultDocumentableMerger.kt b/core/src/main/kotlin/transformers/documentation/DefaultDocumentableMerger.kt deleted file mode 100644 index fe1e5d64..00000000 --- a/core/src/main/kotlin/transformers/documentation/DefaultDocumentableMerger.kt +++ /dev/null @@ -1,307 +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.transformers.documentation - -import org.jetbrains.dokka.DokkaConfiguration -import org.jetbrains.dokka.InternalDokkaApi -import org.jetbrains.dokka.model.* -import org.jetbrains.dokka.model.properties.ExtraProperty -import org.jetbrains.dokka.model.properties.MergeStrategy -import org.jetbrains.dokka.model.properties.mergeExtras -import org.jetbrains.dokka.plugability.DokkaContext -import org.jetbrains.dokka.CoreExtensions - -/** - * Should NOT be used outside of Dokka itself, there are no guarantees - * this class will continue to exist in future releases. - * - * This class resides in core because it is a non-trivial implementation - * for a core extension [CoreExtensions.documentableMerger], which is needed - * in modules that only have access to `dokka-core`. - */ -@InternalDokkaApi -public class DefaultDocumentableMerger(context: DokkaContext) : DocumentableMerger { - private val dependencyInfo = context.getDependencyInfo() - - override fun invoke(modules: Collection<DModule>): DModule? = - modules.reduceOrNull { left, right -> - val list = listOf(left, right) - DModule( - name = modules.map { it.name }.distinct().joinToString("|"), - packages = merge( - list.flatMap { it.packages } - ) { pck1, pck2 -> pck1.mergeWith(pck2) }, - documentation = list.map { it.documentation }.flatMap { it.entries }.associate { (k, v) -> k to v }, - expectPresentInSet = list.firstNotNullOfOrNull { it.expectPresentInSet }, - sourceSets = list.flatMap { it.sourceSets }.toSet() - ).mergeExtras(left, right) - } - - private fun DokkaContext.getDependencyInfo() - : Map<DokkaConfiguration.DokkaSourceSet, List<DokkaConfiguration.DokkaSourceSet>> { - - fun getDependencies(sourceSet: DokkaConfiguration.DokkaSourceSet): List<DokkaConfiguration.DokkaSourceSet> = - listOf(sourceSet) + configuration.sourceSets.filter { - it.sourceSetID in sourceSet.dependentSourceSets - }.flatMap { getDependencies(it) } - - return configuration.sourceSets.associateWith { getDependencies(it) } - } - - private fun <T : Documentable> merge(elements: List<T>, reducer: (T, T) -> T): List<T> = - elements.groupingBy { it.dri } - .reduce { _, left, right -> reducer(left, right) } - .values.toList() - - private fun <T> mergeExpectActual( - elements: List<T>, - reducer: (T, T) -> T - ): List<T> where T : Documentable, T : WithSources { - - fun mergeClashingElements(elements: List<Pair<T, Set<DokkaConfiguration.DokkaSourceSet>>>): List<T> = - elements.groupBy { it.first.name }.values.flatMap { listOfDocumentableToSSIds -> - val merged = listOfDocumentableToSSIds.map { (documentable, sourceSets) -> - when (documentable) { - is DClass -> documentable.copy( - extra = documentable.extra + ClashingDriIdentifier( - sourceSets + (documentable.extra[ClashingDriIdentifier]?.value ?: emptySet()) - ) - ) - is DObject -> documentable.copy( - extra = documentable.extra + ClashingDriIdentifier( - sourceSets + (documentable.extra[ClashingDriIdentifier]?.value ?: emptySet()) - ) - ) - is DAnnotation -> documentable.copy( - extra = documentable.extra + ClashingDriIdentifier( - sourceSets + (documentable.extra[ClashingDriIdentifier]?.value ?: emptySet()) - ) - ) - is DInterface -> documentable.copy( - extra = documentable.extra + ClashingDriIdentifier( - sourceSets + (documentable.extra[ClashingDriIdentifier]?.value ?: emptySet()) - ) - ) - is DEnum -> documentable.copy( - extra = documentable.extra + ClashingDriIdentifier( - sourceSets + (documentable.extra[ClashingDriIdentifier]?.value ?: emptySet()) - ) - ) - is DFunction -> documentable.copy( - extra = documentable.extra + ClashingDriIdentifier( - sourceSets + (documentable.extra[ClashingDriIdentifier]?.value ?: emptySet()) - ) - ) - is DProperty -> documentable.copy( - extra = documentable.extra + ClashingDriIdentifier( - sourceSets + (documentable.extra[ClashingDriIdentifier]?.value ?: emptySet()) - ) - ) - else -> documentable - } - } - @Suppress("UNCHECKED_CAST") - merged as List<T> - } - - - fun analyzeExpectActual(sameDriElements: List<T>): List<T> { - val (expects, actuals) = sameDriElements.partition { it.expectPresentInSet != null } - val groupedByOwnExpectWithActualSourceSetIds = expects.map { expect -> - val actualsForGivenExpect = actuals.filter { actual -> - dependencyInfo[actual.sourceSets.single()] - ?.contains(expect.expectPresentInSet!!) - ?: throw IllegalStateException("Cannot resolve expect/actual relation for ${actual.name}") - } - (listOf(expect) + actualsForGivenExpect) to actualsForGivenExpect.flatMap { it.sourceSets }.toSet() - } - val reducedToOneDocumentableWithActualSourceSetIds = - groupedByOwnExpectWithActualSourceSetIds.map { it.first.reduce(reducer) to it.second } - return reducedToOneDocumentableWithActualSourceSetIds.let(::mergeClashingElements) - } - - - return elements.partition { - (it as? WithIsExpectActual)?.isExpectActual ?: false - }.let { (expectActuals, notExpectActuals) -> - notExpectActuals.map { it to it.sourceSets } - .groupBy { it.first.dri }.values.flatMap(::mergeClashingElements) + - expectActuals.groupBy { it.dri }.values.flatMap(::analyzeExpectActual) - } - } - - public fun DPackage.mergeWith(other: DPackage): DPackage = copy( - functions = mergeExpectActual(functions + other.functions) { f1, f2 -> f1.mergeWith(f2) }, - properties = mergeExpectActual(properties + other.properties) { p1, p2 -> p1.mergeWith(p2) }, - classlikes = mergeExpectActual(classlikes + other.classlikes) { c1, c2 -> c1.mergeWith(c2) }, - documentation = documentation + other.documentation, - expectPresentInSet = expectPresentInSet ?: other.expectPresentInSet, - typealiases = merge(typealiases + other.typealiases) { ta1, ta2 -> ta1.mergeWith(ta2) }, - sourceSets = sourceSets + other.sourceSets - ).mergeExtras(this, other) - - public fun DFunction.mergeWith(other: DFunction): DFunction = copy( - parameters = merge(this.parameters + other.parameters) { p1, p2 -> p1.mergeWith(p2) }, - receiver = receiver?.let { r -> other.receiver?.let { r.mergeWith(it) } ?: r } ?: other.receiver, - documentation = documentation + other.documentation, - expectPresentInSet = expectPresentInSet ?: other.expectPresentInSet, - sources = sources + other.sources, - visibility = visibility + other.visibility, - modifier = modifier + other.modifier, - sourceSets = sourceSets + other.sourceSets, - generics = merge(generics + other.generics) { tp1, tp2 -> tp1.mergeWith(tp2) }, - ).mergeExtras(this, other) - - public fun DProperty.mergeWith(other: DProperty): DProperty = copy( - receiver = receiver?.let { r -> other.receiver?.let { r.mergeWith(it) } ?: r } ?: other.receiver, - documentation = documentation + other.documentation, - expectPresentInSet = expectPresentInSet ?: other.expectPresentInSet, - sources = sources + other.sources, - visibility = visibility + other.visibility, - modifier = modifier + other.modifier, - sourceSets = sourceSets + other.sourceSets, - getter = getter?.let { g -> other.getter?.let { g.mergeWith(it) } ?: g } ?: other.getter, - setter = setter?.let { s -> other.setter?.let { s.mergeWith(it) } ?: s } ?: other.setter, - generics = merge(generics + other.generics) { tp1, tp2 -> tp1.mergeWith(tp2) }, - ).mergeExtras(this, other) - - private fun DClasslike.mergeWith(other: DClasslike): DClasslike = when { - this is DClass && other is DClass -> mergeWith(other) - this is DEnum && other is DEnum -> mergeWith(other) - this is DInterface && other is DInterface -> mergeWith(other) - this is DObject && other is DObject -> mergeWith(other) - this is DAnnotation && other is DAnnotation -> mergeWith(other) - else -> throw IllegalStateException("${this::class.qualifiedName} ${this.name} cannot be merged with ${other::class.qualifiedName} ${other.name}") - } - - private fun DClass.mergeWith(other: DClass): DClass = copy( - constructors = mergeExpectActual( - constructors + other.constructors - ) { f1, f2 -> f1.mergeWith(f2) }, - functions = mergeExpectActual(functions + other.functions) { f1, f2 -> f1.mergeWith(f2) }, - properties = mergeExpectActual(properties + other.properties) { p1, p2 -> p1.mergeWith(p2) }, - classlikes = mergeExpectActual(classlikes + other.classlikes) { c1, c2 -> c1.mergeWith(c2) }, - companion = companion?.let { c -> other.companion?.let { c.mergeWith(it) } ?: c } ?: other.companion, - generics = merge(generics + other.generics) { tp1, tp2 -> tp1.mergeWith(tp2) }, - modifier = modifier + other.modifier, - supertypes = supertypes + other.supertypes, - documentation = documentation + other.documentation, - expectPresentInSet = expectPresentInSet ?: other.expectPresentInSet, - sources = sources + other.sources, - visibility = visibility + other.visibility, - sourceSets = sourceSets + other.sourceSets - ).mergeExtras(this, other) - - private fun DEnum.mergeWith(other: DEnum): DEnum = copy( - entries = merge(entries + other.entries) { ee1, ee2 -> ee1.mergeWith(ee2) }, - constructors = mergeExpectActual( - constructors + other.constructors - ) { f1, f2 -> f1.mergeWith(f2) }, - functions = mergeExpectActual(functions + other.functions) { f1, f2 -> f1.mergeWith(f2) }, - properties = mergeExpectActual(properties + other.properties) { p1, p2 -> p1.mergeWith(p2) }, - classlikes = mergeExpectActual(classlikes + other.classlikes) { c1, c2 -> c1.mergeWith(c2) }, - companion = companion?.let { c -> other.companion?.let { c.mergeWith(it) } ?: c } ?: other.companion, - supertypes = supertypes + other.supertypes, - documentation = documentation + other.documentation, - expectPresentInSet = expectPresentInSet ?: other.expectPresentInSet, - sources = sources + other.sources, - visibility = visibility + other.visibility, - sourceSets = sourceSets + other.sourceSets - ).mergeExtras(this, other) - - private fun DEnumEntry.mergeWith(other: DEnumEntry): DEnumEntry = copy( - functions = mergeExpectActual(functions + other.functions) { f1, f2 -> f1.mergeWith(f2) }, - properties = mergeExpectActual(properties + other.properties) { p1, p2 -> p1.mergeWith(p2) }, - classlikes = mergeExpectActual(classlikes + other.classlikes) { c1, c2 -> c1.mergeWith(c2) }, - documentation = documentation + other.documentation, - expectPresentInSet = expectPresentInSet ?: other.expectPresentInSet, - sourceSets = sourceSets + other.sourceSets - ).mergeExtras(this, other) - - private fun DObject.mergeWith(other: DObject): DObject = copy( - functions = mergeExpectActual(functions + other.functions) { f1, f2 -> f1.mergeWith(f2) }, - properties = mergeExpectActual(properties + other.properties) { p1, p2 -> p1.mergeWith(p2) }, - classlikes = mergeExpectActual(classlikes + other.classlikes) { c1, c2 -> c1.mergeWith(c2) }, - supertypes = supertypes + other.supertypes, - documentation = documentation + other.documentation, - expectPresentInSet = expectPresentInSet ?: other.expectPresentInSet, - sources = sources + other.sources, - visibility = visibility + other.visibility, - sourceSets = sourceSets + other.sourceSets - ).mergeExtras(this, other) - - private fun DInterface.mergeWith(other: DInterface): DInterface = copy( - functions = mergeExpectActual(functions + other.functions) { f1, f2 -> f1.mergeWith(f2) }, - properties = mergeExpectActual(properties + other.properties) { p1, p2 -> p1.mergeWith(p2) }, - classlikes = mergeExpectActual(classlikes + other.classlikes) { c1, c2 -> c1.mergeWith(c2) }, - companion = companion?.let { c -> other.companion?.let { c.mergeWith(it) } ?: c } ?: other.companion, - generics = merge(generics + other.generics) { tp1, tp2 -> tp1.mergeWith(tp2) }, - supertypes = supertypes + other.supertypes, - documentation = documentation + other.documentation, - expectPresentInSet = expectPresentInSet ?: other.expectPresentInSet, - sources = sources + other.sources, - visibility = visibility + other.visibility, - sourceSets = sourceSets + other.sourceSets - ).mergeExtras(this, other) - - private fun DAnnotation.mergeWith(other: DAnnotation): DAnnotation = copy( - constructors = mergeExpectActual( - constructors + other.constructors - ) { f1, f2 -> f1.mergeWith(f2) }, - functions = mergeExpectActual(functions + other.functions) { f1, f2 -> f1.mergeWith(f2) }, - properties = mergeExpectActual(properties + other.properties) { p1, p2 -> p1.mergeWith(p2) }, - classlikes = mergeExpectActual(classlikes + other.classlikes) { c1, c2 -> c1.mergeWith(c2) }, - companion = companion?.let { c -> other.companion?.let { c.mergeWith(it) } ?: c } ?: other.companion, - documentation = documentation + other.documentation, - expectPresentInSet = expectPresentInSet ?: other.expectPresentInSet, - sources = sources + other.sources, - visibility = visibility + other.visibility, - sourceSets = sourceSets + other.sourceSets, - generics = merge(generics + other.generics) { tp1, tp2 -> tp1.mergeWith(tp2) } - ).mergeExtras(this, other) - - private fun DParameter.mergeWith(other: DParameter): DParameter = copy( - documentation = documentation + other.documentation, - expectPresentInSet = expectPresentInSet ?: other.expectPresentInSet, - sourceSets = sourceSets + other.sourceSets - ).mergeExtras(this, other) - - private fun DTypeParameter.mergeWith(other: DTypeParameter): DTypeParameter = copy( - documentation = documentation + other.documentation, - expectPresentInSet = expectPresentInSet ?: other.expectPresentInSet, - sourceSets = sourceSets + other.sourceSets - ).mergeExtras(this, other) - - private fun DTypeAlias.mergeWith(other: DTypeAlias): DTypeAlias = copy( - documentation = documentation + other.documentation, - expectPresentInSet = expectPresentInSet ?: other.expectPresentInSet, - underlyingType = underlyingType + other.underlyingType, - visibility = visibility + other.visibility, - sourceSets = sourceSets + other.sourceSets - ).mergeExtras(this, other) -} - -public data class ClashingDriIdentifier(val value: Set<DokkaConfiguration.DokkaSourceSet>) : ExtraProperty<Documentable> { - public companion object : ExtraProperty.Key<Documentable, ClashingDriIdentifier> { - override fun mergeStrategyFor( - left: ClashingDriIdentifier, - right: ClashingDriIdentifier - ): MergeStrategy<Documentable> = - MergeStrategy.Replace(ClashingDriIdentifier(left.value + right.value)) - } - - override val key: ExtraProperty.Key<Documentable, *> = ClashingDriIdentifier -} - -// TODO [beresnev] remove this copy-paste and use the same method from stdlib instead after updating to 1.5 -private inline fun <T, R : Any> Iterable<T>.firstNotNullOfOrNull(transform: (T) -> R?): R? { - for (element in this) { - val result = transform(element) - if (result != null) { - return result - } - } - return null -} diff --git a/core/src/main/kotlin/transformers/documentation/DocumentableMerger.kt b/core/src/main/kotlin/transformers/documentation/DocumentableMerger.kt deleted file mode 100644 index aff1f763..00000000 --- a/core/src/main/kotlin/transformers/documentation/DocumentableMerger.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.transformers.documentation - -import org.jetbrains.dokka.model.DModule - -public fun interface DocumentableMerger { - public operator fun invoke(modules: Collection<DModule>): DModule? -} - diff --git a/core/src/main/kotlin/transformers/documentation/DocumentableToPageTranslator.kt b/core/src/main/kotlin/transformers/documentation/DocumentableToPageTranslator.kt deleted file mode 100644 index ad35ab1d..00000000 --- a/core/src/main/kotlin/transformers/documentation/DocumentableToPageTranslator.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.transformers.documentation - -import org.jetbrains.dokka.model.DModule -import org.jetbrains.dokka.pages.RootPageNode - -public fun interface DocumentableToPageTranslator { - public operator fun invoke(module: DModule): RootPageNode -} - diff --git a/core/src/main/kotlin/transformers/documentation/DocumentableTransformer.kt b/core/src/main/kotlin/transformers/documentation/DocumentableTransformer.kt deleted file mode 100644 index f680b9f3..00000000 --- a/core/src/main/kotlin/transformers/documentation/DocumentableTransformer.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.transformers.documentation - -import org.jetbrains.dokka.model.DModule -import org.jetbrains.dokka.plugability.DokkaContext - -public fun interface DocumentableTransformer { - public operator fun invoke(original: DModule, context: DokkaContext): DModule -} diff --git a/core/src/main/kotlin/transformers/documentation/PreMergeDocumentableTransformer.kt b/core/src/main/kotlin/transformers/documentation/PreMergeDocumentableTransformer.kt deleted file mode 100644 index 8ae28605..00000000 --- a/core/src/main/kotlin/transformers/documentation/PreMergeDocumentableTransformer.kt +++ /dev/null @@ -1,39 +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.transformers.documentation - -import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet -import org.jetbrains.dokka.DokkaConfiguration.PackageOptions -import org.jetbrains.dokka.model.DModule -import org.jetbrains.dokka.model.Documentable -import org.jetbrains.dokka.model.DocumentableSource -import org.jetbrains.dokka.model.WithSources - -public interface PreMergeDocumentableTransformer { - public operator fun invoke(modules: List<DModule>): List<DModule> -} - -/** - * It is fair to assume that a given [Documentable] is not merged when seen by the [PreMergeDocumentableTransformer]. - * Therefore, it can also be assumed, that there is just a single source set connected to the given [documentable] - * @return the single source set associated with this [documentable]. - */ -@Suppress("UnusedReceiverParameter") // Receiver is used for scoping this function -public fun PreMergeDocumentableTransformer.sourceSet(documentable: Documentable): DokkaSourceSet { - return documentable.sourceSets.single() -} - -/** - * @return The [PackageOptions] associated with this documentable, or null - */ -public fun PreMergeDocumentableTransformer.perPackageOptions(documentable: Documentable): PackageOptions? { - val packageName = documentable.dri.packageName ?: return null - return sourceSet(documentable).perPackageOptions - .sortedByDescending { packageOptions -> packageOptions.matchingRegex.length } - .firstOrNull { packageOptions -> Regex(packageOptions.matchingRegex).matches(packageName) } -} - -public fun <T> PreMergeDocumentableTransformer.source(documentable: T): DocumentableSource where T : Documentable, T : WithSources = - checkNotNull(documentable.sources[sourceSet(documentable)]) diff --git a/core/src/main/kotlin/transformers/pages/PageCreator.kt b/core/src/main/kotlin/transformers/pages/PageCreator.kt deleted file mode 100644 index 8c008f04..00000000 --- a/core/src/main/kotlin/transformers/pages/PageCreator.kt +++ /dev/null @@ -1,15 +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.transformers.pages - -import org.jetbrains.dokka.pages.RootPageNode - -public interface CreationContext - -public object NoCreationContext : CreationContext - -public interface PageCreator<T: CreationContext> { - public operator fun invoke(creationContext: T): RootPageNode -} diff --git a/core/src/main/kotlin/transformers/pages/PageTransformer.kt b/core/src/main/kotlin/transformers/pages/PageTransformer.kt deleted file mode 100644 index b2bbc1d1..00000000 --- a/core/src/main/kotlin/transformers/pages/PageTransformer.kt +++ /dev/null @@ -1,11 +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.transformers.pages - -import org.jetbrains.dokka.pages.RootPageNode - -public fun interface PageTransformer { - public operator fun invoke(input: RootPageNode): RootPageNode -} diff --git a/core/src/main/kotlin/transformers/pages/PageTransformerBuilders.kt b/core/src/main/kotlin/transformers/pages/PageTransformerBuilders.kt deleted file mode 100644 index a00c1578..00000000 --- a/core/src/main/kotlin/transformers/pages/PageTransformerBuilders.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.transformers.pages - -import org.jetbrains.dokka.pages.PageNode -import org.jetbrains.dokka.pages.RootPageNode - -public fun pageScanner(block: PageNode.() -> Unit): PageTransformer { - return PageTransformer { input -> input.invokeOnAll(block) as RootPageNode } -} - -public fun pageMapper(block: PageNode.() -> PageNode): PageTransformer { - return PageTransformer { input -> input.alterChildren(block) as RootPageNode } -} - -public fun pageStructureTransformer(block: RootPageNode.() -> RootPageNode): PageTransformer { - return PageTransformer { input -> block(input) } -} - -public fun PageNode.invokeOnAll(block: PageNode.() -> Unit): PageNode = - this.also(block).also { it.children.forEach { it.invokeOnAll(block) } } - -public fun PageNode.alterChildren(block: PageNode.() -> PageNode): PageNode = - block(this).modified(children = this.children.map { it.alterChildren(block) }) - diff --git a/core/src/main/kotlin/transformers/sources/AsyncSourceToDocumentableTranslator.kt b/core/src/main/kotlin/transformers/sources/AsyncSourceToDocumentableTranslator.kt deleted file mode 100644 index f7f45d25..00000000 --- a/core/src/main/kotlin/transformers/sources/AsyncSourceToDocumentableTranslator.kt +++ /dev/null @@ -1,20 +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.transformers.sources - -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.runBlocking -import org.jetbrains.dokka.DokkaConfiguration -import org.jetbrains.dokka.model.DModule -import org.jetbrains.dokka.plugability.DokkaContext - -public interface AsyncSourceToDocumentableTranslator : SourceToDocumentableTranslator { - public suspend fun invokeSuspending(sourceSet: DokkaConfiguration.DokkaSourceSet, context: DokkaContext): DModule - - override fun invoke(sourceSet: DokkaConfiguration.DokkaSourceSet, context: DokkaContext): DModule = - runBlocking(Dispatchers.Default) { - invokeSuspending(sourceSet, context) - } -} diff --git a/core/src/main/kotlin/transformers/sources/SourceToDocumentableTranslator.kt b/core/src/main/kotlin/transformers/sources/SourceToDocumentableTranslator.kt deleted file mode 100644 index 04f11830..00000000 --- a/core/src/main/kotlin/transformers/sources/SourceToDocumentableTranslator.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.transformers.sources - -import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet -import org.jetbrains.dokka.model.DModule -import org.jetbrains.dokka.plugability.DokkaContext - -public fun interface SourceToDocumentableTranslator { - public fun invoke(sourceSet: DokkaSourceSet, context: DokkaContext): DModule -} 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 &, < with < and > with > - */ -@InternalDokkaApi -public fun String.htmlEscape(): String = replace("&", "&").replace("<", "<").replace(">", ">").replace("\"", """) - -@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) } } -} diff --git a/core/src/main/kotlin/validity/PreGenerationChecker.kt b/core/src/main/kotlin/validity/PreGenerationChecker.kt deleted file mode 100644 index 349b398b..00000000 --- a/core/src/main/kotlin/validity/PreGenerationChecker.kt +++ /dev/null @@ -1,17 +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.validity - -public fun interface PreGenerationChecker : () -> PreGenerationCheckerOutput { - - override fun invoke(): PreGenerationCheckerOutput -} - -public data class PreGenerationCheckerOutput(val result: Boolean, val messages: List<String>) { - - public operator fun plus(pair: Pair<Boolean, List<String>>): Pair<Boolean, List<String>> { - return Pair(result && pair.first, messages + pair.second) - } -} |