diff options
author | Ignat Beresnev <ignat.beresnev@jetbrains.com> | 2023-08-31 20:16:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-31 20:16:01 +0200 |
commit | 02f30b142aa467d3a24cc52a1fe3f2fed7ea1e33 (patch) | |
tree | 66f6d6f089a93b863bf1144666491eca6729ad05 /core/src/main/kotlin/links/DRI.kt | |
parent | 6a181a7a2b03ec263788d137610e86937a57d434 (diff) | |
download | dokka-02f30b142aa467d3a24cc52a1fe3f2fed7ea1e33.tar.gz dokka-02f30b142aa467d3a24cc52a1fe3f2fed7ea1e33.tar.bz2 dokka-02f30b142aa467d3a24cc52a1fe3f2fed7ea1e33.zip |
Enable explicit API mode (#3139)
Diffstat (limited to 'core/src/main/kotlin/links/DRI.kt')
-rw-r--r-- | core/src/main/kotlin/links/DRI.kt | 82 |
1 files changed, 41 insertions, 41 deletions
diff --git a/core/src/main/kotlin/links/DRI.kt b/core/src/main/kotlin/links/DRI.kt index bcd0198b..180d9eb8 100644 --- a/core/src/main/kotlin/links/DRI.kt +++ b/core/src/main/kotlin/links/DRI.kt @@ -12,7 +12,7 @@ import com.fasterxml.jackson.module.kotlin.readValue /** * [DRI] stands for DokkaResourceIdentifier */ -data class DRI( +public data class DRI( val packageName: String? = null, val classNames: String? = null, val callable: Callable? = null, @@ -23,47 +23,47 @@ data class DRI( "${packageName.orEmpty()}/${classNames.orEmpty()}/${callable?.name.orEmpty()}/${callable?.signature() .orEmpty()}/$target/${extra.orEmpty()}" - companion object { - val topLevel = DRI() - + public companion object { + public val topLevel: DRI = DRI() } } -object EnumEntryDRIExtra: DRIExtraProperty<EnumEntryDRIExtra>() +public object EnumEntryDRIExtra: DRIExtraProperty<EnumEntryDRIExtra>() -abstract class DRIExtraProperty<T> { - val key: String = this::class.qualifiedName +public abstract class DRIExtraProperty<T> { + public val key: String = this::class.qualifiedName ?: (this.javaClass.let { it.`package`.name + "." + it.simpleName.ifEmpty { "anonymous" } }) } -class DRIExtraContainer(val data: String? = null) { - val map: MutableMap<String, Any> = if (data != null) OBJECT_MAPPER.readValue(data) else mutableMapOf() - inline operator fun <reified T> get(prop: DRIExtraProperty<T>): T? = +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 } - inline operator fun <reified T> set(prop: DRIExtraProperty<T>, value: T) = - value.also { map[prop.key] = it as Any } + public inline operator fun <reified T> set(prop: DRIExtraProperty<T>, value: T) { + map[prop.key] = value as Any + } - fun encode(): String = OBJECT_MAPPER.writeValueAsString(map) + public fun encode(): String = OBJECT_MAPPER.writeValueAsString(map) private companion object { private val OBJECT_MAPPER = ObjectMapper() } } -val DriOfUnit = DRI("kotlin", "Unit") -val DriOfAny = DRI("kotlin", "Any") +public val DriOfUnit: DRI = DRI("kotlin", "Unit") +public val DriOfAny: DRI = DRI("kotlin", "Any") -fun DRI.withClass(name: String) = copy(classNames = if (classNames.isNullOrBlank()) name else "$classNames.$name") +public fun DRI.withClass(name: String): DRI = copy(classNames = if (classNames.isNullOrBlank()) name else "$classNames.$name") -fun DRI.withTargetToDeclaration() = copy(target = PointingToDeclaration) +public fun DRI.withTargetToDeclaration(): DRI = copy(target = PointingToDeclaration) -fun DRI.withEnumEntryExtra() = copy( +public fun DRI.withEnumEntryExtra(): DRI = copy( extra = DRIExtraContainer(this.extra).also { it[EnumEntryDRIExtra] = EnumEntryDRIExtra }.encode() ) -val DRI.parent: DRI +public val DRI.parent: DRI get() = when { extra != null -> when { DRIExtraContainer(extra)[EnumEntryDRIExtra] != null -> copy( @@ -78,68 +78,68 @@ val DRI.parent: DRI else -> DRI.topLevel } -val DRI.sureClassNames +public val DRI.sureClassNames: String get() = classNames ?: throw IllegalStateException("Malformed DRI. It requires classNames in this context.") -data class Callable( +public data class Callable( val name: String, val receiver: TypeReference? = null, val params: List<TypeReference> ) { - fun signature() = "${receiver?.toString().orEmpty()}#${params.joinToString("#")}" + public fun signature(): String = "${receiver?.toString().orEmpty()}#${params.joinToString("#")}" - companion object + public companion object } @JsonTypeInfo(use = CLASS) -sealed class TypeReference { - companion object +public sealed class TypeReference { + public companion object } -data class JavaClassReference(val name: String) : TypeReference() { +public data class JavaClassReference(val name: String) : TypeReference() { override fun toString(): String = name } -data class TypeParam(val bounds: List<TypeReference>) : TypeReference() +public data class TypeParam(val bounds: List<TypeReference>) : TypeReference() -data class TypeConstructor( +public data class TypeConstructor( val fullyQualifiedName: String, val params: List<TypeReference> ) : TypeReference() { - override fun toString() = fullyQualifiedName + + override fun toString(): String = fullyQualifiedName + (if (params.isNotEmpty()) "[${params.joinToString(",")}]" else "") } -data class RecursiveType(val rank: Int): TypeReference() { - override fun toString() = "^".repeat(rank + 1) +public data class RecursiveType(val rank: Int): TypeReference() { + override fun toString(): String = "^".repeat(rank + 1) } -data class Nullable(val wrapped: TypeReference) : TypeReference() { - override fun toString() = "$wrapped?" +public data class Nullable(val wrapped: TypeReference) : TypeReference() { + override fun toString(): String = "$wrapped?" } -object StarProjection : TypeReference() { - override fun toString() = "*" +public object StarProjection : TypeReference() { + override fun toString(): String = "*" } @JsonTypeInfo(use = CLASS) -sealed class DriTarget { +public sealed class DriTarget { override fun toString(): String = this.javaClass.simpleName - companion object + public companion object } -data class PointingToGenericParameters(val parameterIndex: Int) : DriTarget() { +public data class PointingToGenericParameters(val parameterIndex: Int) : DriTarget() { override fun toString(): String = "PointingToGenericParameters($parameterIndex)" } -object PointingToDeclaration : DriTarget() +public object PointingToDeclaration : DriTarget() -data class PointingToCallableParameters(val parameterIndex: Int) : DriTarget() { +public data class PointingToCallableParameters(val parameterIndex: Int) : DriTarget() { override fun toString(): String = "PointingToCallableParameters($parameterIndex)" } -fun DriTarget.nextTarget(): DriTarget = when (this) { +public fun DriTarget.nextTarget(): DriTarget = when (this) { is PointingToGenericParameters -> PointingToGenericParameters(this.parameterIndex + 1) is PointingToCallableParameters -> PointingToCallableParameters(this.parameterIndex + 1) else -> this |