All Downloads are FREE. Search and download functionalities are using the official Maven repository.

model.additionalExtras.kt Maven / Gradle / Ivy

Go to download

Dokka is an API documentation engine for Kotlin and Java, performing the same function as Javadoc for Java

There is a newer version: 2.0.0
Show newest version
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

class AdditionalModifiers(val content: SourceSetDependent>) : ExtraProperty {
    companion object : ExtraProperty.Key {
        override fun mergeStrategyFor(
            left: AdditionalModifiers,
            right: AdditionalModifiers
        ): MergeStrategy = 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() = content.hashCode()
    override val key: ExtraProperty.Key = AdditionalModifiers
}

fun SourceSetDependent>.toAdditionalModifiers() = AdditionalModifiers(this)

data class Annotations(
    private val myContent: SourceSetDependent>
) : ExtraProperty {
    companion object : ExtraProperty.Key {
        override fun mergeStrategyFor(left: Annotations, right: Annotations): MergeStrategy =
            MergeStrategy.Replace(Annotations(left.myContent + right.myContent))
    }

    override val key: ExtraProperty.Key = Annotations

    data class Annotation(
        val dri: DRI,
        val params: Map,
        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>
        get() = myContent

    val directAnnotations: SourceSetDependent> = annotationsByScope(AnnotationScope.DIRECT)

    val fileLevelAnnotations: SourceSetDependent> = annotationsByScope(AnnotationScope.FILE)

    private fun annotationsByScope(scope: AnnotationScope): SourceSetDependent> =
        myContent.entries.mapNotNull { (key, value) ->
            val withoutFileLevel = value.filter { it.scope == scope }
            if (withoutFileLevel.isEmpty()) null
            else Pair(key, withoutFileLevel)
        }.toMap()

    enum class AnnotationScope {
        DIRECT, FILE
    }
}

fun SourceSetDependent>.toAnnotations() = Annotations(this)

sealed class AnnotationParameterValue
data class AnnotationValue(val annotation: Annotations.Annotation) : AnnotationParameterValue()
data class ArrayValue(val value: List) : AnnotationParameterValue()
data class EnumValue(val enumName: String, val enumDri: DRI) : AnnotationParameterValue()
data class ClassValue(val className: String, val classDRI: DRI) : AnnotationParameterValue()
data class StringValue(val value: String) : AnnotationParameterValue() {
    override fun toString(): String = value
}


object PrimaryConstructorExtra : ExtraProperty, ExtraProperty.Key {
    override val key: ExtraProperty.Key = this
}

data class ActualTypealias(val underlyingType: SourceSetDependent) : ExtraProperty {
    companion object : ExtraProperty.Key {
        override fun mergeStrategyFor(
            left: ActualTypealias,
            right: ActualTypealias
        ) =
            MergeStrategy.Replace(ActualTypealias(left.underlyingType + right.underlyingType))
    }

    override val key: ExtraProperty.Key = ActualTypealias
}

data class ConstructorValues(val values: SourceSetDependent>) : ExtraProperty {
    companion object : ExtraProperty.Key {
        override fun mergeStrategyFor(left: ConstructorValues, right: ConstructorValues) =
            MergeStrategy.Replace(ConstructorValues(left.values + right.values))
    }

    override val key: ExtraProperty.Key = ConstructorValues
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy