aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src
diff options
context:
space:
mode:
authorSzymon Świstun <sswistun@virtuslab.com>2020-02-28 17:54:26 +0100
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-03-06 09:46:38 +0100
commit2abdfd45a8c3d39745b38629153d83871b8ceae6 (patch)
treef41cc61707edcf2541f4788160594a8ce1ab78fe /plugins/base/src
parente34f813a6c3130b574bacb0a31e727ceb39d0e39 (diff)
downloaddokka-2abdfd45a8c3d39745b38629153d83871b8ceae6.tar.gz
dokka-2abdfd45a8c3d39745b38629153d83871b8ceae6.tar.bz2
dokka-2abdfd45a8c3d39745b38629153d83871b8ceae6.zip
fixed enum entries generation
Diffstat (limited to 'plugins/base/src')
-rw-r--r--plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt2
-rw-r--r--plugins/base/src/test/kotlin/enums/EnumsTest.kt52
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 }