diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt | 2 | ||||
-rw-r--r-- | plugins/base/src/test/kotlin/enums/EnumsTest.kt | 52 |
2 files changed, 52 insertions, 2 deletions
diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt index 29441ac1..72ce296d 100644 --- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt @@ -87,7 +87,6 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv override fun visitClassDescriptor(descriptor: ClassDescriptor, parent: DRIWithPlatformInfo): Classlike = when (descriptor.kind) { ClassKind.ENUM_CLASS -> enumDescriptor(descriptor, parent) - ClassKind.ENUM_ENTRY -> enumDescriptor(descriptor, parent) ClassKind.OBJECT -> objectDescriptor(descriptor, parent) ClassKind.INTERFACE -> interfaceDescriptor(descriptor, parent) else -> classDescriptor(descriptor, parent) @@ -378,6 +377,7 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv private fun MemberScope.enumEntries(parent: DRIWithPlatformInfo): List<EnumEntry> = this.getContributedDescriptors(DescriptorKindFilter.CLASSIFIERS) { true } .filterIsInstance<ClassDescriptor>() + .filter { it.kind == ClassKind.ENUM_ENTRY } .map { enumEntryDescriptor(it, parent) } diff --git a/plugins/base/src/test/kotlin/enums/EnumsTest.kt b/plugins/base/src/test/kotlin/enums/EnumsTest.kt index 9ea100a3..ea3238a5 100644 --- a/plugins/base/src/test/kotlin/enums/EnumsTest.kt +++ b/plugins/base/src/test/kotlin/enums/EnumsTest.kt @@ -1,14 +1,17 @@ package enums +import org.jetbrains.dokka.model.Enum import org.jetbrains.dokka.pages.ClasslikePageNode import org.jetbrains.dokka.pages.ModulePageNode +import org.junit.Assert +import org.junit.Assert.* import org.junit.Test import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest class EnumsTest : AbstractCoreTest() { @Test - fun basicEnums() { + fun basicEnum() { val configuration = dokkaConfiguration { passes { pass { @@ -39,6 +42,53 @@ class EnumsTest : AbstractCoreTest() { } } + @Test + fun enumWithCompanion() { + val configuration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("src/") + } + } + } + + testInline( + """ + |/src/main/kotlin/basic/Test.kt + |package enums + | + |enum class Test { + | E1, + | E2; + | companion object {} + |} + """.trimMargin(), + configuration + ) { + documentablesCreationStage = {m -> + assertTrue("Module list cannot be empty", m.isNotEmpty()) + m.first().packages.let { p -> + assertTrue("Package list cannot be empty", p.isNotEmpty()) + p.first().classlikes.let { c -> + assertTrue("Classlikes list cannot be empty", c.isNotEmpty()) + + val enum = c.first() as Enum + assertEquals(enum.name, "Test") + assertEquals(enum.entries.count(), 2) + assertNotNull(enum.companion) + } + } + } + pagesGenerationStage = { + val map = it.getClasslikeToMemberMap() + val test = map.filterKeys { it.name == "Test" }.values.firstOrNull() + assert(test != null) { "Test not found" } + assert(test!!.any { it.name == "E1" } && test.any { it.name == "E2" }) { "Enum entries missing in parent" } + assert(map.keys.any { it.name == "E1" } && map.keys.any { it.name == "E2" }) { "Enum entries missing" } + } + } + } + fun ModulePageNode.getClasslikeToMemberMap() = this.parentMap.filterValues { it is ClasslikePageNode }.entries.groupBy({ it.value }) { it.key } |