Skip to content

Commit

Permalink
Make enum entry constructor sourceset dependent
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcinAman authored and BarkingBad committed Jun 9, 2020
1 parent 435e34f commit 23e0d26
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
6 changes: 2 additions & 4 deletions core/src/main/kotlin/model/aditionalExtras.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,10 @@ data class ActualTypealias(val underlyingType: SourceSetDependent<Bound>) : Extr
override val key: ExtraProperty.Key<DClasslike, ActualTypealias> = ActualTypealias
}

data class ConstructorValues(val values: List<String>) : ExtraProperty<DEnumEntry>{
data class ConstructorValues(val values: SourceSetDependent<List<String>>) : ExtraProperty<DEnumEntry>{
companion object : ExtraProperty.Key<DEnumEntry, ConstructorValues> {
override fun mergeStrategyFor(left: ConstructorValues, right: ConstructorValues) =
MergeStrategy.Fail{
throw IllegalArgumentException("Merging constructor parameters not applicable")
}
MergeStrategy.Replace(ConstructorValues(left.values + right.values))
}

override val key: ExtraProperty.Key<DEnumEntry, ConstructorValues> = ConstructorValues
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
group(styles = setOf(TextStyle.Block)){
annotationsBlock(e)
link(e.name, e.dri, styles = emptySet())
e.extra[ConstructorValues]?.let {
list(it.values, prefix = "(", suffix = ")"){
text(it)
e.extra[ConstructorValues]?.let { constructorValues ->
platformText(constructorValues.values, constructorValues.values.keys){
it.joinToString(prefix = "(", postfix = ")")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ private class DokkaDescriptorVisitor(
extra = PropertyContainer.withAll(
descriptor.additionalExtras(),
descriptor.getAnnotations(),
ConstructorValues(descriptor.getAppliedConstructorParameters())
ConstructorValues(descriptor.getAppliedConstructorParameters().toSourceSetDependent())
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,10 @@ open class DefaultPageCreator(
protected open fun contentForEnumEntry(e: DEnumEntry) = contentBuilder.contentFor(e) {
group(kind = ContentKind.Cover) {
header(1, e.name)
+buildSignature(e)
+contentForDescription(e)
sourceSetDependentHint(e.dri, e.sourceSets.toSet()) {
+buildSignature(e)
+contentForDescription(e)
}
}
group(styles = setOf(ContentStyle.TabbedContent)){
+contentForComments(e)
Expand Down
24 changes: 12 additions & 12 deletions plugins/base/src/test/kotlin/enums/EnumsTest.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package enums

import matchers.content.assertNode
import matchers.content.group
import matchers.content.header
import matchers.content.link
import matchers.content.*
import org.jetbrains.dokka.model.ConstructorValues
import org.jetbrains.dokka.model.DEnum
import org.jetbrains.dokka.pages.*
Expand Down Expand Up @@ -121,8 +118,8 @@ class EnumsTest : AbstractCoreTest() {

assertEquals(1, first.extra.allOfType<ConstructorValues>().size)
assertEquals(1, second.extra.allOfType<ConstructorValues>().size)
assertEquals(listOf("\"e1\"", "1", "true"), first.extra.allOfType<ConstructorValues>().first().values)
assertEquals(listOf("\"e2\"", "2", "false"), second.extra.allOfType<ConstructorValues>().first().values)
assertEquals(listOf("\"e1\"", "1", "true"), first.extra.allOfType<ConstructorValues>().first().values.values.first())
assertEquals(listOf("\"e2\"", "2", "false"), second.extra.allOfType<ConstructorValues>().first().values.values.first())
}
}
}
Expand Down Expand Up @@ -171,7 +168,7 @@ class EnumsTest : AbstractCoreTest() {
val first = enum.entries.first()

assertEquals(1, first.extra.allOfType<ConstructorValues>().size)
assertEquals(emptyList<String>(), first.extra.allOfType<ConstructorValues>().first().values)
assertEquals(emptyList<String>(), first.extra.allOfType<ConstructorValues>().first().values.values.first())
assertNotNull(first.functions.find { it.name == "toBeImplemented" })
}
}
Expand Down Expand Up @@ -207,13 +204,16 @@ class EnumsTest : AbstractCoreTest() {

signature.assertNode {
header(1) { +"E1" }
group {
mapOf("SinceKotlin" to setOf("version")).entries.forEach {
group {
platformHinted {
group {
mapOf("SinceKotlin" to setOf("version")).entries.forEach {
group {
unwrapAnnotation(it)
group {
unwrapAnnotation(it)
}
link { +"E1" }
+"()"
}
link { +"E1" }
}
}
}
Expand Down

0 comments on commit 23e0d26

Please sign in to comment.