diff options
author | Marcin Aman <marcin.aman@gmail.com> | 2021-02-05 14:55:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-05 14:55:45 +0100 |
commit | 70000c87a37caa2a6b518a555f53c98514434403 (patch) | |
tree | 3a0e7a2b797b6edfffc0396bb5f9d35708120e9d /core/src | |
parent | b44e41ec8e3e26c73affaaa98bbd170fde352d96 (diff) | |
download | dokka-70000c87a37caa2a6b518a555f53c98514434403.tar.gz dokka-70000c87a37caa2a6b518a555f53c98514434403.tar.bz2 dokka-70000c87a37caa2a6b518a555f53c98514434403.zip |
Annotations for parameters (#1710)
* Annotations for parameters
* Annotations for parameters
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/main/kotlin/model/Documentable.kt | 60 | ||||
-rw-r--r-- | core/src/main/kotlin/model/additionalExtras.kt | 8 |
2 files changed, 50 insertions, 18 deletions
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<Documentable> { +abstract class Documentable : WithChildren<Documentable>, + AnnotationTarget { abstract val name: String? abstract val dri: DRI abstract val documentation: SourceSetDependent<DocumentationNode> @@ -346,7 +348,14 @@ data class DTypeParameter( bounds: List<Bound>, sourceSets: Set<DokkaSourceSet>, extra: PropertyContainer<DTypeParameter> = 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<TypeParameter> = PropertyContainer.empty() +) : Bound(), WithExtraProperties<TypeParameter> { + override fun withNewExtras(newExtras: PropertyContainer<TypeParameter>): 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<Projection>, - override val presentableName: String? = null -) : TypeConstructor() + 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) +} 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 -) : TypeConstructor() + 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) +} data class Nullable(val inner: Bound) : Bound() sealed class Variance<out T : Bound> : Projection() { abstract val inner: T } + data class Covariance<out T : Bound>(override val inner: T) : Variance<T>() { override fun toString() = "out" } + data class Contravariance<out T : Bound>(override val inner: T) : Variance<T>() { override fun toString() = "in" } + data class Invariance<out T : Bound>(override val inner: T) : Variance<T>() { 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<JavaObject> = PropertyContainer.empty()) : Bound(), + WithExtraProperties<JavaObject> { + override fun withNewExtras(newExtras: PropertyContainer<JavaObject>): JavaObject = + copy(extra = newExtras) +} + object Dynamic : Bound() data class UnresolvedBound(val name: String) : Bound() -fun Variance<TypeParameter>.withDri(dri: DRI) = when(this) { +fun Variance<TypeParameter>.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<Set<ExtraModifiers>>.toAdditionalModifiers() = Additional data class Annotations( private val myContent: SourceSetDependent<List<Annotation>> -) : ExtraProperty<Documentable> { - companion object : ExtraProperty.Key<Documentable, Annotations> { - override fun mergeStrategyFor(left: Annotations, right: Annotations): MergeStrategy<Documentable> = +) : ExtraProperty<AnnotationTarget> { + 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<Documentable, *> = Annotations + override val key: ExtraProperty.Key<AnnotationTarget, *> = Annotations data class Annotation( val dri: DRI, |