diff options
Diffstat (limited to 'plugins/base/src')
5 files changed, 70 insertions, 8 deletions
diff --git a/plugins/base/src/main/kotlin/DokkaBase.kt b/plugins/base/src/main/kotlin/DokkaBase.kt index 4af12991..d236aa01 100644 --- a/plugins/base/src/main/kotlin/DokkaBase.kt +++ b/plugins/base/src/main/kotlin/DokkaBase.kt @@ -10,6 +10,7 @@ import org.jetbrains.dokka.base.signatures.KotlinSignatureProvider import org.jetbrains.dokka.base.signatures.SignatureProvider import org.jetbrains.dokka.base.transformers.documentables.DefaultDocumentableMerger import org.jetbrains.dokka.base.transformers.documentables.InheritorsExtractorTransformer +import org.jetbrains.dokka.base.transformers.pages.annotations.DeprecatedStrikethroughTransformer import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter import org.jetbrains.dokka.base.transformers.pages.comments.DocTagToContentConverter import org.jetbrains.dokka.base.transformers.pages.merger.FallbackPageMergerStrategy @@ -78,6 +79,10 @@ 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/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt index 34dac9f4..57915134 100644 --- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt @@ -28,7 +28,7 @@ open class HtmlRenderer( pageContext: ContentPage, childrenCallback: FlowContent.() -> Unit ) { - val additionalClasses = node.style.joinToString { it.toString().toLowerCase() } + val additionalClasses = node.style.joinToString(" ") { it.toString().toLowerCase() } return when { node.dci.kind == ContentKind.Symbol -> div("symbol $additionalClasses") { childrenCallback() } node.dci.kind == ContentKind.BriefComment -> div("brief $additionalClasses") { childrenCallback() } diff --git a/plugins/base/src/main/kotlin/transformers/pages/annotations/DeprecatedStrikethroughTransformer.kt b/plugins/base/src/main/kotlin/transformers/pages/annotations/DeprecatedStrikethroughTransformer.kt new file mode 100644 index 00000000..55f01ad3 --- /dev/null +++ b/plugins/base/src/main/kotlin/transformers/pages/annotations/DeprecatedStrikethroughTransformer.kt @@ -0,0 +1,57 @@ +package org.jetbrains.dokka.base.transformers.pages.annotations + +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 + +class DeprecatedStrikethroughTransformer(val context: DokkaContext) : PageTransformer { + override fun invoke(input: RootPageNode): RootPageNode = input.transformContentPagesTree { contentPage -> + if (contentPage.documentable?.isDeprecated() == true || contentPage.documentable?.hasDeprecatedChildren() == true) { + val deprecatedDRIs = + contentPage.dri + + contentPage.documentable?.children + ?.filter { it.isDeprecated() } + ?.map { it.dri } + ?.toSet().orEmpty() + + contentPage.modified(content = contentPage.content.addStrikethroughToSignature(deprecatedDRIs)) + } else { + contentPage + } + } + + private fun ContentNode.addStrikethroughToSignature(deprecatedDRIs: Set<DRI>): ContentNode = when (this) { + is ContentGroup -> if (dci.kind == ContentKind.Symbol && deprecatedDRIs.containsAll(dci.dri)) { + copy(style = this.style + setOf(TextStyle.Strikethrough)) + } else { + copy(children = children.map { it.addStrikethroughToSignature(deprecatedDRIs) }) + } + is ContentTable -> copy(children = children.map { it.addStrikethroughToSignature(deprecatedDRIs) as ContentGroup }) + is PlatformHintedContent -> copy(inner = inner.addStrikethroughToSignature(deprecatedDRIs)) + else -> this + } + + private fun Documentable.isDeprecated(): Boolean = when (this) { + is DClass -> this.isKotlinOrJavaDeprecated() + is DAnnotation -> this.isKotlinOrJavaDeprecated() + is DObject -> this.isKotlinOrJavaDeprecated() + is DInterface -> this.isKotlinOrJavaDeprecated() + is DEnum -> this.isKotlinOrJavaDeprecated() + is DFunction -> this.isKotlinOrJavaDeprecated() + is DProperty -> this.isKotlinOrJavaDeprecated() + is DEnumEntry -> this.isKotlinOrJavaDeprecated() + + else -> false + } + + private fun Documentable.hasDeprecatedChildren() = children.any { it.isDeprecated() } + + private fun <T : Documentable> WithExtraProperties<T>.isKotlinOrJavaDeprecated() = + extra[Annotations]?.content?.any { + it.dri == DRI("kotlin", "Deprecated") + || it.dri == DRI("java.lang", "Deprecated") + } == true +}
\ No newline at end of file diff --git a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt index 0e1e0a18..549e765f 100644 --- a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt @@ -145,7 +145,7 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { null, constructors.map { parseFunction(it, dri, true) }, listOf(platformData), - PropertyContainer.empty<Annotation>() + annotations.toList().toExtra() + PropertyContainer.empty<DAnnotation>() + annotations.toList().toExtra() ) isEnum -> DEnum( dri, @@ -159,7 +159,7 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { emptyList(), emptyList(), listOf(platformData), - PropertyContainer.empty<EnumEntry>() + entry.annotations.toList().toExtra() + PropertyContainer.empty<DEnumEntry>() + entry.annotations.toList().toExtra() ) }, documentation, @@ -172,7 +172,7 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { constructors.map { parseFunction(it, dri, true) }, ancestors, listOf(platformData), - PropertyContainer.empty<Enum>() + annotations.toList().toExtra() + PropertyContainer.empty<DEnum>() + annotations.toList().toExtra() ) isInterface -> DInterface( dri, @@ -187,7 +187,7 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { mapTypeParameters(dri), ancestors, listOf(platformData), - PropertyContainer.empty<Interface>() + annotations.toList().toExtra() + PropertyContainer.empty<DInterface>() + annotations.toList().toExtra() ) else -> DClass( dri, @@ -204,7 +204,7 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { documentation, getModifier(), listOf(platformData), - PropertyContainer.empty<Class>() + annotations.toList().toExtra() + PropertyContainer.empty<DClass>() + annotations.toList().toExtra() ) } } @@ -351,7 +351,7 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { accessors.firstOrNull { it.returnType == psi.type }?.let { parseFunction(it, parent) }, psi.getModifier(), listOf(platformData), - PropertyContainer.empty<Property>() + psi.annotations.toList().toExtra() + PropertyContainer.empty<DProperty>() + psi.annotations.toList().toExtra() ) } diff --git a/plugins/base/src/test/kotlin/model/ClassesTest.kt b/plugins/base/src/test/kotlin/model/ClassesTest.kt index 166a72e3..bd35afc5 100644 --- a/plugins/base/src/test/kotlin/model/ClassesTest.kt +++ b/plugins/base/src/test/kotlin/model/ClassesTest.kt @@ -406,7 +406,7 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class inlineModelTest( """@Suppress("abc") class Foo() {}""" ) { - with((this / "classes" / "Foo").cast<Class>()) { + with((this / "classes" / "Foo").cast<DClass>()) { with(extra[Annotations]?.content?.firstOrNull().assertNotNull("annotations")) { dri.toString() equals "kotlin/Suppress////" with(params["names"].assertNotNull("param")) { |