From 70000c87a37caa2a6b518a555f53c98514434403 Mon Sep 17 00:00:00 2001 From: Marcin Aman Date: Fri, 5 Feb 2021 14:55:45 +0100 Subject: Annotations for parameters (#1710) * Annotations for parameters * Annotations for parameters --- core/src/main/kotlin/model/Documentable.kt | 60 ++++++++++++++++++++------ core/src/main/kotlin/model/additionalExtras.kt | 8 ++-- 2 files changed, 50 insertions(+), 18 deletions(-) (limited to 'core/src/main/kotlin') diff --git a/core/src/main/kotlin/model/Documentable.kt b/core/src/main/kotlin/model/Documentable.kt index 62268fef..fcbb9591 100644 --- a/core/src/main/kotlin/model/Documentable.kt +++ b/core/src/main/kotlin/model/Documentable.kt @@ -6,8 +6,10 @@ import org.jetbrains.dokka.model.doc.DocumentationNode import org.jetbrains.dokka.model.properties.PropertyContainer import org.jetbrains.dokka.model.properties.WithExtraProperties +interface AnnotationTarget -abstract class Documentable : WithChildren { +abstract class Documentable : WithChildren, + AnnotationTarget { abstract val name: String? abstract val dri: DRI abstract val documentation: SourceSetDependent @@ -346,7 +348,14 @@ data class DTypeParameter( bounds: List, sourceSets: Set, extra: PropertyContainer = PropertyContainer.empty() - ) : this(Invariance(TypeParameter(dri, name, presentableName)), documentation, expectPresentInSet, bounds, sourceSets, extra) + ) : 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 @@ -376,8 +385,17 @@ data class DTypeAlias( } sealed class Projection -sealed class Bound : Projection() -data class TypeParameter(val dri: DRI, val name: String, val presentableName: String? = null) : Bound() +sealed class Bound : Projection(), AnnotationTarget +data class TypeParameter( + val dri: DRI, + val name: String, + val presentableName: String? = null, + override val extra: PropertyContainer = PropertyContainer.empty() +) : Bound(), WithExtraProperties { + override fun withNewExtras(newExtras: PropertyContainer): TypeParameter = + copy(extra = extra) +} + object Star : Projection() sealed class TypeConstructor : Bound() { @@ -389,49 +407,63 @@ sealed class TypeConstructor : Bound() { data class GenericTypeConstructor( override val dri: DRI, override val projections: List, - override val presentableName: String? = null -) : TypeConstructor() + override val presentableName: String? = null, + override val extra: PropertyContainer = PropertyContainer.empty() +) : TypeConstructor(), WithExtraProperties { + override fun withNewExtras(newExtras: PropertyContainer): GenericTypeConstructor = + copy(extra = newExtras) +} data class FunctionalTypeConstructor( override val dri: DRI, override val projections: List, val isExtensionFunction: Boolean = false, val isSuspendable: Boolean = false, - override val presentableName: String? = null -) : TypeConstructor() + override val presentableName: String? = null, + override val extra: PropertyContainer = PropertyContainer.empty(), +) : TypeConstructor(), WithExtraProperties { + override fun withNewExtras(newExtras: PropertyContainer): FunctionalTypeConstructor = + copy(extra = newExtras) +} data class Nullable(val inner: Bound) : Bound() sealed class Variance : Projection() { abstract val inner: T } + data class Covariance(override val inner: T) : Variance() { override fun toString() = "out" } + data class Contravariance(override val inner: T) : Variance() { override fun toString() = "in" } + data class Invariance(override val inner: T) : Variance() { override fun toString() = "" } data class TypeAliased(val typeAlias: Bound, val inner: Bound) : Bound() data class PrimitiveJavaType(val name: String) : Bound() + object Void : Bound() -object JavaObject : Bound() + +data class JavaObject(override val extra: PropertyContainer = PropertyContainer.empty()) : Bound(), + WithExtraProperties { + override fun withNewExtras(newExtras: PropertyContainer): JavaObject = + copy(extra = newExtras) +} + object Dynamic : Bound() data class UnresolvedBound(val name: String) : Bound() -fun Variance.withDri(dri: DRI) = when(this) { +fun Variance.withDri(dri: DRI) = 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)) } -private fun String.shorten(maxLength: Int) = lineSequence().first().let { - if (it.length != length || it.length > maxLength) it.take(maxLength - 3) + "..." else it -} - fun Documentable.dfs(predicate: (Documentable) -> Boolean): Documentable? = if (predicate(this)) { this diff --git a/core/src/main/kotlin/model/additionalExtras.kt b/core/src/main/kotlin/model/additionalExtras.kt index c67ca7fd..f092572a 100644 --- a/core/src/main/kotlin/model/additionalExtras.kt +++ b/core/src/main/kotlin/model/additionalExtras.kt @@ -23,13 +23,13 @@ fun SourceSetDependent>.toAdditionalModifiers() = Additional data class Annotations( private val myContent: SourceSetDependent> -) : ExtraProperty { - companion object : ExtraProperty.Key { - override fun mergeStrategyFor(left: Annotations, right: Annotations): MergeStrategy = +) : 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 + override val key: ExtraProperty.Key = Annotations data class Annotation( val dri: DRI, -- cgit