diff options
Diffstat (limited to 'plugins')
3 files changed, 65 insertions, 3 deletions
diff --git a/plugins/base/src/main/kotlin/transformers/documentables/SuppressedByConditionDocumentableFilterTransformer.kt b/plugins/base/src/main/kotlin/transformers/documentables/SuppressedByConditionDocumentableFilterTransformer.kt index b0bdd4b7..66b116cc 100644 --- a/plugins/base/src/main/kotlin/transformers/documentables/SuppressedByConditionDocumentableFilterTransformer.kt +++ b/plugins/base/src/main/kotlin/transformers/documentables/SuppressedByConditionDocumentableFilterTransformer.kt @@ -4,7 +4,8 @@ import org.jetbrains.dokka.model.* import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.transformers.documentation.PreMergeDocumentableTransformer -abstract class SuppressedByConditionDocumentableFilterTransformer(val context: DokkaContext) : PreMergeDocumentableTransformer { +abstract class SuppressedByConditionDocumentableFilterTransformer(val context: DokkaContext) : + PreMergeDocumentableTransformer { override fun invoke(modules: List<DModule>): List<DModule> = modules.map { module -> val (documentable, wasChanged) = processModule(module) @@ -82,7 +83,7 @@ abstract class SuppressedByConditionDocumentableFilterTransformer(val context: D } is DEnum -> { val constructors = classlike.constructors.map { processMember(it) } - val entries = classlike.entries.map { processMember(it) } + val entries = classlike.entries.map { processEnumEntry(it) } val wasClassChange = wasClasslikeChanged || (constructors + entries).any { it.changed } (classlike.takeIf { !wasClassChange } ?: classlike.copy( @@ -97,6 +98,21 @@ abstract class SuppressedByConditionDocumentableFilterTransformer(val context: D } } + private fun processEnumEntry(dEnumEntry: DEnumEntry): DocumentableWithChanges<DEnumEntry> { + if (shouldBeSuppressed(dEnumEntry)) return DocumentableWithChanges.filteredDocumentable() + + val functions = dEnumEntry.functions.map { processMember(it) } + val properties = dEnumEntry.properties.map { processMember(it) } + val classlikes = dEnumEntry.classlikes.map { processClassLike(it) } + + val wasChanged = (functions + properties + classlikes).any { it.changed } + return (dEnumEntry.takeIf { !wasChanged } ?: dEnumEntry.copy( + functions = functions.mapNotNull { it.documentable }, + classlikes = classlikes.mapNotNull { it.documentable }, + properties = properties.mapNotNull { it.documentable }, + )).let { DocumentableWithChanges(it, wasChanged) } + } + private fun <T : Documentable> processMember(member: T): DocumentableWithChanges<T> = if (shouldBeSuppressed(member)) DocumentableWithChanges.filteredDocumentable() else DocumentableWithChanges(member, false) diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt index ed5b8c86..4ddd2d39 100644 --- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt @@ -35,6 +35,7 @@ import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.descriptors.annotations.Annotated import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor +import org.jetbrains.kotlin.idea.core.getDirectlyOverriddenDeclarations import org.jetbrains.kotlin.idea.kdoc.findKDoc import org.jetbrains.kotlin.idea.kdoc.resolveKDocLink import org.jetbrains.kotlin.load.kotlin.toSourceElement @@ -48,6 +49,7 @@ import org.jetbrains.kotlin.resolve.constants.KClassValue.Value.LocalClass import org.jetbrains.kotlin.resolve.constants.KClassValue.Value.NormalClass import org.jetbrains.kotlin.resolve.descriptorUtil.annotationClass import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameOrNull +import org.jetbrains.kotlin.resolve.descriptorUtil.overriddenTreeUniqueAsSequence import org.jetbrains.kotlin.resolve.scopes.MemberScope import org.jetbrains.kotlin.resolve.source.KotlinSourceElement import org.jetbrains.kotlin.resolve.source.PsiSourceElement @@ -1042,7 +1044,7 @@ private class DokkaDescriptorVisitor( get() = kind == CallableMemberDescriptor.Kind.FAKE_OVERRIDE || kind == CallableMemberDescriptor.Kind.SYNTHESIZED || containingDeclaration.fqNameOrNull()?.asString() - ?.let { it == "kotlin.Any" || it == "kotlin.Enum" } == true + ?.let { it == "kotlin.Any" || it == "kotlin.Enum" || it == "java.lang.Enum" || it == "java.lang.Object" } == true } private data class AncestryLevel( diff --git a/plugins/base/src/test/kotlin/transformers/InheritedEntriesDocumentableFilterTransfromerTest.kt b/plugins/base/src/test/kotlin/transformers/InheritedEntriesDocumentableFilterTransfromerTest.kt index 9cb956ba..9cde40a5 100644 --- a/plugins/base/src/test/kotlin/transformers/InheritedEntriesDocumentableFilterTransfromerTest.kt +++ b/plugins/base/src/test/kotlin/transformers/InheritedEntriesDocumentableFilterTransfromerTest.kt @@ -1,8 +1,10 @@ package transformers import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest +import org.jetbrains.dokka.model.DEnum import org.junit.jupiter.api.Test import kotlin.test.assertEquals +import kotlin.test.assertTrue class InheritedEntriesDocumentableFilterTransformerTest : BaseAbstractTest() { val suppressingInheritedConfiguration = dokkaConfiguration { @@ -109,4 +111,46 @@ class InheritedEntriesDocumentableFilterTransformerTest : BaseAbstractTest() { } } } + + @Test + fun `should work with enum entries`(){ + testInline( + """ + /src/suppressed/Suppressed.kt + package suppressed + enum class Suppressed { + ENTRY_SUPPRESSED + } + """.trimIndent(), + suppressingInheritedConfiguration + ) { + preMergeDocumentablesTransformationStage = { modules -> + val entry = (modules.flatMap { it.packages }.flatMap { it.classlikes }.first { it.name == "Suppressed" } as DEnum).entries.first() + assertEquals(emptyList(), entry.properties) + assertEquals(emptyList(), entry.functions) + assertEquals(emptyList(), entry.classlikes) + } + } + } + + @Test + fun `should work with enum entries when not suppressing`(){ + testInline( + """ + /src/suppressed/Suppressed.kt + package suppressed + enum class Suppressed { + ENTRY_SUPPRESSED + } + """.trimIndent(), + nonSuppressingInheritedConfiguration + ) { + preMergeDocumentablesTransformationStage = { modules -> + val entry = (modules.flatMap { it.packages }.flatMap { it.classlikes }.first { it.name == "Suppressed" } as DEnum).entries.first() + assertEquals(listOf("name", "ordinal"), entry.properties.map { it.name }) + assertTrue(entry.functions.map { it.name }.containsAll(listOf("compareTo", "equals", "hashCode", "toString"))) + assertEquals(emptyList(), entry.classlikes) + } + } + } }
\ No newline at end of file |