aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/base/src')
-rw-r--r--plugins/base/src/main/kotlin/DokkaBase.kt5
-rw-r--r--plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt7
-rw-r--r--plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt235
-rw-r--r--plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt5
-rw-r--r--plugins/base/src/main/kotlin/signatures/SignatureProvider.kt2
-rw-r--r--plugins/base/src/main/kotlin/transformers/pages/annotations/DeprecatedStrikethroughTransformer.kt67
6 files changed, 137 insertions, 184 deletions
diff --git a/plugins/base/src/main/kotlin/DokkaBase.kt b/plugins/base/src/main/kotlin/DokkaBase.kt
index 9a04e729..18402863 100644
--- a/plugins/base/src/main/kotlin/DokkaBase.kt
+++ b/plugins/base/src/main/kotlin/DokkaBase.kt
@@ -14,7 +14,6 @@ import org.jetbrains.dokka.base.transformers.documentables.DefaultDocumentableMe
import org.jetbrains.dokka.base.transformers.documentables.DocumentableVisibilityFilter
import org.jetbrains.dokka.base.transformers.documentables.ModuleAndPackageDocumentationTransformer
import org.jetbrains.dokka.base.transformers.documentables.ReportUndocumentedTransformer
-import org.jetbrains.dokka.base.transformers.pages.annotations.DeprecatedStrikethroughTransformer
import org.jetbrains.dokka.base.transformers.pages.annotations.SinceKotlinTransformer
import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter
import org.jetbrains.dokka.base.transformers.pages.comments.DocTagToContentConverter
@@ -110,10 +109,6 @@ class DokkaBase : DokkaPlugin() {
}
}
- val deprecatedStrikethroughTransformer by extending {
- CoreExtensions.pageTransformer providing ::DeprecatedStrikethroughTransformer
- }
-
val htmlRenderer by extending {
CoreExtensions.renderer providing ::HtmlRenderer applyIf { format == "html" }
}
diff --git a/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt b/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt
index a551efdc..40f7dfda 100644
--- a/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt
+++ b/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt
@@ -1,6 +1,7 @@
package org.jetbrains.dokka.base.signatures
import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder
+import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.model.*
import org.jetbrains.dokka.model.properties.WithExtraProperties
import org.jetbrains.dokka.pages.*
@@ -128,6 +129,12 @@ interface JvmSignatureUtils {
text(Typography.nbsp.toString())
}
}
+
+ fun <T : Documentable> WithExtraProperties<T>.stylesForDeprecated(sourceSetData: SourceSetData): Set<TextStyle> =
+ if (extra[Annotations]?.content?.get(sourceSetData)?.any {
+ it.dri == DRI("kotlin", "Deprecated")
+ || it.dri == DRI("java.lang", "Deprecated")
+ } == true) setOf(TextStyle.Strikethrough) else emptySet()
}
sealed class AtStrategy
diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
index faca95ee..66596e2d 100644
--- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
+++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
@@ -7,6 +7,7 @@ import org.jetbrains.dokka.links.*
import org.jetbrains.dokka.model.*
import org.jetbrains.dokka.model.Nullable
import org.jetbrains.dokka.model.TypeConstructor
+import org.jetbrains.dokka.model.properties.PropertyContainer
import org.jetbrains.dokka.model.properties.WithExtraProperties
import org.jetbrains.dokka.pages.ContentKind
import org.jetbrains.dokka.pages.ContentNode
@@ -28,7 +29,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
ExtraModifiers.KotlinOnlyModifiers.External to setOf(Platform.js)
)
- override fun signature(documentable: Documentable): ContentNode = when (documentable) {
+ override fun signature(documentable: Documentable): List<ContentNode> = when (documentable) {
is DFunction -> functionSignature(documentable)
is DProperty -> propertySignature(documentable)
is DClasslike -> classlikeSignature(documentable)
@@ -54,54 +55,65 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
}
}
- private fun signature(e: DEnumEntry) =
- contentBuilder.contentFor(
- e,
- ContentKind.Symbol,
- setOf(TextStyle.Monospace),
- sourceSets = e.sourceSets.toSet()
- ) {
- group(styles = setOf(TextStyle.Block)) {
- annotationsBlock(e)
- link(e.name, e.dri, styles = emptySet())
- e.extra[ConstructorValues]?.let { constructorValues ->
- sourceSetDependentText(constructorValues.values, constructorValues.values.keys) {
- it.joinToString(prefix = "(", postfix = ")")
+ private fun signature(e: DEnumEntry): List<ContentNode> =
+ e.sourceSets.map {
+ contentBuilder.contentFor(
+ e,
+ ContentKind.Symbol,
+ setOf(TextStyle.Monospace) + e.stylesForDeprecated(it),
+ sourceSets = setOf(it)
+ ) {
+ group(styles = setOf(TextStyle.Block)) {
+ annotationsBlock(e)
+ link(e.name, e.dri, styles = emptySet())
+ e.extra[ConstructorValues]?.let { constructorValues ->
+ sourceSetDependentText(constructorValues.values, constructorValues.values.keys) {
+ it.joinToString(prefix = "(", postfix = ")")
+ }
}
}
}
}
- private fun actualTypealiasedSignature(dri: DRI, name: String, aliasedTypes: SourceSetDependent<Bound>) =
- aliasedTypes.entries.groupBy({ it.value }, { it.key }).map { (bound, platforms) ->
- contentBuilder.contentFor(dri, platforms.toSet(), ContentKind.Symbol, setOf(TextStyle.Monospace)) {
- text("actual typealias ")
- link(name, dri)
- text(" = ")
- signatureForProjection(bound)
- }
+ private fun actualTypealiasedSignature(c: DClasslike, sourceSet: SourceSetData, aliasedType: Bound) =
+ contentBuilder.contentFor(
+ c,
+ ContentKind.Symbol,
+ setOf(TextStyle.Monospace) + ((c as? WithExtraProperties<out Documentable>)?.stylesForDeprecated(sourceSet)
+ ?: emptySet()),
+ sourceSets = setOf(sourceSet)
+ ) {
+ text("actual typealias ")
+ link(c.name.orEmpty(), c.dri)
+ text(" = ")
+ signatureForProjection(aliasedType)
}
@Suppress("UNCHECKED_CAST")
- private fun <T : DClasslike> classlikeSignature(c: T) =
- (c as? WithExtraProperties<out DClasslike>)?.let {
- c.extra[ActualTypealias]?.let {
- contentBuilder.contentFor(c) {
- +regularSignature(c, sourceSets = c.sourceSets.toSet() - it.underlyingType.keys)
- +actualTypealiasedSignature(c.dri, c.name.orEmpty(), it.underlyingType)
- }
- } ?: regularSignature(c)
- } ?: regularSignature(c)
+ private fun <T : DClasslike> classlikeSignature(c: T): List<ContentNode> =
+ c.sourceSets.map { sourceSetData ->
+ (c as? WithExtraProperties<out DClasslike>)?.extra?.get(ActualTypealias)?.underlyingType?.get(sourceSetData)
+ ?.let {
+ actualTypealiasedSignature(c, sourceSetData, it)
+ } ?: regularSignature(c, sourceSetData)
+ }
- private fun regularSignature(c: DClasslike, sourceSets: Set<SourceSetData> = c.sourceSets.toSet()) =
- contentBuilder.contentFor(c, ContentKind.Symbol, setOf(TextStyle.Monospace), sourceSets = sourceSets) {
+
+ private fun regularSignature(c: DClasslike, sourceSet: SourceSetData) =
+ contentBuilder.contentFor(
+ c,
+ ContentKind.Symbol,
+ setOf(TextStyle.Monospace) + ((c as? WithExtraProperties<out Documentable>)?.stylesForDeprecated(sourceSet)
+ ?: emptySet()),
+ sourceSets = setOf(sourceSet)
+ ) {
annotationsBlock(c)
sourceSetDependentText(
c.visibility,
- sourceSets
+ setOf(sourceSet)
) { it.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "" }
if (c is DClass) {
- sourceSetDependentText(c.modifier, sourceSets) {
+ sourceSetDependentText(c.modifier, setOf(sourceSet)) {
if (it !in ignoredModifiers)
if (c.extra[AdditionalModifiers]?.content?.contains(ExtraModifiers.KotlinOnlyModifiers.Data) == true) ""
else (if (it is JavaModifier.Empty) KotlinModifier.Open else it).let { it.name + " " }
@@ -111,7 +123,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
}
if (c is DInterface) {
c.extra[AdditionalModifiers]?.content?.let { additionalModifiers ->
- sourceSetDependentText(additionalModifiers, sourceSets) { extraModifiers ->
+ sourceSetDependentText(additionalModifiers, setOf(sourceSet)) { extraModifiers ->
if (ExtraModifiers.KotlinOnlyModifiers.Fun in extraModifiers) "fun "
else ""
}
@@ -166,7 +178,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
}
}
if (c is WithSupertypes) {
- c.supertypes.filter { it.key in sourceSets }.map { (s, dris) ->
+ c.supertypes.filter { it.key == sourceSet }.map { (s, dris) ->
list(dris, prefix = " : ", sourceSets = setOf(s)) {
link(it.sureClassNames, it, sourceSets = setOf(s))
}
@@ -174,60 +186,64 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
}
}
- private fun propertySignature(p: DProperty, sourceSets: Set<SourceSetData> = p.sourceSets.toSet()) =
- contentBuilder.contentFor(p, ContentKind.Symbol, setOf(TextStyle.Monospace), sourceSets = sourceSets) {
- annotationsBlock(p)
- sourceSetDependentText(p.visibility) { it.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "" }
- sourceSetDependentText(p.modifier) {
- it.takeIf { it !in ignoredModifiers }?.let {
- if (it is JavaModifier.Empty) KotlinModifier.Open else it
- }?.name?.let { "$it " } ?: ""
- }
- processExtraModifiers(p)
- p.setter?.let { text("var ") } ?: text("val ")
- list(p.generics, prefix = "<", suffix = "> ") {
- +buildSignature(it)
- }
- p.receiver?.also {
- signatureForProjection(it.type)
- text(".")
+ private fun propertySignature(p: DProperty) =
+ p.sourceSets.map {
+ contentBuilder.contentFor(p, ContentKind.Symbol, setOf(TextStyle.Monospace) + p.stylesForDeprecated(it), sourceSets = setOf(it)) {
+ annotationsBlock(p)
+ sourceSetDependentText(p.visibility) { it.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "" }
+ sourceSetDependentText(p.modifier) {
+ it.takeIf { it !in ignoredModifiers }?.let {
+ if (it is JavaModifier.Empty) KotlinModifier.Open else it
+ }?.name?.let { "$it " } ?: ""
+ }
+ processExtraModifiers(p)
+ p.setter?.let { text("var ") } ?: text("val ")
+ list(p.generics, prefix = "<", suffix = "> ") {
+ +buildSignature(it)
+ }
+ p.receiver?.also {
+ signatureForProjection(it.type)
+ text(".")
+ }
+ link(p.name, p.dri)
+ text(": ")
+ signatureForProjection(p.type)
}
- link(p.name, p.dri)
- text(": ")
- signatureForProjection(p.type)
}
- private fun functionSignature(f: DFunction, sourceSets: Set<SourceSetData> = f.sourceSets.toSet()) =
- contentBuilder.contentFor(f, ContentKind.Symbol, setOf(TextStyle.Monospace), sourceSets = sourceSets) {
- annotationsBlock(f)
- sourceSetDependentText(f.visibility) { it.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "" }
- sourceSetDependentText(f.modifier) {
- it.takeIf { it !in ignoredModifiers }?.let {
- if (it is JavaModifier.Empty) KotlinModifier.Open else it
- }?.name?.let { "$it " } ?: ""
- }
- processExtraModifiers(f)
- text("fun ")
- list(f.generics, prefix = "<", suffix = "> ") {
- +buildSignature(it)
- }
- f.receiver?.also {
- signatureForProjection(it.type)
- text(".")
- }
- link(f.name, f.dri)
- text("(")
- list(f.parameters) {
- annotationsInline(it)
- processExtraModifiers(it)
- text(it.name!!)
- text(": ")
- signatureForProjection(it.type)
- }
- text(")")
- if (f.documentReturnType()) {
- text(": ")
- signatureForProjection(f.type)
+ private fun functionSignature(f: DFunction) =
+ f.sourceSets.map {
+ contentBuilder.contentFor(f, ContentKind.Symbol, setOf(TextStyle.Monospace) + f.stylesForDeprecated(it), sourceSets = setOf(it)) {
+ annotationsBlock(f)
+ sourceSetDependentText(f.visibility) { it.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "" }
+ sourceSetDependentText(f.modifier) {
+ it.takeIf { it !in ignoredModifiers }?.let {
+ if (it is JavaModifier.Empty) KotlinModifier.Open else it
+ }?.name?.let { "$it " } ?: ""
+ }
+ processExtraModifiers(f)
+ text("fun ")
+ list(f.generics, prefix = "<", suffix = "> ") {
+ +buildSignature(it)
+ }
+ f.receiver?.also {
+ signatureForProjection(it.type)
+ text(".")
+ }
+ link(f.name, f.dri)
+ text("(")
+ list(f.parameters) {
+ annotationsInline(it)
+ processExtraModifiers(it)
+ text(it.name!!)
+ text(": ")
+ signatureForProjection(it.type)
+ }
+ text(")")
+ if (f.documentReturnType()) {
+ text(": ")
+ signatureForProjection(f.type)
+ }
}
}
@@ -239,30 +255,35 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
}
private fun signature(t: DTypeAlias) =
- contentBuilder.contentFor(t) {
- t.underlyingType.entries.groupBy({ it.value }, { it.key }).map { (type, platforms) ->
- +contentBuilder.contentFor(
- t,
- ContentKind.Symbol,
- setOf(TextStyle.Monospace),
- sourceSets = platforms.toSet()
- ) {
- sourceSetDependentText(t.visibility) { it.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "" }
- processExtraModifiers(t)
- text("typealias ")
- signatureForProjection(t.type)
- text(" = ")
- signatureForProjection(type)
+ t.sourceSets.map {
+ contentBuilder.contentFor(t, styles = t.stylesForDeprecated(it), sourceSets = setOf(it)) {
+ t.underlyingType.entries.groupBy({ it.value }, { it.key }).map { (type, platforms) ->
+ +contentBuilder.contentFor(
+ t,
+ ContentKind.Symbol,
+ setOf(TextStyle.Monospace),
+ sourceSets = platforms.toSet()
+ ) {
+ sourceSetDependentText(t.visibility) { it.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "" }
+ processExtraModifiers(t)
+ text("typealias ")
+ signatureForProjection(t.type)
+ text(" = ")
+ signatureForProjection(type)
+ }
}
}
}
- private fun signature(t: DTypeParameter) = contentBuilder.contentFor(t) {
- link(t.name, t.dri.withTargetToDeclaration())
- list(t.bounds, prefix = " : ") {
- signatureForProjection(it)
+ private fun signature(t: DTypeParameter) =
+ t.sourceSets.map {
+ contentBuilder.contentFor(t, styles = t.stylesForDeprecated(it), sourceSets = setOf(it)) {
+ link(t.name, t.dri.withTargetToDeclaration())
+ list(t.bounds, prefix = " : ") {
+ signatureForProjection(it)
+ }
+ }
}
- }
private fun PageContentBuilder.DocumentableContentBuilder.signatureForProjection(p: Projection): Unit =
when (p) {
diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt
index b312c8f0..5e35c240 100644
--- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt
+++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt
@@ -2,10 +2,7 @@ package org.jetbrains.dokka.base.signatures
import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder
import org.jetbrains.dokka.links.DRI
-import org.jetbrains.dokka.model.AdditionalModifiers
-import org.jetbrains.dokka.model.Annotations
-import org.jetbrains.dokka.model.Documentable
-import org.jetbrains.dokka.model.ExtraModifiers
+import org.jetbrains.dokka.model.*
import org.jetbrains.dokka.model.properties.WithExtraProperties
object KotlinSignatureUtils : JvmSignatureUtils {
diff --git a/plugins/base/src/main/kotlin/signatures/SignatureProvider.kt b/plugins/base/src/main/kotlin/signatures/SignatureProvider.kt
index 01b298c9..e1933fb8 100644
--- a/plugins/base/src/main/kotlin/signatures/SignatureProvider.kt
+++ b/plugins/base/src/main/kotlin/signatures/SignatureProvider.kt
@@ -4,5 +4,5 @@ import org.jetbrains.dokka.model.Documentable
import org.jetbrains.dokka.pages.ContentNode
interface SignatureProvider {
- fun signature(documentable: Documentable): ContentNode
+ fun signature(documentable: Documentable): List<ContentNode>
}
diff --git a/plugins/base/src/main/kotlin/transformers/pages/annotations/DeprecatedStrikethroughTransformer.kt b/plugins/base/src/main/kotlin/transformers/pages/annotations/DeprecatedStrikethroughTransformer.kt
deleted file mode 100644
index ffee64ed..00000000
--- a/plugins/base/src/main/kotlin/transformers/pages/annotations/DeprecatedStrikethroughTransformer.kt
+++ /dev/null
@@ -1,67 +0,0 @@
-package org.jetbrains.dokka.base.transformers.pages.annotations
-
-import org.jetbrains.dokka.base.renderers.platforms
-import org.jetbrains.dokka.links.DRI
-import org.jetbrains.dokka.model.*
-import org.jetbrains.dokka.model.properties.WithExtraProperties
-import org.jetbrains.dokka.pages.*
-import org.jetbrains.dokka.plugability.DokkaContext
-import org.jetbrains.dokka.transformers.pages.PageTransformer
-import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty
-
-class DeprecatedStrikethroughTransformer(val context: DokkaContext) : PageTransformer {
-
- override fun invoke(input: RootPageNode): RootPageNode = input.transformContentPagesTree { contentPage ->
- contentPage.platforms().fold(contentPage) { acc, sourceSetData ->
- listOfNotNull(
- contentPage.documentable?.children?.filter { it.isDeprecated(sourceSetData) }?.map { it.dri },
- contentPage.dri.takeIf { acc.documentable?.isDeprecated(sourceSetData) == true }?.toList()
- ).flatten().ifNotEmpty {
- acc.modified(content = acc.content.addStrikethroughToSignature(sourceSetData, this.toSet()))
- } ?: acc
- }
- }
-
- private fun ContentNode.addStrikethroughToSignature(
- sourceSetData: SourceSetData,
- deprecatedDRIs: Set<DRI>
- ): ContentNode = when (this) {
- is ContentGroup -> if (setOf(sourceSetData) == sourceSets && deprecatedDRIs.containsAll(dci.dri)) {
- copy(style = this.style + setOf(TextStyle.Strikethrough))
- } else {
- copy(children = children.map { it.addStrikethroughToSignature(sourceSetData, deprecatedDRIs) })
- }
- is ContentTable -> copy(children = children.map {
- it.addStrikethroughToSignature(
- sourceSetData,
- deprecatedDRIs
- ) as ContentGroup
- })
- is PlatformHintedContent -> copy(inner = inner.addStrikethroughToSignature(sourceSetData, deprecatedDRIs))
- is ContentDivergentGroup -> copy(children = children.map { it.addStrikethroughToSignature(sourceSetData, deprecatedDRIs) } as List<ContentDivergentInstance>)
- is ContentDivergentInstance -> copy(divergent = divergent.addStrikethroughToSignature(sourceSetData, deprecatedDRIs))
- else -> this
- }
-
- private fun Documentable.isDeprecated(sourceSetData: SourceSetData) = when (this) {
- is DClass -> this.isKotlinOrJavaDeprecated(sourceSetData)
- is DAnnotation -> this.isKotlinOrJavaDeprecated(sourceSetData)
- is DObject -> this.isKotlinOrJavaDeprecated(sourceSetData)
- is DInterface -> this.isKotlinOrJavaDeprecated(sourceSetData)
- is DEnum -> this.isKotlinOrJavaDeprecated(sourceSetData)
- is DFunction -> this.isKotlinOrJavaDeprecated(sourceSetData)
- is DProperty -> this.isKotlinOrJavaDeprecated(sourceSetData)
- is DEnumEntry -> this.isKotlinOrJavaDeprecated(sourceSetData)
-
- else -> false
- }
-
- private fun Documentable.hasDeprecatedChildren(sourceSetData: SourceSetData) =
- children.any { it.isDeprecated(sourceSetData) }
-
- private fun <T : Documentable> WithExtraProperties<T>.isKotlinOrJavaDeprecated(sourceSetData: SourceSetData) =
- extra[Annotations]?.content?.get(sourceSetData)?.any {
- it.dri == DRI("kotlin", "Deprecated")
- || it.dri == DRI("java.lang", "Deprecated")
- } == true
-} \ No newline at end of file