package org.jetbrains.dokka import ru.yole.jkid.CustomSerializer import ru.yole.jkid.ValueSerializer import ru.yole.jkid.deserialization.JKidException import java.io.Serializable import java.net.URL class UrlSerializer : ValueSerializer { override fun fromJsonValue(jsonValue: Any?): URL? { if (jsonValue !is String?) throw JKidException("Expected string representation of URL, got: $jsonValue") return jsonValue?.let { URL(jsonValue) } } override fun toJsonValue(value: URL?): Any? = value?.toExternalForm() } enum class Platform(val key: String) { jvm("jvm"), js("js"); // common("common"); companion object { val DEFAULT = jvm fun fromString(key: String): Platform { return when (key.toLowerCase()) { jvm.key -> jvm js.key -> js // common.key -> common else -> TODO("write normal exception") } } } } interface DokkaConfiguration { val moduleName: String val classpath: List val sourceRoots: List val samples: List val includes: List val outputDir: String val format: String val includeNonPublic: Boolean val includeRootPackage: Boolean val reportUndocumented: Boolean val skipEmptyPackages: Boolean val skipDeprecated: Boolean val jdkVersion: Int val generateIndexPages: Boolean val sourceLinks: List val impliedPlatforms: List val perPackageOptions: List val externalDocumentationLinks: List val languageVersion: String? val apiVersion: String? val noStdlibLink: Boolean val cacheRoot: String? val suppressedFiles: List interface SourceRoot { val path: String val platforms: List val analysisPlatform: Platform } interface SourceLinkDefinition { val path: String val url: String val lineSuffix: String? } interface PackageOptions { val prefix: String val includeNonPublic: Boolean val reportUndocumented: Boolean val skipDeprecated: Boolean val suppress: Boolean } interface ExternalDocumentationLink { @CustomSerializer(UrlSerializer::class) val url: URL @CustomSerializer(UrlSerializer::class) val packageListUrl: URL open class Builder(open var url: URL? = null, open var packageListUrl: URL? = null) { constructor(root: String, packageList: String? = null) : this(URL(root), packageList?.let { URL(it) }) fun build(): DokkaConfiguration.ExternalDocumentationLink = 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") } } } data class SerializeOnlyDokkaConfiguration( override val moduleName: String, override val classpath: List, override val sourceRoots: List, override val samples: List, override val includes: List, override val outputDir: String, override val format: String, override val includeNonPublic: Boolean, override val includeRootPackage: Boolean, override val reportUndocumented: Boolean, override val skipEmptyPackages: Boolean, override val skipDeprecated: Boolean, override val jdkVersion: Int, override val generateIndexPages: Boolean, override val sourceLinks: List, override val impliedPlatforms: List, override val perPackageOptions: List, override val externalDocumentationLinks: List, override val noStdlibLink: Boolean, override val cacheRoot: String?, override val suppressedFiles: List, override val languageVersion: String?, override val apiVersion: String? ) : DokkaConfiguration data class ExternalDocumentationLinkImpl(@CustomSerializer(UrlSerializer::class) override val url: URL, @CustomSerializer(UrlSerializer::class) override val packageListUrl: URL) : Serializable, DokkaConfiguration.ExternalDocumentationLink