diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 384bd635..6eb5c82e 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -10,6 +10,7 @@ kotlinxBinaryCompatibilityValidator = "0.13.0" kotlinCompileTesting = "1.5.0" kotlinPoet = "1.13.0" ksp = "1.8.0-1.0.9" +okeyDoke = "1.3.3" [libraries] autoService-runtime = { module = "com.google.auto.service:auto-service-annotations", version.ref = "autoService" } @@ -36,6 +37,7 @@ squareUp-kotlinPoetMetadata = { module = "com.squareup:kotlinpoet-metadata", ver ksp-runtime = { module = "com.google.devtools.ksp:symbol-processing", version.ref = "ksp" } ksp-api = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "ksp" } +okeyDoke = { module = "com.oneeyedmen:okeydoke", version.ref = "okeyDoke" } [plugins] dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" } diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/EmptySealedClass.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/EmptySealedClass.kt index 1916de17..e5160f60 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/EmptySealedClass.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/EmptySealedClass.kt @@ -1,105 +1,8 @@ package com.livefront.sealedenum.compilation.basic import com.livefront.sealedenum.GenSealedEnum -import org.intellij.lang.annotations.Language sealed class EmptySealedClass { @GenSealedEnum(generateEnum = true) companion object } - -@Language("kotlin") -val emptySealedClassGenerated = """ -package com.livefront.sealedenum.compilation.basic - -import com.livefront.sealedenum.EnumForSealedEnumProvider -import com.livefront.sealedenum.SealedEnum -import com.livefront.sealedenum.SealedEnumWithEnumProvider -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List -import kotlin.reflect.KClass - -/** - * An isomorphic enum for the sealed class [EmptySealedClass] - */ -public enum class EmptySealedClassEnum() - -/** - * The isomorphic [EmptySealedClassEnum] for [this]. - */ -public val EmptySealedClass.`enum`: EmptySealedClassEnum - get() = EmptySealedClassSealedEnum.sealedObjectToEnum(this) - -/** - * The isomorphic [EmptySealedClass] for [this]. - */ -public val EmptySealedClassEnum.sealedObject: EmptySealedClass - get() = EmptySealedClassSealedEnum.enumToSealedObject(this) - -/** - * An implementation of [SealedEnum] for the sealed class [EmptySealedClass] - */ -public object EmptySealedClassSealedEnum : SealedEnum, - SealedEnumWithEnumProvider, - EnumForSealedEnumProvider { - public override val values: List by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - emptyList() - } - - - public override val enumClass: KClass - get() = EmptySealedClassEnum::class - - public override fun ordinalOf(obj: EmptySealedClass): Int = throw - AssertionError("Constructing a EmptySealedClass is impossible, since it has no sealed subclasses") - - public override fun nameOf(obj: EmptySealedClass): String = throw - AssertionError("Constructing a EmptySealedClass is impossible, since it has no sealed subclasses") - - public override fun valueOf(name: String): EmptySealedClass = throw - IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - - public override fun sealedObjectToEnum(obj: EmptySealedClass): EmptySealedClassEnum = throw - AssertionError("Constructing a EmptySealedClass is impossible, since it has no sealed subclasses") - - public override fun enumToSealedObject(`enum`: EmptySealedClassEnum): EmptySealedClass = throw - AssertionError("Constructing a EmptySealedClass is impossible, since it has no sealed subclasses") -} - -/** - * The index of [this] in the values list. - */ -public val EmptySealedClass.ordinal: Int - get() = EmptySealedClassSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val EmptySealedClass.name: String - get() = EmptySealedClassSealedEnum.nameOf(this) - -/** - * A list of all [EmptySealedClass] objects. - */ -public val EmptySealedClass.Companion.values: List - get() = EmptySealedClassSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [EmptySealedClass] - */ -public val EmptySealedClass.Companion.sealedEnum: EmptySealedClassSealedEnum - get() = EmptySealedClassSealedEnum - -/** - * Returns the [EmptySealedClass] object for the given [name]. - * - * If the given name doesn't correspond to any [EmptySealedClass], an [IllegalArgumentException] - * will be thrown. - */ -public fun EmptySealedClass.Companion.valueOf(name: String): EmptySealedClass = - EmptySealedClassSealedEnum.valueOf(name) - -""".trimIndent() diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/EmptySealedClassTests.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/EmptySealedClassTests.kt index ae5513ed..f3a0ebd3 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/EmptySealedClassTests.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/EmptySealedClassTests.kt @@ -1,12 +1,16 @@ package com.livefront.sealedenum.compilation.basic +import com.livefront.sealedenum.testing.SealedEnumApprovalsExtension +import com.livefront.sealedenum.testing.assertApprovedGeneratedFile import com.livefront.sealedenum.testing.assertCompiles -import com.livefront.sealedenum.testing.assertGeneratedFileMatches import com.livefront.sealedenum.testing.compile import com.livefront.sealedenum.testing.getCommonSourceFile +import com.oneeyedmen.okeydoke.Approver import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +@ExtendWith(SealedEnumApprovalsExtension::class) class EmptySealedClassTests { @Test fun `empty sealed class`() { @@ -27,10 +31,10 @@ class EmptySealedClassTests { } @Test - fun `compilation generates correct code`() { + fun Approver.`compilation generates correct code`() { val result = compile(getCommonSourceFile("compilation", "basic", "EmptySealedClass.kt")) assertCompiles(result) - assertGeneratedFileMatches("EmptySealedClass_SealedEnum.kt", emptySealedClassGenerated, result) + assertApprovedGeneratedFile("EmptySealedClass_SealedEnum.kt", result) } } diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/EmptySealedInterface.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/EmptySealedInterface.kt index e7c7d9b0..e11fc1f1 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/EmptySealedInterface.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/EmptySealedInterface.kt @@ -1,107 +1,8 @@ package com.livefront.sealedenum.compilation.basic import com.livefront.sealedenum.GenSealedEnum -import org.intellij.lang.annotations.Language sealed interface EmptySealedInterface { @GenSealedEnum(generateEnum = true) companion object } - -@Language("kotlin") -val emptySealedInterfaceGenerated = """ -package com.livefront.sealedenum.compilation.basic - -import com.livefront.sealedenum.EnumForSealedEnumProvider -import com.livefront.sealedenum.SealedEnum -import com.livefront.sealedenum.SealedEnumWithEnumProvider -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List -import kotlin.reflect.KClass - -/** - * An isomorphic enum for the sealed class [EmptySealedInterface] - */ -public enum class EmptySealedInterfaceEnum() - -/** - * The isomorphic [EmptySealedInterfaceEnum] for [this]. - */ -public val EmptySealedInterface.`enum`: EmptySealedInterfaceEnum - get() = EmptySealedInterfaceSealedEnum.sealedObjectToEnum(this) - -/** - * The isomorphic [EmptySealedInterface] for [this]. - */ -public val EmptySealedInterfaceEnum.sealedObject: EmptySealedInterface - get() = EmptySealedInterfaceSealedEnum.enumToSealedObject(this) - -/** - * An implementation of [SealedEnum] for the sealed class [EmptySealedInterface] - */ -public object EmptySealedInterfaceSealedEnum : SealedEnum, - SealedEnumWithEnumProvider, - EnumForSealedEnumProvider { - public override val values: List by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - emptyList() - } - - - public override val enumClass: KClass - get() = EmptySealedInterfaceEnum::class - - public override fun ordinalOf(obj: EmptySealedInterface): Int = throw - AssertionError("Constructing a EmptySealedInterface is impossible, since it has no sealed subclasses") - - public override fun nameOf(obj: EmptySealedInterface): String = throw - AssertionError("Constructing a EmptySealedInterface is impossible, since it has no sealed subclasses") - - public override fun valueOf(name: String): EmptySealedInterface = throw - IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - - public override fun sealedObjectToEnum(obj: EmptySealedInterface): EmptySealedInterfaceEnum = - throw - AssertionError("Constructing a EmptySealedInterface is impossible, since it has no sealed subclasses") - - public override fun enumToSealedObject(`enum`: EmptySealedInterfaceEnum): EmptySealedInterface = - throw - AssertionError("Constructing a EmptySealedInterface is impossible, since it has no sealed subclasses") -} - -/** - * The index of [this] in the values list. - */ -public val EmptySealedInterface.ordinal: Int - get() = EmptySealedInterfaceSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val EmptySealedInterface.name: String - get() = EmptySealedInterfaceSealedEnum.nameOf(this) - -/** - * A list of all [EmptySealedInterface] objects. - */ -public val EmptySealedInterface.Companion.values: List - get() = EmptySealedInterfaceSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [EmptySealedInterface] - */ -public val EmptySealedInterface.Companion.sealedEnum: EmptySealedInterfaceSealedEnum - get() = EmptySealedInterfaceSealedEnum - -/** - * Returns the [EmptySealedInterface] object for the given [name]. - * - * If the given name doesn't correspond to any [EmptySealedInterface], an [IllegalArgumentException] - * will be thrown. - */ -public fun EmptySealedInterface.Companion.valueOf(name: String): EmptySealedInterface = - EmptySealedInterfaceSealedEnum.valueOf(name) - -""".trimIndent() diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/EmptySealedInterfaceTests.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/EmptySealedInterfaceTests.kt index fb603c69..400f9050 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/EmptySealedInterfaceTests.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/EmptySealedInterfaceTests.kt @@ -1,12 +1,16 @@ package com.livefront.sealedenum.compilation.basic +import com.livefront.sealedenum.testing.SealedEnumApprovalsExtension +import com.livefront.sealedenum.testing.assertApprovedGeneratedFile import com.livefront.sealedenum.testing.assertCompiles -import com.livefront.sealedenum.testing.assertGeneratedFileMatches import com.livefront.sealedenum.testing.compile import com.livefront.sealedenum.testing.getCommonSourceFile +import com.oneeyedmen.okeydoke.Approver import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +@ExtendWith(SealedEnumApprovalsExtension::class) class EmptySealedInterfaceTests { @Test fun `empty sealed interface`() { @@ -27,10 +31,10 @@ class EmptySealedInterfaceTests { } @Test - fun `compilation generates correct code`() { + fun Approver.`compilation generates correct code`() { val result = compile(getCommonSourceFile("compilation", "basic", "EmptySealedInterface.kt")) assertCompiles(result) - assertGeneratedFileMatches("EmptySealedInterface_SealedEnum.kt", emptySealedInterfaceGenerated, result) + assertApprovedGeneratedFile("EmptySealedInterface_SealedEnum.kt", result) } } diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/OneObjectSealedClass.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/OneObjectSealedClass.kt index 2d76d397..d8e0581f 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/OneObjectSealedClass.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/OneObjectSealedClass.kt @@ -1,7 +1,6 @@ package com.livefront.sealedenum.compilation.basic import com.livefront.sealedenum.GenSealedEnum -import org.intellij.lang.annotations.Language sealed class OneObjectSealedClass { object FirstObject : OneObjectSealedClass() @@ -9,113 +8,3 @@ sealed class OneObjectSealedClass { @GenSealedEnum(generateEnum = true) companion object } - -@Language("kotlin") -val oneObjectSealedClassGenerated = """ -package com.livefront.sealedenum.compilation.basic - -import com.livefront.sealedenum.EnumForSealedEnumProvider -import com.livefront.sealedenum.SealedEnum -import com.livefront.sealedenum.SealedEnumWithEnumProvider -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List -import kotlin.reflect.KClass - -/** - * An isomorphic enum for the sealed class [OneObjectSealedClass] - */ -public enum class OneObjectSealedClassEnum() { - OneObjectSealedClass_FirstObject, -} - -/** - * The isomorphic [OneObjectSealedClassEnum] for [this]. - */ -public val OneObjectSealedClass.`enum`: OneObjectSealedClassEnum - get() = OneObjectSealedClassSealedEnum.sealedObjectToEnum(this) - -/** - * The isomorphic [OneObjectSealedClass] for [this]. - */ -public val OneObjectSealedClassEnum.sealedObject: OneObjectSealedClass - get() = OneObjectSealedClassSealedEnum.enumToSealedObject(this) - -/** - * An implementation of [SealedEnum] for the sealed class [OneObjectSealedClass] - */ -public object OneObjectSealedClassSealedEnum : SealedEnum, - SealedEnumWithEnumProvider, - EnumForSealedEnumProvider { - public override val values: List by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - listOf( - OneObjectSealedClass.FirstObject - ) - } - - - public override val enumClass: KClass - get() = OneObjectSealedClassEnum::class - - public override fun ordinalOf(obj: OneObjectSealedClass): Int = when (obj) { - is OneObjectSealedClass.FirstObject -> 0 - } - - public override fun nameOf(obj: OneObjectSealedClass): String = when (obj) { - is OneObjectSealedClass.FirstObject -> "OneObjectSealedClass_FirstObject" - } - - public override fun valueOf(name: String): OneObjectSealedClass = when (name) { - "OneObjectSealedClass_FirstObject" -> OneObjectSealedClass.FirstObject - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } - - public override fun sealedObjectToEnum(obj: OneObjectSealedClass): OneObjectSealedClassEnum = - when (obj) { - is OneObjectSealedClass.FirstObject -> - OneObjectSealedClassEnum.OneObjectSealedClass_FirstObject - } - - public override fun enumToSealedObject(`enum`: OneObjectSealedClassEnum): OneObjectSealedClass = - when (enum) { - OneObjectSealedClassEnum.OneObjectSealedClass_FirstObject -> - OneObjectSealedClass.FirstObject - } -} - -/** - * The index of [this] in the values list. - */ -public val OneObjectSealedClass.ordinal: Int - get() = OneObjectSealedClassSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val OneObjectSealedClass.name: String - get() = OneObjectSealedClassSealedEnum.nameOf(this) - -/** - * A list of all [OneObjectSealedClass] objects. - */ -public val OneObjectSealedClass.Companion.values: List - get() = OneObjectSealedClassSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [OneObjectSealedClass] - */ -public val OneObjectSealedClass.Companion.sealedEnum: OneObjectSealedClassSealedEnum - get() = OneObjectSealedClassSealedEnum - -/** - * Returns the [OneObjectSealedClass] object for the given [name]. - * - * If the given name doesn't correspond to any [OneObjectSealedClass], an [IllegalArgumentException] - * will be thrown. - */ -public fun OneObjectSealedClass.Companion.valueOf(name: String): OneObjectSealedClass = - OneObjectSealedClassSealedEnum.valueOf(name) - -""".trimIndent() diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/OneObjectSealedClassTests.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/OneObjectSealedClassTests.kt index d4baf3ec..f3c93d71 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/OneObjectSealedClassTests.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/OneObjectSealedClassTests.kt @@ -1,12 +1,16 @@ package com.livefront.sealedenum.compilation.basic +import com.livefront.sealedenum.testing.SealedEnumApprovalsExtension +import com.livefront.sealedenum.testing.assertApprovedGeneratedFile import com.livefront.sealedenum.testing.assertCompiles -import com.livefront.sealedenum.testing.assertGeneratedFileMatches import com.livefront.sealedenum.testing.compile import com.livefront.sealedenum.testing.getCommonSourceFile +import com.oneeyedmen.okeydoke.Approver import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +@ExtendWith(SealedEnumApprovalsExtension::class) class OneObjectSealedClassTests { @Test fun `one object sealed class`() { @@ -35,10 +39,10 @@ class OneObjectSealedClassTests { } @Test - fun `compilation generates correct code`() { + fun Approver.`compilation generates correct code`() { val result = compile(getCommonSourceFile("compilation", "basic", "OneObjectSealedClass.kt")) assertCompiles(result) - assertGeneratedFileMatches("OneObjectSealedClass_SealedEnum.kt", oneObjectSealedClassGenerated, result) + assertApprovedGeneratedFile("OneObjectSealedClass_SealedEnum.kt", result) } } diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/OneObjectSealedInterface.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/OneObjectSealedInterface.kt index 20c2cabe..173abc63 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/OneObjectSealedInterface.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/OneObjectSealedInterface.kt @@ -1,7 +1,6 @@ package com.livefront.sealedenum.compilation.basic import com.livefront.sealedenum.GenSealedEnum -import org.intellij.lang.annotations.Language sealed interface OneObjectSealedInterface { object FirstObject : OneObjectSealedInterface @@ -9,113 +8,3 @@ sealed interface OneObjectSealedInterface { @GenSealedEnum(generateEnum = true) companion object } - -@Language("kotlin") -val oneObjectSealedInterfaceGenerated = """ -package com.livefront.sealedenum.compilation.basic - -import com.livefront.sealedenum.EnumForSealedEnumProvider -import com.livefront.sealedenum.SealedEnum -import com.livefront.sealedenum.SealedEnumWithEnumProvider -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List -import kotlin.reflect.KClass - -/** - * An isomorphic enum for the sealed class [OneObjectSealedInterface] - */ -public enum class OneObjectSealedInterfaceEnum() { - OneObjectSealedInterface_FirstObject, -} - -/** - * The isomorphic [OneObjectSealedInterfaceEnum] for [this]. - */ -public val OneObjectSealedInterface.`enum`: OneObjectSealedInterfaceEnum - get() = OneObjectSealedInterfaceSealedEnum.sealedObjectToEnum(this) - -/** - * The isomorphic [OneObjectSealedInterface] for [this]. - */ -public val OneObjectSealedInterfaceEnum.sealedObject: OneObjectSealedInterface - get() = OneObjectSealedInterfaceSealedEnum.enumToSealedObject(this) - -/** - * An implementation of [SealedEnum] for the sealed class [OneObjectSealedInterface] - */ -public object OneObjectSealedInterfaceSealedEnum : SealedEnum, - SealedEnumWithEnumProvider, - EnumForSealedEnumProvider { - public override val values: List by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - listOf( - OneObjectSealedInterface.FirstObject - ) - } - - - public override val enumClass: KClass - get() = OneObjectSealedInterfaceEnum::class - - public override fun ordinalOf(obj: OneObjectSealedInterface): Int = when (obj) { - is OneObjectSealedInterface.FirstObject -> 0 - } - - public override fun nameOf(obj: OneObjectSealedInterface): String = when (obj) { - is OneObjectSealedInterface.FirstObject -> "OneObjectSealedInterface_FirstObject" - } - - public override fun valueOf(name: String): OneObjectSealedInterface = when (name) { - "OneObjectSealedInterface_FirstObject" -> OneObjectSealedInterface.FirstObject - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } - - public override fun sealedObjectToEnum(obj: OneObjectSealedInterface): - OneObjectSealedInterfaceEnum = when (obj) { - is OneObjectSealedInterface.FirstObject -> - OneObjectSealedInterfaceEnum.OneObjectSealedInterface_FirstObject - } - - public override fun enumToSealedObject(`enum`: OneObjectSealedInterfaceEnum): - OneObjectSealedInterface = when (enum) { - OneObjectSealedInterfaceEnum.OneObjectSealedInterface_FirstObject -> - OneObjectSealedInterface.FirstObject - } -} - -/** - * The index of [this] in the values list. - */ -public val OneObjectSealedInterface.ordinal: Int - get() = OneObjectSealedInterfaceSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val OneObjectSealedInterface.name: String - get() = OneObjectSealedInterfaceSealedEnum.nameOf(this) - -/** - * A list of all [OneObjectSealedInterface] objects. - */ -public val OneObjectSealedInterface.Companion.values: List - get() = OneObjectSealedInterfaceSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [OneObjectSealedInterface] - */ -public val OneObjectSealedInterface.Companion.sealedEnum: OneObjectSealedInterfaceSealedEnum - get() = OneObjectSealedInterfaceSealedEnum - -/** - * Returns the [OneObjectSealedInterface] object for the given [name]. - * - * If the given name doesn't correspond to any [OneObjectSealedInterface], an - * [IllegalArgumentException] will be thrown. - */ -public fun OneObjectSealedInterface.Companion.valueOf(name: String): OneObjectSealedInterface = - OneObjectSealedInterfaceSealedEnum.valueOf(name) - -""".trimIndent() diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/OneObjectSealedInterfaceTests.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/OneObjectSealedInterfaceTests.kt index 6cb9d3ad..b3d3d21e 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/OneObjectSealedInterfaceTests.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/OneObjectSealedInterfaceTests.kt @@ -1,12 +1,16 @@ package com.livefront.sealedenum.compilation.basic +import com.livefront.sealedenum.testing.SealedEnumApprovalsExtension +import com.livefront.sealedenum.testing.assertApprovedGeneratedFile import com.livefront.sealedenum.testing.assertCompiles -import com.livefront.sealedenum.testing.assertGeneratedFileMatches import com.livefront.sealedenum.testing.compile import com.livefront.sealedenum.testing.getCommonSourceFile +import com.oneeyedmen.okeydoke.Approver import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +@ExtendWith(SealedEnumApprovalsExtension::class) class OneObjectSealedInterfaceTests { @Test fun `one object sealed interface`() { @@ -35,14 +39,10 @@ class OneObjectSealedInterfaceTests { } @Test - fun `compilation generates correct code`() { + fun Approver.`compilation generates correct code`() { val result = compile(getCommonSourceFile("compilation", "basic", "OneObjectSealedInterface.kt")) assertCompiles(result) - assertGeneratedFileMatches( - "OneObjectSealedInterface_SealedEnum.kt", - oneObjectSealedInterfaceGenerated, - result - ) + assertApprovedGeneratedFile("OneObjectSealedInterface_SealedEnum.kt", result) } } diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/TwoObjectSealedClass.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/TwoObjectSealedClass.kt index ac635e82..7f98fd6b 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/TwoObjectSealedClass.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/TwoObjectSealedClass.kt @@ -1,7 +1,6 @@ package com.livefront.sealedenum.compilation.basic import com.livefront.sealedenum.GenSealedEnum -import org.intellij.lang.annotations.Language sealed class TwoObjectSealedClass { object FirstObject : TwoObjectSealedClass() @@ -11,122 +10,3 @@ sealed class TwoObjectSealedClass { @GenSealedEnum(generateEnum = true) companion object } - -@Language("kotlin") -val twoObjectSealedClassGenerated = """ -package com.livefront.sealedenum.compilation.basic - -import com.livefront.sealedenum.EnumForSealedEnumProvider -import com.livefront.sealedenum.SealedEnum -import com.livefront.sealedenum.SealedEnumWithEnumProvider -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List -import kotlin.reflect.KClass - -/** - * An isomorphic enum for the sealed class [TwoObjectSealedClass] - */ -public enum class TwoObjectSealedClassEnum() { - TwoObjectSealedClass_FirstObject, - TwoObjectSealedClass_SecondObject, -} - -/** - * The isomorphic [TwoObjectSealedClassEnum] for [this]. - */ -public val TwoObjectSealedClass.`enum`: TwoObjectSealedClassEnum - get() = TwoObjectSealedClassSealedEnum.sealedObjectToEnum(this) - -/** - * The isomorphic [TwoObjectSealedClass] for [this]. - */ -public val TwoObjectSealedClassEnum.sealedObject: TwoObjectSealedClass - get() = TwoObjectSealedClassSealedEnum.enumToSealedObject(this) - -/** - * An implementation of [SealedEnum] for the sealed class [TwoObjectSealedClass] - */ -public object TwoObjectSealedClassSealedEnum : SealedEnum, - SealedEnumWithEnumProvider, - EnumForSealedEnumProvider { - public override val values: List by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - listOf( - TwoObjectSealedClass.FirstObject, - TwoObjectSealedClass.SecondObject - ) - } - - - public override val enumClass: KClass - get() = TwoObjectSealedClassEnum::class - - public override fun ordinalOf(obj: TwoObjectSealedClass): Int = when (obj) { - is TwoObjectSealedClass.FirstObject -> 0 - is TwoObjectSealedClass.SecondObject -> 1 - } - - public override fun nameOf(obj: TwoObjectSealedClass): String = when (obj) { - is TwoObjectSealedClass.FirstObject -> "TwoObjectSealedClass_FirstObject" - is TwoObjectSealedClass.SecondObject -> "TwoObjectSealedClass_SecondObject" - } - - public override fun valueOf(name: String): TwoObjectSealedClass = when (name) { - "TwoObjectSealedClass_FirstObject" -> TwoObjectSealedClass.FirstObject - "TwoObjectSealedClass_SecondObject" -> TwoObjectSealedClass.SecondObject - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } - - public override fun sealedObjectToEnum(obj: TwoObjectSealedClass): TwoObjectSealedClassEnum = - when (obj) { - is TwoObjectSealedClass.FirstObject -> - TwoObjectSealedClassEnum.TwoObjectSealedClass_FirstObject - is TwoObjectSealedClass.SecondObject -> - TwoObjectSealedClassEnum.TwoObjectSealedClass_SecondObject - } - - public override fun enumToSealedObject(`enum`: TwoObjectSealedClassEnum): TwoObjectSealedClass = - when (enum) { - TwoObjectSealedClassEnum.TwoObjectSealedClass_FirstObject -> - TwoObjectSealedClass.FirstObject - TwoObjectSealedClassEnum.TwoObjectSealedClass_SecondObject -> - TwoObjectSealedClass.SecondObject - } -} - -/** - * The index of [this] in the values list. - */ -public val TwoObjectSealedClass.ordinal: Int - get() = TwoObjectSealedClassSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val TwoObjectSealedClass.name: String - get() = TwoObjectSealedClassSealedEnum.nameOf(this) - -/** - * A list of all [TwoObjectSealedClass] objects. - */ -public val TwoObjectSealedClass.Companion.values: List - get() = TwoObjectSealedClassSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [TwoObjectSealedClass] - */ -public val TwoObjectSealedClass.Companion.sealedEnum: TwoObjectSealedClassSealedEnum - get() = TwoObjectSealedClassSealedEnum - -/** - * Returns the [TwoObjectSealedClass] object for the given [name]. - * - * If the given name doesn't correspond to any [TwoObjectSealedClass], an [IllegalArgumentException] - * will be thrown. - */ -public fun TwoObjectSealedClass.Companion.valueOf(name: String): TwoObjectSealedClass = - TwoObjectSealedClassSealedEnum.valueOf(name) - -""".trimIndent() diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/TwoObjectSealedClassTests.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/TwoObjectSealedClassTests.kt index 9608ff5b..c88a08b6 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/TwoObjectSealedClassTests.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/TwoObjectSealedClassTests.kt @@ -1,12 +1,16 @@ package com.livefront.sealedenum.compilation.basic +import com.livefront.sealedenum.testing.SealedEnumApprovalsExtension +import com.livefront.sealedenum.testing.assertApprovedGeneratedFile import com.livefront.sealedenum.testing.assertCompiles -import com.livefront.sealedenum.testing.assertGeneratedFileMatches import com.livefront.sealedenum.testing.compile import com.livefront.sealedenum.testing.getCommonSourceFile +import com.oneeyedmen.okeydoke.Approver import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +@ExtendWith(SealedEnumApprovalsExtension::class) class TwoObjectSealedClassTests { @Test fun `two objects sealed class`() { @@ -41,10 +45,10 @@ class TwoObjectSealedClassTests { } @Test - fun `compilation generates correct code`() { + fun Approver.`compilation generates correct code`() { val result = compile(getCommonSourceFile("compilation", "basic", "TwoObjectSealedClass.kt")) assertCompiles(result) - assertGeneratedFileMatches("TwoObjectSealedClass_SealedEnum.kt", twoObjectSealedClassGenerated, result) + assertApprovedGeneratedFile("TwoObjectSealedClass_SealedEnum.kt", result) } } diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/TwoObjectSealedInterface.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/TwoObjectSealedInterface.kt index 064101bd..340879d7 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/TwoObjectSealedInterface.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/TwoObjectSealedInterface.kt @@ -1,7 +1,6 @@ package com.livefront.sealedenum.compilation.basic import com.livefront.sealedenum.GenSealedEnum -import org.intellij.lang.annotations.Language sealed interface TwoObjectSealedInterface { object FirstObject : TwoObjectSealedInterface @@ -11,122 +10,3 @@ sealed interface TwoObjectSealedInterface { @GenSealedEnum(generateEnum = true) companion object } - -@Language("kotlin") -val twoObjectSealedInterfaceGenerated = """ -package com.livefront.sealedenum.compilation.basic - -import com.livefront.sealedenum.EnumForSealedEnumProvider -import com.livefront.sealedenum.SealedEnum -import com.livefront.sealedenum.SealedEnumWithEnumProvider -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List -import kotlin.reflect.KClass - -/** - * An isomorphic enum for the sealed class [TwoObjectSealedInterface] - */ -public enum class TwoObjectSealedInterfaceEnum() { - TwoObjectSealedInterface_FirstObject, - TwoObjectSealedInterface_SecondObject, -} - -/** - * The isomorphic [TwoObjectSealedInterfaceEnum] for [this]. - */ -public val TwoObjectSealedInterface.`enum`: TwoObjectSealedInterfaceEnum - get() = TwoObjectSealedInterfaceSealedEnum.sealedObjectToEnum(this) - -/** - * The isomorphic [TwoObjectSealedInterface] for [this]. - */ -public val TwoObjectSealedInterfaceEnum.sealedObject: TwoObjectSealedInterface - get() = TwoObjectSealedInterfaceSealedEnum.enumToSealedObject(this) - -/** - * An implementation of [SealedEnum] for the sealed class [TwoObjectSealedInterface] - */ -public object TwoObjectSealedInterfaceSealedEnum : SealedEnum, - SealedEnumWithEnumProvider, - EnumForSealedEnumProvider { - public override val values: List by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - listOf( - TwoObjectSealedInterface.FirstObject, - TwoObjectSealedInterface.SecondObject - ) - } - - - public override val enumClass: KClass - get() = TwoObjectSealedInterfaceEnum::class - - public override fun ordinalOf(obj: TwoObjectSealedInterface): Int = when (obj) { - is TwoObjectSealedInterface.FirstObject -> 0 - is TwoObjectSealedInterface.SecondObject -> 1 - } - - public override fun nameOf(obj: TwoObjectSealedInterface): String = when (obj) { - is TwoObjectSealedInterface.FirstObject -> "TwoObjectSealedInterface_FirstObject" - is TwoObjectSealedInterface.SecondObject -> "TwoObjectSealedInterface_SecondObject" - } - - public override fun valueOf(name: String): TwoObjectSealedInterface = when (name) { - "TwoObjectSealedInterface_FirstObject" -> TwoObjectSealedInterface.FirstObject - "TwoObjectSealedInterface_SecondObject" -> TwoObjectSealedInterface.SecondObject - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } - - public override fun sealedObjectToEnum(obj: TwoObjectSealedInterface): - TwoObjectSealedInterfaceEnum = when (obj) { - is TwoObjectSealedInterface.FirstObject -> - TwoObjectSealedInterfaceEnum.TwoObjectSealedInterface_FirstObject - is TwoObjectSealedInterface.SecondObject -> - TwoObjectSealedInterfaceEnum.TwoObjectSealedInterface_SecondObject - } - - public override fun enumToSealedObject(`enum`: TwoObjectSealedInterfaceEnum): - TwoObjectSealedInterface = when (enum) { - TwoObjectSealedInterfaceEnum.TwoObjectSealedInterface_FirstObject -> - TwoObjectSealedInterface.FirstObject - TwoObjectSealedInterfaceEnum.TwoObjectSealedInterface_SecondObject -> - TwoObjectSealedInterface.SecondObject - } -} - -/** - * The index of [this] in the values list. - */ -public val TwoObjectSealedInterface.ordinal: Int - get() = TwoObjectSealedInterfaceSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val TwoObjectSealedInterface.name: String - get() = TwoObjectSealedInterfaceSealedEnum.nameOf(this) - -/** - * A list of all [TwoObjectSealedInterface] objects. - */ -public val TwoObjectSealedInterface.Companion.values: List - get() = TwoObjectSealedInterfaceSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [TwoObjectSealedInterface] - */ -public val TwoObjectSealedInterface.Companion.sealedEnum: TwoObjectSealedInterfaceSealedEnum - get() = TwoObjectSealedInterfaceSealedEnum - -/** - * Returns the [TwoObjectSealedInterface] object for the given [name]. - * - * If the given name doesn't correspond to any [TwoObjectSealedInterface], an - * [IllegalArgumentException] will be thrown. - */ -public fun TwoObjectSealedInterface.Companion.valueOf(name: String): TwoObjectSealedInterface = - TwoObjectSealedInterfaceSealedEnum.valueOf(name) - -""".trimIndent() diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/TwoObjectSealedInterfaceTests.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/TwoObjectSealedInterfaceTests.kt index b828f2de..28679e49 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/TwoObjectSealedInterfaceTests.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/basic/TwoObjectSealedInterfaceTests.kt @@ -1,12 +1,16 @@ package com.livefront.sealedenum.compilation.basic +import com.livefront.sealedenum.testing.SealedEnumApprovalsExtension +import com.livefront.sealedenum.testing.assertApprovedGeneratedFile import com.livefront.sealedenum.testing.assertCompiles -import com.livefront.sealedenum.testing.assertGeneratedFileMatches import com.livefront.sealedenum.testing.compile import com.livefront.sealedenum.testing.getCommonSourceFile +import com.oneeyedmen.okeydoke.Approver import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +@ExtendWith(SealedEnumApprovalsExtension::class) class TwoObjectSealedInterfaceTests { @Test fun `two objects sealed interface`() { @@ -41,14 +45,10 @@ class TwoObjectSealedInterfaceTests { } @Test - fun `compilation generates correct code`() { + fun Approver.`compilation generates correct code`() { val result = compile(getCommonSourceFile("compilation", "basic", "TwoObjectSealedInterface.kt")) assertCompiles(result) - assertGeneratedFileMatches( - "TwoObjectSealedInterface_SealedEnum.kt", - twoObjectSealedInterfaceGenerated, - result - ) + assertApprovedGeneratedFile("TwoObjectSealedInterface_SealedEnum.kt", result) } } diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/generics/GenericSealedClass.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/generics/GenericSealedClass.kt index 6519b8cf..a25fc624 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/generics/GenericSealedClass.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/generics/GenericSealedClass.kt @@ -1,7 +1,6 @@ package com.livefront.sealedenum.compilation.generics import com.livefront.sealedenum.GenSealedEnum -import org.intellij.lang.annotations.Language interface GenericInterfaceOut @@ -16,134 +15,6 @@ sealed class OneTypeParameterSealedClass : GenericInterfaceOut { companion object OneType } -@Language("kotlin") -val oneTypeParameterSealedClassGenerated = """ -package com.livefront.sealedenum.compilation.generics - -import com.livefront.sealedenum.EnumForSealedEnumProvider -import com.livefront.sealedenum.SealedEnum -import com.livefront.sealedenum.SealedEnumWithEnumProvider -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List -import kotlin.reflect.KClass - -/** - * An isomorphic enum for the sealed class [OneTypeParameterSealedClass] - */ -public enum class OneTypeParameterSealedClassEnum() { - OneTypeParameterSealedClass_FirstObject, - OneTypeParameterSealedClass_SecondObject, - OneTypeParameterSealedClass_ThirdObject, -} - -/** - * The isomorphic [OneTypeParameterSealedClassEnum] for [this]. - */ -public val OneTypeParameterSealedClass<*>.`enum`: OneTypeParameterSealedClassEnum - get() = OneTypeParameterSealedClassSealedEnum.sealedObjectToEnum(this) - -/** - * The isomorphic [OneTypeParameterSealedClass] for [this]. - */ -public val OneTypeParameterSealedClassEnum.sealedObject: OneTypeParameterSealedClass<*> - get() = OneTypeParameterSealedClassSealedEnum.enumToSealedObject(this) - -/** - * An implementation of [SealedEnum] for the sealed class [OneTypeParameterSealedClass] - */ -public object OneTypeParameterSealedClassSealedEnum : SealedEnum>, - SealedEnumWithEnumProvider, OneTypeParameterSealedClassEnum>, - EnumForSealedEnumProvider, OneTypeParameterSealedClassEnum> { - public override val values: List> by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - listOf( - OneTypeParameterSealedClass.FirstObject, - OneTypeParameterSealedClass.SecondObject, - OneTypeParameterSealedClass.ThirdObject - ) - } - - - public override val enumClass: KClass - get() = OneTypeParameterSealedClassEnum::class - - public override fun ordinalOf(obj: OneTypeParameterSealedClass<*>): Int = when (obj) { - is OneTypeParameterSealedClass.FirstObject -> 0 - is OneTypeParameterSealedClass.SecondObject -> 1 - is OneTypeParameterSealedClass.ThirdObject -> 2 - } - - public override fun nameOf(obj: OneTypeParameterSealedClass<*>): String = when (obj) { - is OneTypeParameterSealedClass.FirstObject -> "OneTypeParameterSealedClass_FirstObject" - is OneTypeParameterSealedClass.SecondObject -> "OneTypeParameterSealedClass_SecondObject" - is OneTypeParameterSealedClass.ThirdObject -> "OneTypeParameterSealedClass_ThirdObject" - } - - public override fun valueOf(name: String): OneTypeParameterSealedClass<*> = when (name) { - "OneTypeParameterSealedClass_FirstObject" -> OneTypeParameterSealedClass.FirstObject - "OneTypeParameterSealedClass_SecondObject" -> OneTypeParameterSealedClass.SecondObject - "OneTypeParameterSealedClass_ThirdObject" -> OneTypeParameterSealedClass.ThirdObject - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } - - public override fun sealedObjectToEnum(obj: OneTypeParameterSealedClass<*>): - OneTypeParameterSealedClassEnum = when (obj) { - is OneTypeParameterSealedClass.FirstObject -> - OneTypeParameterSealedClassEnum.OneTypeParameterSealedClass_FirstObject - is OneTypeParameterSealedClass.SecondObject -> - OneTypeParameterSealedClassEnum.OneTypeParameterSealedClass_SecondObject - is OneTypeParameterSealedClass.ThirdObject -> - OneTypeParameterSealedClassEnum.OneTypeParameterSealedClass_ThirdObject - } - - public override fun enumToSealedObject(`enum`: OneTypeParameterSealedClassEnum): - OneTypeParameterSealedClass<*> = when (enum) { - OneTypeParameterSealedClassEnum.OneTypeParameterSealedClass_FirstObject -> - OneTypeParameterSealedClass.FirstObject - OneTypeParameterSealedClassEnum.OneTypeParameterSealedClass_SecondObject -> - OneTypeParameterSealedClass.SecondObject - OneTypeParameterSealedClassEnum.OneTypeParameterSealedClass_ThirdObject -> - OneTypeParameterSealedClass.ThirdObject - } -} - -/** - * The index of [this] in the values list. - */ -public val OneTypeParameterSealedClass<*>.ordinal: Int - get() = OneTypeParameterSealedClassSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val OneTypeParameterSealedClass<*>.name: String - get() = OneTypeParameterSealedClassSealedEnum.nameOf(this) - -/** - * A list of all [OneTypeParameterSealedClass] objects. - */ -public val OneTypeParameterSealedClass.OneType.values: List> - get() = OneTypeParameterSealedClassSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [OneTypeParameterSealedClass] - */ -public val OneTypeParameterSealedClass.OneType.sealedEnum: OneTypeParameterSealedClassSealedEnum - get() = OneTypeParameterSealedClassSealedEnum - -/** - * Returns the [OneTypeParameterSealedClass] object for the given [name]. - * - * If the given name doesn't correspond to any [OneTypeParameterSealedClass], an - * [IllegalArgumentException] will be thrown. - */ -public fun OneTypeParameterSealedClass.OneType.valueOf(name: String): OneTypeParameterSealedClass<*> - = OneTypeParameterSealedClassSealedEnum.valueOf(name) - -""".trimIndent() - interface GenericInterfaceTwoOut sealed class TwoTypeParameterSealedClass : GenericInterfaceTwoOut { @@ -155,126 +26,6 @@ sealed class TwoTypeParameterSealedClass : GenericInterfaceTwoOut< companion object TwoType } -@Language("kotlin") -val twoTypeParameterSealedClassGenerated = """ -package com.livefront.sealedenum.compilation.generics - -import com.livefront.sealedenum.EnumForSealedEnumProvider -import com.livefront.sealedenum.SealedEnum -import com.livefront.sealedenum.SealedEnumWithEnumProvider -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List -import kotlin.reflect.KClass - -/** - * An isomorphic enum for the sealed class [TwoTypeParameterSealedClass] - */ -public enum class TwoTypeParameterSealedClassEnum() { - TwoTypeParameterSealedClass_FirstObject, - TwoTypeParameterSealedClass_SecondObject, -} - -/** - * The isomorphic [TwoTypeParameterSealedClassEnum] for [this]. - */ -public val TwoTypeParameterSealedClass<*, *>.`enum`: TwoTypeParameterSealedClassEnum - get() = TwoTypeParameterSealedClassSealedEnum.sealedObjectToEnum(this) - -/** - * The isomorphic [TwoTypeParameterSealedClass] for [this]. - */ -public val TwoTypeParameterSealedClassEnum.sealedObject: TwoTypeParameterSealedClass<*, *> - get() = TwoTypeParameterSealedClassSealedEnum.enumToSealedObject(this) - -/** - * An implementation of [SealedEnum] for the sealed class [TwoTypeParameterSealedClass] - */ -public object TwoTypeParameterSealedClassSealedEnum : SealedEnum>, - SealedEnumWithEnumProvider, TwoTypeParameterSealedClassEnum>, - EnumForSealedEnumProvider, TwoTypeParameterSealedClassEnum> - { - public override val values: List> by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - listOf( - TwoTypeParameterSealedClass.FirstObject, - TwoTypeParameterSealedClass.SecondObject - ) - } - - - public override val enumClass: KClass - get() = TwoTypeParameterSealedClassEnum::class - - public override fun ordinalOf(obj: TwoTypeParameterSealedClass<*, *>): Int = when (obj) { - is TwoTypeParameterSealedClass.FirstObject -> 0 - is TwoTypeParameterSealedClass.SecondObject -> 1 - } - - public override fun nameOf(obj: TwoTypeParameterSealedClass<*, *>): String = when (obj) { - is TwoTypeParameterSealedClass.FirstObject -> "TwoTypeParameterSealedClass_FirstObject" - is TwoTypeParameterSealedClass.SecondObject -> "TwoTypeParameterSealedClass_SecondObject" - } - - public override fun valueOf(name: String): TwoTypeParameterSealedClass<*, *> = when (name) { - "TwoTypeParameterSealedClass_FirstObject" -> TwoTypeParameterSealedClass.FirstObject - "TwoTypeParameterSealedClass_SecondObject" -> TwoTypeParameterSealedClass.SecondObject - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } - - public override fun sealedObjectToEnum(obj: TwoTypeParameterSealedClass<*, *>): - TwoTypeParameterSealedClassEnum = when (obj) { - is TwoTypeParameterSealedClass.FirstObject -> - TwoTypeParameterSealedClassEnum.TwoTypeParameterSealedClass_FirstObject - is TwoTypeParameterSealedClass.SecondObject -> - TwoTypeParameterSealedClassEnum.TwoTypeParameterSealedClass_SecondObject - } - - public override fun enumToSealedObject(`enum`: TwoTypeParameterSealedClassEnum): - TwoTypeParameterSealedClass<*, *> = when (enum) { - TwoTypeParameterSealedClassEnum.TwoTypeParameterSealedClass_FirstObject -> - TwoTypeParameterSealedClass.FirstObject - TwoTypeParameterSealedClassEnum.TwoTypeParameterSealedClass_SecondObject -> - TwoTypeParameterSealedClass.SecondObject - } -} - -/** - * The index of [this] in the values list. - */ -public val TwoTypeParameterSealedClass<*, *>.ordinal: Int - get() = TwoTypeParameterSealedClassSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val TwoTypeParameterSealedClass<*, *>.name: String - get() = TwoTypeParameterSealedClassSealedEnum.nameOf(this) - -/** - * A list of all [TwoTypeParameterSealedClass] objects. - */ -public val TwoTypeParameterSealedClass.TwoType.values: List> - get() = TwoTypeParameterSealedClassSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [TwoTypeParameterSealedClass] - */ -public val TwoTypeParameterSealedClass.TwoType.sealedEnum: TwoTypeParameterSealedClassSealedEnum - get() = TwoTypeParameterSealedClassSealedEnum - -/** - * Returns the [TwoTypeParameterSealedClass] object for the given [name]. - * - * If the given name doesn't correspond to any [TwoTypeParameterSealedClass], an - * [IllegalArgumentException] will be thrown. - */ -public fun TwoTypeParameterSealedClass.TwoType.valueOf(name: String): - TwoTypeParameterSealedClass<*, *> = TwoTypeParameterSealedClassSealedEnum.valueOf(name) - -""".trimIndent() - interface GenericInterfaceInOut sealed class LimitedTypeParameterSealedClass : GenericInterfaceInOut { @@ -286,133 +37,6 @@ sealed class LimitedTypeParameterSealedClass : GenericInt companion object LimitedType } -@Language("kotlin") -val limitedTypeParameterSealedClassGenerated = """ -package com.livefront.sealedenum.compilation.generics - -import com.livefront.sealedenum.EnumForSealedEnumProvider -import com.livefront.sealedenum.SealedEnum -import com.livefront.sealedenum.SealedEnumWithEnumProvider -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List -import kotlin.reflect.KClass - -/** - * An isomorphic enum for the sealed class [LimitedTypeParameterSealedClass] - */ -public enum class LimitedTypeParameterSealedClassEnum() { - LimitedTypeParameterSealedClass_FirstObject, - LimitedTypeParameterSealedClass_SecondObject, -} - -/** - * The isomorphic [LimitedTypeParameterSealedClassEnum] for [this]. - */ -public val LimitedTypeParameterSealedClass<*, *>.`enum`: LimitedTypeParameterSealedClassEnum - get() = LimitedTypeParameterSealedClassSealedEnum.sealedObjectToEnum(this) - -/** - * The isomorphic [LimitedTypeParameterSealedClass] for [this]. - */ -public val LimitedTypeParameterSealedClassEnum.sealedObject: LimitedTypeParameterSealedClass<*, *> - get() = LimitedTypeParameterSealedClassSealedEnum.enumToSealedObject(this) - -/** - * An implementation of [SealedEnum] for the sealed class [LimitedTypeParameterSealedClass] - */ -public object LimitedTypeParameterSealedClassSealedEnum : - SealedEnum>, - SealedEnumWithEnumProvider, LimitedTypeParameterSealedClassEnum>, - EnumForSealedEnumProvider, LimitedTypeParameterSealedClassEnum> - { - public override val values: List> by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - listOf( - LimitedTypeParameterSealedClass.FirstObject, - LimitedTypeParameterSealedClass.SecondObject - ) - } - - - public override val enumClass: KClass - get() = LimitedTypeParameterSealedClassEnum::class - - public override fun ordinalOf(obj: LimitedTypeParameterSealedClass<*, *>): Int = when (obj) { - is LimitedTypeParameterSealedClass.FirstObject -> 0 - is LimitedTypeParameterSealedClass.SecondObject -> 1 - } - - public override fun nameOf(obj: LimitedTypeParameterSealedClass<*, *>): String = when (obj) { - is LimitedTypeParameterSealedClass.FirstObject -> - "LimitedTypeParameterSealedClass_FirstObject" - is LimitedTypeParameterSealedClass.SecondObject -> - "LimitedTypeParameterSealedClass_SecondObject" - } - - public override fun valueOf(name: String): LimitedTypeParameterSealedClass<*, *> = when (name) { - "LimitedTypeParameterSealedClass_FirstObject" -> LimitedTypeParameterSealedClass.FirstObject - "LimitedTypeParameterSealedClass_SecondObject" -> - LimitedTypeParameterSealedClass.SecondObject - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } - - public override fun sealedObjectToEnum(obj: LimitedTypeParameterSealedClass<*, *>): - LimitedTypeParameterSealedClassEnum = when (obj) { - is LimitedTypeParameterSealedClass.FirstObject -> - LimitedTypeParameterSealedClassEnum.LimitedTypeParameterSealedClass_FirstObject - is LimitedTypeParameterSealedClass.SecondObject -> - LimitedTypeParameterSealedClassEnum.LimitedTypeParameterSealedClass_SecondObject - } - - public override fun enumToSealedObject(`enum`: LimitedTypeParameterSealedClassEnum): - LimitedTypeParameterSealedClass<*, *> = when (enum) { - LimitedTypeParameterSealedClassEnum.LimitedTypeParameterSealedClass_FirstObject -> - LimitedTypeParameterSealedClass.FirstObject - LimitedTypeParameterSealedClassEnum.LimitedTypeParameterSealedClass_SecondObject -> - LimitedTypeParameterSealedClass.SecondObject - } -} - -/** - * The index of [this] in the values list. - */ -public val LimitedTypeParameterSealedClass<*, *>.ordinal: Int - get() = LimitedTypeParameterSealedClassSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val LimitedTypeParameterSealedClass<*, *>.name: String - get() = LimitedTypeParameterSealedClassSealedEnum.nameOf(this) - -/** - * A list of all [LimitedTypeParameterSealedClass] objects. - */ -public val LimitedTypeParameterSealedClass.LimitedType.values: - List> - get() = LimitedTypeParameterSealedClassSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [LimitedTypeParameterSealedClass] - */ -public val LimitedTypeParameterSealedClass.LimitedType.sealedEnum: - LimitedTypeParameterSealedClassSealedEnum - get() = LimitedTypeParameterSealedClassSealedEnum - -/** - * Returns the [LimitedTypeParameterSealedClass] object for the given [name]. - * - * If the given name doesn't correspond to any [LimitedTypeParameterSealedClass], an - * [IllegalArgumentException] will be thrown. - */ -public fun LimitedTypeParameterSealedClass.LimitedType.valueOf(name: String): - LimitedTypeParameterSealedClass<*, *> = - LimitedTypeParameterSealedClassSealedEnum.valueOf(name) - -""".trimIndent() - interface MultipleBoundsInterface1 interface MultipleBoundsInterface2 @@ -425,113 +49,3 @@ sealed class MultipleBoundsSealedClass where T : MultipleBoundsInterface1, T @GenSealedEnum(generateEnum = true) companion object } - -@Language("kotlin") -val multipleBoundsSealedClassGenerated = """ -package com.livefront.sealedenum.compilation.generics - -import com.livefront.sealedenum.EnumForSealedEnumProvider -import com.livefront.sealedenum.SealedEnum -import com.livefront.sealedenum.SealedEnumWithEnumProvider -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List -import kotlin.reflect.KClass - -/** - * An isomorphic enum for the sealed class [MultipleBoundsSealedClass] - */ -public enum class MultipleBoundsSealedClassEnum() { - MultipleBoundsSealedClass_FirstObject, -} - -/** - * The isomorphic [MultipleBoundsSealedClassEnum] for [this]. - */ -public val MultipleBoundsSealedClass<*>.`enum`: MultipleBoundsSealedClassEnum - get() = MultipleBoundsSealedClassSealedEnum.sealedObjectToEnum(this) - -/** - * The isomorphic [MultipleBoundsSealedClass] for [this]. - */ -public val MultipleBoundsSealedClassEnum.sealedObject: MultipleBoundsSealedClass<*> - get() = MultipleBoundsSealedClassSealedEnum.enumToSealedObject(this) - -/** - * An implementation of [SealedEnum] for the sealed class [MultipleBoundsSealedClass] - */ -public object MultipleBoundsSealedClassSealedEnum : SealedEnum>, - SealedEnumWithEnumProvider, MultipleBoundsSealedClassEnum>, - EnumForSealedEnumProvider, MultipleBoundsSealedClassEnum> { - public override val values: List> by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - listOf( - MultipleBoundsSealedClass.FirstObject - ) - } - - - public override val enumClass: KClass - get() = MultipleBoundsSealedClassEnum::class - - public override fun ordinalOf(obj: MultipleBoundsSealedClass<*>): Int = when (obj) { - is MultipleBoundsSealedClass.FirstObject -> 0 - } - - public override fun nameOf(obj: MultipleBoundsSealedClass<*>): String = when (obj) { - is MultipleBoundsSealedClass.FirstObject -> "MultipleBoundsSealedClass_FirstObject" - } - - public override fun valueOf(name: String): MultipleBoundsSealedClass<*> = when (name) { - "MultipleBoundsSealedClass_FirstObject" -> MultipleBoundsSealedClass.FirstObject - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } - - public override fun sealedObjectToEnum(obj: MultipleBoundsSealedClass<*>): - MultipleBoundsSealedClassEnum = when (obj) { - is MultipleBoundsSealedClass.FirstObject -> - MultipleBoundsSealedClassEnum.MultipleBoundsSealedClass_FirstObject - } - - public override fun enumToSealedObject(`enum`: MultipleBoundsSealedClassEnum): - MultipleBoundsSealedClass<*> = when (enum) { - MultipleBoundsSealedClassEnum.MultipleBoundsSealedClass_FirstObject -> - MultipleBoundsSealedClass.FirstObject - } -} - -/** - * The index of [this] in the values list. - */ -public val MultipleBoundsSealedClass<*>.ordinal: Int - get() = MultipleBoundsSealedClassSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val MultipleBoundsSealedClass<*>.name: String - get() = MultipleBoundsSealedClassSealedEnum.nameOf(this) - -/** - * A list of all [MultipleBoundsSealedClass] objects. - */ -public val MultipleBoundsSealedClass.Companion.values: List> - get() = MultipleBoundsSealedClassSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [MultipleBoundsSealedClass] - */ -public val MultipleBoundsSealedClass.Companion.sealedEnum: MultipleBoundsSealedClassSealedEnum - get() = MultipleBoundsSealedClassSealedEnum - -/** - * Returns the [MultipleBoundsSealedClass] object for the given [name]. - * - * If the given name doesn't correspond to any [MultipleBoundsSealedClass], an - * [IllegalArgumentException] will be thrown. - */ -public fun MultipleBoundsSealedClass.Companion.valueOf(name: String): MultipleBoundsSealedClass<*> = - MultipleBoundsSealedClassSealedEnum.valueOf(name) - -""".trimIndent() diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/generics/GenericSealedClassTests.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/generics/GenericSealedClassTests.kt index 99789c84..9865f8b1 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/generics/GenericSealedClassTests.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/generics/GenericSealedClassTests.kt @@ -1,12 +1,16 @@ package com.livefront.sealedenum.compilation.generics +import com.livefront.sealedenum.testing.SealedEnumApprovalsExtension +import com.livefront.sealedenum.testing.assertApprovedGeneratedFile import com.livefront.sealedenum.testing.assertCompiles -import com.livefront.sealedenum.testing.assertGeneratedFileMatches import com.livefront.sealedenum.testing.compile import com.livefront.sealedenum.testing.getCommonSourceFile +import com.oneeyedmen.okeydoke.Approver import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +@ExtendWith(SealedEnumApprovalsExtension::class) class GenericSealedClassTests { @Test @@ -22,15 +26,11 @@ class GenericSealedClassTests { } @Test - fun `compilation for one type parameter generates correct code`() { + fun Approver.`compilation for one type parameter generates correct code`() { val result = compile(getCommonSourceFile("compilation", "generics", "GenericSealedClass.kt")) assertCompiles(result) - assertGeneratedFileMatches( - "OneTypeParameterSealedClass_SealedEnum.kt", - oneTypeParameterSealedClassGenerated, - result - ) + assertApprovedGeneratedFile("OneTypeParameterSealedClass_SealedEnum.kt", result) } @Test @@ -45,15 +45,11 @@ class GenericSealedClassTests { } @Test - fun `compilation for two type parameter generates correct code`() { + fun Approver.`compilation for two type parameter generates correct code`() { val result = compile(getCommonSourceFile("compilation", "generics", "GenericSealedClass.kt")) assertCompiles(result) - assertGeneratedFileMatches( - "TwoTypeParameterSealedClass_SealedEnum.kt", - twoTypeParameterSealedClassGenerated, - result - ) + assertApprovedGeneratedFile("TwoTypeParameterSealedClass_SealedEnum.kt", result) } @Test @@ -68,15 +64,11 @@ class GenericSealedClassTests { } @Test - fun `compilation for limited type parameter generates correct code`() { + fun Approver.`compilation for limited type parameter generates correct code`() { val result = compile(getCommonSourceFile("compilation", "generics", "GenericSealedClass.kt")) assertCompiles(result) - assertGeneratedFileMatches( - "LimitedTypeParameterSealedClass_SealedEnum.kt", - limitedTypeParameterSealedClassGenerated, - result - ) + assertApprovedGeneratedFile("LimitedTypeParameterSealedClass_SealedEnum.kt", result) } @Test @@ -90,14 +82,10 @@ class GenericSealedClassTests { } @Test - fun `compilation for multiple bounds sealed class generates correct code`() { + fun Approver.`compilation for multiple bounds sealed class generates correct code`() { val result = compile(getCommonSourceFile("compilation", "generics", "GenericSealedClass.kt")) assertCompiles(result) - assertGeneratedFileMatches( - "MultipleBoundsSealedClass_SealedEnum.kt", - multipleBoundsSealedClassGenerated, - result - ) + assertApprovedGeneratedFile("MultipleBoundsSealedClass_SealedEnum.kt", result) } } diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithAbstractBaseClasses.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithAbstractBaseClasses.kt index fddf8e55..6fb51d49 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithAbstractBaseClasses.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithAbstractBaseClasses.kt @@ -3,7 +3,6 @@ package com.livefront.sealedenum.compilation.generics import com.livefront.sealedenum.GenSealedEnum -import org.intellij.lang.annotations.Language interface BaseClassInterface1 @@ -20,114 +19,6 @@ sealed class SealedEnumWithAbstractBaseClasses : BetaBase() { companion object } -@Language("kotlin") -val sealedEnumWithAbstractBaseClassesGenerated = """ -package com.livefront.sealedenum.compilation.generics - -import com.livefront.sealedenum.EnumForSealedEnumProvider -import com.livefront.sealedenum.SealedEnum -import com.livefront.sealedenum.SealedEnumWithEnumProvider -import kotlin.Any -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List -import kotlin.reflect.KClass - -/** - * An isomorphic enum for the sealed class [SealedEnumWithAbstractBaseClasses] - */ -public enum class SealedEnumWithAbstractBaseClassesEnum( - sealedObject: SealedEnumWithAbstractBaseClasses, -) : BaseClassInterface2 by sealedObject, BaseClassInterface1> by - sealedObject - -/** - * The isomorphic [SealedEnumWithAbstractBaseClassesEnum] for [this]. - */ -public val SealedEnumWithAbstractBaseClasses.`enum`: SealedEnumWithAbstractBaseClassesEnum - get() = SealedEnumWithAbstractBaseClassesSealedEnum.sealedObjectToEnum(this) - -/** - * The isomorphic [SealedEnumWithAbstractBaseClasses] for [this]. - */ -public val SealedEnumWithAbstractBaseClassesEnum.sealedObject: SealedEnumWithAbstractBaseClasses - get() = SealedEnumWithAbstractBaseClassesSealedEnum.enumToSealedObject(this) - -/** - * An implementation of [SealedEnum] for the sealed class [SealedEnumWithAbstractBaseClasses] - */ -public object SealedEnumWithAbstractBaseClassesSealedEnum : - SealedEnum, - SealedEnumWithEnumProvider, - EnumForSealedEnumProvider - { - public override val values: List by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - emptyList() - } - - - public override val enumClass: KClass - get() = SealedEnumWithAbstractBaseClassesEnum::class - - public override fun ordinalOf(obj: SealedEnumWithAbstractBaseClasses): Int = throw - AssertionError("Constructing a SealedEnumWithAbstractBaseClasses is impossible, since it has no sealed subclasses") - - public override fun nameOf(obj: SealedEnumWithAbstractBaseClasses): String = throw - AssertionError("Constructing a SealedEnumWithAbstractBaseClasses is impossible, since it has no sealed subclasses") - - public override fun valueOf(name: String): SealedEnumWithAbstractBaseClasses = throw - IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - - public override fun sealedObjectToEnum(obj: SealedEnumWithAbstractBaseClasses): - SealedEnumWithAbstractBaseClassesEnum = throw - AssertionError("Constructing a SealedEnumWithAbstractBaseClasses is impossible, since it has no sealed subclasses") - - public override fun enumToSealedObject(`enum`: SealedEnumWithAbstractBaseClassesEnum): - SealedEnumWithAbstractBaseClasses = throw - AssertionError("Constructing a SealedEnumWithAbstractBaseClasses is impossible, since it has no sealed subclasses") -} - -/** - * The index of [this] in the values list. - */ -public val SealedEnumWithAbstractBaseClasses.ordinal: Int - get() = SealedEnumWithAbstractBaseClassesSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val SealedEnumWithAbstractBaseClasses.name: String - get() = SealedEnumWithAbstractBaseClassesSealedEnum.nameOf(this) - -/** - * A list of all [SealedEnumWithAbstractBaseClasses] objects. - */ -public val SealedEnumWithAbstractBaseClasses.Companion.values: - List - get() = SealedEnumWithAbstractBaseClassesSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class - * [SealedEnumWithAbstractBaseClasses] - */ -public val SealedEnumWithAbstractBaseClasses.Companion.sealedEnum: - SealedEnumWithAbstractBaseClassesSealedEnum - get() = SealedEnumWithAbstractBaseClassesSealedEnum - -/** - * Returns the [SealedEnumWithAbstractBaseClasses] object for the given [name]. - * - * If the given name doesn't correspond to any [SealedEnumWithAbstractBaseClasses], an - * [IllegalArgumentException] will be thrown. - */ -public fun SealedEnumWithAbstractBaseClasses.Companion.valueOf(name: String): - SealedEnumWithAbstractBaseClasses = - SealedEnumWithAbstractBaseClassesSealedEnum.valueOf(name) - -""".trimIndent() - abstract class GammaBase abstract class DeltaBase : GammaBase(), BaseClassInterface3> @@ -136,115 +27,3 @@ sealed class SealedEnumWithAbstractBaseClassesCovariantType : Delta @GenSealedEnum(generateEnum = true) companion object } - -@Language("kotlin") -val sealedEnumWithAbstractBaseClassesCovariantTypeGenerated = """ -package com.livefront.sealedenum.compilation.generics - -import com.livefront.sealedenum.EnumForSealedEnumProvider -import com.livefront.sealedenum.SealedEnum -import com.livefront.sealedenum.SealedEnumWithEnumProvider -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List -import kotlin.reflect.KClass - -/** - * An isomorphic enum for the sealed class [SealedEnumWithAbstractBaseClassesCovariantType] - */ -public enum class SealedEnumWithAbstractBaseClassesCovariantTypeEnum( - sealedObject: SealedEnumWithAbstractBaseClassesCovariantType<*>, -) : BaseClassInterface3> by sealedObject - -/** - * The isomorphic [SealedEnumWithAbstractBaseClassesCovariantTypeEnum] for [this]. - */ -public val SealedEnumWithAbstractBaseClassesCovariantType<*>.`enum`: - SealedEnumWithAbstractBaseClassesCovariantTypeEnum - get() = SealedEnumWithAbstractBaseClassesCovariantTypeSealedEnum.sealedObjectToEnum(this) - -/** - * The isomorphic [SealedEnumWithAbstractBaseClassesCovariantType] for [this]. - */ -public val SealedEnumWithAbstractBaseClassesCovariantTypeEnum.sealedObject: - SealedEnumWithAbstractBaseClassesCovariantType<*> - get() = SealedEnumWithAbstractBaseClassesCovariantTypeSealedEnum.enumToSealedObject(this) - -/** - * An implementation of [SealedEnum] for the sealed class - * [SealedEnumWithAbstractBaseClassesCovariantType] - */ -public object SealedEnumWithAbstractBaseClassesCovariantTypeSealedEnum : - SealedEnum>, - SealedEnumWithEnumProvider, SealedEnumWithAbstractBaseClassesCovariantTypeEnum>, - EnumForSealedEnumProvider, SealedEnumWithAbstractBaseClassesCovariantTypeEnum> - { - public override val values: List> by lazy(mode - = LazyThreadSafetyMode.PUBLICATION) { - emptyList() - } - - - public override val enumClass: KClass - get() = SealedEnumWithAbstractBaseClassesCovariantTypeEnum::class - - public override fun ordinalOf(obj: SealedEnumWithAbstractBaseClassesCovariantType<*>): Int = - throw - AssertionError("Constructing a SealedEnumWithAbstractBaseClassesCovariantType is impossible, since it has no sealed subclasses") - - public override fun nameOf(obj: SealedEnumWithAbstractBaseClassesCovariantType<*>): String = - throw - AssertionError("Constructing a SealedEnumWithAbstractBaseClassesCovariantType is impossible, since it has no sealed subclasses") - - public override fun valueOf(name: String): SealedEnumWithAbstractBaseClassesCovariantType<*> = - throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - - public override fun sealedObjectToEnum(obj: SealedEnumWithAbstractBaseClassesCovariantType<*>): - SealedEnumWithAbstractBaseClassesCovariantTypeEnum = throw - AssertionError("Constructing a SealedEnumWithAbstractBaseClassesCovariantType is impossible, since it has no sealed subclasses") - - public override - fun enumToSealedObject(`enum`: SealedEnumWithAbstractBaseClassesCovariantTypeEnum): - SealedEnumWithAbstractBaseClassesCovariantType<*> = throw - AssertionError("Constructing a SealedEnumWithAbstractBaseClassesCovariantType is impossible, since it has no sealed subclasses") -} - -/** - * The index of [this] in the values list. - */ -public val SealedEnumWithAbstractBaseClassesCovariantType<*>.ordinal: Int - get() = SealedEnumWithAbstractBaseClassesCovariantTypeSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val SealedEnumWithAbstractBaseClassesCovariantType<*>.name: String - get() = SealedEnumWithAbstractBaseClassesCovariantTypeSealedEnum.nameOf(this) - -/** - * A list of all [SealedEnumWithAbstractBaseClassesCovariantType] objects. - */ -public val SealedEnumWithAbstractBaseClassesCovariantType.Companion.values: - List> - get() = SealedEnumWithAbstractBaseClassesCovariantTypeSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class - * [SealedEnumWithAbstractBaseClassesCovariantType] - */ -public val SealedEnumWithAbstractBaseClassesCovariantType.Companion.sealedEnum: - SealedEnumWithAbstractBaseClassesCovariantTypeSealedEnum - get() = SealedEnumWithAbstractBaseClassesCovariantTypeSealedEnum - -/** - * Returns the [SealedEnumWithAbstractBaseClassesCovariantType] object for the given [name]. - * - * If the given name doesn't correspond to any [SealedEnumWithAbstractBaseClassesCovariantType], an - * [IllegalArgumentException] will be thrown. - */ -public fun SealedEnumWithAbstractBaseClassesCovariantType.Companion.valueOf(name: String): - SealedEnumWithAbstractBaseClassesCovariantType<*> = - SealedEnumWithAbstractBaseClassesCovariantTypeSealedEnum.valueOf(name) - -""".trimIndent() diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithAbstractBaseClassesTests.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithAbstractBaseClassesTests.kt index dee8cb8d..0dd46e78 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithAbstractBaseClassesTests.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithAbstractBaseClassesTests.kt @@ -1,16 +1,20 @@ package com.livefront.sealedenum.compilation.generics +import com.livefront.sealedenum.testing.SealedEnumApprovalsExtension +import com.livefront.sealedenum.testing.assertApprovedGeneratedFile import com.livefront.sealedenum.testing.assertCompiles -import com.livefront.sealedenum.testing.assertGeneratedFileMatches import com.livefront.sealedenum.testing.compile import com.livefront.sealedenum.testing.getCommonSourceFile +import com.oneeyedmen.okeydoke.Approver import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith import kotlin.reflect.KTypeProjection import kotlin.reflect.full.createType import kotlin.reflect.full.isSubtypeOf +@ExtendWith(SealedEnumApprovalsExtension::class) class SealedEnumWithAbstractBaseClassesTests { @Test fun `enum implements correct interfaces with type arguments`() { @@ -56,15 +60,11 @@ class SealedEnumWithAbstractBaseClassesTests { } @Test - fun `compilation for invariant type generates correct code`() { + fun Approver.`compilation for invariant type generates correct code`() { val result = compile(getCommonSourceFile("compilation", "generics", "SealedEnumWithAbstractBaseClasses.kt")) assertCompiles(result) - assertGeneratedFileMatches( - "SealedEnumWithAbstractBaseClasses_SealedEnum.kt", - sealedEnumWithAbstractBaseClassesGenerated, - result - ) + assertApprovedGeneratedFile("SealedEnumWithAbstractBaseClasses_SealedEnum.kt", result) } @Test @@ -95,14 +95,10 @@ class SealedEnumWithAbstractBaseClassesTests { } @Test - fun `compilation for covariant type generates correct code`() { + fun Approver.`compilation for covariant type generates correct code`() { val result = compile(getCommonSourceFile("compilation", "generics", "SealedEnumWithAbstractBaseClasses.kt")) assertCompiles(result) - assertGeneratedFileMatches( - "SealedEnumWithAbstractBaseClassesCovariantType_SealedEnum.kt", - sealedEnumWithAbstractBaseClassesCovariantTypeGenerated, - result - ) + assertApprovedGeneratedFile("SealedEnumWithAbstractBaseClassesCovariantType_SealedEnum.kt", result) } } diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithInterfaces.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithInterfaces.kt index 9220c8b6..7aee159c 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithInterfaces.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithInterfaces.kt @@ -1,7 +1,6 @@ package com.livefront.sealedenum.compilation.generics import com.livefront.sealedenum.GenSealedEnum -import org.intellij.lang.annotations.Language interface TestInterface @@ -16,108 +15,6 @@ sealed class EmptySealedClassWithInterface : TestInterface { companion object } -@Language("kotlin") -val emptySealedClassWithInterfaceGenerated = """ -package com.livefront.sealedenum.compilation.generics - -import com.livefront.sealedenum.EnumForSealedEnumProvider -import com.livefront.sealedenum.SealedEnum -import com.livefront.sealedenum.SealedEnumWithEnumProvider -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List -import kotlin.reflect.KClass - -/** - * An isomorphic enum for the sealed class [EmptySealedClassWithInterface] - */ -public enum class EmptySealedClassWithInterfaceEnum( - sealedObject: EmptySealedClassWithInterface, -) : TestInterface by sealedObject - -/** - * The isomorphic [EmptySealedClassWithInterfaceEnum] for [this]. - */ -public val EmptySealedClassWithInterface.`enum`: EmptySealedClassWithInterfaceEnum - get() = EmptySealedClassWithInterfaceSealedEnum.sealedObjectToEnum(this) - -/** - * The isomorphic [EmptySealedClassWithInterface] for [this]. - */ -public val EmptySealedClassWithInterfaceEnum.sealedObject: EmptySealedClassWithInterface - get() = EmptySealedClassWithInterfaceSealedEnum.enumToSealedObject(this) - -/** - * An implementation of [SealedEnum] for the sealed class [EmptySealedClassWithInterface] - */ -public object EmptySealedClassWithInterfaceSealedEnum : SealedEnum, - SealedEnumWithEnumProvider, - EnumForSealedEnumProvider - { - public override val values: List by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - emptyList() - } - - - public override val enumClass: KClass - get() = EmptySealedClassWithInterfaceEnum::class - - public override fun ordinalOf(obj: EmptySealedClassWithInterface): Int = throw - AssertionError("Constructing a EmptySealedClassWithInterface is impossible, since it has no sealed subclasses") - - public override fun nameOf(obj: EmptySealedClassWithInterface): String = throw - AssertionError("Constructing a EmptySealedClassWithInterface is impossible, since it has no sealed subclasses") - - public override fun valueOf(name: String): EmptySealedClassWithInterface = throw - IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - - public override fun sealedObjectToEnum(obj: EmptySealedClassWithInterface): - EmptySealedClassWithInterfaceEnum = throw - AssertionError("Constructing a EmptySealedClassWithInterface is impossible, since it has no sealed subclasses") - - public override fun enumToSealedObject(`enum`: EmptySealedClassWithInterfaceEnum): - EmptySealedClassWithInterface = throw - AssertionError("Constructing a EmptySealedClassWithInterface is impossible, since it has no sealed subclasses") -} - -/** - * The index of [this] in the values list. - */ -public val EmptySealedClassWithInterface.ordinal: Int - get() = EmptySealedClassWithInterfaceSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val EmptySealedClassWithInterface.name: String - get() = EmptySealedClassWithInterfaceSealedEnum.nameOf(this) - -/** - * A list of all [EmptySealedClassWithInterface] objects. - */ -public val EmptySealedClassWithInterface.Companion.values: List - get() = EmptySealedClassWithInterfaceSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [EmptySealedClassWithInterface] - */ -public val EmptySealedClassWithInterface.Companion.sealedEnum: - EmptySealedClassWithInterfaceSealedEnum - get() = EmptySealedClassWithInterfaceSealedEnum - -/** - * Returns the [EmptySealedClassWithInterface] object for the given [name]. - * - * If the given name doesn't correspond to any [EmptySealedClassWithInterface], an - * [IllegalArgumentException] will be thrown. - */ -public fun EmptySealedClassWithInterface.Companion.valueOf(name: String): - EmptySealedClassWithInterface = EmptySealedClassWithInterfaceSealedEnum.valueOf(name) - -""".trimIndent() - sealed class OneObjectSealedClassWithInterface : TestInterface { object FirstObject : OneObjectSealedClassWithInterface() @@ -125,126 +22,6 @@ sealed class OneObjectSealedClassWithInterface : TestInterface { companion object } -@Language("kotlin") -val oneObjectSealedClassWithInterfaceGenerated = """ -package com.livefront.sealedenum.compilation.generics - -import com.livefront.sealedenum.EnumForSealedEnumProvider -import com.livefront.sealedenum.SealedEnum -import com.livefront.sealedenum.SealedEnumWithEnumProvider -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List -import kotlin.reflect.KClass - -/** - * An isomorphic enum for the sealed class [OneObjectSealedClassWithInterface] - */ -public enum class OneObjectSealedClassWithInterfaceEnum( - sealedObject: OneObjectSealedClassWithInterface, -) : TestInterface by sealedObject { - OneObjectSealedClassWithInterface_FirstObject(com.livefront.sealedenum.compilation.generics.OneObjectSealedClassWithInterface.FirstObject), -} - -/** - * The isomorphic [OneObjectSealedClassWithInterfaceEnum] for [this]. - */ -public val OneObjectSealedClassWithInterface.`enum`: OneObjectSealedClassWithInterfaceEnum - get() = OneObjectSealedClassWithInterfaceSealedEnum.sealedObjectToEnum(this) - -/** - * The isomorphic [OneObjectSealedClassWithInterface] for [this]. - */ -public val OneObjectSealedClassWithInterfaceEnum.sealedObject: OneObjectSealedClassWithInterface - get() = OneObjectSealedClassWithInterfaceSealedEnum.enumToSealedObject(this) - -/** - * An implementation of [SealedEnum] for the sealed class [OneObjectSealedClassWithInterface] - */ -public object OneObjectSealedClassWithInterfaceSealedEnum : - SealedEnum, - SealedEnumWithEnumProvider, - EnumForSealedEnumProvider - { - public override val values: List by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - listOf( - OneObjectSealedClassWithInterface.FirstObject - ) - } - - - public override val enumClass: KClass - get() = OneObjectSealedClassWithInterfaceEnum::class - - public override fun ordinalOf(obj: OneObjectSealedClassWithInterface): Int = when (obj) { - is OneObjectSealedClassWithInterface.FirstObject -> 0 - } - - public override fun nameOf(obj: OneObjectSealedClassWithInterface): String = when (obj) { - is OneObjectSealedClassWithInterface.FirstObject -> - "OneObjectSealedClassWithInterface_FirstObject" - } - - public override fun valueOf(name: String): OneObjectSealedClassWithInterface = when (name) { - "OneObjectSealedClassWithInterface_FirstObject" -> - OneObjectSealedClassWithInterface.FirstObject - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } - - public override fun sealedObjectToEnum(obj: OneObjectSealedClassWithInterface): - OneObjectSealedClassWithInterfaceEnum = when (obj) { - is OneObjectSealedClassWithInterface.FirstObject -> - OneObjectSealedClassWithInterfaceEnum.OneObjectSealedClassWithInterface_FirstObject - } - - public override fun enumToSealedObject(`enum`: OneObjectSealedClassWithInterfaceEnum): - OneObjectSealedClassWithInterface = when (enum) { - OneObjectSealedClassWithInterfaceEnum.OneObjectSealedClassWithInterface_FirstObject -> - OneObjectSealedClassWithInterface.FirstObject - } -} - -/** - * The index of [this] in the values list. - */ -public val OneObjectSealedClassWithInterface.ordinal: Int - get() = OneObjectSealedClassWithInterfaceSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val OneObjectSealedClassWithInterface.name: String - get() = OneObjectSealedClassWithInterfaceSealedEnum.nameOf(this) - -/** - * A list of all [OneObjectSealedClassWithInterface] objects. - */ -public val OneObjectSealedClassWithInterface.Companion.values: - List - get() = OneObjectSealedClassWithInterfaceSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class - * [OneObjectSealedClassWithInterface] - */ -public val OneObjectSealedClassWithInterface.Companion.sealedEnum: - OneObjectSealedClassWithInterfaceSealedEnum - get() = OneObjectSealedClassWithInterfaceSealedEnum - -/** - * Returns the [OneObjectSealedClassWithInterface] object for the given [name]. - * - * If the given name doesn't correspond to any [OneObjectSealedClassWithInterface], an - * [IllegalArgumentException] will be thrown. - */ -public fun OneObjectSealedClassWithInterface.Companion.valueOf(name: String): - OneObjectSealedClassWithInterface = - OneObjectSealedClassWithInterfaceSealedEnum.valueOf(name) - -""".trimIndent() - sealed class TwoObjectSealedClassWithGenericInterface : TestGenericInterface { object FirstObject : TwoObjectSealedClassWithGenericInterface() object SecondObject : TwoObjectSealedClassWithGenericInterface() @@ -253,143 +30,6 @@ sealed class TwoObjectSealedClassWithGenericInterface : TestG companion object } -@Language("kotlin") -val twoObjectSealedClassWithGenericInterfaceGenerated = """ -package com.livefront.sealedenum.compilation.generics - -import com.livefront.sealedenum.EnumForSealedEnumProvider -import com.livefront.sealedenum.SealedEnum -import com.livefront.sealedenum.SealedEnumWithEnumProvider -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List -import kotlin.reflect.KClass - -/** - * An isomorphic enum for the sealed class [TwoObjectSealedClassWithGenericInterface] - */ -public enum class TwoObjectSealedClassWithGenericInterfaceEnum( - sealedObject: TwoObjectSealedClassWithGenericInterface, -) : TestGenericInterface by sealedObject { - TwoObjectSealedClassWithGenericInterface_FirstObject(com.livefront.sealedenum.compilation.generics.TwoObjectSealedClassWithGenericInterface.FirstObject), - TwoObjectSealedClassWithGenericInterface_SecondObject(com.livefront.sealedenum.compilation.generics.TwoObjectSealedClassWithGenericInterface.SecondObject), -} - -/** - * The isomorphic [TwoObjectSealedClassWithGenericInterfaceEnum] for [this]. - */ -public val TwoObjectSealedClassWithGenericInterface.`enum`: - TwoObjectSealedClassWithGenericInterfaceEnum - get() = TwoObjectSealedClassWithGenericInterfaceSealedEnum.sealedObjectToEnum(this) - -/** - * The isomorphic [TwoObjectSealedClassWithGenericInterface] for [this]. - */ -public val TwoObjectSealedClassWithGenericInterfaceEnum.sealedObject: - TwoObjectSealedClassWithGenericInterface - get() = TwoObjectSealedClassWithGenericInterfaceSealedEnum.enumToSealedObject(this) - -/** - * An implementation of [SealedEnum] for the sealed class [TwoObjectSealedClassWithGenericInterface] - */ -public object TwoObjectSealedClassWithGenericInterfaceSealedEnum : - SealedEnum>, - SealedEnumWithEnumProvider, TwoObjectSealedClassWithGenericInterfaceEnum>, - EnumForSealedEnumProvider, TwoObjectSealedClassWithGenericInterfaceEnum> - { - public override val values: List> by - lazy(mode = LazyThreadSafetyMode.PUBLICATION) { - listOf( - TwoObjectSealedClassWithGenericInterface.FirstObject, - TwoObjectSealedClassWithGenericInterface.SecondObject - ) - } - - - public override val enumClass: KClass - get() = TwoObjectSealedClassWithGenericInterfaceEnum::class - - public override fun ordinalOf(obj: TwoObjectSealedClassWithGenericInterface): Int - = when (obj) { - is TwoObjectSealedClassWithGenericInterface.FirstObject -> 0 - is TwoObjectSealedClassWithGenericInterface.SecondObject -> 1 - } - - public override fun nameOf(obj: TwoObjectSealedClassWithGenericInterface): String - = when (obj) { - is TwoObjectSealedClassWithGenericInterface.FirstObject -> - "TwoObjectSealedClassWithGenericInterface_FirstObject" - is TwoObjectSealedClassWithGenericInterface.SecondObject -> - "TwoObjectSealedClassWithGenericInterface_SecondObject" - } - - public override fun valueOf(name: String): - TwoObjectSealedClassWithGenericInterface = when (name) { - "TwoObjectSealedClassWithGenericInterface_FirstObject" -> - TwoObjectSealedClassWithGenericInterface.FirstObject - "TwoObjectSealedClassWithGenericInterface_SecondObject" -> - TwoObjectSealedClassWithGenericInterface.SecondObject - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } - - public override - fun sealedObjectToEnum(obj: TwoObjectSealedClassWithGenericInterface): - TwoObjectSealedClassWithGenericInterfaceEnum = when (obj) { - is TwoObjectSealedClassWithGenericInterface.FirstObject -> - TwoObjectSealedClassWithGenericInterfaceEnum.TwoObjectSealedClassWithGenericInterface_FirstObject - is TwoObjectSealedClassWithGenericInterface.SecondObject -> - TwoObjectSealedClassWithGenericInterfaceEnum.TwoObjectSealedClassWithGenericInterface_SecondObject - } - - public override fun enumToSealedObject(`enum`: TwoObjectSealedClassWithGenericInterfaceEnum): - TwoObjectSealedClassWithGenericInterface = when (enum) { - TwoObjectSealedClassWithGenericInterfaceEnum.TwoObjectSealedClassWithGenericInterface_FirstObject -> - TwoObjectSealedClassWithGenericInterface.FirstObject - TwoObjectSealedClassWithGenericInterfaceEnum.TwoObjectSealedClassWithGenericInterface_SecondObject -> - TwoObjectSealedClassWithGenericInterface.SecondObject - } -} - -/** - * The index of [this] in the values list. - */ -public val TwoObjectSealedClassWithGenericInterface.ordinal: Int - get() = TwoObjectSealedClassWithGenericInterfaceSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val TwoObjectSealedClassWithGenericInterface.name: String - get() = TwoObjectSealedClassWithGenericInterfaceSealedEnum.nameOf(this) - -/** - * A list of all [TwoObjectSealedClassWithGenericInterface] objects. - */ -public val TwoObjectSealedClassWithGenericInterface.Companion.values: - List> - get() = TwoObjectSealedClassWithGenericInterfaceSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class - * [TwoObjectSealedClassWithGenericInterface] - */ -public val TwoObjectSealedClassWithGenericInterface.Companion.sealedEnum: - TwoObjectSealedClassWithGenericInterfaceSealedEnum - get() = TwoObjectSealedClassWithGenericInterfaceSealedEnum - -/** - * Returns the [TwoObjectSealedClassWithGenericInterface] object for the given [name]. - * - * If the given name doesn't correspond to any [TwoObjectSealedClassWithGenericInterface], an - * [IllegalArgumentException] will be thrown. - */ -public fun TwoObjectSealedClassWithGenericInterface.Companion.valueOf(name: String): - TwoObjectSealedClassWithGenericInterface = - TwoObjectSealedClassWithGenericInterfaceSealedEnum.valueOf(name) - -""".trimIndent() - sealed class SealedClassWithGetterInterface : TestGetterInterface { object FirstObject : SealedClassWithGetterInterface() { var hasGetBeenCalled = false @@ -403,118 +43,3 @@ sealed class SealedClassWithGetterInterface : TestGetterInterface { @GenSealedEnum(generateEnum = true) companion object } - -@Language("kotlin") -val sealedClassWithGetterInterface = """ -package com.livefront.sealedenum.compilation.generics - -import com.livefront.sealedenum.EnumForSealedEnumProvider -import com.livefront.sealedenum.SealedEnum -import com.livefront.sealedenum.SealedEnumWithEnumProvider -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List -import kotlin.reflect.KClass - -/** - * An isomorphic enum for the sealed class [SealedClassWithGetterInterface] - */ -public enum class SealedClassWithGetterInterfaceEnum( - sealedObject: SealedClassWithGetterInterface, -) : TestGetterInterface by sealedObject { - SealedClassWithGetterInterface_FirstObject(com.livefront.sealedenum.compilation.generics.SealedClassWithGetterInterface.FirstObject), -} - -/** - * The isomorphic [SealedClassWithGetterInterfaceEnum] for [this]. - */ -public val SealedClassWithGetterInterface.`enum`: SealedClassWithGetterInterfaceEnum - get() = SealedClassWithGetterInterfaceSealedEnum.sealedObjectToEnum(this) - -/** - * The isomorphic [SealedClassWithGetterInterface] for [this]. - */ -public val SealedClassWithGetterInterfaceEnum.sealedObject: SealedClassWithGetterInterface - get() = SealedClassWithGetterInterfaceSealedEnum.enumToSealedObject(this) - -/** - * An implementation of [SealedEnum] for the sealed class [SealedClassWithGetterInterface] - */ -public object SealedClassWithGetterInterfaceSealedEnum : SealedEnum, - SealedEnumWithEnumProvider, - EnumForSealedEnumProvider - { - public override val values: List by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - listOf( - SealedClassWithGetterInterface.FirstObject - ) - } - - - public override val enumClass: KClass - get() = SealedClassWithGetterInterfaceEnum::class - - public override fun ordinalOf(obj: SealedClassWithGetterInterface): Int = when (obj) { - is SealedClassWithGetterInterface.FirstObject -> 0 - } - - public override fun nameOf(obj: SealedClassWithGetterInterface): String = when (obj) { - is SealedClassWithGetterInterface.FirstObject -> - "SealedClassWithGetterInterface_FirstObject" - } - - public override fun valueOf(name: String): SealedClassWithGetterInterface = when (name) { - "SealedClassWithGetterInterface_FirstObject" -> SealedClassWithGetterInterface.FirstObject - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } - - public override fun sealedObjectToEnum(obj: SealedClassWithGetterInterface): - SealedClassWithGetterInterfaceEnum = when (obj) { - is SealedClassWithGetterInterface.FirstObject -> - SealedClassWithGetterInterfaceEnum.SealedClassWithGetterInterface_FirstObject - } - - public override fun enumToSealedObject(`enum`: SealedClassWithGetterInterfaceEnum): - SealedClassWithGetterInterface = when (enum) { - SealedClassWithGetterInterfaceEnum.SealedClassWithGetterInterface_FirstObject -> - SealedClassWithGetterInterface.FirstObject - } -} - -/** - * The index of [this] in the values list. - */ -public val SealedClassWithGetterInterface.ordinal: Int - get() = SealedClassWithGetterInterfaceSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val SealedClassWithGetterInterface.name: String - get() = SealedClassWithGetterInterfaceSealedEnum.nameOf(this) - -/** - * A list of all [SealedClassWithGetterInterface] objects. - */ -public val SealedClassWithGetterInterface.Companion.values: List - get() = SealedClassWithGetterInterfaceSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [SealedClassWithGetterInterface] - */ -public val SealedClassWithGetterInterface.Companion.sealedEnum: - SealedClassWithGetterInterfaceSealedEnum - get() = SealedClassWithGetterInterfaceSealedEnum - -/** - * Returns the [SealedClassWithGetterInterface] object for the given [name]. - * - * If the given name doesn't correspond to any [SealedClassWithGetterInterface], an - * [IllegalArgumentException] will be thrown. - */ -public fun SealedClassWithGetterInterface.Companion.valueOf(name: String): - SealedClassWithGetterInterface = SealedClassWithGetterInterfaceSealedEnum.valueOf(name) - -""".trimIndent() diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithInterfacesTests.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithInterfacesTests.kt index aaf9920d..f62d4961 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithInterfacesTests.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithInterfacesTests.kt @@ -1,19 +1,23 @@ package com.livefront.sealedenum.compilation.generics import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.testing.SealedEnumApprovalsExtension +import com.livefront.sealedenum.testing.assertApprovedGeneratedFile import com.livefront.sealedenum.testing.assertCompiles -import com.livefront.sealedenum.testing.assertGeneratedFileMatches import com.livefront.sealedenum.testing.compile import com.livefront.sealedenum.testing.getCommonSourceFile +import com.oneeyedmen.okeydoke.Approver import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertFalse import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith import kotlin.reflect.KTypeProjection import kotlin.reflect.full.createType import kotlin.reflect.full.isSubclassOf import kotlin.reflect.full.isSubtypeOf +@ExtendWith(SealedEnumApprovalsExtension::class) class SealedEnumWithInterfacesTests { @Test @@ -51,15 +55,11 @@ class SealedEnumWithInterfacesTests { } @Test - fun `compilation for empty sealed class generates correct code`() { + fun Approver.`compilation for empty sealed class generates correct code`() { val result = compile(getCommonSourceFile("compilation", "generics", "SealedEnumWithInterfaces.kt")) assertCompiles(result) - assertGeneratedFileMatches( - "EmptySealedClassWithInterface_SealedEnum.kt", - emptySealedClassWithInterfaceGenerated, - result - ) + assertApprovedGeneratedFile("EmptySealedClassWithInterface_SealedEnum.kt", result) } @Test @@ -96,15 +96,11 @@ class SealedEnumWithInterfacesTests { } @Test - fun `compilation for one object sealed class generates correct code`() { + fun Approver.`compilation for one object sealed class generates correct code`() { val result = compile(getCommonSourceFile("compilation", "generics", "SealedEnumWithInterfaces.kt")) assertCompiles(result) - assertGeneratedFileMatches( - "OneObjectSealedClassWithInterface_SealedEnum.kt", - oneObjectSealedClassWithInterfaceGenerated, - result - ) + assertApprovedGeneratedFile("OneObjectSealedClassWithInterface_SealedEnum.kt", result) } @Test @@ -163,15 +159,11 @@ class SealedEnumWithInterfacesTests { } @Test - fun `compilation for two object sealed class generates correct code`() { + fun Approver.`compilation for two object sealed class generates correct code`() { val result = compile(getCommonSourceFile("compilation", "generics", "SealedEnumWithInterfaces.kt")) assertCompiles(result) - assertGeneratedFileMatches( - "TwoObjectSealedClassWithGenericInterface_SealedEnum.kt", - twoObjectSealedClassWithGenericInterfaceGenerated, - result - ) + assertApprovedGeneratedFile("TwoObjectSealedClassWithGenericInterface_SealedEnum.kt", result) } @Test @@ -188,14 +180,10 @@ class SealedEnumWithInterfacesTests { } @Test - fun `compilation for sealed class with getter interface generates correct code`() { + fun Approver.`compilation for sealed class with getter interface generates correct code`() { val result = compile(getCommonSourceFile("compilation", "generics", "SealedEnumWithInterfaces.kt")) assertCompiles(result) - assertGeneratedFileMatches( - "SealedClassWithGetterInterface_SealedEnum.kt", - sealedClassWithGetterInterface, - result - ) + assertApprovedGeneratedFile("SealedClassWithGetterInterface_SealedEnum.kt", result) } } diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchy.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchy.kt index b35c806a..461b01f5 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchy.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchy.kt @@ -1,7 +1,6 @@ package com.livefront.sealedenum.compilation.hierarchy import com.livefront.sealedenum.GenSealedEnum -import org.intellij.lang.annotations.Language class FirstClassHierarchy { @@ -19,222 +18,6 @@ class FirstClassHierarchy { } } -@Language("kotlin") -val firstClassHierarchyAGenerated = """ -package com.livefront.sealedenum.compilation.hierarchy - -import com.livefront.sealedenum.EnumForSealedEnumProvider -import com.livefront.sealedenum.SealedEnum -import com.livefront.sealedenum.SealedEnumWithEnumProvider -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List -import kotlin.reflect.KClass - -/** - * An isomorphic enum for the sealed class [FirstClassHierarchy.A] - */ -public enum class FirstClassHierarchy_AEnum() { - FirstClassHierarchy_A_B_C, -} - -/** - * The isomorphic [FirstClassHierarchy_AEnum] for [this]. - */ -public val FirstClassHierarchy.A.`enum`: FirstClassHierarchy_AEnum - get() = FirstClassHierarchy_ASealedEnum.sealedObjectToEnum(this) - -/** - * The isomorphic [FirstClassHierarchy.A] for [this]. - */ -public val FirstClassHierarchy_AEnum.sealedObject: FirstClassHierarchy.A - get() = FirstClassHierarchy_ASealedEnum.enumToSealedObject(this) - -/** - * An implementation of [SealedEnum] for the sealed class [FirstClassHierarchy.A] - */ -public object FirstClassHierarchy_ASealedEnum : SealedEnum, - SealedEnumWithEnumProvider, - EnumForSealedEnumProvider { - public override val values: List by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - listOf( - FirstClassHierarchy.A.B.C - ) - } - - - public override val enumClass: KClass - get() = FirstClassHierarchy_AEnum::class - - public override fun ordinalOf(obj: FirstClassHierarchy.A): Int = when (obj) { - is FirstClassHierarchy.A.B.C -> 0 - } - - public override fun nameOf(obj: FirstClassHierarchy.A): String = when (obj) { - is FirstClassHierarchy.A.B.C -> "FirstClassHierarchy_A_B_C" - } - - public override fun valueOf(name: String): FirstClassHierarchy.A = when (name) { - "FirstClassHierarchy_A_B_C" -> FirstClassHierarchy.A.B.C - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } - - public override fun sealedObjectToEnum(obj: FirstClassHierarchy.A): FirstClassHierarchy_AEnum = - when (obj) { - is FirstClassHierarchy.A.B.C -> FirstClassHierarchy_AEnum.FirstClassHierarchy_A_B_C - } - - public override fun enumToSealedObject(`enum`: FirstClassHierarchy_AEnum): FirstClassHierarchy.A - = when (enum) { - FirstClassHierarchy_AEnum.FirstClassHierarchy_A_B_C -> FirstClassHierarchy.A.B.C - } -} - -/** - * The index of [this] in the values list. - */ -public val FirstClassHierarchy.A.ordinal: Int - get() = FirstClassHierarchy_ASealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val FirstClassHierarchy.A.name: String - get() = FirstClassHierarchy_ASealedEnum.nameOf(this) - -/** - * A list of all [FirstClassHierarchy.A] objects. - */ -public val FirstClassHierarchy.A.Companion.values: List - get() = FirstClassHierarchy_ASealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [FirstClassHierarchy.A] - */ -public val FirstClassHierarchy.A.Companion.sealedEnum: FirstClassHierarchy_ASealedEnum - get() = FirstClassHierarchy_ASealedEnum - -/** - * Returns the [FirstClassHierarchy.A] object for the given [name]. - * - * If the given name doesn't correspond to any [FirstClassHierarchy.A], an - * [IllegalArgumentException] will be thrown. - */ -public fun FirstClassHierarchy.A.Companion.valueOf(name: String): FirstClassHierarchy.A = - FirstClassHierarchy_ASealedEnum.valueOf(name) - -""".trimIndent() - -@Language("kotlin") -val firstClassHierarchyBGenerated = """ -package com.livefront.sealedenum.compilation.hierarchy - -import com.livefront.sealedenum.EnumForSealedEnumProvider -import com.livefront.sealedenum.SealedEnum -import com.livefront.sealedenum.SealedEnumWithEnumProvider -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List -import kotlin.reflect.KClass - -/** - * An isomorphic enum for the sealed class [FirstClassHierarchy.A.B] - */ -public enum class FirstClassHierarchy_A_BEnum() { - FirstClassHierarchy_A_B_C, -} - -/** - * The isomorphic [FirstClassHierarchy_A_BEnum] for [this]. - */ -public val FirstClassHierarchy.A.B.`enum`: FirstClassHierarchy_A_BEnum - get() = FirstClassHierarchy_A_BSealedEnum.sealedObjectToEnum(this) - -/** - * The isomorphic [FirstClassHierarchy.A.B] for [this]. - */ -public val FirstClassHierarchy_A_BEnum.sealedObject: FirstClassHierarchy.A.B - get() = FirstClassHierarchy_A_BSealedEnum.enumToSealedObject(this) - -/** - * An implementation of [SealedEnum] for the sealed class [FirstClassHierarchy.A.B] - */ -public object FirstClassHierarchy_A_BSealedEnum : SealedEnum, - SealedEnumWithEnumProvider, - EnumForSealedEnumProvider { - public override val values: List by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - listOf( - FirstClassHierarchy.A.B.C - ) - } - - - public override val enumClass: KClass - get() = FirstClassHierarchy_A_BEnum::class - - public override fun ordinalOf(obj: FirstClassHierarchy.A.B): Int = when (obj) { - is FirstClassHierarchy.A.B.C -> 0 - } - - public override fun nameOf(obj: FirstClassHierarchy.A.B): String = when (obj) { - is FirstClassHierarchy.A.B.C -> "FirstClassHierarchy_A_B_C" - } - - public override fun valueOf(name: String): FirstClassHierarchy.A.B = when (name) { - "FirstClassHierarchy_A_B_C" -> FirstClassHierarchy.A.B.C - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } - - public override fun sealedObjectToEnum(obj: FirstClassHierarchy.A.B): - FirstClassHierarchy_A_BEnum = when (obj) { - is FirstClassHierarchy.A.B.C -> FirstClassHierarchy_A_BEnum.FirstClassHierarchy_A_B_C - } - - public override fun enumToSealedObject(`enum`: FirstClassHierarchy_A_BEnum): - FirstClassHierarchy.A.B = when (enum) { - FirstClassHierarchy_A_BEnum.FirstClassHierarchy_A_B_C -> FirstClassHierarchy.A.B.C - } -} - -/** - * The index of [this] in the values list. - */ -public val FirstClassHierarchy.A.B.ordinal: Int - get() = FirstClassHierarchy_A_BSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val FirstClassHierarchy.A.B.name: String - get() = FirstClassHierarchy_A_BSealedEnum.nameOf(this) - -/** - * A list of all [FirstClassHierarchy.A.B] objects. - */ -public val FirstClassHierarchy.A.B.Companion.values: List - get() = FirstClassHierarchy_A_BSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [FirstClassHierarchy.A.B] - */ -public val FirstClassHierarchy.A.B.Companion.sealedEnum: FirstClassHierarchy_A_BSealedEnum - get() = FirstClassHierarchy_A_BSealedEnum - -/** - * Returns the [FirstClassHierarchy.A.B] object for the given [name]. - * - * If the given name doesn't correspond to any [FirstClassHierarchy.A.B], an - * [IllegalArgumentException] will be thrown. - */ -public fun FirstClassHierarchy.A.B.Companion.valueOf(name: String): FirstClassHierarchy.A.B = - FirstClassHierarchy_A_BSealedEnum.valueOf(name) - -""".trimIndent() - class SecondClassHierarchy { sealed class Z { @@ -279,394 +62,3 @@ class SecondClassHierarchy { companion object } } - -@Language("kotlin") -val secondClassHierarchyZGenerated = """ -package com.livefront.sealedenum.compilation.hierarchy - -import com.livefront.sealedenum.SealedEnum -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List - -/** - * An implementation of [SealedEnum] for the sealed class [SecondClassHierarchy.Z] - */ -public object SecondClassHierarchy_ZSealedEnum : SealedEnum { - public override val values: List by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - listOf( - SecondClassHierarchy.Z.Y, - SecondClassHierarchy.Z.X.W, - SecondClassHierarchy.Z.X.V, - SecondClassHierarchy.Z.X.U.T, - SecondClassHierarchy.Z.X.S.R, - SecondClassHierarchy.Z.Q.P, - SecondClassHierarchy.Z.O - ) - } - - - public override fun ordinalOf(obj: SecondClassHierarchy.Z): Int = when (obj) { - is SecondClassHierarchy.Z.Y -> 0 - is SecondClassHierarchy.Z.X.W -> 1 - is SecondClassHierarchy.Z.X.V -> 2 - is SecondClassHierarchy.Z.X.U.T -> 3 - is SecondClassHierarchy.Z.X.S.R -> 4 - is SecondClassHierarchy.Z.Q.P -> 5 - is SecondClassHierarchy.Z.O -> 6 - } - - public override fun nameOf(obj: SecondClassHierarchy.Z): String = when (obj) { - is SecondClassHierarchy.Z.Y -> "SecondClassHierarchy_Z_Y" - is SecondClassHierarchy.Z.X.W -> "SecondClassHierarchy_Z_X_W" - is SecondClassHierarchy.Z.X.V -> "SecondClassHierarchy_Z_X_V" - is SecondClassHierarchy.Z.X.U.T -> "SecondClassHierarchy_Z_X_U_T" - is SecondClassHierarchy.Z.X.S.R -> "SecondClassHierarchy_Z_X_S_R" - is SecondClassHierarchy.Z.Q.P -> "SecondClassHierarchy_Z_Q_P" - is SecondClassHierarchy.Z.O -> "SecondClassHierarchy_Z_O" - } - - public override fun valueOf(name: String): SecondClassHierarchy.Z = when (name) { - "SecondClassHierarchy_Z_Y" -> SecondClassHierarchy.Z.Y - "SecondClassHierarchy_Z_X_W" -> SecondClassHierarchy.Z.X.W - "SecondClassHierarchy_Z_X_V" -> SecondClassHierarchy.Z.X.V - "SecondClassHierarchy_Z_X_U_T" -> SecondClassHierarchy.Z.X.U.T - "SecondClassHierarchy_Z_X_S_R" -> SecondClassHierarchy.Z.X.S.R - "SecondClassHierarchy_Z_Q_P" -> SecondClassHierarchy.Z.Q.P - "SecondClassHierarchy_Z_O" -> SecondClassHierarchy.Z.O - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } -} - -/** - * The index of [this] in the values list. - */ -public val SecondClassHierarchy.Z.ordinal: Int - get() = SecondClassHierarchy_ZSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val SecondClassHierarchy.Z.name: String - get() = SecondClassHierarchy_ZSealedEnum.nameOf(this) - -/** - * A list of all [SecondClassHierarchy.Z] objects. - */ -public val SecondClassHierarchy.Z.Companion.values: List - get() = SecondClassHierarchy_ZSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [SecondClassHierarchy.Z] - */ -public val SecondClassHierarchy.Z.Companion.sealedEnum: SecondClassHierarchy_ZSealedEnum - get() = SecondClassHierarchy_ZSealedEnum - -/** - * Returns the [SecondClassHierarchy.Z] object for the given [name]. - * - * If the given name doesn't correspond to any [SecondClassHierarchy.Z], an - * [IllegalArgumentException] will be thrown. - */ -public fun SecondClassHierarchy.Z.Companion.valueOf(name: String): SecondClassHierarchy.Z = - SecondClassHierarchy_ZSealedEnum.valueOf(name) - -""".trimIndent() - -@Language("kotlin") -val secondClassHierarchyZXGenerated = """ -package com.livefront.sealedenum.compilation.hierarchy - -import com.livefront.sealedenum.SealedEnum -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List - -/** - * An implementation of [SealedEnum] for the sealed class [SecondClassHierarchy.Z.X] - */ -public object SecondClassHierarchy_Z_XSealedEnum : SealedEnum { - public override val values: List by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - listOf( - SecondClassHierarchy.Z.X.W, - SecondClassHierarchy.Z.X.V, - SecondClassHierarchy.Z.X.U.T, - SecondClassHierarchy.Z.X.S.R - ) - } - - - public override fun ordinalOf(obj: SecondClassHierarchy.Z.X): Int = when (obj) { - is SecondClassHierarchy.Z.X.W -> 0 - is SecondClassHierarchy.Z.X.V -> 1 - is SecondClassHierarchy.Z.X.U.T -> 2 - is SecondClassHierarchy.Z.X.S.R -> 3 - } - - public override fun nameOf(obj: SecondClassHierarchy.Z.X): String = when (obj) { - is SecondClassHierarchy.Z.X.W -> "SecondClassHierarchy_Z_X_W" - is SecondClassHierarchy.Z.X.V -> "SecondClassHierarchy_Z_X_V" - is SecondClassHierarchy.Z.X.U.T -> "SecondClassHierarchy_Z_X_U_T" - is SecondClassHierarchy.Z.X.S.R -> "SecondClassHierarchy_Z_X_S_R" - } - - public override fun valueOf(name: String): SecondClassHierarchy.Z.X = when (name) { - "SecondClassHierarchy_Z_X_W" -> SecondClassHierarchy.Z.X.W - "SecondClassHierarchy_Z_X_V" -> SecondClassHierarchy.Z.X.V - "SecondClassHierarchy_Z_X_U_T" -> SecondClassHierarchy.Z.X.U.T - "SecondClassHierarchy_Z_X_S_R" -> SecondClassHierarchy.Z.X.S.R - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } -} - -/** - * The index of [this] in the values list. - */ -public val SecondClassHierarchy.Z.X.ordinal: Int - get() = SecondClassHierarchy_Z_XSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val SecondClassHierarchy.Z.X.name: String - get() = SecondClassHierarchy_Z_XSealedEnum.nameOf(this) - -/** - * A list of all [SecondClassHierarchy.Z.X] objects. - */ -public val SecondClassHierarchy.Z.X.Companion.values: List - get() = SecondClassHierarchy_Z_XSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [SecondClassHierarchy.Z.X] - */ -public val SecondClassHierarchy.Z.X.Companion.sealedEnum: SecondClassHierarchy_Z_XSealedEnum - get() = SecondClassHierarchy_Z_XSealedEnum - -/** - * Returns the [SecondClassHierarchy.Z.X] object for the given [name]. - * - * If the given name doesn't correspond to any [SecondClassHierarchy.Z.X], an - * [IllegalArgumentException] will be thrown. - */ -public fun SecondClassHierarchy.Z.X.Companion.valueOf(name: String): SecondClassHierarchy.Z.X = - SecondClassHierarchy_Z_XSealedEnum.valueOf(name) - -""".trimIndent() - -@Language("kotlin") -val secondClassHierarchyZXUGenerated = """ -package com.livefront.sealedenum.compilation.hierarchy - -import com.livefront.sealedenum.SealedEnum -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List - -/** - * An implementation of [SealedEnum] for the sealed class [SecondClassHierarchy.Z.X.U] - */ -public object SecondClassHierarchy_Z_X_USealedEnum : SealedEnum { - public override val values: List by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - listOf( - SecondClassHierarchy.Z.X.U.T - ) - } - - - public override fun ordinalOf(obj: SecondClassHierarchy.Z.X.U): Int = when (obj) { - is SecondClassHierarchy.Z.X.U.T -> 0 - } - - public override fun nameOf(obj: SecondClassHierarchy.Z.X.U): String = when (obj) { - is SecondClassHierarchy.Z.X.U.T -> "SecondClassHierarchy_Z_X_U_T" - } - - public override fun valueOf(name: String): SecondClassHierarchy.Z.X.U = when (name) { - "SecondClassHierarchy_Z_X_U_T" -> SecondClassHierarchy.Z.X.U.T - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } -} - -/** - * The index of [this] in the values list. - */ -public val SecondClassHierarchy.Z.X.U.ordinal: Int - get() = SecondClassHierarchy_Z_X_USealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val SecondClassHierarchy.Z.X.U.name: String - get() = SecondClassHierarchy_Z_X_USealedEnum.nameOf(this) - -/** - * A list of all [SecondClassHierarchy.Z.X.U] objects. - */ -public val SecondClassHierarchy.Z.X.U.Companion.values: List - get() = SecondClassHierarchy_Z_X_USealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [SecondClassHierarchy.Z.X.U] - */ -public val SecondClassHierarchy.Z.X.U.Companion.sealedEnum: SecondClassHierarchy_Z_X_USealedEnum - get() = SecondClassHierarchy_Z_X_USealedEnum - -/** - * Returns the [SecondClassHierarchy.Z.X.U] object for the given [name]. - * - * If the given name doesn't correspond to any [SecondClassHierarchy.Z.X.U], an - * [IllegalArgumentException] will be thrown. - */ -public fun SecondClassHierarchy.Z.X.U.Companion.valueOf(name: String): SecondClassHierarchy.Z.X.U = - SecondClassHierarchy_Z_X_USealedEnum.valueOf(name) - -""".trimIndent() - -@Language("kotlin") -val secondClassHierarchyZXSGenerated = """ -package com.livefront.sealedenum.compilation.hierarchy - -import com.livefront.sealedenum.SealedEnum -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List - -/** - * An implementation of [SealedEnum] for the sealed class [SecondClassHierarchy.Z.X.S] - */ -public object SecondClassHierarchy_Z_X_SSealedEnum : SealedEnum { - public override val values: List by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - listOf( - SecondClassHierarchy.Z.X.S.R - ) - } - - - public override fun ordinalOf(obj: SecondClassHierarchy.Z.X.S): Int = when (obj) { - is SecondClassHierarchy.Z.X.S.R -> 0 - } - - public override fun nameOf(obj: SecondClassHierarchy.Z.X.S): String = when (obj) { - is SecondClassHierarchy.Z.X.S.R -> "SecondClassHierarchy_Z_X_S_R" - } - - public override fun valueOf(name: String): SecondClassHierarchy.Z.X.S = when (name) { - "SecondClassHierarchy_Z_X_S_R" -> SecondClassHierarchy.Z.X.S.R - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } -} - -/** - * The index of [this] in the values list. - */ -public val SecondClassHierarchy.Z.X.S.ordinal: Int - get() = SecondClassHierarchy_Z_X_SSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val SecondClassHierarchy.Z.X.S.name: String - get() = SecondClassHierarchy_Z_X_SSealedEnum.nameOf(this) - -/** - * A list of all [SecondClassHierarchy.Z.X.S] objects. - */ -public val SecondClassHierarchy.Z.X.S.Companion.values: List - get() = SecondClassHierarchy_Z_X_SSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [SecondClassHierarchy.Z.X.S] - */ -public val SecondClassHierarchy.Z.X.S.Companion.sealedEnum: SecondClassHierarchy_Z_X_SSealedEnum - get() = SecondClassHierarchy_Z_X_SSealedEnum - -/** - * Returns the [SecondClassHierarchy.Z.X.S] object for the given [name]. - * - * If the given name doesn't correspond to any [SecondClassHierarchy.Z.X.S], an - * [IllegalArgumentException] will be thrown. - */ -public fun SecondClassHierarchy.Z.X.S.Companion.valueOf(name: String): SecondClassHierarchy.Z.X.S = - SecondClassHierarchy_Z_X_SSealedEnum.valueOf(name) - -""".trimIndent() - -@Language("kotlin") -val secondClassHierarchyZQGenerated = """ -package com.livefront.sealedenum.compilation.hierarchy - -import com.livefront.sealedenum.SealedEnum -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List - -/** - * An implementation of [SealedEnum] for the sealed class [SecondClassHierarchy.Z.Q] - */ -public object SecondClassHierarchy_Z_QSealedEnum : SealedEnum { - public override val values: List by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - listOf( - SecondClassHierarchy.Z.Q.P - ) - } - - - public override fun ordinalOf(obj: SecondClassHierarchy.Z.Q): Int = when (obj) { - is SecondClassHierarchy.Z.Q.P -> 0 - } - - public override fun nameOf(obj: SecondClassHierarchy.Z.Q): String = when (obj) { - is SecondClassHierarchy.Z.Q.P -> "SecondClassHierarchy_Z_Q_P" - } - - public override fun valueOf(name: String): SecondClassHierarchy.Z.Q = when (name) { - "SecondClassHierarchy_Z_Q_P" -> SecondClassHierarchy.Z.Q.P - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } -} - -/** - * The index of [this] in the values list. - */ -public val SecondClassHierarchy.Z.Q.ordinal: Int - get() = SecondClassHierarchy_Z_QSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val SecondClassHierarchy.Z.Q.name: String - get() = SecondClassHierarchy_Z_QSealedEnum.nameOf(this) - -/** - * A list of all [SecondClassHierarchy.Z.Q] objects. - */ -public val SecondClassHierarchy.Z.Q.Companion.values: List - get() = SecondClassHierarchy_Z_QSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [SecondClassHierarchy.Z.Q] - */ -public val SecondClassHierarchy.Z.Q.Companion.sealedEnum: SecondClassHierarchy_Z_QSealedEnum - get() = SecondClassHierarchy_Z_QSealedEnum - -/** - * Returns the [SecondClassHierarchy.Z.Q] object for the given [name]. - * - * If the given name doesn't correspond to any [SecondClassHierarchy.Z.Q], an - * [IllegalArgumentException] will be thrown. - */ -public fun SecondClassHierarchy.Z.Q.Companion.valueOf(name: String): SecondClassHierarchy.Z.Q = - SecondClassHierarchy_Z_QSealedEnum.valueOf(name) - -""".trimIndent() diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.kt index 46dadb49..c9d02945 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.kt @@ -1,12 +1,16 @@ package com.livefront.sealedenum.compilation.hierarchy +import com.livefront.sealedenum.testing.SealedEnumApprovalsExtension +import com.livefront.sealedenum.testing.assertApprovedGeneratedFile import com.livefront.sealedenum.testing.assertCompiles -import com.livefront.sealedenum.testing.assertGeneratedFileMatches import com.livefront.sealedenum.testing.compile import com.livefront.sealedenum.testing.getCommonSourceFile +import com.oneeyedmen.okeydoke.Approver import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +@ExtendWith(SealedEnumApprovalsExtension::class) class SealedClassHierarchyTests { @Test @@ -20,15 +24,11 @@ class SealedClassHierarchyTests { } @Test - fun `compilation for first hierarchy A generates correct code`() { + fun Approver.`compilation for first hierarchy A generates correct code`() { val result = compile(getCommonSourceFile("compilation", "hierarchy", "SealedClassHierarchy.kt")) assertCompiles(result) - assertGeneratedFileMatches( - "FirstClassHierarchy.A_SealedEnum.kt", - firstClassHierarchyAGenerated, - result - ) + assertApprovedGeneratedFile("FirstClassHierarchy.A_SealedEnum.kt", result) } @Test @@ -42,15 +42,11 @@ class SealedClassHierarchyTests { } @Test - fun `compilation for first hierarchy B generates correct code`() { + fun Approver.`compilation for first hierarchy B generates correct code`() { val result = compile(getCommonSourceFile("compilation", "hierarchy", "SealedClassHierarchy.kt")) assertCompiles(result) - assertGeneratedFileMatches( - "FirstClassHierarchy.A.B_SealedEnum.kt", - firstClassHierarchyBGenerated, - result - ) + assertApprovedGeneratedFile("FirstClassHierarchy.A.B_SealedEnum.kt", result) } @Test @@ -105,15 +101,11 @@ class SealedClassHierarchyTests { } @Test - fun `compilation for second hierarchy Z generates correct code`() { + fun Approver.`compilation for second hierarchy Z generates correct code`() { val result = compile(getCommonSourceFile("compilation", "hierarchy", "SealedClassHierarchy.kt")) assertCompiles(result) - assertGeneratedFileMatches( - "SecondClassHierarchy.Z_SealedEnum.kt", - secondClassHierarchyZGenerated, - result - ) + assertApprovedGeneratedFile("SecondClassHierarchy.Z_SealedEnum.kt", result) } @Test @@ -150,15 +142,11 @@ class SealedClassHierarchyTests { } @Test - fun `compilation for second hierarchy X generates correct code`() { + fun Approver.`compilation for second hierarchy X generates correct code`() { val result = compile(getCommonSourceFile("compilation", "hierarchy", "SealedClassHierarchy.kt")) assertCompiles(result) - assertGeneratedFileMatches( - "SecondClassHierarchy.Z.X_SealedEnum.kt", - secondClassHierarchyZXGenerated, - result - ) + assertApprovedGeneratedFile("SecondClassHierarchy.Z.X_SealedEnum.kt", result) } @Test @@ -175,15 +163,11 @@ class SealedClassHierarchyTests { } @Test - fun `compilation for second hierarchy U generates correct code`() { + fun Approver.`compilation for second hierarchy U generates correct code`() { val result = compile(getCommonSourceFile("compilation", "hierarchy", "SealedClassHierarchy.kt")) assertCompiles(result) - assertGeneratedFileMatches( - "SecondClassHierarchy.Z.X.U_SealedEnum.kt", - secondClassHierarchyZXUGenerated, - result - ) + assertApprovedGeneratedFile("SecondClassHierarchy.Z.X.U_SealedEnum.kt", result) } @Test @@ -200,15 +184,11 @@ class SealedClassHierarchyTests { } @Test - fun `compilation for second hierarchy S generates correct code`() { + fun Approver.`compilation for second hierarchy S generates correct code`() { val result = compile(getCommonSourceFile("compilation", "hierarchy", "SealedClassHierarchy.kt")) assertCompiles(result) - assertGeneratedFileMatches( - "SecondClassHierarchy.Z.X.S_SealedEnum.kt", - secondClassHierarchyZXSGenerated, - result - ) + assertApprovedGeneratedFile("SecondClassHierarchy.Z.X.S_SealedEnum.kt", result) } @Test @@ -225,14 +205,10 @@ class SealedClassHierarchyTests { } @Test - fun `compilation for second hierarchy Q generates correct code`() { + fun Approver.`compilation for second hierarchy Q generates correct code`() { val result = compile(getCommonSourceFile("compilation", "hierarchy", "SealedClassHierarchy.kt")) assertCompiles(result) - assertGeneratedFileMatches( - "SecondClassHierarchy.Z.Q_SealedEnum.kt", - secondClassHierarchyZQGenerated, - result - ) + assertApprovedGeneratedFile("SecondClassHierarchy.Z.Q_SealedEnum.kt", result) } } diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchy.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchy.kt index 7678157a..feae92d4 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchy.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchy.kt @@ -1,7 +1,6 @@ package com.livefront.sealedenum.compilation.hierarchy import com.livefront.sealedenum.GenSealedEnum -import org.intellij.lang.annotations.Language class FirstInterfaceHierarchy { @@ -19,225 +18,6 @@ class FirstInterfaceHierarchy { } } -@Language("kotlin") -val firstInterfaceHierarchyAGenerated = """ -package com.livefront.sealedenum.compilation.hierarchy - -import com.livefront.sealedenum.EnumForSealedEnumProvider -import com.livefront.sealedenum.SealedEnum -import com.livefront.sealedenum.SealedEnumWithEnumProvider -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List -import kotlin.reflect.KClass - -/** - * An isomorphic enum for the sealed class [FirstInterfaceHierarchy.A] - */ -public enum class FirstInterfaceHierarchy_AEnum() { - FirstInterfaceHierarchy_A_B_C, -} - -/** - * The isomorphic [FirstInterfaceHierarchy_AEnum] for [this]. - */ -public val FirstInterfaceHierarchy.A.`enum`: FirstInterfaceHierarchy_AEnum - get() = FirstInterfaceHierarchy_ASealedEnum.sealedObjectToEnum(this) - -/** - * The isomorphic [FirstInterfaceHierarchy.A] for [this]. - */ -public val FirstInterfaceHierarchy_AEnum.sealedObject: FirstInterfaceHierarchy.A - get() = FirstInterfaceHierarchy_ASealedEnum.enumToSealedObject(this) - -/** - * An implementation of [SealedEnum] for the sealed class [FirstInterfaceHierarchy.A] - */ -public object FirstInterfaceHierarchy_ASealedEnum : SealedEnum, - SealedEnumWithEnumProvider, - EnumForSealedEnumProvider { - public override val values: List by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - listOf( - FirstInterfaceHierarchy.A.B.C - ) - } - - - public override val enumClass: KClass - get() = FirstInterfaceHierarchy_AEnum::class - - public override fun ordinalOf(obj: FirstInterfaceHierarchy.A): Int = when (obj) { - is FirstInterfaceHierarchy.A.B.C -> 0 - } - - public override fun nameOf(obj: FirstInterfaceHierarchy.A): String = when (obj) { - is FirstInterfaceHierarchy.A.B.C -> "FirstInterfaceHierarchy_A_B_C" - } - - public override fun valueOf(name: String): FirstInterfaceHierarchy.A = when (name) { - "FirstInterfaceHierarchy_A_B_C" -> FirstInterfaceHierarchy.A.B.C - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } - - public override fun sealedObjectToEnum(obj: FirstInterfaceHierarchy.A): - FirstInterfaceHierarchy_AEnum = when (obj) { - is FirstInterfaceHierarchy.A.B.C -> - FirstInterfaceHierarchy_AEnum.FirstInterfaceHierarchy_A_B_C - } - - public override fun enumToSealedObject(`enum`: FirstInterfaceHierarchy_AEnum): - FirstInterfaceHierarchy.A = when (enum) { - FirstInterfaceHierarchy_AEnum.FirstInterfaceHierarchy_A_B_C -> FirstInterfaceHierarchy.A.B.C - } -} - -/** - * The index of [this] in the values list. - */ -public val FirstInterfaceHierarchy.A.ordinal: Int - get() = FirstInterfaceHierarchy_ASealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val FirstInterfaceHierarchy.A.name: String - get() = FirstInterfaceHierarchy_ASealedEnum.nameOf(this) - -/** - * A list of all [FirstInterfaceHierarchy.A] objects. - */ -public val FirstInterfaceHierarchy.A.Companion.values: List - get() = FirstInterfaceHierarchy_ASealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [FirstInterfaceHierarchy.A] - */ -public val FirstInterfaceHierarchy.A.Companion.sealedEnum: FirstInterfaceHierarchy_ASealedEnum - get() = FirstInterfaceHierarchy_ASealedEnum - -/** - * Returns the [FirstInterfaceHierarchy.A] object for the given [name]. - * - * If the given name doesn't correspond to any [FirstInterfaceHierarchy.A], an - * [IllegalArgumentException] will be thrown. - */ -public fun FirstInterfaceHierarchy.A.Companion.valueOf(name: String): FirstInterfaceHierarchy.A = - FirstInterfaceHierarchy_ASealedEnum.valueOf(name) - -""".trimIndent() - -@Language("kotlin") -val firstInterfaceHierarchyBGenerated = """ -package com.livefront.sealedenum.compilation.hierarchy - -import com.livefront.sealedenum.EnumForSealedEnumProvider -import com.livefront.sealedenum.SealedEnum -import com.livefront.sealedenum.SealedEnumWithEnumProvider -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List -import kotlin.reflect.KClass - -/** - * An isomorphic enum for the sealed class [FirstInterfaceHierarchy.A.B] - */ -public enum class FirstInterfaceHierarchy_A_BEnum() { - FirstInterfaceHierarchy_A_B_C, -} - -/** - * The isomorphic [FirstInterfaceHierarchy_A_BEnum] for [this]. - */ -public val FirstInterfaceHierarchy.A.B.`enum`: FirstInterfaceHierarchy_A_BEnum - get() = FirstInterfaceHierarchy_A_BSealedEnum.sealedObjectToEnum(this) - -/** - * The isomorphic [FirstInterfaceHierarchy.A.B] for [this]. - */ -public val FirstInterfaceHierarchy_A_BEnum.sealedObject: FirstInterfaceHierarchy.A.B - get() = FirstInterfaceHierarchy_A_BSealedEnum.enumToSealedObject(this) - -/** - * An implementation of [SealedEnum] for the sealed class [FirstInterfaceHierarchy.A.B] - */ -public object FirstInterfaceHierarchy_A_BSealedEnum : SealedEnum, - SealedEnumWithEnumProvider, - EnumForSealedEnumProvider { - public override val values: List by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - listOf( - FirstInterfaceHierarchy.A.B.C - ) - } - - - public override val enumClass: KClass - get() = FirstInterfaceHierarchy_A_BEnum::class - - public override fun ordinalOf(obj: FirstInterfaceHierarchy.A.B): Int = when (obj) { - is FirstInterfaceHierarchy.A.B.C -> 0 - } - - public override fun nameOf(obj: FirstInterfaceHierarchy.A.B): String = when (obj) { - is FirstInterfaceHierarchy.A.B.C -> "FirstInterfaceHierarchy_A_B_C" - } - - public override fun valueOf(name: String): FirstInterfaceHierarchy.A.B = when (name) { - "FirstInterfaceHierarchy_A_B_C" -> FirstInterfaceHierarchy.A.B.C - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } - - public override fun sealedObjectToEnum(obj: FirstInterfaceHierarchy.A.B): - FirstInterfaceHierarchy_A_BEnum = when (obj) { - is FirstInterfaceHierarchy.A.B.C -> - FirstInterfaceHierarchy_A_BEnum.FirstInterfaceHierarchy_A_B_C - } - - public override fun enumToSealedObject(`enum`: FirstInterfaceHierarchy_A_BEnum): - FirstInterfaceHierarchy.A.B = when (enum) { - FirstInterfaceHierarchy_A_BEnum.FirstInterfaceHierarchy_A_B_C -> - FirstInterfaceHierarchy.A.B.C - } -} - -/** - * The index of [this] in the values list. - */ -public val FirstInterfaceHierarchy.A.B.ordinal: Int - get() = FirstInterfaceHierarchy_A_BSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val FirstInterfaceHierarchy.A.B.name: String - get() = FirstInterfaceHierarchy_A_BSealedEnum.nameOf(this) - -/** - * A list of all [FirstInterfaceHierarchy.A.B] objects. - */ -public val FirstInterfaceHierarchy.A.B.Companion.values: List - get() = FirstInterfaceHierarchy_A_BSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [FirstInterfaceHierarchy.A.B] - */ -public val FirstInterfaceHierarchy.A.B.Companion.sealedEnum: FirstInterfaceHierarchy_A_BSealedEnum - get() = FirstInterfaceHierarchy_A_BSealedEnum - -/** - * Returns the [FirstInterfaceHierarchy.A.B] object for the given [name]. - * - * If the given name doesn't correspond to any [FirstInterfaceHierarchy.A.B], an - * [IllegalArgumentException] will be thrown. - */ -public fun FirstInterfaceHierarchy.A.B.Companion.valueOf(name: String): FirstInterfaceHierarchy.A.B - = FirstInterfaceHierarchy_A_BSealedEnum.valueOf(name) - -""".trimIndent() - class SecondInterfaceHierarchy { sealed interface A { @@ -282,398 +62,3 @@ class SecondInterfaceHierarchy { companion object } } - -@Language("kotlin") -val secondInterfaceHierarchyAGenerated = """ -package com.livefront.sealedenum.compilation.hierarchy - -import com.livefront.sealedenum.SealedEnum -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List - -/** - * An implementation of [SealedEnum] for the sealed class [SecondInterfaceHierarchy.A] - */ -public object SecondInterfaceHierarchy_ASealedEnum : SealedEnum { - public override val values: List by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - listOf( - SecondInterfaceHierarchy.A.B, - SecondInterfaceHierarchy.A.C.D, - SecondInterfaceHierarchy.A.C.E, - SecondInterfaceHierarchy.A.C.F.G, - SecondInterfaceHierarchy.A.C.H.I, - SecondInterfaceHierarchy.A.J.K, - SecondInterfaceHierarchy.A.L - ) - } - - - public override fun ordinalOf(obj: SecondInterfaceHierarchy.A): Int = when (obj) { - is SecondInterfaceHierarchy.A.B -> 0 - is SecondInterfaceHierarchy.A.C.D -> 1 - is SecondInterfaceHierarchy.A.C.E -> 2 - is SecondInterfaceHierarchy.A.C.F.G -> 3 - is SecondInterfaceHierarchy.A.C.H.I -> 4 - is SecondInterfaceHierarchy.A.J.K -> 5 - is SecondInterfaceHierarchy.A.L -> 6 - } - - public override fun nameOf(obj: SecondInterfaceHierarchy.A): String = when (obj) { - is SecondInterfaceHierarchy.A.B -> "SecondInterfaceHierarchy_A_B" - is SecondInterfaceHierarchy.A.C.D -> "SecondInterfaceHierarchy_A_C_D" - is SecondInterfaceHierarchy.A.C.E -> "SecondInterfaceHierarchy_A_C_E" - is SecondInterfaceHierarchy.A.C.F.G -> "SecondInterfaceHierarchy_A_C_F_G" - is SecondInterfaceHierarchy.A.C.H.I -> "SecondInterfaceHierarchy_A_C_H_I" - is SecondInterfaceHierarchy.A.J.K -> "SecondInterfaceHierarchy_A_J_K" - is SecondInterfaceHierarchy.A.L -> "SecondInterfaceHierarchy_A_L" - } - - public override fun valueOf(name: String): SecondInterfaceHierarchy.A = when (name) { - "SecondInterfaceHierarchy_A_B" -> SecondInterfaceHierarchy.A.B - "SecondInterfaceHierarchy_A_C_D" -> SecondInterfaceHierarchy.A.C.D - "SecondInterfaceHierarchy_A_C_E" -> SecondInterfaceHierarchy.A.C.E - "SecondInterfaceHierarchy_A_C_F_G" -> SecondInterfaceHierarchy.A.C.F.G - "SecondInterfaceHierarchy_A_C_H_I" -> SecondInterfaceHierarchy.A.C.H.I - "SecondInterfaceHierarchy_A_J_K" -> SecondInterfaceHierarchy.A.J.K - "SecondInterfaceHierarchy_A_L" -> SecondInterfaceHierarchy.A.L - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } -} - -/** - * The index of [this] in the values list. - */ -public val SecondInterfaceHierarchy.A.ordinal: Int - get() = SecondInterfaceHierarchy_ASealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val SecondInterfaceHierarchy.A.name: String - get() = SecondInterfaceHierarchy_ASealedEnum.nameOf(this) - -/** - * A list of all [SecondInterfaceHierarchy.A] objects. - */ -public val SecondInterfaceHierarchy.A.Companion.values: List - get() = SecondInterfaceHierarchy_ASealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [SecondInterfaceHierarchy.A] - */ -public val SecondInterfaceHierarchy.A.Companion.sealedEnum: SecondInterfaceHierarchy_ASealedEnum - get() = SecondInterfaceHierarchy_ASealedEnum - -/** - * Returns the [SecondInterfaceHierarchy.A] object for the given [name]. - * - * If the given name doesn't correspond to any [SecondInterfaceHierarchy.A], an - * [IllegalArgumentException] will be thrown. - */ -public fun SecondInterfaceHierarchy.A.Companion.valueOf(name: String): SecondInterfaceHierarchy.A = - SecondInterfaceHierarchy_ASealedEnum.valueOf(name) - -""".trimIndent() - -@Language("kotlin") -val secondInterfaceHierarchyACGenerated = """ -package com.livefront.sealedenum.compilation.hierarchy - -import com.livefront.sealedenum.SealedEnum -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List - -/** - * An implementation of [SealedEnum] for the sealed class [SecondInterfaceHierarchy.A.C] - */ -public object SecondInterfaceHierarchy_A_CSealedEnum : SealedEnum { - public override val values: List by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - listOf( - SecondInterfaceHierarchy.A.C.D, - SecondInterfaceHierarchy.A.C.E, - SecondInterfaceHierarchy.A.C.F.G, - SecondInterfaceHierarchy.A.C.H.I - ) - } - - - public override fun ordinalOf(obj: SecondInterfaceHierarchy.A.C): Int = when (obj) { - is SecondInterfaceHierarchy.A.C.D -> 0 - is SecondInterfaceHierarchy.A.C.E -> 1 - is SecondInterfaceHierarchy.A.C.F.G -> 2 - is SecondInterfaceHierarchy.A.C.H.I -> 3 - } - - public override fun nameOf(obj: SecondInterfaceHierarchy.A.C): String = when (obj) { - is SecondInterfaceHierarchy.A.C.D -> "SecondInterfaceHierarchy_A_C_D" - is SecondInterfaceHierarchy.A.C.E -> "SecondInterfaceHierarchy_A_C_E" - is SecondInterfaceHierarchy.A.C.F.G -> "SecondInterfaceHierarchy_A_C_F_G" - is SecondInterfaceHierarchy.A.C.H.I -> "SecondInterfaceHierarchy_A_C_H_I" - } - - public override fun valueOf(name: String): SecondInterfaceHierarchy.A.C = when (name) { - "SecondInterfaceHierarchy_A_C_D" -> SecondInterfaceHierarchy.A.C.D - "SecondInterfaceHierarchy_A_C_E" -> SecondInterfaceHierarchy.A.C.E - "SecondInterfaceHierarchy_A_C_F_G" -> SecondInterfaceHierarchy.A.C.F.G - "SecondInterfaceHierarchy_A_C_H_I" -> SecondInterfaceHierarchy.A.C.H.I - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } -} - -/** - * The index of [this] in the values list. - */ -public val SecondInterfaceHierarchy.A.C.ordinal: Int - get() = SecondInterfaceHierarchy_A_CSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val SecondInterfaceHierarchy.A.C.name: String - get() = SecondInterfaceHierarchy_A_CSealedEnum.nameOf(this) - -/** - * A list of all [SecondInterfaceHierarchy.A.C] objects. - */ -public val SecondInterfaceHierarchy.A.C.Companion.values: List - get() = SecondInterfaceHierarchy_A_CSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [SecondInterfaceHierarchy.A.C] - */ -public val SecondInterfaceHierarchy.A.C.Companion.sealedEnum: SecondInterfaceHierarchy_A_CSealedEnum - get() = SecondInterfaceHierarchy_A_CSealedEnum - -/** - * Returns the [SecondInterfaceHierarchy.A.C] object for the given [name]. - * - * If the given name doesn't correspond to any [SecondInterfaceHierarchy.A.C], an - * [IllegalArgumentException] will be thrown. - */ -public fun SecondInterfaceHierarchy.A.C.Companion.valueOf(name: String): - SecondInterfaceHierarchy.A.C = SecondInterfaceHierarchy_A_CSealedEnum.valueOf(name) - -""".trimIndent() - -@Language("kotlin") -val secondInterfaceHierarchyACFGenerated = """ -package com.livefront.sealedenum.compilation.hierarchy - -import com.livefront.sealedenum.SealedEnum -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List - -/** - * An implementation of [SealedEnum] for the sealed class [SecondInterfaceHierarchy.A.C.F] - */ -public object SecondInterfaceHierarchy_A_C_FSealedEnum : SealedEnum - { - public override val values: List by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - listOf( - SecondInterfaceHierarchy.A.C.F.G - ) - } - - - public override fun ordinalOf(obj: SecondInterfaceHierarchy.A.C.F): Int = when (obj) { - is SecondInterfaceHierarchy.A.C.F.G -> 0 - } - - public override fun nameOf(obj: SecondInterfaceHierarchy.A.C.F): String = when (obj) { - is SecondInterfaceHierarchy.A.C.F.G -> "SecondInterfaceHierarchy_A_C_F_G" - } - - public override fun valueOf(name: String): SecondInterfaceHierarchy.A.C.F = when (name) { - "SecondInterfaceHierarchy_A_C_F_G" -> SecondInterfaceHierarchy.A.C.F.G - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } -} - -/** - * The index of [this] in the values list. - */ -public val SecondInterfaceHierarchy.A.C.F.ordinal: Int - get() = SecondInterfaceHierarchy_A_C_FSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val SecondInterfaceHierarchy.A.C.F.name: String - get() = SecondInterfaceHierarchy_A_C_FSealedEnum.nameOf(this) - -/** - * A list of all [SecondInterfaceHierarchy.A.C.F] objects. - */ -public val SecondInterfaceHierarchy.A.C.F.Companion.values: List - get() = SecondInterfaceHierarchy_A_C_FSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [SecondInterfaceHierarchy.A.C.F] - */ -public val SecondInterfaceHierarchy.A.C.F.Companion.sealedEnum: - SecondInterfaceHierarchy_A_C_FSealedEnum - get() = SecondInterfaceHierarchy_A_C_FSealedEnum - -/** - * Returns the [SecondInterfaceHierarchy.A.C.F] object for the given [name]. - * - * If the given name doesn't correspond to any [SecondInterfaceHierarchy.A.C.F], an - * [IllegalArgumentException] will be thrown. - */ -public fun SecondInterfaceHierarchy.A.C.F.Companion.valueOf(name: String): - SecondInterfaceHierarchy.A.C.F = SecondInterfaceHierarchy_A_C_FSealedEnum.valueOf(name) - -""".trimIndent() - -@Language("kotlin") -val secondInterfaceHierarchyACHGenerated = """ -package com.livefront.sealedenum.compilation.hierarchy - -import com.livefront.sealedenum.SealedEnum -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List - -/** - * An implementation of [SealedEnum] for the sealed class [SecondInterfaceHierarchy.A.C.H] - */ -public object SecondInterfaceHierarchy_A_C_HSealedEnum : SealedEnum - { - public override val values: List by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - listOf( - SecondInterfaceHierarchy.A.C.H.I - ) - } - - - public override fun ordinalOf(obj: SecondInterfaceHierarchy.A.C.H): Int = when (obj) { - is SecondInterfaceHierarchy.A.C.H.I -> 0 - } - - public override fun nameOf(obj: SecondInterfaceHierarchy.A.C.H): String = when (obj) { - is SecondInterfaceHierarchy.A.C.H.I -> "SecondInterfaceHierarchy_A_C_H_I" - } - - public override fun valueOf(name: String): SecondInterfaceHierarchy.A.C.H = when (name) { - "SecondInterfaceHierarchy_A_C_H_I" -> SecondInterfaceHierarchy.A.C.H.I - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } -} - -/** - * The index of [this] in the values list. - */ -public val SecondInterfaceHierarchy.A.C.H.ordinal: Int - get() = SecondInterfaceHierarchy_A_C_HSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val SecondInterfaceHierarchy.A.C.H.name: String - get() = SecondInterfaceHierarchy_A_C_HSealedEnum.nameOf(this) - -/** - * A list of all [SecondInterfaceHierarchy.A.C.H] objects. - */ -public val SecondInterfaceHierarchy.A.C.H.Companion.values: List - get() = SecondInterfaceHierarchy_A_C_HSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [SecondInterfaceHierarchy.A.C.H] - */ -public val SecondInterfaceHierarchy.A.C.H.Companion.sealedEnum: - SecondInterfaceHierarchy_A_C_HSealedEnum - get() = SecondInterfaceHierarchy_A_C_HSealedEnum - -/** - * Returns the [SecondInterfaceHierarchy.A.C.H] object for the given [name]. - * - * If the given name doesn't correspond to any [SecondInterfaceHierarchy.A.C.H], an - * [IllegalArgumentException] will be thrown. - */ -public fun SecondInterfaceHierarchy.A.C.H.Companion.valueOf(name: String): - SecondInterfaceHierarchy.A.C.H = SecondInterfaceHierarchy_A_C_HSealedEnum.valueOf(name) - -""".trimIndent() - -@Language("kotlin") -val secondInterfaceHierarchyAJGenerated = """ -package com.livefront.sealedenum.compilation.hierarchy - -import com.livefront.sealedenum.SealedEnum -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List - -/** - * An implementation of [SealedEnum] for the sealed class [SecondInterfaceHierarchy.A.J] - */ -public object SecondInterfaceHierarchy_A_JSealedEnum : SealedEnum { - public override val values: List by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - listOf( - SecondInterfaceHierarchy.A.J.K - ) - } - - - public override fun ordinalOf(obj: SecondInterfaceHierarchy.A.J): Int = when (obj) { - is SecondInterfaceHierarchy.A.J.K -> 0 - } - - public override fun nameOf(obj: SecondInterfaceHierarchy.A.J): String = when (obj) { - is SecondInterfaceHierarchy.A.J.K -> "SecondInterfaceHierarchy_A_J_K" - } - - public override fun valueOf(name: String): SecondInterfaceHierarchy.A.J = when (name) { - "SecondInterfaceHierarchy_A_J_K" -> SecondInterfaceHierarchy.A.J.K - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } -} - -/** - * The index of [this] in the values list. - */ -public val SecondInterfaceHierarchy.A.J.ordinal: Int - get() = SecondInterfaceHierarchy_A_JSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val SecondInterfaceHierarchy.A.J.name: String - get() = SecondInterfaceHierarchy_A_JSealedEnum.nameOf(this) - -/** - * A list of all [SecondInterfaceHierarchy.A.J] objects. - */ -public val SecondInterfaceHierarchy.A.J.Companion.values: List - get() = SecondInterfaceHierarchy_A_JSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [SecondInterfaceHierarchy.A.J] - */ -public val SecondInterfaceHierarchy.A.J.Companion.sealedEnum: SecondInterfaceHierarchy_A_JSealedEnum - get() = SecondInterfaceHierarchy_A_JSealedEnum - -/** - * Returns the [SecondInterfaceHierarchy.A.J] object for the given [name]. - * - * If the given name doesn't correspond to any [SecondInterfaceHierarchy.A.J], an - * [IllegalArgumentException] will be thrown. - */ -public fun SecondInterfaceHierarchy.A.J.Companion.valueOf(name: String): - SecondInterfaceHierarchy.A.J = SecondInterfaceHierarchy_A_JSealedEnum.valueOf(name) - -""".trimIndent() diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.kt index 3a80dce6..61a62ae3 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.kt @@ -1,12 +1,16 @@ package com.livefront.sealedenum.compilation.hierarchy +import com.livefront.sealedenum.testing.SealedEnumApprovalsExtension +import com.livefront.sealedenum.testing.assertApprovedGeneratedFile import com.livefront.sealedenum.testing.assertCompiles -import com.livefront.sealedenum.testing.assertGeneratedFileMatches import com.livefront.sealedenum.testing.compile import com.livefront.sealedenum.testing.getCommonSourceFile +import com.oneeyedmen.okeydoke.Approver import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +@ExtendWith(SealedEnumApprovalsExtension::class) class SealedInterfaceHierarchyTests { @Test @@ -20,15 +24,11 @@ class SealedInterfaceHierarchyTests { } @Test - fun `compilation for first hierarchy A generates correct code`() { + fun Approver.`compilation for first hierarchy A generates correct code`() { val result = compile(getCommonSourceFile("compilation", "hierarchy", "SealedInterfaceHierarchy.kt")) assertCompiles(result) - assertGeneratedFileMatches( - "FirstInterfaceHierarchy.A_SealedEnum.kt", - firstInterfaceHierarchyAGenerated, - result - ) + assertApprovedGeneratedFile("FirstInterfaceHierarchy.A_SealedEnum.kt", result) } @Test @@ -42,15 +42,11 @@ class SealedInterfaceHierarchyTests { } @Test - fun `compilation for first hierarchy B generates correct code`() { + fun Approver.`compilation for first hierarchy B generates correct code`() { val result = compile(getCommonSourceFile("compilation", "hierarchy", "SealedInterfaceHierarchy.kt")) assertCompiles(result) - assertGeneratedFileMatches( - "FirstInterfaceHierarchy.A.B_SealedEnum.kt", - firstInterfaceHierarchyBGenerated, - result - ) + assertApprovedGeneratedFile("FirstInterfaceHierarchy.A.B_SealedEnum.kt", result) } @Test @@ -105,15 +101,11 @@ class SealedInterfaceHierarchyTests { } @Test - fun `compilation for second hierarchy A generates correct code`() { + fun Approver.`compilation for second hierarchy A generates correct code`() { val result = compile(getCommonSourceFile("compilation", "hierarchy", "SealedInterfaceHierarchy.kt")) assertCompiles(result) - assertGeneratedFileMatches( - "SecondInterfaceHierarchy.A_SealedEnum.kt", - secondInterfaceHierarchyAGenerated, - result - ) + assertApprovedGeneratedFile("SecondInterfaceHierarchy.A_SealedEnum.kt", result) } @Test @@ -150,15 +142,11 @@ class SealedInterfaceHierarchyTests { } @Test - fun `compilation for second hierarchy C generates correct code`() { + fun Approver.`compilation for second hierarchy C generates correct code`() { val result = compile(getCommonSourceFile("compilation", "hierarchy", "SealedInterfaceHierarchy.kt")) assertCompiles(result) - assertGeneratedFileMatches( - "SecondInterfaceHierarchy.A.C_SealedEnum.kt", - secondInterfaceHierarchyACGenerated, - result - ) + assertApprovedGeneratedFile("SecondInterfaceHierarchy.A.C_SealedEnum.kt", result) } @Test @@ -175,15 +163,11 @@ class SealedInterfaceHierarchyTests { } @Test - fun `compilation for second hierarchy F generates correct code`() { + fun Approver.`compilation for second hierarchy F generates correct code`() { val result = compile(getCommonSourceFile("compilation", "hierarchy", "SealedInterfaceHierarchy.kt")) assertCompiles(result) - assertGeneratedFileMatches( - "SecondInterfaceHierarchy.A.C.F_SealedEnum.kt", - secondInterfaceHierarchyACFGenerated, - result - ) + assertApprovedGeneratedFile("SecondInterfaceHierarchy.A.C.F_SealedEnum.kt", result) } @Test @@ -200,15 +184,11 @@ class SealedInterfaceHierarchyTests { } @Test - fun `compilation for second hierarchy H generates correct code`() { + fun Approver.`compilation for second hierarchy H generates correct code`() { val result = compile(getCommonSourceFile("compilation", "hierarchy", "SealedInterfaceHierarchy.kt")) assertCompiles(result) - assertGeneratedFileMatches( - "SecondInterfaceHierarchy.A.C.H_SealedEnum.kt", - secondInterfaceHierarchyACHGenerated, - result - ) + assertApprovedGeneratedFile("SecondInterfaceHierarchy.A.C.H_SealedEnum.kt", result) } @Test @@ -225,14 +205,10 @@ class SealedInterfaceHierarchyTests { } @Test - fun `compilation for second hierarchy J generates correct code`() { + fun Approver.`compilation for second hierarchy J generates correct code`() { val result = compile(getCommonSourceFile("compilation", "hierarchy", "SealedInterfaceHierarchy.kt")) assertCompiles(result) - assertGeneratedFileMatches( - "SecondInterfaceHierarchy.A.J_SealedEnum.kt", - secondInterfaceHierarchyAJGenerated, - result - ) + assertApprovedGeneratedFile("SecondInterfaceHierarchy.A.J_SealedEnum.kt", result) } } diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/location/NestedClass.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/location/NestedClass.kt index 3c1f03df..f7e02721 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/location/NestedClass.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/location/NestedClass.kt @@ -1,7 +1,6 @@ package com.livefront.sealedenum.compilation.location import com.livefront.sealedenum.GenSealedEnum -import org.intellij.lang.annotations.Language class OuterClass { sealed class InsideOneClassSealedClass { @@ -14,90 +13,6 @@ class OuterClass { } } -@Language("kotlin") -val insideOneClassSealedClassGenerated = """ -package com.livefront.sealedenum.compilation.location - -import com.livefront.sealedenum.SealedEnum -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List - -/** - * An implementation of [SealedEnum] for the sealed class [OuterClass.InsideOneClassSealedClass] - */ -public object OuterClass_InsideOneClassSealedClassSealedEnum : - SealedEnum { - public override val values: List by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - listOf( - OuterClass.InsideOneClassSealedClass.FirstObject, - OuterClass.InsideOneClassSealedClass.SecondObject - ) - } - - - public override fun ordinalOf(obj: OuterClass.InsideOneClassSealedClass): Int = when (obj) { - is OuterClass.InsideOneClassSealedClass.FirstObject -> 0 - is OuterClass.InsideOneClassSealedClass.SecondObject -> 1 - } - - public override fun nameOf(obj: OuterClass.InsideOneClassSealedClass): String = when (obj) { - is OuterClass.InsideOneClassSealedClass.FirstObject -> - "OuterClass_InsideOneClassSealedClass_FirstObject" - is OuterClass.InsideOneClassSealedClass.SecondObject -> - "OuterClass_InsideOneClassSealedClass_SecondObject" - } - - public override fun valueOf(name: String): OuterClass.InsideOneClassSealedClass = when (name) { - "OuterClass_InsideOneClassSealedClass_FirstObject" -> - OuterClass.InsideOneClassSealedClass.FirstObject - "OuterClass_InsideOneClassSealedClass_SecondObject" -> - OuterClass.InsideOneClassSealedClass.SecondObject - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } -} - -/** - * The index of [this] in the values list. - */ -public val OuterClass.InsideOneClassSealedClass.ordinal: Int - get() = OuterClass_InsideOneClassSealedClassSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val OuterClass.InsideOneClassSealedClass.name: String - get() = OuterClass_InsideOneClassSealedClassSealedEnum.nameOf(this) - -/** - * A list of all [OuterClass.InsideOneClassSealedClass] objects. - */ -public val OuterClass.InsideOneClassSealedClass.Companion.values: - List - get() = OuterClass_InsideOneClassSealedClassSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class - * [OuterClass.InsideOneClassSealedClass] - */ -public val OuterClass.InsideOneClassSealedClass.Companion.sealedEnum: - OuterClass_InsideOneClassSealedClassSealedEnum - get() = OuterClass_InsideOneClassSealedClassSealedEnum - -/** - * Returns the [OuterClass.InsideOneClassSealedClass] object for the given [name]. - * - * If the given name doesn't correspond to any [OuterClass.InsideOneClassSealedClass], an - * [IllegalArgumentException] will be thrown. - */ -public fun OuterClass.InsideOneClassSealedClass.Companion.valueOf(name: String): - OuterClass.InsideOneClassSealedClass = - OuterClass_InsideOneClassSealedClassSealedEnum.valueOf(name) - -""".trimIndent() - class FirstOuterClass { class SecondOuterClass { sealed class InsideTwoClassesSealedClass { @@ -110,95 +25,3 @@ class FirstOuterClass { } } } - -@Language("kotlin") -val insideTwoClassesSealedClassGenerated = """ -package com.livefront.sealedenum.compilation.location - -import com.livefront.sealedenum.SealedEnum -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List - -/** - * An implementation of [SealedEnum] for the sealed class - * [FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass] - */ -public object FirstOuterClass_SecondOuterClass_InsideTwoClassesSealedClassSealedEnum : - SealedEnum { - public override val values: List - by lazy(mode = LazyThreadSafetyMode.PUBLICATION) { - listOf( - FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass.FirstObject, - FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass.SecondObject - ) - } - - - public override - fun ordinalOf(obj: FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass): Int = - when (obj) { - is FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass.FirstObject -> 0 - is FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass.SecondObject -> 1 - } - - public override fun nameOf(obj: FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass): - String = when (obj) { - is FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass.FirstObject -> - "FirstOuterClass_SecondOuterClass_InsideTwoClassesSealedClass_FirstObject" - is FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass.SecondObject -> - "FirstOuterClass_SecondOuterClass_InsideTwoClassesSealedClass_SecondObject" - } - - public override fun valueOf(name: String): - FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass = when (name) { - "FirstOuterClass_SecondOuterClass_InsideTwoClassesSealedClass_FirstObject" -> - FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass.FirstObject - "FirstOuterClass_SecondOuterClass_InsideTwoClassesSealedClass_SecondObject" -> - FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass.SecondObject - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } -} - -/** - * The index of [this] in the values list. - */ -public val FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass.ordinal: Int - get() = FirstOuterClass_SecondOuterClass_InsideTwoClassesSealedClassSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass.name: String - get() = FirstOuterClass_SecondOuterClass_InsideTwoClassesSealedClassSealedEnum.nameOf(this) - -/** - * A list of all [FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass] objects. - */ -public val FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass.Companion.values: - List - get() = FirstOuterClass_SecondOuterClass_InsideTwoClassesSealedClassSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class - * [FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass] - */ -public val FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass.Companion.sealedEnum: - FirstOuterClass_SecondOuterClass_InsideTwoClassesSealedClassSealedEnum - get() = FirstOuterClass_SecondOuterClass_InsideTwoClassesSealedClassSealedEnum - -/** - * Returns the [FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass] object for the given - * [name]. - * - * If the given name doesn't correspond to any - * [FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass], an [IllegalArgumentException] will - * be thrown. - */ -public - fun FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass.Companion.valueOf(name: String): - FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass = - FirstOuterClass_SecondOuterClass_InsideTwoClassesSealedClassSealedEnum.valueOf(name) - -""".trimIndent() diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/location/NestedClassTests.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/location/NestedClassTests.kt index c147761a..f8110c5a 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/location/NestedClassTests.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/location/NestedClassTests.kt @@ -1,12 +1,16 @@ package com.livefront.sealedenum.compilation.location +import com.livefront.sealedenum.testing.SealedEnumApprovalsExtension +import com.livefront.sealedenum.testing.assertApprovedGeneratedFile import com.livefront.sealedenum.testing.assertCompiles -import com.livefront.sealedenum.testing.assertGeneratedFileMatches import com.livefront.sealedenum.testing.compile import com.livefront.sealedenum.testing.getCommonSourceFile +import com.oneeyedmen.okeydoke.Approver import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +@ExtendWith(SealedEnumApprovalsExtension::class) class NestedClassTests { @Test @@ -21,15 +25,11 @@ class NestedClassTests { } @Test - fun `compilation for inside one class generates correct code`() { + fun Approver.`compilation for inside one class generates correct code`() { val result = compile(getCommonSourceFile("compilation", "location", "NestedClass.kt")) assertCompiles(result) - assertGeneratedFileMatches( - "OuterClass.InsideOneClassSealedClass_SealedEnum.kt", - insideOneClassSealedClassGenerated, - result - ) + assertApprovedGeneratedFile("OuterClass.InsideOneClassSealedClass_SealedEnum.kt", result) } @Test @@ -44,13 +44,12 @@ class NestedClassTests { } @Test - fun `compilation for inside two classes generates correct code`() { + fun Approver.`compilation for inside two classes generates correct code`() { val result = compile(getCommonSourceFile("compilation", "location", "NestedClass.kt")) assertCompiles(result) - assertGeneratedFileMatches( + assertApprovedGeneratedFile( "FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass_SealedEnum.kt", - insideTwoClassesSealedClassGenerated, result ) } diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/location/OutsideSealedClass.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/location/OutsideSealedClass.kt index 3d2ce0ce..670c82b0 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/location/OutsideSealedClass.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/location/OutsideSealedClass.kt @@ -1,7 +1,6 @@ package com.livefront.sealedenum.compilation.location import com.livefront.sealedenum.GenSealedEnum -import org.intellij.lang.annotations.Language sealed class AlphaOutsideSealedClass { @GenSealedEnum(generateEnum = true) @@ -10,114 +9,6 @@ sealed class AlphaOutsideSealedClass { object AlphaFirstObject : AlphaOutsideSealedClass() -@Language("kotlin") -val alphaOutsideSealedClassGenerated = """ -package com.livefront.sealedenum.compilation.location - -import com.livefront.sealedenum.EnumForSealedEnumProvider -import com.livefront.sealedenum.SealedEnum -import com.livefront.sealedenum.SealedEnumWithEnumProvider -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List -import kotlin.reflect.KClass - -/** - * An isomorphic enum for the sealed class [AlphaOutsideSealedClass] - */ -public enum class AlphaOutsideSealedClassEnum() { - AlphaFirstObject, -} - -/** - * The isomorphic [AlphaOutsideSealedClassEnum] for [this]. - */ -public val AlphaOutsideSealedClass.`enum`: AlphaOutsideSealedClassEnum - get() = AlphaOutsideSealedClassSealedEnum.sealedObjectToEnum(this) - -/** - * The isomorphic [AlphaOutsideSealedClass] for [this]. - */ -public val AlphaOutsideSealedClassEnum.sealedObject: AlphaOutsideSealedClass - get() = AlphaOutsideSealedClassSealedEnum.enumToSealedObject(this) - -/** - * An implementation of [SealedEnum] for the sealed class [AlphaOutsideSealedClass] - */ -public object AlphaOutsideSealedClassSealedEnum : SealedEnum, - SealedEnumWithEnumProvider, - EnumForSealedEnumProvider { - public override val values: List by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - listOf( - AlphaFirstObject - ) - } - - - public override val enumClass: KClass - get() = AlphaOutsideSealedClassEnum::class - - public override fun ordinalOf(obj: AlphaOutsideSealedClass): Int = when (obj) { - is AlphaFirstObject -> 0 - } - - public override fun nameOf(obj: AlphaOutsideSealedClass): String = when (obj) { - is AlphaFirstObject -> "AlphaFirstObject" - } - - public override fun valueOf(name: String): AlphaOutsideSealedClass = when (name) { - "AlphaFirstObject" -> AlphaFirstObject - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } - - public override fun sealedObjectToEnum(obj: AlphaOutsideSealedClass): - AlphaOutsideSealedClassEnum = when (obj) { - is AlphaFirstObject -> AlphaOutsideSealedClassEnum.AlphaFirstObject - } - - public override fun enumToSealedObject(`enum`: AlphaOutsideSealedClassEnum): - AlphaOutsideSealedClass = when (enum) { - AlphaOutsideSealedClassEnum.AlphaFirstObject -> AlphaFirstObject - } -} - -/** - * The index of [this] in the values list. - */ -public val AlphaOutsideSealedClass.ordinal: Int - get() = AlphaOutsideSealedClassSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val AlphaOutsideSealedClass.name: String - get() = AlphaOutsideSealedClassSealedEnum.nameOf(this) - -/** - * A list of all [AlphaOutsideSealedClass] objects. - */ -public val AlphaOutsideSealedClass.Companion.values: List - get() = AlphaOutsideSealedClassSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [AlphaOutsideSealedClass] - */ -public val AlphaOutsideSealedClass.Companion.sealedEnum: AlphaOutsideSealedClassSealedEnum - get() = AlphaOutsideSealedClassSealedEnum - -/** - * Returns the [AlphaOutsideSealedClass] object for the given [name]. - * - * If the given name doesn't correspond to any [AlphaOutsideSealedClass], an - * [IllegalArgumentException] will be thrown. - */ -public fun AlphaOutsideSealedClass.Companion.valueOf(name: String): AlphaOutsideSealedClass = - AlphaOutsideSealedClassSealedEnum.valueOf(name) - -""".trimIndent() - sealed class BetaOutsideSealedClass { @GenSealedEnum(generateEnum = true) companion object @@ -131,135 +22,6 @@ object BetaThirdObject : BetaOutsideSealedClass() object BetaFourthObject : BetaOutsideSealedClass() -@Language("kotlin") -val betaOutsideSealedClassGenerated = """ -package com.livefront.sealedenum.compilation.location - -import com.livefront.sealedenum.EnumForSealedEnumProvider -import com.livefront.sealedenum.SealedEnum -import com.livefront.sealedenum.SealedEnumWithEnumProvider -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List -import kotlin.reflect.KClass - -/** - * An isomorphic enum for the sealed class [BetaOutsideSealedClass] - */ -public enum class BetaOutsideSealedClassEnum() { - BetaFirstObject, - BetaFourthObject, - BetaSecondObject, - BetaThirdObject, -} - -/** - * The isomorphic [BetaOutsideSealedClassEnum] for [this]. - */ -public val BetaOutsideSealedClass.`enum`: BetaOutsideSealedClassEnum - get() = BetaOutsideSealedClassSealedEnum.sealedObjectToEnum(this) - -/** - * The isomorphic [BetaOutsideSealedClass] for [this]. - */ -public val BetaOutsideSealedClassEnum.sealedObject: BetaOutsideSealedClass - get() = BetaOutsideSealedClassSealedEnum.enumToSealedObject(this) - -/** - * An implementation of [SealedEnum] for the sealed class [BetaOutsideSealedClass] - */ -public object BetaOutsideSealedClassSealedEnum : SealedEnum, - SealedEnumWithEnumProvider, - EnumForSealedEnumProvider { - public override val values: List by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - listOf( - BetaFirstObject, - BetaFourthObject, - BetaSecondObject, - BetaThirdObject - ) - } - - - public override val enumClass: KClass - get() = BetaOutsideSealedClassEnum::class - - public override fun ordinalOf(obj: BetaOutsideSealedClass): Int = when (obj) { - is BetaFirstObject -> 0 - is BetaFourthObject -> 1 - is BetaSecondObject -> 2 - is BetaThirdObject -> 3 - } - - public override fun nameOf(obj: BetaOutsideSealedClass): String = when (obj) { - is BetaFirstObject -> "BetaFirstObject" - is BetaFourthObject -> "BetaFourthObject" - is BetaSecondObject -> "BetaSecondObject" - is BetaThirdObject -> "BetaThirdObject" - } - - public override fun valueOf(name: String): BetaOutsideSealedClass = when (name) { - "BetaFirstObject" -> BetaFirstObject - "BetaFourthObject" -> BetaFourthObject - "BetaSecondObject" -> BetaSecondObject - "BetaThirdObject" -> BetaThirdObject - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } - - public override fun sealedObjectToEnum(obj: BetaOutsideSealedClass): BetaOutsideSealedClassEnum - = when (obj) { - is BetaFirstObject -> BetaOutsideSealedClassEnum.BetaFirstObject - is BetaFourthObject -> BetaOutsideSealedClassEnum.BetaFourthObject - is BetaSecondObject -> BetaOutsideSealedClassEnum.BetaSecondObject - is BetaThirdObject -> BetaOutsideSealedClassEnum.BetaThirdObject - } - - public override fun enumToSealedObject(`enum`: BetaOutsideSealedClassEnum): - BetaOutsideSealedClass = when (enum) { - BetaOutsideSealedClassEnum.BetaFirstObject -> BetaFirstObject - BetaOutsideSealedClassEnum.BetaFourthObject -> BetaFourthObject - BetaOutsideSealedClassEnum.BetaSecondObject -> BetaSecondObject - BetaOutsideSealedClassEnum.BetaThirdObject -> BetaThirdObject - } -} - -/** - * The index of [this] in the values list. - */ -public val BetaOutsideSealedClass.ordinal: Int - get() = BetaOutsideSealedClassSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val BetaOutsideSealedClass.name: String - get() = BetaOutsideSealedClassSealedEnum.nameOf(this) - -/** - * A list of all [BetaOutsideSealedClass] objects. - */ -public val BetaOutsideSealedClass.Companion.values: List - get() = BetaOutsideSealedClassSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [BetaOutsideSealedClass] - */ -public val BetaOutsideSealedClass.Companion.sealedEnum: BetaOutsideSealedClassSealedEnum - get() = BetaOutsideSealedClassSealedEnum - -/** - * Returns the [BetaOutsideSealedClass] object for the given [name]. - * - * If the given name doesn't correspond to any [BetaOutsideSealedClass], an - * [IllegalArgumentException] will be thrown. - */ -public fun BetaOutsideSealedClass.Companion.valueOf(name: String): BetaOutsideSealedClass = - BetaOutsideSealedClassSealedEnum.valueOf(name) - -""".trimIndent() - object GammaFirstObject : GammaOutsideSealedClass() sealed class GammaOutsideSealedClass { @@ -274,137 +36,6 @@ object GammaThirdObject : GammaOutsideSealedClass() object GammaFourthObject : GammaOutsideSealedClass() -@Language("kotlin") -val gammaOutsideSealedClassGenerated = """ -package com.livefront.sealedenum.compilation.location - -import com.livefront.sealedenum.EnumForSealedEnumProvider -import com.livefront.sealedenum.SealedEnum -import com.livefront.sealedenum.SealedEnumWithEnumProvider -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List -import kotlin.reflect.KClass - -/** - * An isomorphic enum for the sealed class [GammaOutsideSealedClass] - */ -public enum class GammaOutsideSealedClassEnum() { - GammaOutsideSealedClass_GammaSecondObject, - GammaFirstObject, - GammaFourthObject, - GammaThirdObject, -} - -/** - * The isomorphic [GammaOutsideSealedClassEnum] for [this]. - */ -public val GammaOutsideSealedClass.`enum`: GammaOutsideSealedClassEnum - get() = GammaOutsideSealedClassSealedEnum.sealedObjectToEnum(this) - -/** - * The isomorphic [GammaOutsideSealedClass] for [this]. - */ -public val GammaOutsideSealedClassEnum.sealedObject: GammaOutsideSealedClass - get() = GammaOutsideSealedClassSealedEnum.enumToSealedObject(this) - -/** - * An implementation of [SealedEnum] for the sealed class [GammaOutsideSealedClass] - */ -public object GammaOutsideSealedClassSealedEnum : SealedEnum, - SealedEnumWithEnumProvider, - EnumForSealedEnumProvider { - public override val values: List by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - listOf( - GammaOutsideSealedClass.GammaSecondObject, - GammaFirstObject, - GammaFourthObject, - GammaThirdObject - ) - } - - - public override val enumClass: KClass - get() = GammaOutsideSealedClassEnum::class - - public override fun ordinalOf(obj: GammaOutsideSealedClass): Int = when (obj) { - is GammaOutsideSealedClass.GammaSecondObject -> 0 - is GammaFirstObject -> 1 - is GammaFourthObject -> 2 - is GammaThirdObject -> 3 - } - - public override fun nameOf(obj: GammaOutsideSealedClass): String = when (obj) { - is GammaOutsideSealedClass.GammaSecondObject -> "GammaOutsideSealedClass_GammaSecondObject" - is GammaFirstObject -> "GammaFirstObject" - is GammaFourthObject -> "GammaFourthObject" - is GammaThirdObject -> "GammaThirdObject" - } - - public override fun valueOf(name: String): GammaOutsideSealedClass = when (name) { - "GammaOutsideSealedClass_GammaSecondObject" -> GammaOutsideSealedClass.GammaSecondObject - "GammaFirstObject" -> GammaFirstObject - "GammaFourthObject" -> GammaFourthObject - "GammaThirdObject" -> GammaThirdObject - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } - - public override fun sealedObjectToEnum(obj: GammaOutsideSealedClass): - GammaOutsideSealedClassEnum = when (obj) { - is GammaOutsideSealedClass.GammaSecondObject -> - GammaOutsideSealedClassEnum.GammaOutsideSealedClass_GammaSecondObject - is GammaFirstObject -> GammaOutsideSealedClassEnum.GammaFirstObject - is GammaFourthObject -> GammaOutsideSealedClassEnum.GammaFourthObject - is GammaThirdObject -> GammaOutsideSealedClassEnum.GammaThirdObject - } - - public override fun enumToSealedObject(`enum`: GammaOutsideSealedClassEnum): - GammaOutsideSealedClass = when (enum) { - GammaOutsideSealedClassEnum.GammaOutsideSealedClass_GammaSecondObject -> - GammaOutsideSealedClass.GammaSecondObject - GammaOutsideSealedClassEnum.GammaFirstObject -> GammaFirstObject - GammaOutsideSealedClassEnum.GammaFourthObject -> GammaFourthObject - GammaOutsideSealedClassEnum.GammaThirdObject -> GammaThirdObject - } -} - -/** - * The index of [this] in the values list. - */ -public val GammaOutsideSealedClass.ordinal: Int - get() = GammaOutsideSealedClassSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val GammaOutsideSealedClass.name: String - get() = GammaOutsideSealedClassSealedEnum.nameOf(this) - -/** - * A list of all [GammaOutsideSealedClass] objects. - */ -public val GammaOutsideSealedClass.Companion.values: List - get() = GammaOutsideSealedClassSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [GammaOutsideSealedClass] - */ -public val GammaOutsideSealedClass.Companion.sealedEnum: GammaOutsideSealedClassSealedEnum - get() = GammaOutsideSealedClassSealedEnum - -/** - * Returns the [GammaOutsideSealedClass] object for the given [name]. - * - * If the given name doesn't correspond to any [GammaOutsideSealedClass], an - * [IllegalArgumentException] will be thrown. - */ -public fun GammaOutsideSealedClass.Companion.valueOf(name: String): GammaOutsideSealedClass = - GammaOutsideSealedClassSealedEnum.valueOf(name) - -""".trimIndent() - sealed class DeltaOutsideSealedClass { object DeltaObject : DeltaOutsideSealedClass() @@ -413,120 +44,3 @@ sealed class DeltaOutsideSealedClass { } object DeltaObject : DeltaOutsideSealedClass() - -@Language("kotlin") -val deltaOutsideSealedClassGenerated = """ -package com.livefront.sealedenum.compilation.location - -import com.livefront.sealedenum.EnumForSealedEnumProvider -import com.livefront.sealedenum.SealedEnum -import com.livefront.sealedenum.SealedEnumWithEnumProvider -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List -import kotlin.reflect.KClass - -/** - * An isomorphic enum for the sealed class [DeltaOutsideSealedClass] - */ -public enum class DeltaOutsideSealedClassEnum() { - DeltaOutsideSealedClass_DeltaObject, - DeltaObject, -} - -/** - * The isomorphic [DeltaOutsideSealedClassEnum] for [this]. - */ -public val DeltaOutsideSealedClass.`enum`: DeltaOutsideSealedClassEnum - get() = DeltaOutsideSealedClassSealedEnum.sealedObjectToEnum(this) - -/** - * The isomorphic [DeltaOutsideSealedClass] for [this]. - */ -public val DeltaOutsideSealedClassEnum.sealedObject: DeltaOutsideSealedClass - get() = DeltaOutsideSealedClassSealedEnum.enumToSealedObject(this) - -/** - * An implementation of [SealedEnum] for the sealed class [DeltaOutsideSealedClass] - */ -public object DeltaOutsideSealedClassSealedEnum : SealedEnum, - SealedEnumWithEnumProvider, - EnumForSealedEnumProvider { - public override val values: List by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - listOf( - DeltaOutsideSealedClass.DeltaObject, - DeltaObject - ) - } - - - public override val enumClass: KClass - get() = DeltaOutsideSealedClassEnum::class - - public override fun ordinalOf(obj: DeltaOutsideSealedClass): Int = when (obj) { - is DeltaOutsideSealedClass.DeltaObject -> 0 - is DeltaObject -> 1 - } - - public override fun nameOf(obj: DeltaOutsideSealedClass): String = when (obj) { - is DeltaOutsideSealedClass.DeltaObject -> "DeltaOutsideSealedClass_DeltaObject" - is DeltaObject -> "DeltaObject" - } - - public override fun valueOf(name: String): DeltaOutsideSealedClass = when (name) { - "DeltaOutsideSealedClass_DeltaObject" -> DeltaOutsideSealedClass.DeltaObject - "DeltaObject" -> DeltaObject - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } - - public override fun sealedObjectToEnum(obj: DeltaOutsideSealedClass): - DeltaOutsideSealedClassEnum = when (obj) { - is DeltaOutsideSealedClass.DeltaObject -> - DeltaOutsideSealedClassEnum.DeltaOutsideSealedClass_DeltaObject - is DeltaObject -> DeltaOutsideSealedClassEnum.DeltaObject - } - - public override fun enumToSealedObject(`enum`: DeltaOutsideSealedClassEnum): - DeltaOutsideSealedClass = when (enum) { - DeltaOutsideSealedClassEnum.DeltaOutsideSealedClass_DeltaObject -> - DeltaOutsideSealedClass.DeltaObject - DeltaOutsideSealedClassEnum.DeltaObject -> DeltaObject - } -} - -/** - * The index of [this] in the values list. - */ -public val DeltaOutsideSealedClass.ordinal: Int - get() = DeltaOutsideSealedClassSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val DeltaOutsideSealedClass.name: String - get() = DeltaOutsideSealedClassSealedEnum.nameOf(this) - -/** - * A list of all [DeltaOutsideSealedClass] objects. - */ -public val DeltaOutsideSealedClass.Companion.values: List - get() = DeltaOutsideSealedClassSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [DeltaOutsideSealedClass] - */ -public val DeltaOutsideSealedClass.Companion.sealedEnum: DeltaOutsideSealedClassSealedEnum - get() = DeltaOutsideSealedClassSealedEnum - -/** - * Returns the [DeltaOutsideSealedClass] object for the given [name]. - * - * If the given name doesn't correspond to any [DeltaOutsideSealedClass], an - * [IllegalArgumentException] will be thrown. - */ -public fun DeltaOutsideSealedClass.Companion.valueOf(name: String): DeltaOutsideSealedClass = - DeltaOutsideSealedClassSealedEnum.valueOf(name) - -""".trimIndent() diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/location/OutsideSealedClassTests.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/location/OutsideSealedClassTests.kt index d4994a7d..d01cd2a0 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/location/OutsideSealedClassTests.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/location/OutsideSealedClassTests.kt @@ -1,12 +1,16 @@ package com.livefront.sealedenum.compilation.location +import com.livefront.sealedenum.testing.SealedEnumApprovalsExtension +import com.livefront.sealedenum.testing.assertApprovedGeneratedFile import com.livefront.sealedenum.testing.assertCompiles -import com.livefront.sealedenum.testing.assertGeneratedFileMatches import com.livefront.sealedenum.testing.compile import com.livefront.sealedenum.testing.getCommonSourceFile +import com.oneeyedmen.okeydoke.Approver import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +@ExtendWith(SealedEnumApprovalsExtension::class) class OutsideSealedClassTests { @Test @@ -31,11 +35,11 @@ class OutsideSealedClassTests { } @Test - fun `compilation for alpha outside sealed class generates correct code`() { + fun Approver.`compilation for alpha outside sealed class generates correct code`() { val result = compile(getCommonSourceFile("compilation", "location", "OutsideSealedClass.kt")) assertCompiles(result) - assertGeneratedFileMatches("AlphaOutsideSealedClass_SealedEnum.kt", alphaOutsideSealedClassGenerated, result) + assertApprovedGeneratedFile("AlphaOutsideSealedClass_SealedEnum.kt", result) } @Test @@ -73,11 +77,11 @@ class OutsideSealedClassTests { } @Test - fun `compilation for beta outside sealed class generates correct code`() { + fun Approver.`compilation for beta outside sealed class generates correct code`() { val result = compile(getCommonSourceFile("compilation", "location", "OutsideSealedClass.kt")) assertCompiles(result) - assertGeneratedFileMatches("BetaOutsideSealedClass_SealedEnum.kt", betaOutsideSealedClassGenerated, result) + assertApprovedGeneratedFile("BetaOutsideSealedClass_SealedEnum.kt", result) } @Test @@ -115,11 +119,11 @@ class OutsideSealedClassTests { } @Test - fun `compilation for gamma outside sealed class generates correct code`() { + fun Approver.`compilation for gamma outside sealed class generates correct code`() { val result = compile(getCommonSourceFile("compilation", "location", "OutsideSealedClass.kt")) assertCompiles(result) - assertGeneratedFileMatches("GammaOutsideSealedClass_SealedEnum.kt", gammaOutsideSealedClassGenerated, result) + assertApprovedGeneratedFile("GammaOutsideSealedClass_SealedEnum.kt", result) } @Test @@ -150,10 +154,10 @@ class OutsideSealedClassTests { } @Test - fun `compilation for delta outside sealed class generates correct code`() { + fun Approver.`compilation for delta outside sealed class generates correct code`() { val result = compile(getCommonSourceFile("compilation", "location", "OutsideSealedClass.kt")) assertCompiles(result) - assertGeneratedFileMatches("DeltaOutsideSealedClass_SealedEnum.kt", deltaOutsideSealedClassGenerated, result) + assertApprovedGeneratedFile("DeltaOutsideSealedClass_SealedEnum.kt", result) } } diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/location/SplitAcrossFilesSealedClass.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/location/SplitAcrossFilesSealedClass.kt index a71f68bb..16d70d48 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/location/SplitAcrossFilesSealedClass.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/location/SplitAcrossFilesSealedClass.kt @@ -1,132 +1,9 @@ package com.livefront.sealedenum.compilation.location import com.livefront.sealedenum.GenSealedEnum -import org.intellij.lang.annotations.Language sealed class SplitAcrossFilesSealedClass { @GenSealedEnum(generateEnum = true) companion object } - -@Language("kotlin") -val splitAcrossFilesSealedClassGenerated = """ -package com.livefront.sealedenum.compilation.location - -import com.livefront.sealedenum.EnumForSealedEnumProvider -import com.livefront.sealedenum.SealedEnum -import com.livefront.sealedenum.SealedEnumWithEnumProvider -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List -import kotlin.reflect.KClass - -/** - * An isomorphic enum for the sealed class [SplitAcrossFilesSealedClass] - */ -public enum class SplitAcrossFilesSealedClassEnum() { - SplitAcrossFilesSubclassA, - SplitAcrossFilesSubclassB, - SplitAcrossFilesSubclassC, -} - -/** - * The isomorphic [SplitAcrossFilesSealedClassEnum] for [this]. - */ -public val SplitAcrossFilesSealedClass.`enum`: SplitAcrossFilesSealedClassEnum - get() = SplitAcrossFilesSealedClassSealedEnum.sealedObjectToEnum(this) - -/** - * The isomorphic [SplitAcrossFilesSealedClass] for [this]. - */ -public val SplitAcrossFilesSealedClassEnum.sealedObject: SplitAcrossFilesSealedClass - get() = SplitAcrossFilesSealedClassSealedEnum.enumToSealedObject(this) - -/** - * An implementation of [SealedEnum] for the sealed class [SplitAcrossFilesSealedClass] - */ -public object SplitAcrossFilesSealedClassSealedEnum : SealedEnum, - SealedEnumWithEnumProvider, - EnumForSealedEnumProvider { - public override val values: List by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - listOf( - SplitAcrossFilesSubclassA, - SplitAcrossFilesSubclassB, - SplitAcrossFilesSubclassC - ) - } - - - public override val enumClass: KClass - get() = SplitAcrossFilesSealedClassEnum::class - - public override fun ordinalOf(obj: SplitAcrossFilesSealedClass): Int = when (obj) { - is SplitAcrossFilesSubclassA -> 0 - is SplitAcrossFilesSubclassB -> 1 - is SplitAcrossFilesSubclassC -> 2 - } - - public override fun nameOf(obj: SplitAcrossFilesSealedClass): String = when (obj) { - is SplitAcrossFilesSubclassA -> "SplitAcrossFilesSubclassA" - is SplitAcrossFilesSubclassB -> "SplitAcrossFilesSubclassB" - is SplitAcrossFilesSubclassC -> "SplitAcrossFilesSubclassC" - } - - public override fun valueOf(name: String): SplitAcrossFilesSealedClass = when (name) { - "SplitAcrossFilesSubclassA" -> SplitAcrossFilesSubclassA - "SplitAcrossFilesSubclassB" -> SplitAcrossFilesSubclassB - "SplitAcrossFilesSubclassC" -> SplitAcrossFilesSubclassC - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } - - public override fun sealedObjectToEnum(obj: SplitAcrossFilesSealedClass): - SplitAcrossFilesSealedClassEnum = when (obj) { - is SplitAcrossFilesSubclassA -> SplitAcrossFilesSealedClassEnum.SplitAcrossFilesSubclassA - is SplitAcrossFilesSubclassB -> SplitAcrossFilesSealedClassEnum.SplitAcrossFilesSubclassB - is SplitAcrossFilesSubclassC -> SplitAcrossFilesSealedClassEnum.SplitAcrossFilesSubclassC - } - - public override fun enumToSealedObject(`enum`: SplitAcrossFilesSealedClassEnum): - SplitAcrossFilesSealedClass = when (enum) { - SplitAcrossFilesSealedClassEnum.SplitAcrossFilesSubclassA -> SplitAcrossFilesSubclassA - SplitAcrossFilesSealedClassEnum.SplitAcrossFilesSubclassB -> SplitAcrossFilesSubclassB - SplitAcrossFilesSealedClassEnum.SplitAcrossFilesSubclassC -> SplitAcrossFilesSubclassC - } -} - -/** - * The index of [this] in the values list. - */ -public val SplitAcrossFilesSealedClass.ordinal: Int - get() = SplitAcrossFilesSealedClassSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val SplitAcrossFilesSealedClass.name: String - get() = SplitAcrossFilesSealedClassSealedEnum.nameOf(this) - -/** - * A list of all [SplitAcrossFilesSealedClass] objects. - */ -public val SplitAcrossFilesSealedClass.Companion.values: List - get() = SplitAcrossFilesSealedClassSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [SplitAcrossFilesSealedClass] - */ -public val SplitAcrossFilesSealedClass.Companion.sealedEnum: SplitAcrossFilesSealedClassSealedEnum - get() = SplitAcrossFilesSealedClassSealedEnum - -/** - * Returns the [SplitAcrossFilesSealedClass] object for the given [name]. - * - * If the given name doesn't correspond to any [SplitAcrossFilesSealedClass], an - * [IllegalArgumentException] will be thrown. - */ -public fun SplitAcrossFilesSealedClass.Companion.valueOf(name: String): SplitAcrossFilesSealedClass - = SplitAcrossFilesSealedClassSealedEnum.valueOf(name) - -""".trimIndent() diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/location/SplitAcrossFilesSealedClassTests.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/location/SplitAcrossFilesSealedClassTests.kt index bcf57e0d..6de37612 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/location/SplitAcrossFilesSealedClassTests.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/location/SplitAcrossFilesSealedClassTests.kt @@ -1,12 +1,16 @@ package com.livefront.sealedenum.compilation.location +import com.livefront.sealedenum.testing.SealedEnumApprovalsExtension +import com.livefront.sealedenum.testing.assertApprovedGeneratedFile import com.livefront.sealedenum.testing.assertCompiles -import com.livefront.sealedenum.testing.assertGeneratedFileMatches import com.livefront.sealedenum.testing.compile import com.livefront.sealedenum.testing.getCommonSourceFile +import com.oneeyedmen.okeydoke.Approver import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +@ExtendWith(SealedEnumApprovalsExtension::class) class SplitAcrossFilesSealedClassTests { @Test @@ -30,7 +34,7 @@ class SplitAcrossFilesSealedClassTests { } @Test - fun `compilation for objects split across files generates correct code`() { + fun Approver.`compilation for objects split across files generates correct code`() { val result = compile( getCommonSourceFile("compilation", "location", "SplitAcrossFilesSealedClass.kt"), getCommonSourceFile("compilation", "location", "SplitAcrossFilesSubclassA.kt"), @@ -39,10 +43,6 @@ class SplitAcrossFilesSealedClassTests { ) assertCompiles(result) - assertGeneratedFileMatches( - "SplitAcrossFilesSealedClass_SealedEnum.kt", - splitAcrossFilesSealedClassGenerated, - result - ) + assertApprovedGeneratedFile("SplitAcrossFilesSealedClass_SealedEnum.kt", result) } } diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/traversal/TraversalOrder.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/traversal/TraversalOrder.kt index e7665f50..fbc9a1de 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/traversal/TraversalOrder.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/traversal/TraversalOrder.kt @@ -1,10 +1,9 @@ -@file:Suppress("MatchingDeclarationName") +@file:Suppress("MatchingDeclarationName", "Filename") package com.livefront.sealedenum.compilation.traversal import com.livefront.sealedenum.GenSealedEnum import com.livefront.sealedenum.TreeTraversalOrder -import org.intellij.lang.annotations.Language sealed class Tree { @@ -60,736 +59,3 @@ sealed class Tree { @GenSealedEnum(traversalOrder = TreeTraversalOrder.LEVEL_ORDER, generateEnum = true) companion object } - -@Language("kotlin") -val treeGenerated = """ -package com.livefront.sealedenum.compilation.traversal - -import com.livefront.sealedenum.EnumForSealedEnumProvider -import com.livefront.sealedenum.SealedEnum -import com.livefront.sealedenum.SealedEnumWithEnumProvider -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List -import kotlin.reflect.KClass - -/** - * An isomorphic enum for the sealed class [Tree] - */ -public enum class TreeLevelOrderEnum() { - Tree_A, - Tree_K, - Tree_T, - Tree_L_S, - Tree_B_C_D, - Tree_B_C_E, - Tree_B_C_J, - Tree_L_M_N, - Tree_L_M_O, - Tree_L_P_Q, - Tree_L_P_R, - Tree_B_C_F_G, - Tree_B_C_F_H, - Tree_B_C_F_I, -} - -/** - * The isomorphic [TreeLevelOrderEnum] for [this]. - */ -public val Tree.levelOrderEnum: TreeLevelOrderEnum - get() = TreeLevelOrderSealedEnum.sealedObjectToEnum(this) - -/** - * The isomorphic [Tree] for [this]. - */ -public val TreeLevelOrderEnum.sealedObject: Tree - get() = TreeLevelOrderSealedEnum.enumToSealedObject(this) - -/** - * An implementation of [SealedEnum] for the sealed class [Tree] - */ -public object TreeLevelOrderSealedEnum : SealedEnum, - SealedEnumWithEnumProvider, - EnumForSealedEnumProvider { - public override val values: List by lazy(mode = LazyThreadSafetyMode.PUBLICATION) { - listOf( - Tree.A, - Tree.K, - Tree.T, - Tree.L.S, - Tree.B.C.D, - Tree.B.C.E, - Tree.B.C.J, - Tree.L.M.N, - Tree.L.M.O, - Tree.L.P.Q, - Tree.L.P.R, - Tree.B.C.F.G, - Tree.B.C.F.H, - Tree.B.C.F.I - ) - } - - - public override val enumClass: KClass - get() = TreeLevelOrderEnum::class - - public override fun ordinalOf(obj: Tree): Int = when (obj) { - is Tree.A -> 0 - is Tree.K -> 1 - is Tree.T -> 2 - is Tree.L.S -> 3 - is Tree.B.C.D -> 4 - is Tree.B.C.E -> 5 - is Tree.B.C.J -> 6 - is Tree.L.M.N -> 7 - is Tree.L.M.O -> 8 - is Tree.L.P.Q -> 9 - is Tree.L.P.R -> 10 - is Tree.B.C.F.G -> 11 - is Tree.B.C.F.H -> 12 - is Tree.B.C.F.I -> 13 - } - - public override fun nameOf(obj: Tree): String = when (obj) { - is Tree.A -> "Tree_A" - is Tree.K -> "Tree_K" - is Tree.T -> "Tree_T" - is Tree.L.S -> "Tree_L_S" - is Tree.B.C.D -> "Tree_B_C_D" - is Tree.B.C.E -> "Tree_B_C_E" - is Tree.B.C.J -> "Tree_B_C_J" - is Tree.L.M.N -> "Tree_L_M_N" - is Tree.L.M.O -> "Tree_L_M_O" - is Tree.L.P.Q -> "Tree_L_P_Q" - is Tree.L.P.R -> "Tree_L_P_R" - is Tree.B.C.F.G -> "Tree_B_C_F_G" - is Tree.B.C.F.H -> "Tree_B_C_F_H" - is Tree.B.C.F.I -> "Tree_B_C_F_I" - } - - public override fun valueOf(name: String): Tree = when (name) { - "Tree_A" -> Tree.A - "Tree_K" -> Tree.K - "Tree_T" -> Tree.T - "Tree_L_S" -> Tree.L.S - "Tree_B_C_D" -> Tree.B.C.D - "Tree_B_C_E" -> Tree.B.C.E - "Tree_B_C_J" -> Tree.B.C.J - "Tree_L_M_N" -> Tree.L.M.N - "Tree_L_M_O" -> Tree.L.M.O - "Tree_L_P_Q" -> Tree.L.P.Q - "Tree_L_P_R" -> Tree.L.P.R - "Tree_B_C_F_G" -> Tree.B.C.F.G - "Tree_B_C_F_H" -> Tree.B.C.F.H - "Tree_B_C_F_I" -> Tree.B.C.F.I - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } - - public override fun sealedObjectToEnum(obj: Tree): TreeLevelOrderEnum = when (obj) { - is Tree.A -> TreeLevelOrderEnum.Tree_A - is Tree.K -> TreeLevelOrderEnum.Tree_K - is Tree.T -> TreeLevelOrderEnum.Tree_T - is Tree.L.S -> TreeLevelOrderEnum.Tree_L_S - is Tree.B.C.D -> TreeLevelOrderEnum.Tree_B_C_D - is Tree.B.C.E -> TreeLevelOrderEnum.Tree_B_C_E - is Tree.B.C.J -> TreeLevelOrderEnum.Tree_B_C_J - is Tree.L.M.N -> TreeLevelOrderEnum.Tree_L_M_N - is Tree.L.M.O -> TreeLevelOrderEnum.Tree_L_M_O - is Tree.L.P.Q -> TreeLevelOrderEnum.Tree_L_P_Q - is Tree.L.P.R -> TreeLevelOrderEnum.Tree_L_P_R - is Tree.B.C.F.G -> TreeLevelOrderEnum.Tree_B_C_F_G - is Tree.B.C.F.H -> TreeLevelOrderEnum.Tree_B_C_F_H - is Tree.B.C.F.I -> TreeLevelOrderEnum.Tree_B_C_F_I - } - - public override fun enumToSealedObject(`enum`: TreeLevelOrderEnum): Tree = when (enum) { - TreeLevelOrderEnum.Tree_A -> Tree.A - TreeLevelOrderEnum.Tree_K -> Tree.K - TreeLevelOrderEnum.Tree_T -> Tree.T - TreeLevelOrderEnum.Tree_L_S -> Tree.L.S - TreeLevelOrderEnum.Tree_B_C_D -> Tree.B.C.D - TreeLevelOrderEnum.Tree_B_C_E -> Tree.B.C.E - TreeLevelOrderEnum.Tree_B_C_J -> Tree.B.C.J - TreeLevelOrderEnum.Tree_L_M_N -> Tree.L.M.N - TreeLevelOrderEnum.Tree_L_M_O -> Tree.L.M.O - TreeLevelOrderEnum.Tree_L_P_Q -> Tree.L.P.Q - TreeLevelOrderEnum.Tree_L_P_R -> Tree.L.P.R - TreeLevelOrderEnum.Tree_B_C_F_G -> Tree.B.C.F.G - TreeLevelOrderEnum.Tree_B_C_F_H -> Tree.B.C.F.H - TreeLevelOrderEnum.Tree_B_C_F_I -> Tree.B.C.F.I - } -} - -/** - * The index of [this] in the values list. - */ -public val Tree.levelOrderOrdinal: Int - get() = TreeLevelOrderSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val Tree.levelOrderName: String - get() = TreeLevelOrderSealedEnum.nameOf(this) - -/** - * A list of all [Tree] objects. - */ -public val Tree.Companion.levelOrderValues: List - get() = TreeLevelOrderSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [Tree] - */ -public val Tree.Companion.levelOrderSealedEnum: TreeLevelOrderSealedEnum - get() = TreeLevelOrderSealedEnum - -/** - * Returns the [Tree] object for the given [name]. - * - * If the given name doesn't correspond to any [Tree], an [IllegalArgumentException] will be thrown. - */ -public fun Tree.Companion.levelOrderValueOf(name: String): Tree = - TreeLevelOrderSealedEnum.valueOf(name) - -/** - * An isomorphic enum for the sealed class [Tree] - */ -public enum class TreePostOrderEnum() { - Tree_B_C_F_G, - Tree_B_C_F_H, - Tree_B_C_F_I, - Tree_B_C_D, - Tree_B_C_E, - Tree_B_C_J, - Tree_L_M_N, - Tree_L_M_O, - Tree_L_P_Q, - Tree_L_P_R, - Tree_L_S, - Tree_A, - Tree_K, - Tree_T, -} - -/** - * The isomorphic [TreePostOrderEnum] for [this]. - */ -public val Tree.postOrderEnum: TreePostOrderEnum - get() = TreePostOrderSealedEnum.sealedObjectToEnum(this) - -/** - * The isomorphic [Tree] for [this]. - */ -public val TreePostOrderEnum.sealedObject: Tree - get() = TreePostOrderSealedEnum.enumToSealedObject(this) - -/** - * An implementation of [SealedEnum] for the sealed class [Tree] - */ -public object TreePostOrderSealedEnum : SealedEnum, - SealedEnumWithEnumProvider, - EnumForSealedEnumProvider { - public override val values: List by lazy(mode = LazyThreadSafetyMode.PUBLICATION) { - listOf( - Tree.B.C.F.G, - Tree.B.C.F.H, - Tree.B.C.F.I, - Tree.B.C.D, - Tree.B.C.E, - Tree.B.C.J, - Tree.L.M.N, - Tree.L.M.O, - Tree.L.P.Q, - Tree.L.P.R, - Tree.L.S, - Tree.A, - Tree.K, - Tree.T - ) - } - - - public override val enumClass: KClass - get() = TreePostOrderEnum::class - - public override fun ordinalOf(obj: Tree): Int = when (obj) { - is Tree.B.C.F.G -> 0 - is Tree.B.C.F.H -> 1 - is Tree.B.C.F.I -> 2 - is Tree.B.C.D -> 3 - is Tree.B.C.E -> 4 - is Tree.B.C.J -> 5 - is Tree.L.M.N -> 6 - is Tree.L.M.O -> 7 - is Tree.L.P.Q -> 8 - is Tree.L.P.R -> 9 - is Tree.L.S -> 10 - is Tree.A -> 11 - is Tree.K -> 12 - is Tree.T -> 13 - } - - public override fun nameOf(obj: Tree): String = when (obj) { - is Tree.B.C.F.G -> "Tree_B_C_F_G" - is Tree.B.C.F.H -> "Tree_B_C_F_H" - is Tree.B.C.F.I -> "Tree_B_C_F_I" - is Tree.B.C.D -> "Tree_B_C_D" - is Tree.B.C.E -> "Tree_B_C_E" - is Tree.B.C.J -> "Tree_B_C_J" - is Tree.L.M.N -> "Tree_L_M_N" - is Tree.L.M.O -> "Tree_L_M_O" - is Tree.L.P.Q -> "Tree_L_P_Q" - is Tree.L.P.R -> "Tree_L_P_R" - is Tree.L.S -> "Tree_L_S" - is Tree.A -> "Tree_A" - is Tree.K -> "Tree_K" - is Tree.T -> "Tree_T" - } - - public override fun valueOf(name: String): Tree = when (name) { - "Tree_B_C_F_G" -> Tree.B.C.F.G - "Tree_B_C_F_H" -> Tree.B.C.F.H - "Tree_B_C_F_I" -> Tree.B.C.F.I - "Tree_B_C_D" -> Tree.B.C.D - "Tree_B_C_E" -> Tree.B.C.E - "Tree_B_C_J" -> Tree.B.C.J - "Tree_L_M_N" -> Tree.L.M.N - "Tree_L_M_O" -> Tree.L.M.O - "Tree_L_P_Q" -> Tree.L.P.Q - "Tree_L_P_R" -> Tree.L.P.R - "Tree_L_S" -> Tree.L.S - "Tree_A" -> Tree.A - "Tree_K" -> Tree.K - "Tree_T" -> Tree.T - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } - - public override fun sealedObjectToEnum(obj: Tree): TreePostOrderEnum = when (obj) { - is Tree.B.C.F.G -> TreePostOrderEnum.Tree_B_C_F_G - is Tree.B.C.F.H -> TreePostOrderEnum.Tree_B_C_F_H - is Tree.B.C.F.I -> TreePostOrderEnum.Tree_B_C_F_I - is Tree.B.C.D -> TreePostOrderEnum.Tree_B_C_D - is Tree.B.C.E -> TreePostOrderEnum.Tree_B_C_E - is Tree.B.C.J -> TreePostOrderEnum.Tree_B_C_J - is Tree.L.M.N -> TreePostOrderEnum.Tree_L_M_N - is Tree.L.M.O -> TreePostOrderEnum.Tree_L_M_O - is Tree.L.P.Q -> TreePostOrderEnum.Tree_L_P_Q - is Tree.L.P.R -> TreePostOrderEnum.Tree_L_P_R - is Tree.L.S -> TreePostOrderEnum.Tree_L_S - is Tree.A -> TreePostOrderEnum.Tree_A - is Tree.K -> TreePostOrderEnum.Tree_K - is Tree.T -> TreePostOrderEnum.Tree_T - } - - public override fun enumToSealedObject(`enum`: TreePostOrderEnum): Tree = when (enum) { - TreePostOrderEnum.Tree_B_C_F_G -> Tree.B.C.F.G - TreePostOrderEnum.Tree_B_C_F_H -> Tree.B.C.F.H - TreePostOrderEnum.Tree_B_C_F_I -> Tree.B.C.F.I - TreePostOrderEnum.Tree_B_C_D -> Tree.B.C.D - TreePostOrderEnum.Tree_B_C_E -> Tree.B.C.E - TreePostOrderEnum.Tree_B_C_J -> Tree.B.C.J - TreePostOrderEnum.Tree_L_M_N -> Tree.L.M.N - TreePostOrderEnum.Tree_L_M_O -> Tree.L.M.O - TreePostOrderEnum.Tree_L_P_Q -> Tree.L.P.Q - TreePostOrderEnum.Tree_L_P_R -> Tree.L.P.R - TreePostOrderEnum.Tree_L_S -> Tree.L.S - TreePostOrderEnum.Tree_A -> Tree.A - TreePostOrderEnum.Tree_K -> Tree.K - TreePostOrderEnum.Tree_T -> Tree.T - } -} - -/** - * The index of [this] in the values list. - */ -public val Tree.postOrderOrdinal: Int - get() = TreePostOrderSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val Tree.postOrderName: String - get() = TreePostOrderSealedEnum.nameOf(this) - -/** - * A list of all [Tree] objects. - */ -public val Tree.Companion.postOrderValues: List - get() = TreePostOrderSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [Tree] - */ -public val Tree.Companion.postOrderSealedEnum: TreePostOrderSealedEnum - get() = TreePostOrderSealedEnum - -/** - * Returns the [Tree] object for the given [name]. - * - * If the given name doesn't correspond to any [Tree], an [IllegalArgumentException] will be thrown. - */ -public fun Tree.Companion.postOrderValueOf(name: String): Tree = - TreePostOrderSealedEnum.valueOf(name) - -/** - * An isomorphic enum for the sealed class [Tree] - */ -public enum class TreeInOrderEnum() { - Tree_A, - Tree_B_C_D, - Tree_B_C_E, - Tree_B_C_F_G, - Tree_B_C_F_H, - Tree_B_C_F_I, - Tree_B_C_J, - Tree_K, - Tree_L_M_N, - Tree_L_M_O, - Tree_L_P_Q, - Tree_L_P_R, - Tree_L_S, - Tree_T, -} - -/** - * The isomorphic [TreeInOrderEnum] for [this]. - */ -public val Tree.inOrderEnum: TreeInOrderEnum - get() = TreeInOrderSealedEnum.sealedObjectToEnum(this) - -/** - * The isomorphic [Tree] for [this]. - */ -public val TreeInOrderEnum.sealedObject: Tree - get() = TreeInOrderSealedEnum.enumToSealedObject(this) - -/** - * An implementation of [SealedEnum] for the sealed class [Tree] - */ -public object TreeInOrderSealedEnum : SealedEnum, - SealedEnumWithEnumProvider, - EnumForSealedEnumProvider { - public override val values: List by lazy(mode = LazyThreadSafetyMode.PUBLICATION) { - listOf( - Tree.A, - Tree.B.C.D, - Tree.B.C.E, - Tree.B.C.F.G, - Tree.B.C.F.H, - Tree.B.C.F.I, - Tree.B.C.J, - Tree.K, - Tree.L.M.N, - Tree.L.M.O, - Tree.L.P.Q, - Tree.L.P.R, - Tree.L.S, - Tree.T - ) - } - - - public override val enumClass: KClass - get() = TreeInOrderEnum::class - - public override fun ordinalOf(obj: Tree): Int = when (obj) { - is Tree.A -> 0 - is Tree.B.C.D -> 1 - is Tree.B.C.E -> 2 - is Tree.B.C.F.G -> 3 - is Tree.B.C.F.H -> 4 - is Tree.B.C.F.I -> 5 - is Tree.B.C.J -> 6 - is Tree.K -> 7 - is Tree.L.M.N -> 8 - is Tree.L.M.O -> 9 - is Tree.L.P.Q -> 10 - is Tree.L.P.R -> 11 - is Tree.L.S -> 12 - is Tree.T -> 13 - } - - public override fun nameOf(obj: Tree): String = when (obj) { - is Tree.A -> "Tree_A" - is Tree.B.C.D -> "Tree_B_C_D" - is Tree.B.C.E -> "Tree_B_C_E" - is Tree.B.C.F.G -> "Tree_B_C_F_G" - is Tree.B.C.F.H -> "Tree_B_C_F_H" - is Tree.B.C.F.I -> "Tree_B_C_F_I" - is Tree.B.C.J -> "Tree_B_C_J" - is Tree.K -> "Tree_K" - is Tree.L.M.N -> "Tree_L_M_N" - is Tree.L.M.O -> "Tree_L_M_O" - is Tree.L.P.Q -> "Tree_L_P_Q" - is Tree.L.P.R -> "Tree_L_P_R" - is Tree.L.S -> "Tree_L_S" - is Tree.T -> "Tree_T" - } - - public override fun valueOf(name: String): Tree = when (name) { - "Tree_A" -> Tree.A - "Tree_B_C_D" -> Tree.B.C.D - "Tree_B_C_E" -> Tree.B.C.E - "Tree_B_C_F_G" -> Tree.B.C.F.G - "Tree_B_C_F_H" -> Tree.B.C.F.H - "Tree_B_C_F_I" -> Tree.B.C.F.I - "Tree_B_C_J" -> Tree.B.C.J - "Tree_K" -> Tree.K - "Tree_L_M_N" -> Tree.L.M.N - "Tree_L_M_O" -> Tree.L.M.O - "Tree_L_P_Q" -> Tree.L.P.Q - "Tree_L_P_R" -> Tree.L.P.R - "Tree_L_S" -> Tree.L.S - "Tree_T" -> Tree.T - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } - - public override fun sealedObjectToEnum(obj: Tree): TreeInOrderEnum = when (obj) { - is Tree.A -> TreeInOrderEnum.Tree_A - is Tree.B.C.D -> TreeInOrderEnum.Tree_B_C_D - is Tree.B.C.E -> TreeInOrderEnum.Tree_B_C_E - is Tree.B.C.F.G -> TreeInOrderEnum.Tree_B_C_F_G - is Tree.B.C.F.H -> TreeInOrderEnum.Tree_B_C_F_H - is Tree.B.C.F.I -> TreeInOrderEnum.Tree_B_C_F_I - is Tree.B.C.J -> TreeInOrderEnum.Tree_B_C_J - is Tree.K -> TreeInOrderEnum.Tree_K - is Tree.L.M.N -> TreeInOrderEnum.Tree_L_M_N - is Tree.L.M.O -> TreeInOrderEnum.Tree_L_M_O - is Tree.L.P.Q -> TreeInOrderEnum.Tree_L_P_Q - is Tree.L.P.R -> TreeInOrderEnum.Tree_L_P_R - is Tree.L.S -> TreeInOrderEnum.Tree_L_S - is Tree.T -> TreeInOrderEnum.Tree_T - } - - public override fun enumToSealedObject(`enum`: TreeInOrderEnum): Tree = when (enum) { - TreeInOrderEnum.Tree_A -> Tree.A - TreeInOrderEnum.Tree_B_C_D -> Tree.B.C.D - TreeInOrderEnum.Tree_B_C_E -> Tree.B.C.E - TreeInOrderEnum.Tree_B_C_F_G -> Tree.B.C.F.G - TreeInOrderEnum.Tree_B_C_F_H -> Tree.B.C.F.H - TreeInOrderEnum.Tree_B_C_F_I -> Tree.B.C.F.I - TreeInOrderEnum.Tree_B_C_J -> Tree.B.C.J - TreeInOrderEnum.Tree_K -> Tree.K - TreeInOrderEnum.Tree_L_M_N -> Tree.L.M.N - TreeInOrderEnum.Tree_L_M_O -> Tree.L.M.O - TreeInOrderEnum.Tree_L_P_Q -> Tree.L.P.Q - TreeInOrderEnum.Tree_L_P_R -> Tree.L.P.R - TreeInOrderEnum.Tree_L_S -> Tree.L.S - TreeInOrderEnum.Tree_T -> Tree.T - } -} - -/** - * The index of [this] in the values list. - */ -public val Tree.inOrderOrdinal: Int - get() = TreeInOrderSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val Tree.inOrderName: String - get() = TreeInOrderSealedEnum.nameOf(this) - -/** - * A list of all [Tree] objects. - */ -public val Tree.Companion.inOrderValues: List - get() = TreeInOrderSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [Tree] - */ -public val Tree.Companion.inOrderSealedEnum: TreeInOrderSealedEnum - get() = TreeInOrderSealedEnum - -/** - * Returns the [Tree] object for the given [name]. - * - * If the given name doesn't correspond to any [Tree], an [IllegalArgumentException] will be thrown. - */ -public fun Tree.Companion.inOrderValueOf(name: String): Tree = TreeInOrderSealedEnum.valueOf(name) - -/** - * An isomorphic enum for the sealed class [Tree] - */ -public enum class TreePreOrderEnum() { - Tree_A, - Tree_K, - Tree_T, - Tree_B_C_D, - Tree_B_C_E, - Tree_B_C_J, - Tree_B_C_F_G, - Tree_B_C_F_H, - Tree_B_C_F_I, - Tree_L_S, - Tree_L_M_N, - Tree_L_M_O, - Tree_L_P_Q, - Tree_L_P_R, -} - -/** - * The isomorphic [TreePreOrderEnum] for [this]. - */ -public val Tree.preOrderEnum: TreePreOrderEnum - get() = TreePreOrderSealedEnum.sealedObjectToEnum(this) - -/** - * The isomorphic [Tree] for [this]. - */ -public val TreePreOrderEnum.sealedObject: Tree - get() = TreePreOrderSealedEnum.enumToSealedObject(this) - -/** - * An implementation of [SealedEnum] for the sealed class [Tree] - */ -public object TreePreOrderSealedEnum : SealedEnum, - SealedEnumWithEnumProvider, - EnumForSealedEnumProvider { - public override val values: List by lazy(mode = LazyThreadSafetyMode.PUBLICATION) { - listOf( - Tree.A, - Tree.K, - Tree.T, - Tree.B.C.D, - Tree.B.C.E, - Tree.B.C.J, - Tree.B.C.F.G, - Tree.B.C.F.H, - Tree.B.C.F.I, - Tree.L.S, - Tree.L.M.N, - Tree.L.M.O, - Tree.L.P.Q, - Tree.L.P.R - ) - } - - - public override val enumClass: KClass - get() = TreePreOrderEnum::class - - public override fun ordinalOf(obj: Tree): Int = when (obj) { - is Tree.A -> 0 - is Tree.K -> 1 - is Tree.T -> 2 - is Tree.B.C.D -> 3 - is Tree.B.C.E -> 4 - is Tree.B.C.J -> 5 - is Tree.B.C.F.G -> 6 - is Tree.B.C.F.H -> 7 - is Tree.B.C.F.I -> 8 - is Tree.L.S -> 9 - is Tree.L.M.N -> 10 - is Tree.L.M.O -> 11 - is Tree.L.P.Q -> 12 - is Tree.L.P.R -> 13 - } - - public override fun nameOf(obj: Tree): String = when (obj) { - is Tree.A -> "Tree_A" - is Tree.K -> "Tree_K" - is Tree.T -> "Tree_T" - is Tree.B.C.D -> "Tree_B_C_D" - is Tree.B.C.E -> "Tree_B_C_E" - is Tree.B.C.J -> "Tree_B_C_J" - is Tree.B.C.F.G -> "Tree_B_C_F_G" - is Tree.B.C.F.H -> "Tree_B_C_F_H" - is Tree.B.C.F.I -> "Tree_B_C_F_I" - is Tree.L.S -> "Tree_L_S" - is Tree.L.M.N -> "Tree_L_M_N" - is Tree.L.M.O -> "Tree_L_M_O" - is Tree.L.P.Q -> "Tree_L_P_Q" - is Tree.L.P.R -> "Tree_L_P_R" - } - - public override fun valueOf(name: String): Tree = when (name) { - "Tree_A" -> Tree.A - "Tree_K" -> Tree.K - "Tree_T" -> Tree.T - "Tree_B_C_D" -> Tree.B.C.D - "Tree_B_C_E" -> Tree.B.C.E - "Tree_B_C_J" -> Tree.B.C.J - "Tree_B_C_F_G" -> Tree.B.C.F.G - "Tree_B_C_F_H" -> Tree.B.C.F.H - "Tree_B_C_F_I" -> Tree.B.C.F.I - "Tree_L_S" -> Tree.L.S - "Tree_L_M_N" -> Tree.L.M.N - "Tree_L_M_O" -> Tree.L.M.O - "Tree_L_P_Q" -> Tree.L.P.Q - "Tree_L_P_R" -> Tree.L.P.R - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } - - public override fun sealedObjectToEnum(obj: Tree): TreePreOrderEnum = when (obj) { - is Tree.A -> TreePreOrderEnum.Tree_A - is Tree.K -> TreePreOrderEnum.Tree_K - is Tree.T -> TreePreOrderEnum.Tree_T - is Tree.B.C.D -> TreePreOrderEnum.Tree_B_C_D - is Tree.B.C.E -> TreePreOrderEnum.Tree_B_C_E - is Tree.B.C.J -> TreePreOrderEnum.Tree_B_C_J - is Tree.B.C.F.G -> TreePreOrderEnum.Tree_B_C_F_G - is Tree.B.C.F.H -> TreePreOrderEnum.Tree_B_C_F_H - is Tree.B.C.F.I -> TreePreOrderEnum.Tree_B_C_F_I - is Tree.L.S -> TreePreOrderEnum.Tree_L_S - is Tree.L.M.N -> TreePreOrderEnum.Tree_L_M_N - is Tree.L.M.O -> TreePreOrderEnum.Tree_L_M_O - is Tree.L.P.Q -> TreePreOrderEnum.Tree_L_P_Q - is Tree.L.P.R -> TreePreOrderEnum.Tree_L_P_R - } - - public override fun enumToSealedObject(`enum`: TreePreOrderEnum): Tree = when (enum) { - TreePreOrderEnum.Tree_A -> Tree.A - TreePreOrderEnum.Tree_K -> Tree.K - TreePreOrderEnum.Tree_T -> Tree.T - TreePreOrderEnum.Tree_B_C_D -> Tree.B.C.D - TreePreOrderEnum.Tree_B_C_E -> Tree.B.C.E - TreePreOrderEnum.Tree_B_C_J -> Tree.B.C.J - TreePreOrderEnum.Tree_B_C_F_G -> Tree.B.C.F.G - TreePreOrderEnum.Tree_B_C_F_H -> Tree.B.C.F.H - TreePreOrderEnum.Tree_B_C_F_I -> Tree.B.C.F.I - TreePreOrderEnum.Tree_L_S -> Tree.L.S - TreePreOrderEnum.Tree_L_M_N -> Tree.L.M.N - TreePreOrderEnum.Tree_L_M_O -> Tree.L.M.O - TreePreOrderEnum.Tree_L_P_Q -> Tree.L.P.Q - TreePreOrderEnum.Tree_L_P_R -> Tree.L.P.R - } -} - -/** - * The index of [this] in the values list. - */ -public val Tree.preOrderOrdinal: Int - get() = TreePreOrderSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val Tree.preOrderName: String - get() = TreePreOrderSealedEnum.nameOf(this) - -/** - * A list of all [Tree] objects. - */ -public val Tree.Companion.preOrderValues: List - get() = TreePreOrderSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [Tree] - */ -public val Tree.Companion.preOrderSealedEnum: TreePreOrderSealedEnum - get() = TreePreOrderSealedEnum - -/** - * Returns the [Tree] object for the given [name]. - * - * If the given name doesn't correspond to any [Tree], an [IllegalArgumentException] will be thrown. - */ -public fun Tree.Companion.preOrderValueOf(name: String): Tree = TreePreOrderSealedEnum.valueOf(name) - -""".trimIndent() diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/traversal/TraversalOrderTests.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/traversal/TraversalOrderTests.kt index 61110ea5..55cbe454 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/traversal/TraversalOrderTests.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/traversal/TraversalOrderTests.kt @@ -1,12 +1,16 @@ package com.livefront.sealedenum.compilation.traversal +import com.livefront.sealedenum.testing.SealedEnumApprovalsExtension +import com.livefront.sealedenum.testing.assertApprovedGeneratedFile import com.livefront.sealedenum.testing.assertCompiles -import com.livefront.sealedenum.testing.assertGeneratedFileMatches import com.livefront.sealedenum.testing.compile import com.livefront.sealedenum.testing.getCommonSourceFile +import com.oneeyedmen.okeydoke.Approver import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +@ExtendWith(SealedEnumApprovalsExtension::class) class TraversalOrderTests { @Test @@ -258,10 +262,10 @@ class TraversalOrderTests { } @Test - fun `compilation generates correct code`() { + fun Approver.`compilation generates correct code`() { val result = compile(getCommonSourceFile("compilation", "traversal", "TraversalOrder.kt")) assertCompiles(result) - assertGeneratedFileMatches("Tree_SealedEnum.kt", treeGenerated, result) + assertApprovedGeneratedFile("Tree_SealedEnum.kt", result) } } diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/usecases/EnvironmentsSealedEnum.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/usecases/EnvironmentsSealedEnum.kt index 5bbd74e1..b3859cdb 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/usecases/EnvironmentsSealedEnum.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/usecases/EnvironmentsSealedEnum.kt @@ -1,7 +1,6 @@ package com.livefront.sealedenum.compilation.usecases import com.livefront.sealedenum.GenSealedEnum -import org.intellij.lang.annotations.Language interface Uri { val scheme: String @@ -34,132 +33,3 @@ sealed class Environments( @GenSealedEnum(generateEnum = true) companion object } - -@Language("kotlin") -val environmentsGenerated = """ -package com.livefront.sealedenum.compilation.usecases - -import com.livefront.sealedenum.EnumForSealedEnumProvider -import com.livefront.sealedenum.SealedEnum -import com.livefront.sealedenum.SealedEnumWithEnumProvider -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List -import kotlin.reflect.KClass - -/** - * An isomorphic enum for the sealed class [Environments] - */ -public enum class EnvironmentsEnum( - sealedObject: Environments, -) : Uri by sealedObject { - Environments_Http_Livefront(com.livefront.sealedenum.compilation.usecases.Environments.Http.Livefront), - Environments_Http_Google(com.livefront.sealedenum.compilation.usecases.Environments.Http.Google), - Environments_Https_Livefront(com.livefront.sealedenum.compilation.usecases.Environments.Https.Livefront), - Environments_Https_Google(com.livefront.sealedenum.compilation.usecases.Environments.Https.Google), -} - -/** - * The isomorphic [EnvironmentsEnum] for [this]. - */ -public val Environments.`enum`: EnvironmentsEnum - get() = EnvironmentsSealedEnum.sealedObjectToEnum(this) - -/** - * The isomorphic [Environments] for [this]. - */ -public val EnvironmentsEnum.sealedObject: Environments - get() = EnvironmentsSealedEnum.enumToSealedObject(this) - -/** - * An implementation of [SealedEnum] for the sealed class [Environments] - */ -public object EnvironmentsSealedEnum : SealedEnum, - SealedEnumWithEnumProvider, - EnumForSealedEnumProvider { - public override val values: List by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - listOf( - Environments.Http.Livefront, - Environments.Http.Google, - Environments.Https.Livefront, - Environments.Https.Google - ) - } - - - public override val enumClass: KClass - get() = EnvironmentsEnum::class - - public override fun ordinalOf(obj: Environments): Int = when (obj) { - is Environments.Http.Livefront -> 0 - is Environments.Http.Google -> 1 - is Environments.Https.Livefront -> 2 - is Environments.Https.Google -> 3 - } - - public override fun nameOf(obj: Environments): String = when (obj) { - is Environments.Http.Livefront -> "Environments_Http_Livefront" - is Environments.Http.Google -> "Environments_Http_Google" - is Environments.Https.Livefront -> "Environments_Https_Livefront" - is Environments.Https.Google -> "Environments_Https_Google" - } - - public override fun valueOf(name: String): Environments = when (name) { - "Environments_Http_Livefront" -> Environments.Http.Livefront - "Environments_Http_Google" -> Environments.Http.Google - "Environments_Https_Livefront" -> Environments.Https.Livefront - "Environments_Https_Google" -> Environments.Https.Google - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } - - public override fun sealedObjectToEnum(obj: Environments): EnvironmentsEnum = when (obj) { - is Environments.Http.Livefront -> EnvironmentsEnum.Environments_Http_Livefront - is Environments.Http.Google -> EnvironmentsEnum.Environments_Http_Google - is Environments.Https.Livefront -> EnvironmentsEnum.Environments_Https_Livefront - is Environments.Https.Google -> EnvironmentsEnum.Environments_Https_Google - } - - public override fun enumToSealedObject(`enum`: EnvironmentsEnum): Environments = when (enum) { - EnvironmentsEnum.Environments_Http_Livefront -> Environments.Http.Livefront - EnvironmentsEnum.Environments_Http_Google -> Environments.Http.Google - EnvironmentsEnum.Environments_Https_Livefront -> Environments.Https.Livefront - EnvironmentsEnum.Environments_Https_Google -> Environments.Https.Google - } -} - -/** - * The index of [this] in the values list. - */ -public val Environments.ordinal: Int - get() = EnvironmentsSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val Environments.name: String - get() = EnvironmentsSealedEnum.nameOf(this) - -/** - * A list of all [Environments] objects. - */ -public val Environments.Companion.values: List - get() = EnvironmentsSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [Environments] - */ -public val Environments.Companion.sealedEnum: EnvironmentsSealedEnum - get() = EnvironmentsSealedEnum - -/** - * Returns the [Environments] object for the given [name]. - * - * If the given name doesn't correspond to any [Environments], an [IllegalArgumentException] will be - * thrown. - */ -public fun Environments.Companion.valueOf(name: String): Environments = - EnvironmentsSealedEnum.valueOf(name) - -""".trimIndent() diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/usecases/EnvironmentsSealedEnumTests.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/usecases/EnvironmentsSealedEnumTests.kt index 348c67e6..58b695f7 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/usecases/EnvironmentsSealedEnumTests.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/usecases/EnvironmentsSealedEnumTests.kt @@ -1,11 +1,14 @@ package com.livefront.sealedenum.compilation.usecases +import com.livefront.sealedenum.testing.SealedEnumApprovalsExtension +import com.livefront.sealedenum.testing.assertApprovedGeneratedFile import com.livefront.sealedenum.testing.assertCompiles -import com.livefront.sealedenum.testing.assertGeneratedFileMatches import com.livefront.sealedenum.testing.compile import com.livefront.sealedenum.testing.getCommonSourceFile +import com.oneeyedmen.okeydoke.Approver import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith class EnvironmentManager( enumClass: Class, @@ -18,6 +21,7 @@ class EnvironmentManager( var currentEnvironment = defaultEnvironment } +@ExtendWith(SealedEnumApprovalsExtension::class) class EnvironmentsSealedEnumTests { @Test fun `environment manager from direct enum`() { @@ -66,10 +70,10 @@ class EnvironmentsSealedEnumTests { } @Test - fun `compilation generates correct code`() { + fun Approver.`compilation generates correct code`() { val result = compile(getCommonSourceFile("compilation", "usecases", "EnvironmentsSealedEnum.kt")) assertCompiles(result) - assertGeneratedFileMatches("Environments_SealedEnum.kt", environmentsGenerated, result) + assertApprovedGeneratedFile("Environments_SealedEnum.kt", result) } } diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/usecases/Flag.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/usecases/Flag.kt index a5a325e1..939e6c1f 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/usecases/Flag.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/usecases/Flag.kt @@ -1,7 +1,6 @@ package com.livefront.sealedenum.compilation.usecases import com.livefront.sealedenum.GenSealedEnum -import org.intellij.lang.annotations.Language sealed class Flag { val i: Int = 1 shl ordinal @@ -12,112 +11,3 @@ sealed class Flag { @GenSealedEnum(generateEnum = true) companion object } - -@Language("kotlin") -val flagGenerated = """ -package com.livefront.sealedenum.compilation.usecases - -import com.livefront.sealedenum.EnumForSealedEnumProvider -import com.livefront.sealedenum.SealedEnum -import com.livefront.sealedenum.SealedEnumWithEnumProvider -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List -import kotlin.reflect.KClass - -/** - * An isomorphic enum for the sealed class [Flag] - */ -public enum class FlagEnum() { - Flag_FirstFlag, - Flag_SecondFlag, -} - -/** - * The isomorphic [FlagEnum] for [this]. - */ -public val Flag.`enum`: FlagEnum - get() = FlagSealedEnum.sealedObjectToEnum(this) - -/** - * The isomorphic [Flag] for [this]. - */ -public val FlagEnum.sealedObject: Flag - get() = FlagSealedEnum.enumToSealedObject(this) - -/** - * An implementation of [SealedEnum] for the sealed class [Flag] - */ -public object FlagSealedEnum : SealedEnum, SealedEnumWithEnumProvider, - EnumForSealedEnumProvider { - public override val values: List by lazy(mode = LazyThreadSafetyMode.PUBLICATION) { - listOf( - Flag.FirstFlag, - Flag.SecondFlag - ) - } - - - public override val enumClass: KClass - get() = FlagEnum::class - - public override fun ordinalOf(obj: Flag): Int = when (obj) { - is Flag.FirstFlag -> 0 - is Flag.SecondFlag -> 1 - } - - public override fun nameOf(obj: Flag): String = when (obj) { - is Flag.FirstFlag -> "Flag_FirstFlag" - is Flag.SecondFlag -> "Flag_SecondFlag" - } - - public override fun valueOf(name: String): Flag = when (name) { - "Flag_FirstFlag" -> Flag.FirstFlag - "Flag_SecondFlag" -> Flag.SecondFlag - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } - - public override fun sealedObjectToEnum(obj: Flag): FlagEnum = when (obj) { - is Flag.FirstFlag -> FlagEnum.Flag_FirstFlag - is Flag.SecondFlag -> FlagEnum.Flag_SecondFlag - } - - public override fun enumToSealedObject(`enum`: FlagEnum): Flag = when (enum) { - FlagEnum.Flag_FirstFlag -> Flag.FirstFlag - FlagEnum.Flag_SecondFlag -> Flag.SecondFlag - } -} - -/** - * The index of [this] in the values list. - */ -public val Flag.ordinal: Int - get() = FlagSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val Flag.name: String - get() = FlagSealedEnum.nameOf(this) - -/** - * A list of all [Flag] objects. - */ -public val Flag.Companion.values: List - get() = FlagSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [Flag] - */ -public val Flag.Companion.sealedEnum: FlagSealedEnum - get() = FlagSealedEnum - -/** - * Returns the [Flag] object for the given [name]. - * - * If the given name doesn't correspond to any [Flag], an [IllegalArgumentException] will be thrown. - */ -public fun Flag.Companion.valueOf(name: String): Flag = FlagSealedEnum.valueOf(name) - -""".trimIndent() diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/usecases/FlagTests.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/usecases/FlagTests.kt index 0cc707c5..b608874b 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/usecases/FlagTests.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/usecases/FlagTests.kt @@ -1,12 +1,16 @@ package com.livefront.sealedenum.compilation.usecases +import com.livefront.sealedenum.testing.SealedEnumApprovalsExtension +import com.livefront.sealedenum.testing.assertApprovedGeneratedFile import com.livefront.sealedenum.testing.assertCompiles -import com.livefront.sealedenum.testing.assertGeneratedFileMatches import com.livefront.sealedenum.testing.compile import com.livefront.sealedenum.testing.getCommonSourceFile +import com.oneeyedmen.okeydoke.Approver import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +@ExtendWith(SealedEnumApprovalsExtension::class) class FlagTests { @Test fun `two objects sealed class`() { @@ -41,10 +45,10 @@ class FlagTests { } @Test - fun `compilation generates correct code`() { + fun Approver.`compilation generates correct code`() { val result = compile(getCommonSourceFile("compilation", "usecases", "Flag.kt")) assertCompiles(result) - assertGeneratedFileMatches("Flag_SealedEnum.kt", flagGenerated, result) + assertApprovedGeneratedFile("Flag_SealedEnum.kt", result) } } diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/visibility/PrivateInterfaceSealedClass.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/visibility/PrivateInterfaceSealedClass.kt index 6be43861..b281b464 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/visibility/PrivateInterfaceSealedClass.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/visibility/PrivateInterfaceSealedClass.kt @@ -1,7 +1,6 @@ package com.livefront.sealedenum.compilation.visibility import com.livefront.sealedenum.GenSealedEnum -import org.intellij.lang.annotations.Language sealed class PrivateInterfaceSealedClass : JavaPrivateInterfaceSubclass(JavaPrivateInterfaceOuterClass()), PrivateInterface { @@ -15,122 +14,3 @@ sealed class PrivateInterfaceSealedClass : } private interface PrivateInterface - -@Language("kotlin") -val privateInterfaceSealedClassGenerated = """ -package com.livefront.sealedenum.compilation.visibility - -import com.livefront.sealedenum.EnumForSealedEnumProvider -import com.livefront.sealedenum.SealedEnum -import com.livefront.sealedenum.SealedEnumWithEnumProvider -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List -import kotlin.reflect.KClass - -/** - * An isomorphic enum for the sealed class [PrivateInterfaceSealedClass] - */ -public enum class PrivateInterfaceSealedClassEnum() { - PrivateInterfaceSealedClass_FirstObject, - PrivateInterfaceSealedClass_SecondObject, -} - -/** - * The isomorphic [PrivateInterfaceSealedClassEnum] for [this]. - */ -public val PrivateInterfaceSealedClass.`enum`: PrivateInterfaceSealedClassEnum - get() = PrivateInterfaceSealedClassSealedEnum.sealedObjectToEnum(this) - -/** - * The isomorphic [PrivateInterfaceSealedClass] for [this]. - */ -public val PrivateInterfaceSealedClassEnum.sealedObject: PrivateInterfaceSealedClass - get() = PrivateInterfaceSealedClassSealedEnum.enumToSealedObject(this) - -/** - * An implementation of [SealedEnum] for the sealed class [PrivateInterfaceSealedClass] - */ -public object PrivateInterfaceSealedClassSealedEnum : SealedEnum, - SealedEnumWithEnumProvider, - EnumForSealedEnumProvider { - public override val values: List by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - listOf( - PrivateInterfaceSealedClass.FirstObject, - PrivateInterfaceSealedClass.SecondObject - ) - } - - - public override val enumClass: KClass - get() = PrivateInterfaceSealedClassEnum::class - - public override fun ordinalOf(obj: PrivateInterfaceSealedClass): Int = when (obj) { - is PrivateInterfaceSealedClass.FirstObject -> 0 - is PrivateInterfaceSealedClass.SecondObject -> 1 - } - - public override fun nameOf(obj: PrivateInterfaceSealedClass): String = when (obj) { - is PrivateInterfaceSealedClass.FirstObject -> "PrivateInterfaceSealedClass_FirstObject" - is PrivateInterfaceSealedClass.SecondObject -> "PrivateInterfaceSealedClass_SecondObject" - } - - public override fun valueOf(name: String): PrivateInterfaceSealedClass = when (name) { - "PrivateInterfaceSealedClass_FirstObject" -> PrivateInterfaceSealedClass.FirstObject - "PrivateInterfaceSealedClass_SecondObject" -> PrivateInterfaceSealedClass.SecondObject - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } - - public override fun sealedObjectToEnum(obj: PrivateInterfaceSealedClass): - PrivateInterfaceSealedClassEnum = when (obj) { - is PrivateInterfaceSealedClass.FirstObject -> - PrivateInterfaceSealedClassEnum.PrivateInterfaceSealedClass_FirstObject - is PrivateInterfaceSealedClass.SecondObject -> - PrivateInterfaceSealedClassEnum.PrivateInterfaceSealedClass_SecondObject - } - - public override fun enumToSealedObject(`enum`: PrivateInterfaceSealedClassEnum): - PrivateInterfaceSealedClass = when (enum) { - PrivateInterfaceSealedClassEnum.PrivateInterfaceSealedClass_FirstObject -> - PrivateInterfaceSealedClass.FirstObject - PrivateInterfaceSealedClassEnum.PrivateInterfaceSealedClass_SecondObject -> - PrivateInterfaceSealedClass.SecondObject - } -} - -/** - * The index of [this] in the values list. - */ -public val PrivateInterfaceSealedClass.ordinal: Int - get() = PrivateInterfaceSealedClassSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val PrivateInterfaceSealedClass.name: String - get() = PrivateInterfaceSealedClassSealedEnum.nameOf(this) - -/** - * A list of all [PrivateInterfaceSealedClass] objects. - */ -public val PrivateInterfaceSealedClass.Companion.values: List - get() = PrivateInterfaceSealedClassSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [PrivateInterfaceSealedClass] - */ -public val PrivateInterfaceSealedClass.Companion.sealedEnum: PrivateInterfaceSealedClassSealedEnum - get() = PrivateInterfaceSealedClassSealedEnum - -/** - * Returns the [PrivateInterfaceSealedClass] object for the given [name]. - * - * If the given name doesn't correspond to any [PrivateInterfaceSealedClass], an - * [IllegalArgumentException] will be thrown. - */ -public fun PrivateInterfaceSealedClass.Companion.valueOf(name: String): PrivateInterfaceSealedClass - = PrivateInterfaceSealedClassSealedEnum.valueOf(name) - -""".trimIndent() diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/visibility/PrivateInterfaceSealedClassTests.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/visibility/PrivateInterfaceSealedClassTests.kt index 2cea3166..c09fad8e 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/visibility/PrivateInterfaceSealedClassTests.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/visibility/PrivateInterfaceSealedClassTests.kt @@ -1,12 +1,16 @@ package com.livefront.sealedenum.compilation.visibility +import com.livefront.sealedenum.testing.SealedEnumApprovalsExtension +import com.livefront.sealedenum.testing.assertApprovedGeneratedFile import com.livefront.sealedenum.testing.assertCompiles -import com.livefront.sealedenum.testing.assertGeneratedFileMatches import com.livefront.sealedenum.testing.compile import com.livefront.sealedenum.testing.getCommonSourceFile +import com.oneeyedmen.okeydoke.Approver import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +@ExtendWith(SealedEnumApprovalsExtension::class) class PrivateInterfaceSealedClassTests { @Test @@ -48,16 +52,12 @@ class PrivateInterfaceSealedClassTests { } @Test - fun `compilation generates correct code`() { + fun Approver.`compilation generates correct code`() { val result = compile( getCommonSourceFile("compilation", "visibility", "PrivateInterfaceSealedClass.kt") ) assertCompiles(result) - assertGeneratedFileMatches( - "PrivateInterfaceSealedClass_SealedEnum.kt", - privateInterfaceSealedClassGenerated, - result - ) + assertApprovedGeneratedFile("PrivateInterfaceSealedClass_SealedEnum.kt", result) } } diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/visibility/ProtectedInterfaceSealedClass.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/visibility/ProtectedInterfaceSealedClass.kt index 280fa7cf..e8c9e6a7 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/visibility/ProtectedInterfaceSealedClass.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/visibility/ProtectedInterfaceSealedClass.kt @@ -1,9 +1,8 @@ -@file:Suppress("MatchingDeclarationName") +@file:Suppress("MatchingDeclarationName", "Filename") package com.livefront.sealedenum.compilation.visibility import com.livefront.sealedenum.GenSealedEnum -import org.intellij.lang.annotations.Language open class ProtectedInterfaceOuterClass { @@ -20,149 +19,3 @@ open class ProtectedInterfaceOuterClass { companion object } } - -@Language("kotlin") -val protectedInterfaceSealedClassGenerated = """ -package com.livefront.sealedenum.compilation.visibility - -import com.livefront.sealedenum.EnumForSealedEnumProvider -import com.livefront.sealedenum.SealedEnum -import com.livefront.sealedenum.SealedEnumWithEnumProvider -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List -import kotlin.reflect.KClass - -/** - * An isomorphic enum for the sealed class - * [ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass] - */ -public enum class ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassEnum( - sealedObject: ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass, -) : JavaProtectedInterfaceBaseClass.ProtectedInterface by sealedObject { - ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClass_FirstObject(com.livefront.sealedenum.compilation.visibility.ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.FirstObject), - ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClass_SecondObject(com.livefront.sealedenum.compilation.visibility.ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.SecondObject), -} - -/** - * The isomorphic [ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassEnum] for [this]. - */ -public val ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.`enum`: - ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassEnum - get() = - ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassSealedEnum.sealedObjectToEnum(this) - -/** - * The isomorphic [ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass] for [this]. - */ -public val ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassEnum.sealedObject: - ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass - get() = - ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassSealedEnum.enumToSealedObject(this) - -/** - * An implementation of [SealedEnum] for the sealed class - * [ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass] - */ -public object ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassSealedEnum : - SealedEnum, - SealedEnumWithEnumProvider, - EnumForSealedEnumProvider - { - public override val values: List by - lazy(mode = LazyThreadSafetyMode.PUBLICATION) { - listOf( - ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.FirstObject, - ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.SecondObject - ) - } - - - public override val enumClass: - KClass - get() = ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassEnum::class - - public override fun ordinalOf(obj: ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass): - Int = when (obj) { - is ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.FirstObject -> 0 - is ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.SecondObject -> 1 - } - - public override fun nameOf(obj: ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass): - String = when (obj) { - is ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.FirstObject -> - "ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClass_FirstObject" - is ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.SecondObject -> - "ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClass_SecondObject" - } - - public override fun valueOf(name: String): - ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass = when (name) { - "ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClass_FirstObject" -> - ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.FirstObject - "ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClass_SecondObject" -> - ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.SecondObject - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } - - public override - fun sealedObjectToEnum(obj: ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass): - ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassEnum = when (obj) { - is ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.FirstObject -> - ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassEnum.ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClass_FirstObject - is ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.SecondObject -> - ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassEnum.ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClass_SecondObject - } - - public override - fun enumToSealedObject(`enum`: ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassEnum): - ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass = when (enum) { - ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassEnum.ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClass_FirstObject -> - ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.FirstObject - ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassEnum.ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClass_SecondObject -> - ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.SecondObject - } -} - -/** - * The index of [this] in the values list. - */ -public val ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.ordinal: Int - get() = ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.name: String - get() = ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassSealedEnum.nameOf(this) - -/** - * A list of all [ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass] objects. - */ -public val ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.Companion.values: - List - get() = ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class - * [ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass] - */ -public val ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.Companion.sealedEnum: - ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassSealedEnum - get() = ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassSealedEnum - -/** - * Returns the [ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass] object for the given - * [name]. - * - * If the given name doesn't correspond to any - * [ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass], an [IllegalArgumentException] will be - * thrown. - */ -public - fun ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.Companion.valueOf(name: String): - ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass = - ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassSealedEnum.valueOf(name) - -""".trimIndent() diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/visibility/ProtectedInterfaceSealedClassTests.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/visibility/ProtectedInterfaceSealedClassTests.kt index 3ead0bcc..f79d3567 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/visibility/ProtectedInterfaceSealedClassTests.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/visibility/ProtectedInterfaceSealedClassTests.kt @@ -1,15 +1,19 @@ package com.livefront.sealedenum.compilation.visibility +import com.livefront.sealedenum.testing.SealedEnumApprovalsExtension +import com.livefront.sealedenum.testing.assertApprovedGeneratedFile import com.livefront.sealedenum.testing.assertCompiles -import com.livefront.sealedenum.testing.assertGeneratedFileMatches import com.livefront.sealedenum.testing.compile import com.livefront.sealedenum.testing.getCommonSourceFile +import com.oneeyedmen.okeydoke.Approver import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Test import org.junit.jupiter.api.condition.DisabledIf +import org.junit.jupiter.api.extension.ExtendWith import kotlin.reflect.full.isSubclassOf +@ExtendWith(SealedEnumApprovalsExtension::class) class ProtectedInterfaceSealedClassTests { @Test @@ -67,16 +71,12 @@ class ProtectedInterfaceSealedClassTests { */ @Test @DisabledIf("com.livefront.sealedenum.testing.ProcessingTypeGetter#isKSP") - fun `compilation generates correct code`() { + fun Approver.`compilation generates correct code`() { val result = compile( getCommonSourceFile("compilation", "visibility", "ProtectedInterfaceSealedClass.kt") ) assertCompiles(result) - assertGeneratedFileMatches( - "ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass_SealedEnum.kt", - protectedInterfaceSealedClassGenerated, - result - ) + assertApprovedGeneratedFile("ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass_SealedEnum.kt", result) } } diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/visibility/ProtectedInterfaceSealedClassWithDifferentPackageBaseClass.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/visibility/ProtectedInterfaceSealedClassWithDifferentPackageBaseClass.kt index 6b7da9de..d3671cff 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/visibility/ProtectedInterfaceSealedClassWithDifferentPackageBaseClass.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/visibility/ProtectedInterfaceSealedClassWithDifferentPackageBaseClass.kt @@ -1,9 +1,8 @@ -@file:Suppress("MatchingDeclarationName") +@file:Suppress("MatchingDeclarationName", "Filename") package com.livefront.sealedenum.compilation.visibility import com.livefront.sealedenum.GenSealedEnum -import org.intellij.lang.annotations.Language open class ProtectedInterfaceOuterClassWithDifferentPackageBaseClass { @@ -21,184 +20,3 @@ open class ProtectedInterfaceOuterClassWithDifferentPackageBaseClass { companion object } } - -@Language("kotlin") -val protectedInterfaceSealedClassWithDifferentPackageBaseClassGenerated = """ -package com.livefront.sealedenum.compilation.visibility - -import com.livefront.sealedenum.EnumForSealedEnumProvider -import com.livefront.sealedenum.SealedEnum -import com.livefront.sealedenum.SealedEnumWithEnumProvider -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List -import kotlin.reflect.KClass - -/** - * An isomorphic enum for the sealed class - * [ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass] - */ -public enum class - ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassEnum() - { - ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClass_FirstObject, - ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClass_SecondObject, -} - -/** - * The isomorphic - * [ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassEnum] for - * [this]. - */ -public - val ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.`enum`: - ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassEnum - get() = - ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassSealedEnum.sealedObjectToEnum(this) - -/** - * The isomorphic - * [ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass] for - * [this]. - */ -public - val ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassEnum.sealedObject: - ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass - get() = - ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassSealedEnum.enumToSealedObject(this) - -/** - * An implementation of [SealedEnum] for the sealed class - * [ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass] - */ -public object - ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassSealedEnum - : - SealedEnum, - SealedEnumWithEnumProvider, - EnumForSealedEnumProvider - { - public override val values: - List - by lazy(mode = LazyThreadSafetyMode.PUBLICATION) { - listOf( - ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.FirstObject, - ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.SecondObject - ) - } - - - public override val enumClass: - KClass - get() = - ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassEnum::class - - public override - fun ordinalOf(obj: ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass): - Int = when (obj) { - is - ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.FirstObject -> - 0 - is - ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.SecondObject -> - 1 - } - - public override - fun nameOf(obj: ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass): - String = when (obj) { - is - ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.FirstObject -> - "ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClass_FirstObject" - is - ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.SecondObject -> - "ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClass_SecondObject" - } - - public override fun valueOf(name: String): - ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass - = when (name) { - "ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClass_FirstObject" -> - ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.FirstObject - "ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClass_SecondObject" -> - ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.SecondObject - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } - - public override - fun sealedObjectToEnum(obj: ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass): - ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassEnum - = when (obj) { - is - ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.FirstObject -> - ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassEnum.ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClass_FirstObject - is - ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.SecondObject -> - ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassEnum.ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClass_SecondObject - } - - public override - fun enumToSealedObject(`enum`: ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassEnum): - ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass - = when (enum) { - ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassEnum.ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClass_FirstObject -> - ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.FirstObject - ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassEnum.ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClass_SecondObject -> - ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.SecondObject - } -} - -/** - * The index of [this] in the values list. - */ -public - val ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.ordinal: - Int - get() = - ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public - val ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.name: - String - get() = - ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassSealedEnum.nameOf(this) - -/** - * A list of all - * [ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass] objects. - */ -public - val ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.Companion.values: - List - get() = - ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class - * [ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass] - */ -public - val ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.Companion.sealedEnum: - ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassSealedEnum - get() = - ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassSealedEnum - -/** - * Returns the - * [ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass] object for - * the given [name]. - * - * If the given name doesn't correspond to any - * [ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass], an - * [IllegalArgumentException] will be thrown. - */ -public - fun ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.Companion.valueOf(name: String): - ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass = - ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassSealedEnum.valueOf(name) - -""".trimIndent() diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/visibility/ProtectedInterfaceSealedClassWithDifferentPackageBaseClassTests.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/visibility/ProtectedInterfaceSealedClassWithDifferentPackageBaseClassTests.kt index 7a57a0f9..928c57f8 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/visibility/ProtectedInterfaceSealedClassWithDifferentPackageBaseClassTests.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/visibility/ProtectedInterfaceSealedClassWithDifferentPackageBaseClassTests.kt @@ -1,12 +1,16 @@ package com.livefront.sealedenum.compilation.visibility +import com.livefront.sealedenum.testing.SealedEnumApprovalsExtension +import com.livefront.sealedenum.testing.assertApprovedGeneratedFile import com.livefront.sealedenum.testing.assertCompiles -import com.livefront.sealedenum.testing.assertGeneratedFileMatches import com.livefront.sealedenum.testing.compile import com.livefront.sealedenum.testing.getCommonSourceFile +import com.oneeyedmen.okeydoke.Approver import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +@ExtendWith(SealedEnumApprovalsExtension::class) class ProtectedInterfaceSealedClassWithDifferentPackageBaseClassTests { @Test @@ -50,7 +54,7 @@ class ProtectedInterfaceSealedClassWithDifferentPackageBaseClassTests { } @Test - fun `compilation generates correct code`() { + fun Approver.`compilation generates correct code`() { val result = compile( getCommonSourceFile( "compilation", @@ -60,9 +64,8 @@ class ProtectedInterfaceSealedClassWithDifferentPackageBaseClassTests { ) assertCompiles(result) - assertGeneratedFileMatches( + assertApprovedGeneratedFile( "ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass_SealedEnum.kt", - protectedInterfaceSealedClassWithDifferentPackageBaseClassGenerated, result ) } diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/visibility/VisibilitySealedClass.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/visibility/VisibilitySealedClass.kt index 51cf04bd..26f80e1f 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/visibility/VisibilitySealedClass.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/visibility/VisibilitySealedClass.kt @@ -1,7 +1,6 @@ package com.livefront.sealedenum.compilation.visibility import com.livefront.sealedenum.GenSealedEnum -import org.intellij.lang.annotations.Language sealed class InternalObjectsSealedClass { internal object FirstObject : InternalObjectsSealedClass() @@ -16,136 +15,6 @@ sealed class InternalObjectsSealedClass { companion object } -@Language("kotlin") -val internalObjectsSealedClassGenerated = """ -package com.livefront.sealedenum.compilation.visibility - -import com.livefront.sealedenum.EnumForSealedEnumProvider -import com.livefront.sealedenum.SealedEnum -import com.livefront.sealedenum.SealedEnumWithEnumProvider -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List -import kotlin.reflect.KClass - -/** - * An isomorphic enum for the sealed class [InternalObjectsSealedClass] - */ -public enum class InternalObjectsSealedClassEnum() { - InternalObjectsSealedClass_FirstObject, - InternalObjectsSealedClass_SecondObject, - InternalObjectsSealedClass_InnerSealedClass_ThirdObject, -} - -/** - * The isomorphic [InternalObjectsSealedClassEnum] for [this]. - */ -public val InternalObjectsSealedClass.`enum`: InternalObjectsSealedClassEnum - get() = InternalObjectsSealedClassSealedEnum.sealedObjectToEnum(this) - -/** - * The isomorphic [InternalObjectsSealedClass] for [this]. - */ -public val InternalObjectsSealedClassEnum.sealedObject: InternalObjectsSealedClass - get() = InternalObjectsSealedClassSealedEnum.enumToSealedObject(this) - -/** - * An implementation of [SealedEnum] for the sealed class [InternalObjectsSealedClass] - */ -public object InternalObjectsSealedClassSealedEnum : SealedEnum, - SealedEnumWithEnumProvider, - EnumForSealedEnumProvider { - public override val values: List by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - listOf( - InternalObjectsSealedClass.FirstObject, - InternalObjectsSealedClass.SecondObject, - InternalObjectsSealedClass.InnerSealedClass.ThirdObject - ) - } - - - public override val enumClass: KClass - get() = InternalObjectsSealedClassEnum::class - - public override fun ordinalOf(obj: InternalObjectsSealedClass): Int = when (obj) { - is InternalObjectsSealedClass.FirstObject -> 0 - is InternalObjectsSealedClass.SecondObject -> 1 - is InternalObjectsSealedClass.InnerSealedClass.ThirdObject -> 2 - } - - public override fun nameOf(obj: InternalObjectsSealedClass): String = when (obj) { - is InternalObjectsSealedClass.FirstObject -> "InternalObjectsSealedClass_FirstObject" - is InternalObjectsSealedClass.SecondObject -> "InternalObjectsSealedClass_SecondObject" - is InternalObjectsSealedClass.InnerSealedClass.ThirdObject -> - "InternalObjectsSealedClass_InnerSealedClass_ThirdObject" - } - - public override fun valueOf(name: String): InternalObjectsSealedClass = when (name) { - "InternalObjectsSealedClass_FirstObject" -> InternalObjectsSealedClass.FirstObject - "InternalObjectsSealedClass_SecondObject" -> InternalObjectsSealedClass.SecondObject - "InternalObjectsSealedClass_InnerSealedClass_ThirdObject" -> - InternalObjectsSealedClass.InnerSealedClass.ThirdObject - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } - - public override fun sealedObjectToEnum(obj: InternalObjectsSealedClass): - InternalObjectsSealedClassEnum = when (obj) { - is InternalObjectsSealedClass.FirstObject -> - InternalObjectsSealedClassEnum.InternalObjectsSealedClass_FirstObject - is InternalObjectsSealedClass.SecondObject -> - InternalObjectsSealedClassEnum.InternalObjectsSealedClass_SecondObject - is InternalObjectsSealedClass.InnerSealedClass.ThirdObject -> - InternalObjectsSealedClassEnum.InternalObjectsSealedClass_InnerSealedClass_ThirdObject - } - - public override fun enumToSealedObject(`enum`: InternalObjectsSealedClassEnum): - InternalObjectsSealedClass = when (enum) { - InternalObjectsSealedClassEnum.InternalObjectsSealedClass_FirstObject -> - InternalObjectsSealedClass.FirstObject - InternalObjectsSealedClassEnum.InternalObjectsSealedClass_SecondObject -> - InternalObjectsSealedClass.SecondObject - InternalObjectsSealedClassEnum.InternalObjectsSealedClass_InnerSealedClass_ThirdObject -> - InternalObjectsSealedClass.InnerSealedClass.ThirdObject - } -} - -/** - * The index of [this] in the values list. - */ -public val InternalObjectsSealedClass.ordinal: Int - get() = InternalObjectsSealedClassSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val InternalObjectsSealedClass.name: String - get() = InternalObjectsSealedClassSealedEnum.nameOf(this) - -/** - * A list of all [InternalObjectsSealedClass] objects. - */ -public val InternalObjectsSealedClass.Companion.values: List - get() = InternalObjectsSealedClassSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [InternalObjectsSealedClass] - */ -public val InternalObjectsSealedClass.Companion.sealedEnum: InternalObjectsSealedClassSealedEnum - get() = InternalObjectsSealedClassSealedEnum - -/** - * Returns the [InternalObjectsSealedClass] object for the given [name]. - * - * If the given name doesn't correspond to any [InternalObjectsSealedClass], an - * [IllegalArgumentException] will be thrown. - */ -public fun InternalObjectsSealedClass.Companion.valueOf(name: String): InternalObjectsSealedClass = - InternalObjectsSealedClassSealedEnum.valueOf(name) - -""".trimIndent() - internal sealed class InternalSealedClass { object FirstObject : InternalSealedClass() @@ -155,123 +24,6 @@ internal sealed class InternalSealedClass { companion object } -@Language("kotlin") -val internalSealedClassGenerated = """ -package com.livefront.sealedenum.compilation.visibility - -import com.livefront.sealedenum.EnumForSealedEnumProvider -import com.livefront.sealedenum.SealedEnum -import com.livefront.sealedenum.SealedEnumWithEnumProvider -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List -import kotlin.reflect.KClass - -/** - * An isomorphic enum for the sealed class [InternalSealedClass] - */ -internal enum class InternalSealedClassEnum() { - InternalSealedClass_FirstObject, - InternalSealedClass_SecondObject, -} - -/** - * The isomorphic [InternalSealedClassEnum] for [this]. - */ -internal val InternalSealedClass.`enum`: InternalSealedClassEnum - get() = InternalSealedClassSealedEnum.sealedObjectToEnum(this) - -/** - * The isomorphic [InternalSealedClass] for [this]. - */ -internal val InternalSealedClassEnum.sealedObject: InternalSealedClass - get() = InternalSealedClassSealedEnum.enumToSealedObject(this) - -/** - * An implementation of [SealedEnum] for the sealed class [InternalSealedClass] - */ -internal object InternalSealedClassSealedEnum : SealedEnum, - SealedEnumWithEnumProvider, - EnumForSealedEnumProvider { - public override val values: List by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - listOf( - InternalSealedClass.FirstObject, - InternalSealedClass.SecondObject - ) - } - - - public override val enumClass: KClass - get() = InternalSealedClassEnum::class - - public override fun ordinalOf(obj: InternalSealedClass): Int = when (obj) { - is InternalSealedClass.FirstObject -> 0 - is InternalSealedClass.SecondObject -> 1 - } - - public override fun nameOf(obj: InternalSealedClass): String = when (obj) { - is InternalSealedClass.FirstObject -> "InternalSealedClass_FirstObject" - is InternalSealedClass.SecondObject -> "InternalSealedClass_SecondObject" - } - - public override fun valueOf(name: String): InternalSealedClass = when (name) { - "InternalSealedClass_FirstObject" -> InternalSealedClass.FirstObject - "InternalSealedClass_SecondObject" -> InternalSealedClass.SecondObject - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } - - public override fun sealedObjectToEnum(obj: InternalSealedClass): InternalSealedClassEnum = when - (obj) { - is InternalSealedClass.FirstObject -> - InternalSealedClassEnum.InternalSealedClass_FirstObject - is InternalSealedClass.SecondObject -> - InternalSealedClassEnum.InternalSealedClass_SecondObject - } - - public override fun enumToSealedObject(`enum`: InternalSealedClassEnum): InternalSealedClass = - when (enum) { - InternalSealedClassEnum.InternalSealedClass_FirstObject -> InternalSealedClass.FirstObject - InternalSealedClassEnum.InternalSealedClass_SecondObject -> InternalSealedClass.SecondObject - } -} - -/** - * The index of [this] in the values list. - */ -internal val InternalSealedClass.ordinal: Int - get() = InternalSealedClassSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -internal val InternalSealedClass.name: String - get() = InternalSealedClassSealedEnum.nameOf(this) - -/** - * A list of all [InternalSealedClass] objects. - */ -internal val InternalSealedClass.Companion.values: List - get() = InternalSealedClassSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [InternalSealedClass] - */ -internal val InternalSealedClass.Companion.sealedEnum: InternalSealedClassSealedEnum - get() = InternalSealedClassSealedEnum - -/** - * Returns the [InternalSealedClass] object for the given [name]. - * - * If the given name doesn't correspond to any [InternalSealedClass], an [IllegalArgumentException] - * will be thrown. - */ -internal fun InternalSealedClass.Companion.valueOf(name: String): InternalSealedClass = - InternalSealedClassSealedEnum.valueOf(name) - -""".trimIndent() - sealed class InternalCompanionSealedClass { object FirstObject : InternalCompanionSealedClass() @@ -281,126 +33,6 @@ sealed class InternalCompanionSealedClass { internal companion object } -@Language("kotlin") -val internalCompanionSealedClassGenerated = """ -package com.livefront.sealedenum.compilation.visibility - -import com.livefront.sealedenum.EnumForSealedEnumProvider -import com.livefront.sealedenum.SealedEnum -import com.livefront.sealedenum.SealedEnumWithEnumProvider -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List -import kotlin.reflect.KClass - -/** - * An isomorphic enum for the sealed class [InternalCompanionSealedClass] - */ -public enum class InternalCompanionSealedClassEnum() { - InternalCompanionSealedClass_FirstObject, - InternalCompanionSealedClass_SecondObject, -} - -/** - * The isomorphic [InternalCompanionSealedClassEnum] for [this]. - */ -public val InternalCompanionSealedClass.`enum`: InternalCompanionSealedClassEnum - get() = InternalCompanionSealedClassSealedEnum.sealedObjectToEnum(this) - -/** - * The isomorphic [InternalCompanionSealedClass] for [this]. - */ -public val InternalCompanionSealedClassEnum.sealedObject: InternalCompanionSealedClass - get() = InternalCompanionSealedClassSealedEnum.enumToSealedObject(this) - -/** - * An implementation of [SealedEnum] for the sealed class [InternalCompanionSealedClass] - */ -public object InternalCompanionSealedClassSealedEnum : SealedEnum, - SealedEnumWithEnumProvider, - EnumForSealedEnumProvider { - public override val values: List by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - listOf( - InternalCompanionSealedClass.FirstObject, - InternalCompanionSealedClass.SecondObject - ) - } - - - public override val enumClass: KClass - get() = InternalCompanionSealedClassEnum::class - - public override fun ordinalOf(obj: InternalCompanionSealedClass): Int = when (obj) { - is InternalCompanionSealedClass.FirstObject -> 0 - is InternalCompanionSealedClass.SecondObject -> 1 - } - - public override fun nameOf(obj: InternalCompanionSealedClass): String = when (obj) { - is InternalCompanionSealedClass.FirstObject -> "InternalCompanionSealedClass_FirstObject" - is InternalCompanionSealedClass.SecondObject -> "InternalCompanionSealedClass_SecondObject" - } - - public override fun valueOf(name: String): InternalCompanionSealedClass = when (name) { - "InternalCompanionSealedClass_FirstObject" -> InternalCompanionSealedClass.FirstObject - "InternalCompanionSealedClass_SecondObject" -> InternalCompanionSealedClass.SecondObject - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } - - public override fun sealedObjectToEnum(obj: InternalCompanionSealedClass): - InternalCompanionSealedClassEnum = when (obj) { - is InternalCompanionSealedClass.FirstObject -> - InternalCompanionSealedClassEnum.InternalCompanionSealedClass_FirstObject - is InternalCompanionSealedClass.SecondObject -> - InternalCompanionSealedClassEnum.InternalCompanionSealedClass_SecondObject - } - - public override fun enumToSealedObject(`enum`: InternalCompanionSealedClassEnum): - InternalCompanionSealedClass = when (enum) { - InternalCompanionSealedClassEnum.InternalCompanionSealedClass_FirstObject -> - InternalCompanionSealedClass.FirstObject - InternalCompanionSealedClassEnum.InternalCompanionSealedClass_SecondObject -> - InternalCompanionSealedClass.SecondObject - } -} - -/** - * The index of [this] in the values list. - */ -public val InternalCompanionSealedClass.ordinal: Int - get() = InternalCompanionSealedClassSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val InternalCompanionSealedClass.name: String - get() = InternalCompanionSealedClassSealedEnum.nameOf(this) - -/** - * A list of all [InternalCompanionSealedClass] objects. - */ -internal val InternalCompanionSealedClass.Companion.values: List - get() = InternalCompanionSealedClassSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [InternalCompanionSealedClass] - */ -internal val InternalCompanionSealedClass.Companion.sealedEnum: - InternalCompanionSealedClassSealedEnum - get() = InternalCompanionSealedClassSealedEnum - -/** - * Returns the [InternalCompanionSealedClass] object for the given [name]. - * - * If the given name doesn't correspond to any [InternalCompanionSealedClass], an - * [IllegalArgumentException] will be thrown. - */ -internal fun InternalCompanionSealedClass.Companion.valueOf(name: String): - InternalCompanionSealedClass = InternalCompanionSealedClassSealedEnum.valueOf(name) - -""".trimIndent() - internal sealed class InternalSealedAndCompanionSealedClass { object FirstObject : InternalSealedAndCompanionSealedClass() @@ -409,133 +41,3 @@ internal sealed class InternalSealedAndCompanionSealedClass { @GenSealedEnum(generateEnum = true) internal companion object } - -@Language("kotlin") -val internalSealedAndCompanionSealedClassGenerated = """ -package com.livefront.sealedenum.compilation.visibility - -import com.livefront.sealedenum.EnumForSealedEnumProvider -import com.livefront.sealedenum.SealedEnum -import com.livefront.sealedenum.SealedEnumWithEnumProvider -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List -import kotlin.reflect.KClass - -/** - * An isomorphic enum for the sealed class [InternalSealedAndCompanionSealedClass] - */ -internal enum class InternalSealedAndCompanionSealedClassEnum() { - InternalSealedAndCompanionSealedClass_FirstObject, - InternalSealedAndCompanionSealedClass_SecondObject, -} - -/** - * The isomorphic [InternalSealedAndCompanionSealedClassEnum] for [this]. - */ -internal val InternalSealedAndCompanionSealedClass.`enum`: InternalSealedAndCompanionSealedClassEnum - get() = InternalSealedAndCompanionSealedClassSealedEnum.sealedObjectToEnum(this) - -/** - * The isomorphic [InternalSealedAndCompanionSealedClass] for [this]. - */ -internal val InternalSealedAndCompanionSealedClassEnum.sealedObject: - InternalSealedAndCompanionSealedClass - get() = InternalSealedAndCompanionSealedClassSealedEnum.enumToSealedObject(this) - -/** - * An implementation of [SealedEnum] for the sealed class [InternalSealedAndCompanionSealedClass] - */ -internal object InternalSealedAndCompanionSealedClassSealedEnum : - SealedEnum, - SealedEnumWithEnumProvider, - EnumForSealedEnumProvider - { - public override val values: List by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - listOf( - InternalSealedAndCompanionSealedClass.FirstObject, - InternalSealedAndCompanionSealedClass.SecondObject - ) - } - - - public override val enumClass: KClass - get() = InternalSealedAndCompanionSealedClassEnum::class - - public override fun ordinalOf(obj: InternalSealedAndCompanionSealedClass): Int = when (obj) { - is InternalSealedAndCompanionSealedClass.FirstObject -> 0 - is InternalSealedAndCompanionSealedClass.SecondObject -> 1 - } - - public override fun nameOf(obj: InternalSealedAndCompanionSealedClass): String = when (obj) { - is InternalSealedAndCompanionSealedClass.FirstObject -> - "InternalSealedAndCompanionSealedClass_FirstObject" - is InternalSealedAndCompanionSealedClass.SecondObject -> - "InternalSealedAndCompanionSealedClass_SecondObject" - } - - public override fun valueOf(name: String): InternalSealedAndCompanionSealedClass = when (name) { - "InternalSealedAndCompanionSealedClass_FirstObject" -> - InternalSealedAndCompanionSealedClass.FirstObject - "InternalSealedAndCompanionSealedClass_SecondObject" -> - InternalSealedAndCompanionSealedClass.SecondObject - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } - - public override fun sealedObjectToEnum(obj: InternalSealedAndCompanionSealedClass): - InternalSealedAndCompanionSealedClassEnum = when (obj) { - is InternalSealedAndCompanionSealedClass.FirstObject -> - InternalSealedAndCompanionSealedClassEnum.InternalSealedAndCompanionSealedClass_FirstObject - is InternalSealedAndCompanionSealedClass.SecondObject -> - InternalSealedAndCompanionSealedClassEnum.InternalSealedAndCompanionSealedClass_SecondObject - } - - public override fun enumToSealedObject(`enum`: InternalSealedAndCompanionSealedClassEnum): - InternalSealedAndCompanionSealedClass = when (enum) { - InternalSealedAndCompanionSealedClassEnum.InternalSealedAndCompanionSealedClass_FirstObject -> - InternalSealedAndCompanionSealedClass.FirstObject - InternalSealedAndCompanionSealedClassEnum.InternalSealedAndCompanionSealedClass_SecondObject -> - InternalSealedAndCompanionSealedClass.SecondObject - } -} - -/** - * The index of [this] in the values list. - */ -internal val InternalSealedAndCompanionSealedClass.ordinal: Int - get() = InternalSealedAndCompanionSealedClassSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -internal val InternalSealedAndCompanionSealedClass.name: String - get() = InternalSealedAndCompanionSealedClassSealedEnum.nameOf(this) - -/** - * A list of all [InternalSealedAndCompanionSealedClass] objects. - */ -internal val InternalSealedAndCompanionSealedClass.Companion.values: - List - get() = InternalSealedAndCompanionSealedClassSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class - * [InternalSealedAndCompanionSealedClass] - */ -internal val InternalSealedAndCompanionSealedClass.Companion.sealedEnum: - InternalSealedAndCompanionSealedClassSealedEnum - get() = InternalSealedAndCompanionSealedClassSealedEnum - -/** - * Returns the [InternalSealedAndCompanionSealedClass] object for the given [name]. - * - * If the given name doesn't correspond to any [InternalSealedAndCompanionSealedClass], an - * [IllegalArgumentException] will be thrown. - */ -internal fun InternalSealedAndCompanionSealedClass.Companion.valueOf(name: String): - InternalSealedAndCompanionSealedClass = - InternalSealedAndCompanionSealedClassSealedEnum.valueOf(name) - -""".trimIndent() diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/visibility/VisibilitySealedClassTests.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/visibility/VisibilitySealedClassTests.kt index 8c8d9cd8..5fb60142 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/visibility/VisibilitySealedClassTests.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/compilation/visibility/VisibilitySealedClassTests.kt @@ -1,18 +1,22 @@ package com.livefront.sealedenum.compilation.visibility import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.testing.SealedEnumApprovalsExtension +import com.livefront.sealedenum.testing.assertApprovedGeneratedFile import com.livefront.sealedenum.testing.assertCompiles -import com.livefront.sealedenum.testing.assertGeneratedFileMatches import com.livefront.sealedenum.testing.compile import com.livefront.sealedenum.testing.getCommonSourceFile +import com.oneeyedmen.okeydoke.Approver import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith import kotlin.reflect.KVisibility /** * Verifies that generated [SealedEnum] implementations, extension properties and methods have valid visibilities. */ +@ExtendWith(SealedEnumApprovalsExtension::class) class VisibilitySealedClassTests { @Nested @@ -64,15 +68,11 @@ class VisibilitySealedClassTests { } @Test - fun `compilation generates correct code`() { + fun Approver.`compilation generates correct code`() { val result = compile(getCommonSourceFile("compilation", "visibility", "VisibilitySealedClass.kt")) assertCompiles(result) - assertGeneratedFileMatches( - "InternalObjectsSealedClass_SealedEnum.kt", - internalObjectsSealedClassGenerated, - result - ) + assertApprovedGeneratedFile("InternalObjectsSealedClass_SealedEnum.kt", result) } } @@ -120,11 +120,11 @@ class VisibilitySealedClassTests { } @Test - fun `compilation generates correct code`() { + fun Approver.`compilation generates correct code`() { val result = compile(getCommonSourceFile("compilation", "visibility", "VisibilitySealedClass.kt")) assertCompiles(result) - assertGeneratedFileMatches("InternalSealedClass_SealedEnum.kt", internalSealedClassGenerated, result) + assertApprovedGeneratedFile("InternalSealedClass_SealedEnum.kt", result) } } @@ -175,15 +175,11 @@ class VisibilitySealedClassTests { } @Test - fun `compilation generates correct code`() { + fun Approver.`compilation generates correct code`() { val result = compile(getCommonSourceFile("compilation", "visibility", "VisibilitySealedClass.kt")) assertCompiles(result) - assertGeneratedFileMatches( - "InternalCompanionSealedClass_SealedEnum.kt", - internalCompanionSealedClassGenerated, - result - ) + assertApprovedGeneratedFile("InternalCompanionSealedClass_SealedEnum.kt", result) } } @@ -237,15 +233,11 @@ class VisibilitySealedClassTests { } @Test - fun `compilation generates correct code`() { + fun Approver.`compilation generates correct code`() { val result = compile(getCommonSourceFile("compilation", "visibility", "VisibilitySealedClass.kt")) assertCompiles(result) - assertGeneratedFileMatches( - "InternalSealedAndCompanionSealedClass_SealedEnum.kt", - internalSealedAndCompanionSealedClassGenerated, - result - ) + assertApprovedGeneratedFile("InternalSealedAndCompanionSealedClass_SealedEnum.kt", result) } } } diff --git a/processing-tests/common/test/kotlin/com/livefront/sealedenum/testing/CompilationAssertions.kt b/processing-tests/common/test/kotlin/com/livefront/sealedenum/testing/CompilationAssertions.kt index 03dbefeb..2bc61130 100644 --- a/processing-tests/common/test/kotlin/com/livefront/sealedenum/testing/CompilationAssertions.kt +++ b/processing-tests/common/test/kotlin/com/livefront/sealedenum/testing/CompilationAssertions.kt @@ -1,8 +1,16 @@ package com.livefront.sealedenum.testing +import com.oneeyedmen.okeydoke.Approver +import com.oneeyedmen.okeydoke.ApproverFactory +import com.oneeyedmen.okeydoke.Checker +import com.oneeyedmen.okeydoke.Formatters +import com.oneeyedmen.okeydoke.Serializers +import com.oneeyedmen.okeydoke.Sources +import com.oneeyedmen.okeydoke.junit5.ApprovalsExtension import com.tschuchort.compiletesting.KotlinCompilation -import org.intellij.lang.annotations.Language import org.junit.jupiter.api.Assertions.assertEquals +import org.opentest4j.AssertionFailedError +import java.io.File /** * Asserts that the given [result] compiled successfully. @@ -19,16 +27,37 @@ internal fun assertFails(result: KotlinCompilation.Result) { } /** - * Asserts that the contents of the generated source file with the name of [fileName] is equal to [expected] for the - * given [result] of compilation. + * Asserts that the contents of the generated source file with the name of [fileName] for the given [result] of + * compilation is approved */ -internal fun assertGeneratedFileMatches( - fileName: String, - @Language("kotlin") expected: String, - result: KotlinCompilation.Result -) { - assertEquals( - expected, - result.outputDirectory.parentFile.walk().first { it.name == fileName }.readText() +internal fun Approver.assertApprovedGeneratedFile(fileName: String, result: KotlinCompilation.Result) { + val fileText = result.outputDirectory.parentFile.walk().first { it.name == fileName }.readText() + assertApproved(fileText) +} + +object SealedEnumApproverFactory : ApproverFactory { + override fun createApprover(testName: String, testClass: Class<*>): Approver = Approver( + testName, + Sources.`in`(File("src/test/kotlin"), testClass.getPackage()), + Formatters.stringFormatter(), + Serializers.stringSerializer(), + SealedEnumStringChecker ) } + +object SealedEnumStringChecker : Checker { + override fun assertEquals(expectedMayBeNull: String?, actualMayBeNull: String?) { + if (expectedMayBeNull == null && actualMayBeNull == null) return + // Ignore windows line separator + if (expectedMayBeNull == null || actualMayBeNull == null || expectedMayBeNull.replace( + "\r\n", + "\n" + ) != actualMayBeNull.replace("\r\n", "\n") + ) { + System.err.println("Expected: $expectedMayBeNull\nActual: $actualMayBeNull") + throw AssertionFailedError("Actual was not the same as approved", expectedMayBeNull, actualMayBeNull) + } + } +} + +class SealedEnumApprovalsExtension : ApprovalsExtension(SealedEnumApproverFactory) diff --git a/processing-tests/ksp-tests/build.gradle.kts b/processing-tests/ksp-tests/build.gradle.kts index 7265f7bd..e8d1332b 100644 --- a/processing-tests/ksp-tests/build.gradle.kts +++ b/processing-tests/ksp-tests/build.gradle.kts @@ -34,6 +34,7 @@ dependencies { testImplementation(libs.junit.jupiter) testImplementation(libs.kotlinCompileTesting.base) testImplementation(libs.kotlinCompileTesting.ksp) + testImplementation(libs.okeyDoke) testImplementation(kotlin("reflect")) testImplementation(projects.runtime) testImplementation(libs.ksp.runtime) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/basic/EmptySealedClassTests.compilation generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/basic/EmptySealedClassTests.compilation generates correct code.approved new file mode 100644 index 00000000..7f1bcf18 --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/basic/EmptySealedClassTests.compilation generates correct code.approved @@ -0,0 +1,91 @@ +package com.livefront.sealedenum.compilation.basic + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [EmptySealedClass] + */ +public enum class EmptySealedClassEnum() + +/** + * The isomorphic [EmptySealedClassEnum] for [this]. + */ +public val EmptySealedClass.`enum`: EmptySealedClassEnum + get() = EmptySealedClassSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [EmptySealedClass] for [this]. + */ +public val EmptySealedClassEnum.sealedObject: EmptySealedClass + get() = EmptySealedClassSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [EmptySealedClass] + */ +public object EmptySealedClassSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + emptyList() + } + + + public override val enumClass: KClass + get() = EmptySealedClassEnum::class + + public override fun ordinalOf(obj: EmptySealedClass): Int = throw + AssertionError("Constructing a EmptySealedClass is impossible, since it has no sealed subclasses") + + public override fun nameOf(obj: EmptySealedClass): String = throw + AssertionError("Constructing a EmptySealedClass is impossible, since it has no sealed subclasses") + + public override fun valueOf(name: String): EmptySealedClass = throw + IllegalArgumentException("""No sealed enum constant $name""") + + public override fun sealedObjectToEnum(obj: EmptySealedClass): EmptySealedClassEnum = throw + AssertionError("Constructing a EmptySealedClass is impossible, since it has no sealed subclasses") + + public override fun enumToSealedObject(`enum`: EmptySealedClassEnum): EmptySealedClass = throw + AssertionError("Constructing a EmptySealedClass is impossible, since it has no sealed subclasses") +} + +/** + * The index of [this] in the values list. + */ +public val EmptySealedClass.ordinal: Int + get() = EmptySealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val EmptySealedClass.name: String + get() = EmptySealedClassSealedEnum.nameOf(this) + +/** + * A list of all [EmptySealedClass] objects. + */ +public val EmptySealedClass.Companion.values: List + get() = EmptySealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [EmptySealedClass] + */ +public val EmptySealedClass.Companion.sealedEnum: EmptySealedClassSealedEnum + get() = EmptySealedClassSealedEnum + +/** + * Returns the [EmptySealedClass] object for the given [name]. + * + * If the given name doesn't correspond to any [EmptySealedClass], an [IllegalArgumentException] + * will be thrown. + */ +public fun EmptySealedClass.Companion.valueOf(name: String): EmptySealedClass = + EmptySealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/basic/EmptySealedInterfaceTests.compilation generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/basic/EmptySealedInterfaceTests.compilation generates correct code.approved new file mode 100644 index 00000000..3aa7e18c --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/basic/EmptySealedInterfaceTests.compilation generates correct code.approved @@ -0,0 +1,93 @@ +package com.livefront.sealedenum.compilation.basic + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [EmptySealedInterface] + */ +public enum class EmptySealedInterfaceEnum() + +/** + * The isomorphic [EmptySealedInterfaceEnum] for [this]. + */ +public val EmptySealedInterface.`enum`: EmptySealedInterfaceEnum + get() = EmptySealedInterfaceSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [EmptySealedInterface] for [this]. + */ +public val EmptySealedInterfaceEnum.sealedObject: EmptySealedInterface + get() = EmptySealedInterfaceSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [EmptySealedInterface] + */ +public object EmptySealedInterfaceSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + emptyList() + } + + + public override val enumClass: KClass + get() = EmptySealedInterfaceEnum::class + + public override fun ordinalOf(obj: EmptySealedInterface): Int = throw + AssertionError("Constructing a EmptySealedInterface is impossible, since it has no sealed subclasses") + + public override fun nameOf(obj: EmptySealedInterface): String = throw + AssertionError("Constructing a EmptySealedInterface is impossible, since it has no sealed subclasses") + + public override fun valueOf(name: String): EmptySealedInterface = throw + IllegalArgumentException("""No sealed enum constant $name""") + + public override fun sealedObjectToEnum(obj: EmptySealedInterface): EmptySealedInterfaceEnum = + throw + AssertionError("Constructing a EmptySealedInterface is impossible, since it has no sealed subclasses") + + public override fun enumToSealedObject(`enum`: EmptySealedInterfaceEnum): EmptySealedInterface = + throw + AssertionError("Constructing a EmptySealedInterface is impossible, since it has no sealed subclasses") +} + +/** + * The index of [this] in the values list. + */ +public val EmptySealedInterface.ordinal: Int + get() = EmptySealedInterfaceSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val EmptySealedInterface.name: String + get() = EmptySealedInterfaceSealedEnum.nameOf(this) + +/** + * A list of all [EmptySealedInterface] objects. + */ +public val EmptySealedInterface.Companion.values: List + get() = EmptySealedInterfaceSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [EmptySealedInterface] + */ +public val EmptySealedInterface.Companion.sealedEnum: EmptySealedInterfaceSealedEnum + get() = EmptySealedInterfaceSealedEnum + +/** + * Returns the [EmptySealedInterface] object for the given [name]. + * + * If the given name doesn't correspond to any [EmptySealedInterface], an [IllegalArgumentException] + * will be thrown. + */ +public fun EmptySealedInterface.Companion.valueOf(name: String): EmptySealedInterface = + EmptySealedInterfaceSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/basic/OneObjectSealedClassTests.compilation generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/basic/OneObjectSealedClassTests.compilation generates correct code.approved new file mode 100644 index 00000000..8a33f7bc --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/basic/OneObjectSealedClassTests.compilation generates correct code.approved @@ -0,0 +1,105 @@ +package com.livefront.sealedenum.compilation.basic + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [OneObjectSealedClass] + */ +public enum class OneObjectSealedClassEnum() { + OneObjectSealedClass_FirstObject, +} + +/** + * The isomorphic [OneObjectSealedClassEnum] for [this]. + */ +public val OneObjectSealedClass.`enum`: OneObjectSealedClassEnum + get() = OneObjectSealedClassSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [OneObjectSealedClass] for [this]. + */ +public val OneObjectSealedClassEnum.sealedObject: OneObjectSealedClass + get() = OneObjectSealedClassSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [OneObjectSealedClass] + */ +public object OneObjectSealedClassSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + OneObjectSealedClass.FirstObject + ) + } + + + public override val enumClass: KClass + get() = OneObjectSealedClassEnum::class + + public override fun ordinalOf(obj: OneObjectSealedClass): Int = when (obj) { + is OneObjectSealedClass.FirstObject -> 0 + } + + public override fun nameOf(obj: OneObjectSealedClass): String = when (obj) { + is OneObjectSealedClass.FirstObject -> "OneObjectSealedClass_FirstObject" + } + + public override fun valueOf(name: String): OneObjectSealedClass = when (name) { + "OneObjectSealedClass_FirstObject" -> OneObjectSealedClass.FirstObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: OneObjectSealedClass): OneObjectSealedClassEnum = + when (obj) { + is OneObjectSealedClass.FirstObject -> + OneObjectSealedClassEnum.OneObjectSealedClass_FirstObject + } + + public override fun enumToSealedObject(`enum`: OneObjectSealedClassEnum): OneObjectSealedClass = + when (enum) { + OneObjectSealedClassEnum.OneObjectSealedClass_FirstObject -> + OneObjectSealedClass.FirstObject + } +} + +/** + * The index of [this] in the values list. + */ +public val OneObjectSealedClass.ordinal: Int + get() = OneObjectSealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val OneObjectSealedClass.name: String + get() = OneObjectSealedClassSealedEnum.nameOf(this) + +/** + * A list of all [OneObjectSealedClass] objects. + */ +public val OneObjectSealedClass.Companion.values: List + get() = OneObjectSealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [OneObjectSealedClass] + */ +public val OneObjectSealedClass.Companion.sealedEnum: OneObjectSealedClassSealedEnum + get() = OneObjectSealedClassSealedEnum + +/** + * Returns the [OneObjectSealedClass] object for the given [name]. + * + * If the given name doesn't correspond to any [OneObjectSealedClass], an [IllegalArgumentException] + * will be thrown. + */ +public fun OneObjectSealedClass.Companion.valueOf(name: String): OneObjectSealedClass = + OneObjectSealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/basic/OneObjectSealedInterfaceTests.compilation generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/basic/OneObjectSealedInterfaceTests.compilation generates correct code.approved new file mode 100644 index 00000000..d082d543 --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/basic/OneObjectSealedInterfaceTests.compilation generates correct code.approved @@ -0,0 +1,105 @@ +package com.livefront.sealedenum.compilation.basic + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [OneObjectSealedInterface] + */ +public enum class OneObjectSealedInterfaceEnum() { + OneObjectSealedInterface_FirstObject, +} + +/** + * The isomorphic [OneObjectSealedInterfaceEnum] for [this]. + */ +public val OneObjectSealedInterface.`enum`: OneObjectSealedInterfaceEnum + get() = OneObjectSealedInterfaceSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [OneObjectSealedInterface] for [this]. + */ +public val OneObjectSealedInterfaceEnum.sealedObject: OneObjectSealedInterface + get() = OneObjectSealedInterfaceSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [OneObjectSealedInterface] + */ +public object OneObjectSealedInterfaceSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + OneObjectSealedInterface.FirstObject + ) + } + + + public override val enumClass: KClass + get() = OneObjectSealedInterfaceEnum::class + + public override fun ordinalOf(obj: OneObjectSealedInterface): Int = when (obj) { + is OneObjectSealedInterface.FirstObject -> 0 + } + + public override fun nameOf(obj: OneObjectSealedInterface): String = when (obj) { + is OneObjectSealedInterface.FirstObject -> "OneObjectSealedInterface_FirstObject" + } + + public override fun valueOf(name: String): OneObjectSealedInterface = when (name) { + "OneObjectSealedInterface_FirstObject" -> OneObjectSealedInterface.FirstObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: OneObjectSealedInterface): + OneObjectSealedInterfaceEnum = when (obj) { + is OneObjectSealedInterface.FirstObject -> + OneObjectSealedInterfaceEnum.OneObjectSealedInterface_FirstObject + } + + public override fun enumToSealedObject(`enum`: OneObjectSealedInterfaceEnum): + OneObjectSealedInterface = when (enum) { + OneObjectSealedInterfaceEnum.OneObjectSealedInterface_FirstObject -> + OneObjectSealedInterface.FirstObject + } +} + +/** + * The index of [this] in the values list. + */ +public val OneObjectSealedInterface.ordinal: Int + get() = OneObjectSealedInterfaceSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val OneObjectSealedInterface.name: String + get() = OneObjectSealedInterfaceSealedEnum.nameOf(this) + +/** + * A list of all [OneObjectSealedInterface] objects. + */ +public val OneObjectSealedInterface.Companion.values: List + get() = OneObjectSealedInterfaceSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [OneObjectSealedInterface] + */ +public val OneObjectSealedInterface.Companion.sealedEnum: OneObjectSealedInterfaceSealedEnum + get() = OneObjectSealedInterfaceSealedEnum + +/** + * Returns the [OneObjectSealedInterface] object for the given [name]. + * + * If the given name doesn't correspond to any [OneObjectSealedInterface], an + * [IllegalArgumentException] will be thrown. + */ +public fun OneObjectSealedInterface.Companion.valueOf(name: String): OneObjectSealedInterface = + OneObjectSealedInterfaceSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/basic/TwoObjectSealedClassTests.compilation generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/basic/TwoObjectSealedClassTests.compilation generates correct code.approved new file mode 100644 index 00000000..f387ad6f --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/basic/TwoObjectSealedClassTests.compilation generates correct code.approved @@ -0,0 +1,114 @@ +package com.livefront.sealedenum.compilation.basic + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [TwoObjectSealedClass] + */ +public enum class TwoObjectSealedClassEnum() { + TwoObjectSealedClass_FirstObject, + TwoObjectSealedClass_SecondObject, +} + +/** + * The isomorphic [TwoObjectSealedClassEnum] for [this]. + */ +public val TwoObjectSealedClass.`enum`: TwoObjectSealedClassEnum + get() = TwoObjectSealedClassSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [TwoObjectSealedClass] for [this]. + */ +public val TwoObjectSealedClassEnum.sealedObject: TwoObjectSealedClass + get() = TwoObjectSealedClassSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [TwoObjectSealedClass] + */ +public object TwoObjectSealedClassSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + TwoObjectSealedClass.FirstObject, + TwoObjectSealedClass.SecondObject + ) + } + + + public override val enumClass: KClass + get() = TwoObjectSealedClassEnum::class + + public override fun ordinalOf(obj: TwoObjectSealedClass): Int = when (obj) { + is TwoObjectSealedClass.FirstObject -> 0 + is TwoObjectSealedClass.SecondObject -> 1 + } + + public override fun nameOf(obj: TwoObjectSealedClass): String = when (obj) { + is TwoObjectSealedClass.FirstObject -> "TwoObjectSealedClass_FirstObject" + is TwoObjectSealedClass.SecondObject -> "TwoObjectSealedClass_SecondObject" + } + + public override fun valueOf(name: String): TwoObjectSealedClass = when (name) { + "TwoObjectSealedClass_FirstObject" -> TwoObjectSealedClass.FirstObject + "TwoObjectSealedClass_SecondObject" -> TwoObjectSealedClass.SecondObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: TwoObjectSealedClass): TwoObjectSealedClassEnum = + when (obj) { + is TwoObjectSealedClass.FirstObject -> + TwoObjectSealedClassEnum.TwoObjectSealedClass_FirstObject + is TwoObjectSealedClass.SecondObject -> + TwoObjectSealedClassEnum.TwoObjectSealedClass_SecondObject + } + + public override fun enumToSealedObject(`enum`: TwoObjectSealedClassEnum): TwoObjectSealedClass = + when (enum) { + TwoObjectSealedClassEnum.TwoObjectSealedClass_FirstObject -> + TwoObjectSealedClass.FirstObject + TwoObjectSealedClassEnum.TwoObjectSealedClass_SecondObject -> + TwoObjectSealedClass.SecondObject + } +} + +/** + * The index of [this] in the values list. + */ +public val TwoObjectSealedClass.ordinal: Int + get() = TwoObjectSealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val TwoObjectSealedClass.name: String + get() = TwoObjectSealedClassSealedEnum.nameOf(this) + +/** + * A list of all [TwoObjectSealedClass] objects. + */ +public val TwoObjectSealedClass.Companion.values: List + get() = TwoObjectSealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [TwoObjectSealedClass] + */ +public val TwoObjectSealedClass.Companion.sealedEnum: TwoObjectSealedClassSealedEnum + get() = TwoObjectSealedClassSealedEnum + +/** + * Returns the [TwoObjectSealedClass] object for the given [name]. + * + * If the given name doesn't correspond to any [TwoObjectSealedClass], an [IllegalArgumentException] + * will be thrown. + */ +public fun TwoObjectSealedClass.Companion.valueOf(name: String): TwoObjectSealedClass = + TwoObjectSealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/basic/TwoObjectSealedInterfaceTests.compilation generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/basic/TwoObjectSealedInterfaceTests.compilation generates correct code.approved new file mode 100644 index 00000000..5e68ea07 --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/basic/TwoObjectSealedInterfaceTests.compilation generates correct code.approved @@ -0,0 +1,114 @@ +package com.livefront.sealedenum.compilation.basic + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [TwoObjectSealedInterface] + */ +public enum class TwoObjectSealedInterfaceEnum() { + TwoObjectSealedInterface_FirstObject, + TwoObjectSealedInterface_SecondObject, +} + +/** + * The isomorphic [TwoObjectSealedInterfaceEnum] for [this]. + */ +public val TwoObjectSealedInterface.`enum`: TwoObjectSealedInterfaceEnum + get() = TwoObjectSealedInterfaceSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [TwoObjectSealedInterface] for [this]. + */ +public val TwoObjectSealedInterfaceEnum.sealedObject: TwoObjectSealedInterface + get() = TwoObjectSealedInterfaceSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [TwoObjectSealedInterface] + */ +public object TwoObjectSealedInterfaceSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + TwoObjectSealedInterface.FirstObject, + TwoObjectSealedInterface.SecondObject + ) + } + + + public override val enumClass: KClass + get() = TwoObjectSealedInterfaceEnum::class + + public override fun ordinalOf(obj: TwoObjectSealedInterface): Int = when (obj) { + is TwoObjectSealedInterface.FirstObject -> 0 + is TwoObjectSealedInterface.SecondObject -> 1 + } + + public override fun nameOf(obj: TwoObjectSealedInterface): String = when (obj) { + is TwoObjectSealedInterface.FirstObject -> "TwoObjectSealedInterface_FirstObject" + is TwoObjectSealedInterface.SecondObject -> "TwoObjectSealedInterface_SecondObject" + } + + public override fun valueOf(name: String): TwoObjectSealedInterface = when (name) { + "TwoObjectSealedInterface_FirstObject" -> TwoObjectSealedInterface.FirstObject + "TwoObjectSealedInterface_SecondObject" -> TwoObjectSealedInterface.SecondObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: TwoObjectSealedInterface): + TwoObjectSealedInterfaceEnum = when (obj) { + is TwoObjectSealedInterface.FirstObject -> + TwoObjectSealedInterfaceEnum.TwoObjectSealedInterface_FirstObject + is TwoObjectSealedInterface.SecondObject -> + TwoObjectSealedInterfaceEnum.TwoObjectSealedInterface_SecondObject + } + + public override fun enumToSealedObject(`enum`: TwoObjectSealedInterfaceEnum): + TwoObjectSealedInterface = when (enum) { + TwoObjectSealedInterfaceEnum.TwoObjectSealedInterface_FirstObject -> + TwoObjectSealedInterface.FirstObject + TwoObjectSealedInterfaceEnum.TwoObjectSealedInterface_SecondObject -> + TwoObjectSealedInterface.SecondObject + } +} + +/** + * The index of [this] in the values list. + */ +public val TwoObjectSealedInterface.ordinal: Int + get() = TwoObjectSealedInterfaceSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val TwoObjectSealedInterface.name: String + get() = TwoObjectSealedInterfaceSealedEnum.nameOf(this) + +/** + * A list of all [TwoObjectSealedInterface] objects. + */ +public val TwoObjectSealedInterface.Companion.values: List + get() = TwoObjectSealedInterfaceSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [TwoObjectSealedInterface] + */ +public val TwoObjectSealedInterface.Companion.sealedEnum: TwoObjectSealedInterfaceSealedEnum + get() = TwoObjectSealedInterfaceSealedEnum + +/** + * Returns the [TwoObjectSealedInterface] object for the given [name]. + * + * If the given name doesn't correspond to any [TwoObjectSealedInterface], an + * [IllegalArgumentException] will be thrown. + */ +public fun TwoObjectSealedInterface.Companion.valueOf(name: String): TwoObjectSealedInterface = + TwoObjectSealedInterfaceSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/GenericSealedClassTests.compilation for limited type parameter generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/GenericSealedClassTests.compilation for limited type parameter generates correct code.approved new file mode 100644 index 00000000..4e029fa1 --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/GenericSealedClassTests.compilation for limited type parameter generates correct code.approved @@ -0,0 +1,122 @@ +package com.livefront.sealedenum.compilation.generics + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [LimitedTypeParameterSealedClass] + */ +public enum class LimitedTypeParameterSealedClassEnum() { + LimitedTypeParameterSealedClass_FirstObject, + LimitedTypeParameterSealedClass_SecondObject, +} + +/** + * The isomorphic [LimitedTypeParameterSealedClassEnum] for [this]. + */ +public val LimitedTypeParameterSealedClass<*, *>.`enum`: LimitedTypeParameterSealedClassEnum + get() = LimitedTypeParameterSealedClassSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [LimitedTypeParameterSealedClass] for [this]. + */ +public val LimitedTypeParameterSealedClassEnum.sealedObject: LimitedTypeParameterSealedClass<*, *> + get() = LimitedTypeParameterSealedClassSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [LimitedTypeParameterSealedClass] + */ +public object LimitedTypeParameterSealedClassSealedEnum : + SealedEnum>, + SealedEnumWithEnumProvider, LimitedTypeParameterSealedClassEnum>, + EnumForSealedEnumProvider, LimitedTypeParameterSealedClassEnum> + { + public override val values: List> by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + LimitedTypeParameterSealedClass.FirstObject, + LimitedTypeParameterSealedClass.SecondObject + ) + } + + + public override val enumClass: KClass + get() = LimitedTypeParameterSealedClassEnum::class + + public override fun ordinalOf(obj: LimitedTypeParameterSealedClass<*, *>): Int = when (obj) { + is LimitedTypeParameterSealedClass.FirstObject -> 0 + is LimitedTypeParameterSealedClass.SecondObject -> 1 + } + + public override fun nameOf(obj: LimitedTypeParameterSealedClass<*, *>): String = when (obj) { + is LimitedTypeParameterSealedClass.FirstObject -> + "LimitedTypeParameterSealedClass_FirstObject" + is LimitedTypeParameterSealedClass.SecondObject -> + "LimitedTypeParameterSealedClass_SecondObject" + } + + public override fun valueOf(name: String): LimitedTypeParameterSealedClass<*, *> = when (name) { + "LimitedTypeParameterSealedClass_FirstObject" -> LimitedTypeParameterSealedClass.FirstObject + "LimitedTypeParameterSealedClass_SecondObject" -> + LimitedTypeParameterSealedClass.SecondObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: LimitedTypeParameterSealedClass<*, *>): + LimitedTypeParameterSealedClassEnum = when (obj) { + is LimitedTypeParameterSealedClass.FirstObject -> + LimitedTypeParameterSealedClassEnum.LimitedTypeParameterSealedClass_FirstObject + is LimitedTypeParameterSealedClass.SecondObject -> + LimitedTypeParameterSealedClassEnum.LimitedTypeParameterSealedClass_SecondObject + } + + public override fun enumToSealedObject(`enum`: LimitedTypeParameterSealedClassEnum): + LimitedTypeParameterSealedClass<*, *> = when (enum) { + LimitedTypeParameterSealedClassEnum.LimitedTypeParameterSealedClass_FirstObject -> + LimitedTypeParameterSealedClass.FirstObject + LimitedTypeParameterSealedClassEnum.LimitedTypeParameterSealedClass_SecondObject -> + LimitedTypeParameterSealedClass.SecondObject + } +} + +/** + * The index of [this] in the values list. + */ +public val LimitedTypeParameterSealedClass<*, *>.ordinal: Int + get() = LimitedTypeParameterSealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val LimitedTypeParameterSealedClass<*, *>.name: String + get() = LimitedTypeParameterSealedClassSealedEnum.nameOf(this) + +/** + * A list of all [LimitedTypeParameterSealedClass] objects. + */ +public val LimitedTypeParameterSealedClass.LimitedType.values: + List> + get() = LimitedTypeParameterSealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [LimitedTypeParameterSealedClass] + */ +public val LimitedTypeParameterSealedClass.LimitedType.sealedEnum: + LimitedTypeParameterSealedClassSealedEnum + get() = LimitedTypeParameterSealedClassSealedEnum + +/** + * Returns the [LimitedTypeParameterSealedClass] object for the given [name]. + * + * If the given name doesn't correspond to any [LimitedTypeParameterSealedClass], an + * [IllegalArgumentException] will be thrown. + */ +public fun LimitedTypeParameterSealedClass.LimitedType.valueOf(name: String): + LimitedTypeParameterSealedClass<*, *> = + LimitedTypeParameterSealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/GenericSealedClassTests.compilation for multiple bounds sealed class generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/GenericSealedClassTests.compilation for multiple bounds sealed class generates correct code.approved new file mode 100644 index 00000000..36522d71 --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/GenericSealedClassTests.compilation for multiple bounds sealed class generates correct code.approved @@ -0,0 +1,105 @@ +package com.livefront.sealedenum.compilation.generics + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [MultipleBoundsSealedClass] + */ +public enum class MultipleBoundsSealedClassEnum() { + MultipleBoundsSealedClass_FirstObject, +} + +/** + * The isomorphic [MultipleBoundsSealedClassEnum] for [this]. + */ +public val MultipleBoundsSealedClass<*>.`enum`: MultipleBoundsSealedClassEnum + get() = MultipleBoundsSealedClassSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [MultipleBoundsSealedClass] for [this]. + */ +public val MultipleBoundsSealedClassEnum.sealedObject: MultipleBoundsSealedClass<*> + get() = MultipleBoundsSealedClassSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [MultipleBoundsSealedClass] + */ +public object MultipleBoundsSealedClassSealedEnum : SealedEnum>, + SealedEnumWithEnumProvider, MultipleBoundsSealedClassEnum>, + EnumForSealedEnumProvider, MultipleBoundsSealedClassEnum> { + public override val values: List> by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + MultipleBoundsSealedClass.FirstObject + ) + } + + + public override val enumClass: KClass + get() = MultipleBoundsSealedClassEnum::class + + public override fun ordinalOf(obj: MultipleBoundsSealedClass<*>): Int = when (obj) { + is MultipleBoundsSealedClass.FirstObject -> 0 + } + + public override fun nameOf(obj: MultipleBoundsSealedClass<*>): String = when (obj) { + is MultipleBoundsSealedClass.FirstObject -> "MultipleBoundsSealedClass_FirstObject" + } + + public override fun valueOf(name: String): MultipleBoundsSealedClass<*> = when (name) { + "MultipleBoundsSealedClass_FirstObject" -> MultipleBoundsSealedClass.FirstObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: MultipleBoundsSealedClass<*>): + MultipleBoundsSealedClassEnum = when (obj) { + is MultipleBoundsSealedClass.FirstObject -> + MultipleBoundsSealedClassEnum.MultipleBoundsSealedClass_FirstObject + } + + public override fun enumToSealedObject(`enum`: MultipleBoundsSealedClassEnum): + MultipleBoundsSealedClass<*> = when (enum) { + MultipleBoundsSealedClassEnum.MultipleBoundsSealedClass_FirstObject -> + MultipleBoundsSealedClass.FirstObject + } +} + +/** + * The index of [this] in the values list. + */ +public val MultipleBoundsSealedClass<*>.ordinal: Int + get() = MultipleBoundsSealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val MultipleBoundsSealedClass<*>.name: String + get() = MultipleBoundsSealedClassSealedEnum.nameOf(this) + +/** + * A list of all [MultipleBoundsSealedClass] objects. + */ +public val MultipleBoundsSealedClass.Companion.values: List> + get() = MultipleBoundsSealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [MultipleBoundsSealedClass] + */ +public val MultipleBoundsSealedClass.Companion.sealedEnum: MultipleBoundsSealedClassSealedEnum + get() = MultipleBoundsSealedClassSealedEnum + +/** + * Returns the [MultipleBoundsSealedClass] object for the given [name]. + * + * If the given name doesn't correspond to any [MultipleBoundsSealedClass], an + * [IllegalArgumentException] will be thrown. + */ +public fun MultipleBoundsSealedClass.Companion.valueOf(name: String): MultipleBoundsSealedClass<*> = + MultipleBoundsSealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/GenericSealedClassTests.compilation for one type parameter generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/GenericSealedClassTests.compilation for one type parameter generates correct code.approved new file mode 100644 index 00000000..02456492 --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/GenericSealedClassTests.compilation for one type parameter generates correct code.approved @@ -0,0 +1,123 @@ +package com.livefront.sealedenum.compilation.generics + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [OneTypeParameterSealedClass] + */ +public enum class OneTypeParameterSealedClassEnum() { + OneTypeParameterSealedClass_FirstObject, + OneTypeParameterSealedClass_SecondObject, + OneTypeParameterSealedClass_ThirdObject, +} + +/** + * The isomorphic [OneTypeParameterSealedClassEnum] for [this]. + */ +public val OneTypeParameterSealedClass<*>.`enum`: OneTypeParameterSealedClassEnum + get() = OneTypeParameterSealedClassSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [OneTypeParameterSealedClass] for [this]. + */ +public val OneTypeParameterSealedClassEnum.sealedObject: OneTypeParameterSealedClass<*> + get() = OneTypeParameterSealedClassSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [OneTypeParameterSealedClass] + */ +public object OneTypeParameterSealedClassSealedEnum : SealedEnum>, + SealedEnumWithEnumProvider, OneTypeParameterSealedClassEnum>, + EnumForSealedEnumProvider, OneTypeParameterSealedClassEnum> { + public override val values: List> by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + OneTypeParameterSealedClass.FirstObject, + OneTypeParameterSealedClass.SecondObject, + OneTypeParameterSealedClass.ThirdObject + ) + } + + + public override val enumClass: KClass + get() = OneTypeParameterSealedClassEnum::class + + public override fun ordinalOf(obj: OneTypeParameterSealedClass<*>): Int = when (obj) { + is OneTypeParameterSealedClass.FirstObject -> 0 + is OneTypeParameterSealedClass.SecondObject -> 1 + is OneTypeParameterSealedClass.ThirdObject -> 2 + } + + public override fun nameOf(obj: OneTypeParameterSealedClass<*>): String = when (obj) { + is OneTypeParameterSealedClass.FirstObject -> "OneTypeParameterSealedClass_FirstObject" + is OneTypeParameterSealedClass.SecondObject -> "OneTypeParameterSealedClass_SecondObject" + is OneTypeParameterSealedClass.ThirdObject -> "OneTypeParameterSealedClass_ThirdObject" + } + + public override fun valueOf(name: String): OneTypeParameterSealedClass<*> = when (name) { + "OneTypeParameterSealedClass_FirstObject" -> OneTypeParameterSealedClass.FirstObject + "OneTypeParameterSealedClass_SecondObject" -> OneTypeParameterSealedClass.SecondObject + "OneTypeParameterSealedClass_ThirdObject" -> OneTypeParameterSealedClass.ThirdObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: OneTypeParameterSealedClass<*>): + OneTypeParameterSealedClassEnum = when (obj) { + is OneTypeParameterSealedClass.FirstObject -> + OneTypeParameterSealedClassEnum.OneTypeParameterSealedClass_FirstObject + is OneTypeParameterSealedClass.SecondObject -> + OneTypeParameterSealedClassEnum.OneTypeParameterSealedClass_SecondObject + is OneTypeParameterSealedClass.ThirdObject -> + OneTypeParameterSealedClassEnum.OneTypeParameterSealedClass_ThirdObject + } + + public override fun enumToSealedObject(`enum`: OneTypeParameterSealedClassEnum): + OneTypeParameterSealedClass<*> = when (enum) { + OneTypeParameterSealedClassEnum.OneTypeParameterSealedClass_FirstObject -> + OneTypeParameterSealedClass.FirstObject + OneTypeParameterSealedClassEnum.OneTypeParameterSealedClass_SecondObject -> + OneTypeParameterSealedClass.SecondObject + OneTypeParameterSealedClassEnum.OneTypeParameterSealedClass_ThirdObject -> + OneTypeParameterSealedClass.ThirdObject + } +} + +/** + * The index of [this] in the values list. + */ +public val OneTypeParameterSealedClass<*>.ordinal: Int + get() = OneTypeParameterSealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val OneTypeParameterSealedClass<*>.name: String + get() = OneTypeParameterSealedClassSealedEnum.nameOf(this) + +/** + * A list of all [OneTypeParameterSealedClass] objects. + */ +public val OneTypeParameterSealedClass.OneType.values: List> + get() = OneTypeParameterSealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [OneTypeParameterSealedClass] + */ +public val OneTypeParameterSealedClass.OneType.sealedEnum: OneTypeParameterSealedClassSealedEnum + get() = OneTypeParameterSealedClassSealedEnum + +/** + * Returns the [OneTypeParameterSealedClass] object for the given [name]. + * + * If the given name doesn't correspond to any [OneTypeParameterSealedClass], an + * [IllegalArgumentException] will be thrown. + */ +public fun OneTypeParameterSealedClass.OneType.valueOf(name: String): OneTypeParameterSealedClass<*> + = OneTypeParameterSealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/GenericSealedClassTests.compilation for two type parameter generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/GenericSealedClassTests.compilation for two type parameter generates correct code.approved new file mode 100644 index 00000000..61f50f53 --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/GenericSealedClassTests.compilation for two type parameter generates correct code.approved @@ -0,0 +1,115 @@ +package com.livefront.sealedenum.compilation.generics + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [TwoTypeParameterSealedClass] + */ +public enum class TwoTypeParameterSealedClassEnum() { + TwoTypeParameterSealedClass_FirstObject, + TwoTypeParameterSealedClass_SecondObject, +} + +/** + * The isomorphic [TwoTypeParameterSealedClassEnum] for [this]. + */ +public val TwoTypeParameterSealedClass<*, *>.`enum`: TwoTypeParameterSealedClassEnum + get() = TwoTypeParameterSealedClassSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [TwoTypeParameterSealedClass] for [this]. + */ +public val TwoTypeParameterSealedClassEnum.sealedObject: TwoTypeParameterSealedClass<*, *> + get() = TwoTypeParameterSealedClassSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [TwoTypeParameterSealedClass] + */ +public object TwoTypeParameterSealedClassSealedEnum : SealedEnum>, + SealedEnumWithEnumProvider, TwoTypeParameterSealedClassEnum>, + EnumForSealedEnumProvider, TwoTypeParameterSealedClassEnum> + { + public override val values: List> by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + TwoTypeParameterSealedClass.FirstObject, + TwoTypeParameterSealedClass.SecondObject + ) + } + + + public override val enumClass: KClass + get() = TwoTypeParameterSealedClassEnum::class + + public override fun ordinalOf(obj: TwoTypeParameterSealedClass<*, *>): Int = when (obj) { + is TwoTypeParameterSealedClass.FirstObject -> 0 + is TwoTypeParameterSealedClass.SecondObject -> 1 + } + + public override fun nameOf(obj: TwoTypeParameterSealedClass<*, *>): String = when (obj) { + is TwoTypeParameterSealedClass.FirstObject -> "TwoTypeParameterSealedClass_FirstObject" + is TwoTypeParameterSealedClass.SecondObject -> "TwoTypeParameterSealedClass_SecondObject" + } + + public override fun valueOf(name: String): TwoTypeParameterSealedClass<*, *> = when (name) { + "TwoTypeParameterSealedClass_FirstObject" -> TwoTypeParameterSealedClass.FirstObject + "TwoTypeParameterSealedClass_SecondObject" -> TwoTypeParameterSealedClass.SecondObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: TwoTypeParameterSealedClass<*, *>): + TwoTypeParameterSealedClassEnum = when (obj) { + is TwoTypeParameterSealedClass.FirstObject -> + TwoTypeParameterSealedClassEnum.TwoTypeParameterSealedClass_FirstObject + is TwoTypeParameterSealedClass.SecondObject -> + TwoTypeParameterSealedClassEnum.TwoTypeParameterSealedClass_SecondObject + } + + public override fun enumToSealedObject(`enum`: TwoTypeParameterSealedClassEnum): + TwoTypeParameterSealedClass<*, *> = when (enum) { + TwoTypeParameterSealedClassEnum.TwoTypeParameterSealedClass_FirstObject -> + TwoTypeParameterSealedClass.FirstObject + TwoTypeParameterSealedClassEnum.TwoTypeParameterSealedClass_SecondObject -> + TwoTypeParameterSealedClass.SecondObject + } +} + +/** + * The index of [this] in the values list. + */ +public val TwoTypeParameterSealedClass<*, *>.ordinal: Int + get() = TwoTypeParameterSealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val TwoTypeParameterSealedClass<*, *>.name: String + get() = TwoTypeParameterSealedClassSealedEnum.nameOf(this) + +/** + * A list of all [TwoTypeParameterSealedClass] objects. + */ +public val TwoTypeParameterSealedClass.TwoType.values: List> + get() = TwoTypeParameterSealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [TwoTypeParameterSealedClass] + */ +public val TwoTypeParameterSealedClass.TwoType.sealedEnum: TwoTypeParameterSealedClassSealedEnum + get() = TwoTypeParameterSealedClassSealedEnum + +/** + * Returns the [TwoTypeParameterSealedClass] object for the given [name]. + * + * If the given name doesn't correspond to any [TwoTypeParameterSealedClass], an + * [IllegalArgumentException] will be thrown. + */ +public fun TwoTypeParameterSealedClass.TwoType.valueOf(name: String): + TwoTypeParameterSealedClass<*, *> = TwoTypeParameterSealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithAbstractBaseClassesTests.compilation for covariant type generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithAbstractBaseClassesTests.compilation for covariant type generates correct code.approved new file mode 100644 index 00000000..34e1b65f --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithAbstractBaseClassesTests.compilation for covariant type generates correct code.approved @@ -0,0 +1,107 @@ +package com.livefront.sealedenum.compilation.generics + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [SealedEnumWithAbstractBaseClassesCovariantType] + */ +public enum class SealedEnumWithAbstractBaseClassesCovariantTypeEnum( + sealedObject: SealedEnumWithAbstractBaseClassesCovariantType<*>, +) : BaseClassInterface3> by sealedObject + +/** + * The isomorphic [SealedEnumWithAbstractBaseClassesCovariantTypeEnum] for [this]. + */ +public val SealedEnumWithAbstractBaseClassesCovariantType<*>.`enum`: + SealedEnumWithAbstractBaseClassesCovariantTypeEnum + get() = SealedEnumWithAbstractBaseClassesCovariantTypeSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [SealedEnumWithAbstractBaseClassesCovariantType] for [this]. + */ +public val SealedEnumWithAbstractBaseClassesCovariantTypeEnum.sealedObject: + SealedEnumWithAbstractBaseClassesCovariantType<*> + get() = SealedEnumWithAbstractBaseClassesCovariantTypeSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class + * [SealedEnumWithAbstractBaseClassesCovariantType] + */ +public object SealedEnumWithAbstractBaseClassesCovariantTypeSealedEnum : + SealedEnum>, + SealedEnumWithEnumProvider, SealedEnumWithAbstractBaseClassesCovariantTypeEnum>, + EnumForSealedEnumProvider, SealedEnumWithAbstractBaseClassesCovariantTypeEnum> + { + public override val values: List> by lazy(mode + = LazyThreadSafetyMode.PUBLICATION) { + emptyList() + } + + + public override val enumClass: KClass + get() = SealedEnumWithAbstractBaseClassesCovariantTypeEnum::class + + public override fun ordinalOf(obj: SealedEnumWithAbstractBaseClassesCovariantType<*>): Int = + throw + AssertionError("Constructing a SealedEnumWithAbstractBaseClassesCovariantType is impossible, since it has no sealed subclasses") + + public override fun nameOf(obj: SealedEnumWithAbstractBaseClassesCovariantType<*>): String = + throw + AssertionError("Constructing a SealedEnumWithAbstractBaseClassesCovariantType is impossible, since it has no sealed subclasses") + + public override fun valueOf(name: String): SealedEnumWithAbstractBaseClassesCovariantType<*> = + throw IllegalArgumentException("""No sealed enum constant $name""") + + public override fun sealedObjectToEnum(obj: SealedEnumWithAbstractBaseClassesCovariantType<*>): + SealedEnumWithAbstractBaseClassesCovariantTypeEnum = throw + AssertionError("Constructing a SealedEnumWithAbstractBaseClassesCovariantType is impossible, since it has no sealed subclasses") + + public override + fun enumToSealedObject(`enum`: SealedEnumWithAbstractBaseClassesCovariantTypeEnum): + SealedEnumWithAbstractBaseClassesCovariantType<*> = throw + AssertionError("Constructing a SealedEnumWithAbstractBaseClassesCovariantType is impossible, since it has no sealed subclasses") +} + +/** + * The index of [this] in the values list. + */ +public val SealedEnumWithAbstractBaseClassesCovariantType<*>.ordinal: Int + get() = SealedEnumWithAbstractBaseClassesCovariantTypeSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val SealedEnumWithAbstractBaseClassesCovariantType<*>.name: String + get() = SealedEnumWithAbstractBaseClassesCovariantTypeSealedEnum.nameOf(this) + +/** + * A list of all [SealedEnumWithAbstractBaseClassesCovariantType] objects. + */ +public val SealedEnumWithAbstractBaseClassesCovariantType.Companion.values: + List> + get() = SealedEnumWithAbstractBaseClassesCovariantTypeSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class + * [SealedEnumWithAbstractBaseClassesCovariantType] + */ +public val SealedEnumWithAbstractBaseClassesCovariantType.Companion.sealedEnum: + SealedEnumWithAbstractBaseClassesCovariantTypeSealedEnum + get() = SealedEnumWithAbstractBaseClassesCovariantTypeSealedEnum + +/** + * Returns the [SealedEnumWithAbstractBaseClassesCovariantType] object for the given [name]. + * + * If the given name doesn't correspond to any [SealedEnumWithAbstractBaseClassesCovariantType], an + * [IllegalArgumentException] will be thrown. + */ +public fun SealedEnumWithAbstractBaseClassesCovariantType.Companion.valueOf(name: String): + SealedEnumWithAbstractBaseClassesCovariantType<*> = + SealedEnumWithAbstractBaseClassesCovariantTypeSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithAbstractBaseClassesTests.compilation for invariant type generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithAbstractBaseClassesTests.compilation for invariant type generates correct code.approved new file mode 100644 index 00000000..f232deda --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithAbstractBaseClassesTests.compilation for invariant type generates correct code.approved @@ -0,0 +1,103 @@ +package com.livefront.sealedenum.compilation.generics + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Any +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [SealedEnumWithAbstractBaseClasses] + */ +public enum class SealedEnumWithAbstractBaseClassesEnum( + sealedObject: SealedEnumWithAbstractBaseClasses, +) : BaseClassInterface2 by sealedObject, BaseClassInterface1> by + sealedObject + +/** + * The isomorphic [SealedEnumWithAbstractBaseClassesEnum] for [this]. + */ +public val SealedEnumWithAbstractBaseClasses.`enum`: SealedEnumWithAbstractBaseClassesEnum + get() = SealedEnumWithAbstractBaseClassesSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [SealedEnumWithAbstractBaseClasses] for [this]. + */ +public val SealedEnumWithAbstractBaseClassesEnum.sealedObject: SealedEnumWithAbstractBaseClasses + get() = SealedEnumWithAbstractBaseClassesSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [SealedEnumWithAbstractBaseClasses] + */ +public object SealedEnumWithAbstractBaseClassesSealedEnum : + SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider + { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + emptyList() + } + + + public override val enumClass: KClass + get() = SealedEnumWithAbstractBaseClassesEnum::class + + public override fun ordinalOf(obj: SealedEnumWithAbstractBaseClasses): Int = throw + AssertionError("Constructing a SealedEnumWithAbstractBaseClasses is impossible, since it has no sealed subclasses") + + public override fun nameOf(obj: SealedEnumWithAbstractBaseClasses): String = throw + AssertionError("Constructing a SealedEnumWithAbstractBaseClasses is impossible, since it has no sealed subclasses") + + public override fun valueOf(name: String): SealedEnumWithAbstractBaseClasses = throw + IllegalArgumentException("""No sealed enum constant $name""") + + public override fun sealedObjectToEnum(obj: SealedEnumWithAbstractBaseClasses): + SealedEnumWithAbstractBaseClassesEnum = throw + AssertionError("Constructing a SealedEnumWithAbstractBaseClasses is impossible, since it has no sealed subclasses") + + public override fun enumToSealedObject(`enum`: SealedEnumWithAbstractBaseClassesEnum): + SealedEnumWithAbstractBaseClasses = throw + AssertionError("Constructing a SealedEnumWithAbstractBaseClasses is impossible, since it has no sealed subclasses") +} + +/** + * The index of [this] in the values list. + */ +public val SealedEnumWithAbstractBaseClasses.ordinal: Int + get() = SealedEnumWithAbstractBaseClassesSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val SealedEnumWithAbstractBaseClasses.name: String + get() = SealedEnumWithAbstractBaseClassesSealedEnum.nameOf(this) + +/** + * A list of all [SealedEnumWithAbstractBaseClasses] objects. + */ +public val SealedEnumWithAbstractBaseClasses.Companion.values: + List + get() = SealedEnumWithAbstractBaseClassesSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class + * [SealedEnumWithAbstractBaseClasses] + */ +public val SealedEnumWithAbstractBaseClasses.Companion.sealedEnum: + SealedEnumWithAbstractBaseClassesSealedEnum + get() = SealedEnumWithAbstractBaseClassesSealedEnum + +/** + * Returns the [SealedEnumWithAbstractBaseClasses] object for the given [name]. + * + * If the given name doesn't correspond to any [SealedEnumWithAbstractBaseClasses], an + * [IllegalArgumentException] will be thrown. + */ +public fun SealedEnumWithAbstractBaseClasses.Companion.valueOf(name: String): + SealedEnumWithAbstractBaseClasses = + SealedEnumWithAbstractBaseClassesSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithInterfacesTests.compilation for empty sealed class generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithInterfacesTests.compilation for empty sealed class generates correct code.approved new file mode 100644 index 00000000..730e4bc9 --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithInterfacesTests.compilation for empty sealed class generates correct code.approved @@ -0,0 +1,97 @@ +package com.livefront.sealedenum.compilation.generics + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [EmptySealedClassWithInterface] + */ +public enum class EmptySealedClassWithInterfaceEnum( + sealedObject: EmptySealedClassWithInterface, +) : TestInterface by sealedObject + +/** + * The isomorphic [EmptySealedClassWithInterfaceEnum] for [this]. + */ +public val EmptySealedClassWithInterface.`enum`: EmptySealedClassWithInterfaceEnum + get() = EmptySealedClassWithInterfaceSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [EmptySealedClassWithInterface] for [this]. + */ +public val EmptySealedClassWithInterfaceEnum.sealedObject: EmptySealedClassWithInterface + get() = EmptySealedClassWithInterfaceSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [EmptySealedClassWithInterface] + */ +public object EmptySealedClassWithInterfaceSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider + { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + emptyList() + } + + + public override val enumClass: KClass + get() = EmptySealedClassWithInterfaceEnum::class + + public override fun ordinalOf(obj: EmptySealedClassWithInterface): Int = throw + AssertionError("Constructing a EmptySealedClassWithInterface is impossible, since it has no sealed subclasses") + + public override fun nameOf(obj: EmptySealedClassWithInterface): String = throw + AssertionError("Constructing a EmptySealedClassWithInterface is impossible, since it has no sealed subclasses") + + public override fun valueOf(name: String): EmptySealedClassWithInterface = throw + IllegalArgumentException("""No sealed enum constant $name""") + + public override fun sealedObjectToEnum(obj: EmptySealedClassWithInterface): + EmptySealedClassWithInterfaceEnum = throw + AssertionError("Constructing a EmptySealedClassWithInterface is impossible, since it has no sealed subclasses") + + public override fun enumToSealedObject(`enum`: EmptySealedClassWithInterfaceEnum): + EmptySealedClassWithInterface = throw + AssertionError("Constructing a EmptySealedClassWithInterface is impossible, since it has no sealed subclasses") +} + +/** + * The index of [this] in the values list. + */ +public val EmptySealedClassWithInterface.ordinal: Int + get() = EmptySealedClassWithInterfaceSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val EmptySealedClassWithInterface.name: String + get() = EmptySealedClassWithInterfaceSealedEnum.nameOf(this) + +/** + * A list of all [EmptySealedClassWithInterface] objects. + */ +public val EmptySealedClassWithInterface.Companion.values: List + get() = EmptySealedClassWithInterfaceSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [EmptySealedClassWithInterface] + */ +public val EmptySealedClassWithInterface.Companion.sealedEnum: + EmptySealedClassWithInterfaceSealedEnum + get() = EmptySealedClassWithInterfaceSealedEnum + +/** + * Returns the [EmptySealedClassWithInterface] object for the given [name]. + * + * If the given name doesn't correspond to any [EmptySealedClassWithInterface], an + * [IllegalArgumentException] will be thrown. + */ +public fun EmptySealedClassWithInterface.Companion.valueOf(name: String): + EmptySealedClassWithInterface = EmptySealedClassWithInterfaceSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithInterfacesTests.compilation for one object sealed class generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithInterfacesTests.compilation for one object sealed class generates correct code.approved new file mode 100644 index 00000000..f261136a --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithInterfacesTests.compilation for one object sealed class generates correct code.approved @@ -0,0 +1,115 @@ +package com.livefront.sealedenum.compilation.generics + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [OneObjectSealedClassWithInterface] + */ +public enum class OneObjectSealedClassWithInterfaceEnum( + sealedObject: OneObjectSealedClassWithInterface, +) : TestInterface by sealedObject { + OneObjectSealedClassWithInterface_FirstObject(com.livefront.sealedenum.compilation.generics.OneObjectSealedClassWithInterface.FirstObject), +} + +/** + * The isomorphic [OneObjectSealedClassWithInterfaceEnum] for [this]. + */ +public val OneObjectSealedClassWithInterface.`enum`: OneObjectSealedClassWithInterfaceEnum + get() = OneObjectSealedClassWithInterfaceSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [OneObjectSealedClassWithInterface] for [this]. + */ +public val OneObjectSealedClassWithInterfaceEnum.sealedObject: OneObjectSealedClassWithInterface + get() = OneObjectSealedClassWithInterfaceSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [OneObjectSealedClassWithInterface] + */ +public object OneObjectSealedClassWithInterfaceSealedEnum : + SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider + { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + OneObjectSealedClassWithInterface.FirstObject + ) + } + + + public override val enumClass: KClass + get() = OneObjectSealedClassWithInterfaceEnum::class + + public override fun ordinalOf(obj: OneObjectSealedClassWithInterface): Int = when (obj) { + is OneObjectSealedClassWithInterface.FirstObject -> 0 + } + + public override fun nameOf(obj: OneObjectSealedClassWithInterface): String = when (obj) { + is OneObjectSealedClassWithInterface.FirstObject -> + "OneObjectSealedClassWithInterface_FirstObject" + } + + public override fun valueOf(name: String): OneObjectSealedClassWithInterface = when (name) { + "OneObjectSealedClassWithInterface_FirstObject" -> + OneObjectSealedClassWithInterface.FirstObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: OneObjectSealedClassWithInterface): + OneObjectSealedClassWithInterfaceEnum = when (obj) { + is OneObjectSealedClassWithInterface.FirstObject -> + OneObjectSealedClassWithInterfaceEnum.OneObjectSealedClassWithInterface_FirstObject + } + + public override fun enumToSealedObject(`enum`: OneObjectSealedClassWithInterfaceEnum): + OneObjectSealedClassWithInterface = when (enum) { + OneObjectSealedClassWithInterfaceEnum.OneObjectSealedClassWithInterface_FirstObject -> + OneObjectSealedClassWithInterface.FirstObject + } +} + +/** + * The index of [this] in the values list. + */ +public val OneObjectSealedClassWithInterface.ordinal: Int + get() = OneObjectSealedClassWithInterfaceSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val OneObjectSealedClassWithInterface.name: String + get() = OneObjectSealedClassWithInterfaceSealedEnum.nameOf(this) + +/** + * A list of all [OneObjectSealedClassWithInterface] objects. + */ +public val OneObjectSealedClassWithInterface.Companion.values: + List + get() = OneObjectSealedClassWithInterfaceSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class + * [OneObjectSealedClassWithInterface] + */ +public val OneObjectSealedClassWithInterface.Companion.sealedEnum: + OneObjectSealedClassWithInterfaceSealedEnum + get() = OneObjectSealedClassWithInterfaceSealedEnum + +/** + * Returns the [OneObjectSealedClassWithInterface] object for the given [name]. + * + * If the given name doesn't correspond to any [OneObjectSealedClassWithInterface], an + * [IllegalArgumentException] will be thrown. + */ +public fun OneObjectSealedClassWithInterface.Companion.valueOf(name: String): + OneObjectSealedClassWithInterface = + OneObjectSealedClassWithInterfaceSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithInterfacesTests.compilation for sealed class with getter interface generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithInterfacesTests.compilation for sealed class with getter interface generates correct code.approved new file mode 100644 index 00000000..5a50bd5f --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithInterfacesTests.compilation for sealed class with getter interface generates correct code.approved @@ -0,0 +1,110 @@ +package com.livefront.sealedenum.compilation.generics + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [SealedClassWithGetterInterface] + */ +public enum class SealedClassWithGetterInterfaceEnum( + sealedObject: SealedClassWithGetterInterface, +) : TestGetterInterface by sealedObject { + SealedClassWithGetterInterface_FirstObject(com.livefront.sealedenum.compilation.generics.SealedClassWithGetterInterface.FirstObject), +} + +/** + * The isomorphic [SealedClassWithGetterInterfaceEnum] for [this]. + */ +public val SealedClassWithGetterInterface.`enum`: SealedClassWithGetterInterfaceEnum + get() = SealedClassWithGetterInterfaceSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [SealedClassWithGetterInterface] for [this]. + */ +public val SealedClassWithGetterInterfaceEnum.sealedObject: SealedClassWithGetterInterface + get() = SealedClassWithGetterInterfaceSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [SealedClassWithGetterInterface] + */ +public object SealedClassWithGetterInterfaceSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider + { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + SealedClassWithGetterInterface.FirstObject + ) + } + + + public override val enumClass: KClass + get() = SealedClassWithGetterInterfaceEnum::class + + public override fun ordinalOf(obj: SealedClassWithGetterInterface): Int = when (obj) { + is SealedClassWithGetterInterface.FirstObject -> 0 + } + + public override fun nameOf(obj: SealedClassWithGetterInterface): String = when (obj) { + is SealedClassWithGetterInterface.FirstObject -> + "SealedClassWithGetterInterface_FirstObject" + } + + public override fun valueOf(name: String): SealedClassWithGetterInterface = when (name) { + "SealedClassWithGetterInterface_FirstObject" -> SealedClassWithGetterInterface.FirstObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: SealedClassWithGetterInterface): + SealedClassWithGetterInterfaceEnum = when (obj) { + is SealedClassWithGetterInterface.FirstObject -> + SealedClassWithGetterInterfaceEnum.SealedClassWithGetterInterface_FirstObject + } + + public override fun enumToSealedObject(`enum`: SealedClassWithGetterInterfaceEnum): + SealedClassWithGetterInterface = when (enum) { + SealedClassWithGetterInterfaceEnum.SealedClassWithGetterInterface_FirstObject -> + SealedClassWithGetterInterface.FirstObject + } +} + +/** + * The index of [this] in the values list. + */ +public val SealedClassWithGetterInterface.ordinal: Int + get() = SealedClassWithGetterInterfaceSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val SealedClassWithGetterInterface.name: String + get() = SealedClassWithGetterInterfaceSealedEnum.nameOf(this) + +/** + * A list of all [SealedClassWithGetterInterface] objects. + */ +public val SealedClassWithGetterInterface.Companion.values: List + get() = SealedClassWithGetterInterfaceSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [SealedClassWithGetterInterface] + */ +public val SealedClassWithGetterInterface.Companion.sealedEnum: + SealedClassWithGetterInterfaceSealedEnum + get() = SealedClassWithGetterInterfaceSealedEnum + +/** + * Returns the [SealedClassWithGetterInterface] object for the given [name]. + * + * If the given name doesn't correspond to any [SealedClassWithGetterInterface], an + * [IllegalArgumentException] will be thrown. + */ +public fun SealedClassWithGetterInterface.Companion.valueOf(name: String): + SealedClassWithGetterInterface = SealedClassWithGetterInterfaceSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithInterfacesTests.compilation for two object sealed class generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithInterfacesTests.compilation for two object sealed class generates correct code.approved new file mode 100644 index 00000000..0dc39bae --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithInterfacesTests.compilation for two object sealed class generates correct code.approved @@ -0,0 +1,132 @@ +package com.livefront.sealedenum.compilation.generics + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [TwoObjectSealedClassWithGenericInterface] + */ +public enum class TwoObjectSealedClassWithGenericInterfaceEnum( + sealedObject: TwoObjectSealedClassWithGenericInterface, +) : TestGenericInterface by sealedObject { + TwoObjectSealedClassWithGenericInterface_FirstObject(com.livefront.sealedenum.compilation.generics.TwoObjectSealedClassWithGenericInterface.FirstObject), + TwoObjectSealedClassWithGenericInterface_SecondObject(com.livefront.sealedenum.compilation.generics.TwoObjectSealedClassWithGenericInterface.SecondObject), +} + +/** + * The isomorphic [TwoObjectSealedClassWithGenericInterfaceEnum] for [this]. + */ +public val TwoObjectSealedClassWithGenericInterface.`enum`: + TwoObjectSealedClassWithGenericInterfaceEnum + get() = TwoObjectSealedClassWithGenericInterfaceSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [TwoObjectSealedClassWithGenericInterface] for [this]. + */ +public val TwoObjectSealedClassWithGenericInterfaceEnum.sealedObject: + TwoObjectSealedClassWithGenericInterface + get() = TwoObjectSealedClassWithGenericInterfaceSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [TwoObjectSealedClassWithGenericInterface] + */ +public object TwoObjectSealedClassWithGenericInterfaceSealedEnum : + SealedEnum>, + SealedEnumWithEnumProvider, TwoObjectSealedClassWithGenericInterfaceEnum>, + EnumForSealedEnumProvider, TwoObjectSealedClassWithGenericInterfaceEnum> + { + public override val values: List> by + lazy(mode = LazyThreadSafetyMode.PUBLICATION) { + listOf( + TwoObjectSealedClassWithGenericInterface.FirstObject, + TwoObjectSealedClassWithGenericInterface.SecondObject + ) + } + + + public override val enumClass: KClass + get() = TwoObjectSealedClassWithGenericInterfaceEnum::class + + public override fun ordinalOf(obj: TwoObjectSealedClassWithGenericInterface): Int + = when (obj) { + is TwoObjectSealedClassWithGenericInterface.FirstObject -> 0 + is TwoObjectSealedClassWithGenericInterface.SecondObject -> 1 + } + + public override fun nameOf(obj: TwoObjectSealedClassWithGenericInterface): String + = when (obj) { + is TwoObjectSealedClassWithGenericInterface.FirstObject -> + "TwoObjectSealedClassWithGenericInterface_FirstObject" + is TwoObjectSealedClassWithGenericInterface.SecondObject -> + "TwoObjectSealedClassWithGenericInterface_SecondObject" + } + + public override fun valueOf(name: String): + TwoObjectSealedClassWithGenericInterface = when (name) { + "TwoObjectSealedClassWithGenericInterface_FirstObject" -> + TwoObjectSealedClassWithGenericInterface.FirstObject + "TwoObjectSealedClassWithGenericInterface_SecondObject" -> + TwoObjectSealedClassWithGenericInterface.SecondObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override + fun sealedObjectToEnum(obj: TwoObjectSealedClassWithGenericInterface): + TwoObjectSealedClassWithGenericInterfaceEnum = when (obj) { + is TwoObjectSealedClassWithGenericInterface.FirstObject -> + TwoObjectSealedClassWithGenericInterfaceEnum.TwoObjectSealedClassWithGenericInterface_FirstObject + is TwoObjectSealedClassWithGenericInterface.SecondObject -> + TwoObjectSealedClassWithGenericInterfaceEnum.TwoObjectSealedClassWithGenericInterface_SecondObject + } + + public override fun enumToSealedObject(`enum`: TwoObjectSealedClassWithGenericInterfaceEnum): + TwoObjectSealedClassWithGenericInterface = when (enum) { + TwoObjectSealedClassWithGenericInterfaceEnum.TwoObjectSealedClassWithGenericInterface_FirstObject -> + TwoObjectSealedClassWithGenericInterface.FirstObject + TwoObjectSealedClassWithGenericInterfaceEnum.TwoObjectSealedClassWithGenericInterface_SecondObject -> + TwoObjectSealedClassWithGenericInterface.SecondObject + } +} + +/** + * The index of [this] in the values list. + */ +public val TwoObjectSealedClassWithGenericInterface.ordinal: Int + get() = TwoObjectSealedClassWithGenericInterfaceSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val TwoObjectSealedClassWithGenericInterface.name: String + get() = TwoObjectSealedClassWithGenericInterfaceSealedEnum.nameOf(this) + +/** + * A list of all [TwoObjectSealedClassWithGenericInterface] objects. + */ +public val TwoObjectSealedClassWithGenericInterface.Companion.values: + List> + get() = TwoObjectSealedClassWithGenericInterfaceSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class + * [TwoObjectSealedClassWithGenericInterface] + */ +public val TwoObjectSealedClassWithGenericInterface.Companion.sealedEnum: + TwoObjectSealedClassWithGenericInterfaceSealedEnum + get() = TwoObjectSealedClassWithGenericInterfaceSealedEnum + +/** + * Returns the [TwoObjectSealedClassWithGenericInterface] object for the given [name]. + * + * If the given name doesn't correspond to any [TwoObjectSealedClassWithGenericInterface], an + * [IllegalArgumentException] will be thrown. + */ +public fun TwoObjectSealedClassWithGenericInterface.Companion.valueOf(name: String): + TwoObjectSealedClassWithGenericInterface = + TwoObjectSealedClassWithGenericInterfaceSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for first hierarchy A generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for first hierarchy A generates correct code.approved new file mode 100644 index 00000000..f8dfb5d3 --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for first hierarchy A generates correct code.approved @@ -0,0 +1,103 @@ +package com.livefront.sealedenum.compilation.hierarchy + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [FirstClassHierarchy.A] + */ +public enum class FirstClassHierarchy_AEnum() { + FirstClassHierarchy_A_B_C, +} + +/** + * The isomorphic [FirstClassHierarchy_AEnum] for [this]. + */ +public val FirstClassHierarchy.A.`enum`: FirstClassHierarchy_AEnum + get() = FirstClassHierarchy_ASealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [FirstClassHierarchy.A] for [this]. + */ +public val FirstClassHierarchy_AEnum.sealedObject: FirstClassHierarchy.A + get() = FirstClassHierarchy_ASealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [FirstClassHierarchy.A] + */ +public object FirstClassHierarchy_ASealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + FirstClassHierarchy.A.B.C + ) + } + + + public override val enumClass: KClass + get() = FirstClassHierarchy_AEnum::class + + public override fun ordinalOf(obj: FirstClassHierarchy.A): Int = when (obj) { + is FirstClassHierarchy.A.B.C -> 0 + } + + public override fun nameOf(obj: FirstClassHierarchy.A): String = when (obj) { + is FirstClassHierarchy.A.B.C -> "FirstClassHierarchy_A_B_C" + } + + public override fun valueOf(name: String): FirstClassHierarchy.A = when (name) { + "FirstClassHierarchy_A_B_C" -> FirstClassHierarchy.A.B.C + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: FirstClassHierarchy.A): FirstClassHierarchy_AEnum = + when (obj) { + is FirstClassHierarchy.A.B.C -> FirstClassHierarchy_AEnum.FirstClassHierarchy_A_B_C + } + + public override fun enumToSealedObject(`enum`: FirstClassHierarchy_AEnum): FirstClassHierarchy.A + = when (enum) { + FirstClassHierarchy_AEnum.FirstClassHierarchy_A_B_C -> FirstClassHierarchy.A.B.C + } +} + +/** + * The index of [this] in the values list. + */ +public val FirstClassHierarchy.A.ordinal: Int + get() = FirstClassHierarchy_ASealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val FirstClassHierarchy.A.name: String + get() = FirstClassHierarchy_ASealedEnum.nameOf(this) + +/** + * A list of all [FirstClassHierarchy.A] objects. + */ +public val FirstClassHierarchy.A.Companion.values: List + get() = FirstClassHierarchy_ASealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [FirstClassHierarchy.A] + */ +public val FirstClassHierarchy.A.Companion.sealedEnum: FirstClassHierarchy_ASealedEnum + get() = FirstClassHierarchy_ASealedEnum + +/** + * Returns the [FirstClassHierarchy.A] object for the given [name]. + * + * If the given name doesn't correspond to any [FirstClassHierarchy.A], an + * [IllegalArgumentException] will be thrown. + */ +public fun FirstClassHierarchy.A.Companion.valueOf(name: String): FirstClassHierarchy.A = + FirstClassHierarchy_ASealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for first hierarchy B generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for first hierarchy B generates correct code.approved new file mode 100644 index 00000000..9bfd16fe --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for first hierarchy B generates correct code.approved @@ -0,0 +1,103 @@ +package com.livefront.sealedenum.compilation.hierarchy + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [FirstClassHierarchy.A.B] + */ +public enum class FirstClassHierarchy_A_BEnum() { + FirstClassHierarchy_A_B_C, +} + +/** + * The isomorphic [FirstClassHierarchy_A_BEnum] for [this]. + */ +public val FirstClassHierarchy.A.B.`enum`: FirstClassHierarchy_A_BEnum + get() = FirstClassHierarchy_A_BSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [FirstClassHierarchy.A.B] for [this]. + */ +public val FirstClassHierarchy_A_BEnum.sealedObject: FirstClassHierarchy.A.B + get() = FirstClassHierarchy_A_BSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [FirstClassHierarchy.A.B] + */ +public object FirstClassHierarchy_A_BSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + FirstClassHierarchy.A.B.C + ) + } + + + public override val enumClass: KClass + get() = FirstClassHierarchy_A_BEnum::class + + public override fun ordinalOf(obj: FirstClassHierarchy.A.B): Int = when (obj) { + is FirstClassHierarchy.A.B.C -> 0 + } + + public override fun nameOf(obj: FirstClassHierarchy.A.B): String = when (obj) { + is FirstClassHierarchy.A.B.C -> "FirstClassHierarchy_A_B_C" + } + + public override fun valueOf(name: String): FirstClassHierarchy.A.B = when (name) { + "FirstClassHierarchy_A_B_C" -> FirstClassHierarchy.A.B.C + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: FirstClassHierarchy.A.B): + FirstClassHierarchy_A_BEnum = when (obj) { + is FirstClassHierarchy.A.B.C -> FirstClassHierarchy_A_BEnum.FirstClassHierarchy_A_B_C + } + + public override fun enumToSealedObject(`enum`: FirstClassHierarchy_A_BEnum): + FirstClassHierarchy.A.B = when (enum) { + FirstClassHierarchy_A_BEnum.FirstClassHierarchy_A_B_C -> FirstClassHierarchy.A.B.C + } +} + +/** + * The index of [this] in the values list. + */ +public val FirstClassHierarchy.A.B.ordinal: Int + get() = FirstClassHierarchy_A_BSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val FirstClassHierarchy.A.B.name: String + get() = FirstClassHierarchy_A_BSealedEnum.nameOf(this) + +/** + * A list of all [FirstClassHierarchy.A.B] objects. + */ +public val FirstClassHierarchy.A.B.Companion.values: List + get() = FirstClassHierarchy_A_BSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [FirstClassHierarchy.A.B] + */ +public val FirstClassHierarchy.A.B.Companion.sealedEnum: FirstClassHierarchy_A_BSealedEnum + get() = FirstClassHierarchy_A_BSealedEnum + +/** + * Returns the [FirstClassHierarchy.A.B] object for the given [name]. + * + * If the given name doesn't correspond to any [FirstClassHierarchy.A.B], an + * [IllegalArgumentException] will be thrown. + */ +public fun FirstClassHierarchy.A.B.Companion.valueOf(name: String): FirstClassHierarchy.A.B = + FirstClassHierarchy_A_BSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for second hierarchy Q generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for second hierarchy Q generates correct code.approved new file mode 100644 index 00000000..1dcd3819 --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for second hierarchy Q generates correct code.approved @@ -0,0 +1,66 @@ +package com.livefront.sealedenum.compilation.hierarchy + +import com.livefront.sealedenum.SealedEnum +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List + +/** + * An implementation of [SealedEnum] for the sealed class [SecondClassHierarchy.Z.Q] + */ +public object SecondClassHierarchy_Z_QSealedEnum : SealedEnum { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + SecondClassHierarchy.Z.Q.P + ) + } + + + public override fun ordinalOf(obj: SecondClassHierarchy.Z.Q): Int = when (obj) { + is SecondClassHierarchy.Z.Q.P -> 0 + } + + public override fun nameOf(obj: SecondClassHierarchy.Z.Q): String = when (obj) { + is SecondClassHierarchy.Z.Q.P -> "SecondClassHierarchy_Z_Q_P" + } + + public override fun valueOf(name: String): SecondClassHierarchy.Z.Q = when (name) { + "SecondClassHierarchy_Z_Q_P" -> SecondClassHierarchy.Z.Q.P + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } +} + +/** + * The index of [this] in the values list. + */ +public val SecondClassHierarchy.Z.Q.ordinal: Int + get() = SecondClassHierarchy_Z_QSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val SecondClassHierarchy.Z.Q.name: String + get() = SecondClassHierarchy_Z_QSealedEnum.nameOf(this) + +/** + * A list of all [SecondClassHierarchy.Z.Q] objects. + */ +public val SecondClassHierarchy.Z.Q.Companion.values: List + get() = SecondClassHierarchy_Z_QSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [SecondClassHierarchy.Z.Q] + */ +public val SecondClassHierarchy.Z.Q.Companion.sealedEnum: SecondClassHierarchy_Z_QSealedEnum + get() = SecondClassHierarchy_Z_QSealedEnum + +/** + * Returns the [SecondClassHierarchy.Z.Q] object for the given [name]. + * + * If the given name doesn't correspond to any [SecondClassHierarchy.Z.Q], an + * [IllegalArgumentException] will be thrown. + */ +public fun SecondClassHierarchy.Z.Q.Companion.valueOf(name: String): SecondClassHierarchy.Z.Q = + SecondClassHierarchy_Z_QSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for second hierarchy S generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for second hierarchy S generates correct code.approved new file mode 100644 index 00000000..5a74be38 --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for second hierarchy S generates correct code.approved @@ -0,0 +1,66 @@ +package com.livefront.sealedenum.compilation.hierarchy + +import com.livefront.sealedenum.SealedEnum +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List + +/** + * An implementation of [SealedEnum] for the sealed class [SecondClassHierarchy.Z.X.S] + */ +public object SecondClassHierarchy_Z_X_SSealedEnum : SealedEnum { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + SecondClassHierarchy.Z.X.S.R + ) + } + + + public override fun ordinalOf(obj: SecondClassHierarchy.Z.X.S): Int = when (obj) { + is SecondClassHierarchy.Z.X.S.R -> 0 + } + + public override fun nameOf(obj: SecondClassHierarchy.Z.X.S): String = when (obj) { + is SecondClassHierarchy.Z.X.S.R -> "SecondClassHierarchy_Z_X_S_R" + } + + public override fun valueOf(name: String): SecondClassHierarchy.Z.X.S = when (name) { + "SecondClassHierarchy_Z_X_S_R" -> SecondClassHierarchy.Z.X.S.R + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } +} + +/** + * The index of [this] in the values list. + */ +public val SecondClassHierarchy.Z.X.S.ordinal: Int + get() = SecondClassHierarchy_Z_X_SSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val SecondClassHierarchy.Z.X.S.name: String + get() = SecondClassHierarchy_Z_X_SSealedEnum.nameOf(this) + +/** + * A list of all [SecondClassHierarchy.Z.X.S] objects. + */ +public val SecondClassHierarchy.Z.X.S.Companion.values: List + get() = SecondClassHierarchy_Z_X_SSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [SecondClassHierarchy.Z.X.S] + */ +public val SecondClassHierarchy.Z.X.S.Companion.sealedEnum: SecondClassHierarchy_Z_X_SSealedEnum + get() = SecondClassHierarchy_Z_X_SSealedEnum + +/** + * Returns the [SecondClassHierarchy.Z.X.S] object for the given [name]. + * + * If the given name doesn't correspond to any [SecondClassHierarchy.Z.X.S], an + * [IllegalArgumentException] will be thrown. + */ +public fun SecondClassHierarchy.Z.X.S.Companion.valueOf(name: String): SecondClassHierarchy.Z.X.S = + SecondClassHierarchy_Z_X_SSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for second hierarchy U generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for second hierarchy U generates correct code.approved new file mode 100644 index 00000000..166e0908 --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for second hierarchy U generates correct code.approved @@ -0,0 +1,66 @@ +package com.livefront.sealedenum.compilation.hierarchy + +import com.livefront.sealedenum.SealedEnum +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List + +/** + * An implementation of [SealedEnum] for the sealed class [SecondClassHierarchy.Z.X.U] + */ +public object SecondClassHierarchy_Z_X_USealedEnum : SealedEnum { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + SecondClassHierarchy.Z.X.U.T + ) + } + + + public override fun ordinalOf(obj: SecondClassHierarchy.Z.X.U): Int = when (obj) { + is SecondClassHierarchy.Z.X.U.T -> 0 + } + + public override fun nameOf(obj: SecondClassHierarchy.Z.X.U): String = when (obj) { + is SecondClassHierarchy.Z.X.U.T -> "SecondClassHierarchy_Z_X_U_T" + } + + public override fun valueOf(name: String): SecondClassHierarchy.Z.X.U = when (name) { + "SecondClassHierarchy_Z_X_U_T" -> SecondClassHierarchy.Z.X.U.T + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } +} + +/** + * The index of [this] in the values list. + */ +public val SecondClassHierarchy.Z.X.U.ordinal: Int + get() = SecondClassHierarchy_Z_X_USealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val SecondClassHierarchy.Z.X.U.name: String + get() = SecondClassHierarchy_Z_X_USealedEnum.nameOf(this) + +/** + * A list of all [SecondClassHierarchy.Z.X.U] objects. + */ +public val SecondClassHierarchy.Z.X.U.Companion.values: List + get() = SecondClassHierarchy_Z_X_USealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [SecondClassHierarchy.Z.X.U] + */ +public val SecondClassHierarchy.Z.X.U.Companion.sealedEnum: SecondClassHierarchy_Z_X_USealedEnum + get() = SecondClassHierarchy_Z_X_USealedEnum + +/** + * Returns the [SecondClassHierarchy.Z.X.U] object for the given [name]. + * + * If the given name doesn't correspond to any [SecondClassHierarchy.Z.X.U], an + * [IllegalArgumentException] will be thrown. + */ +public fun SecondClassHierarchy.Z.X.U.Companion.valueOf(name: String): SecondClassHierarchy.Z.X.U = + SecondClassHierarchy_Z_X_USealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for second hierarchy X generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for second hierarchy X generates correct code.approved new file mode 100644 index 00000000..a5204887 --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for second hierarchy X generates correct code.approved @@ -0,0 +1,78 @@ +package com.livefront.sealedenum.compilation.hierarchy + +import com.livefront.sealedenum.SealedEnum +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List + +/** + * An implementation of [SealedEnum] for the sealed class [SecondClassHierarchy.Z.X] + */ +public object SecondClassHierarchy_Z_XSealedEnum : SealedEnum { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + SecondClassHierarchy.Z.X.W, + SecondClassHierarchy.Z.X.V, + SecondClassHierarchy.Z.X.U.T, + SecondClassHierarchy.Z.X.S.R + ) + } + + + public override fun ordinalOf(obj: SecondClassHierarchy.Z.X): Int = when (obj) { + is SecondClassHierarchy.Z.X.W -> 0 + is SecondClassHierarchy.Z.X.V -> 1 + is SecondClassHierarchy.Z.X.U.T -> 2 + is SecondClassHierarchy.Z.X.S.R -> 3 + } + + public override fun nameOf(obj: SecondClassHierarchy.Z.X): String = when (obj) { + is SecondClassHierarchy.Z.X.W -> "SecondClassHierarchy_Z_X_W" + is SecondClassHierarchy.Z.X.V -> "SecondClassHierarchy_Z_X_V" + is SecondClassHierarchy.Z.X.U.T -> "SecondClassHierarchy_Z_X_U_T" + is SecondClassHierarchy.Z.X.S.R -> "SecondClassHierarchy_Z_X_S_R" + } + + public override fun valueOf(name: String): SecondClassHierarchy.Z.X = when (name) { + "SecondClassHierarchy_Z_X_W" -> SecondClassHierarchy.Z.X.W + "SecondClassHierarchy_Z_X_V" -> SecondClassHierarchy.Z.X.V + "SecondClassHierarchy_Z_X_U_T" -> SecondClassHierarchy.Z.X.U.T + "SecondClassHierarchy_Z_X_S_R" -> SecondClassHierarchy.Z.X.S.R + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } +} + +/** + * The index of [this] in the values list. + */ +public val SecondClassHierarchy.Z.X.ordinal: Int + get() = SecondClassHierarchy_Z_XSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val SecondClassHierarchy.Z.X.name: String + get() = SecondClassHierarchy_Z_XSealedEnum.nameOf(this) + +/** + * A list of all [SecondClassHierarchy.Z.X] objects. + */ +public val SecondClassHierarchy.Z.X.Companion.values: List + get() = SecondClassHierarchy_Z_XSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [SecondClassHierarchy.Z.X] + */ +public val SecondClassHierarchy.Z.X.Companion.sealedEnum: SecondClassHierarchy_Z_XSealedEnum + get() = SecondClassHierarchy_Z_XSealedEnum + +/** + * Returns the [SecondClassHierarchy.Z.X] object for the given [name]. + * + * If the given name doesn't correspond to any [SecondClassHierarchy.Z.X], an + * [IllegalArgumentException] will be thrown. + */ +public fun SecondClassHierarchy.Z.X.Companion.valueOf(name: String): SecondClassHierarchy.Z.X = + SecondClassHierarchy_Z_XSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for second hierarchy Z generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for second hierarchy Z generates correct code.approved new file mode 100644 index 00000000..7a677833 --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for second hierarchy Z generates correct code.approved @@ -0,0 +1,90 @@ +package com.livefront.sealedenum.compilation.hierarchy + +import com.livefront.sealedenum.SealedEnum +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List + +/** + * An implementation of [SealedEnum] for the sealed class [SecondClassHierarchy.Z] + */ +public object SecondClassHierarchy_ZSealedEnum : SealedEnum { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + SecondClassHierarchy.Z.Y, + SecondClassHierarchy.Z.X.W, + SecondClassHierarchy.Z.X.V, + SecondClassHierarchy.Z.X.U.T, + SecondClassHierarchy.Z.X.S.R, + SecondClassHierarchy.Z.Q.P, + SecondClassHierarchy.Z.O + ) + } + + + public override fun ordinalOf(obj: SecondClassHierarchy.Z): Int = when (obj) { + is SecondClassHierarchy.Z.Y -> 0 + is SecondClassHierarchy.Z.X.W -> 1 + is SecondClassHierarchy.Z.X.V -> 2 + is SecondClassHierarchy.Z.X.U.T -> 3 + is SecondClassHierarchy.Z.X.S.R -> 4 + is SecondClassHierarchy.Z.Q.P -> 5 + is SecondClassHierarchy.Z.O -> 6 + } + + public override fun nameOf(obj: SecondClassHierarchy.Z): String = when (obj) { + is SecondClassHierarchy.Z.Y -> "SecondClassHierarchy_Z_Y" + is SecondClassHierarchy.Z.X.W -> "SecondClassHierarchy_Z_X_W" + is SecondClassHierarchy.Z.X.V -> "SecondClassHierarchy_Z_X_V" + is SecondClassHierarchy.Z.X.U.T -> "SecondClassHierarchy_Z_X_U_T" + is SecondClassHierarchy.Z.X.S.R -> "SecondClassHierarchy_Z_X_S_R" + is SecondClassHierarchy.Z.Q.P -> "SecondClassHierarchy_Z_Q_P" + is SecondClassHierarchy.Z.O -> "SecondClassHierarchy_Z_O" + } + + public override fun valueOf(name: String): SecondClassHierarchy.Z = when (name) { + "SecondClassHierarchy_Z_Y" -> SecondClassHierarchy.Z.Y + "SecondClassHierarchy_Z_X_W" -> SecondClassHierarchy.Z.X.W + "SecondClassHierarchy_Z_X_V" -> SecondClassHierarchy.Z.X.V + "SecondClassHierarchy_Z_X_U_T" -> SecondClassHierarchy.Z.X.U.T + "SecondClassHierarchy_Z_X_S_R" -> SecondClassHierarchy.Z.X.S.R + "SecondClassHierarchy_Z_Q_P" -> SecondClassHierarchy.Z.Q.P + "SecondClassHierarchy_Z_O" -> SecondClassHierarchy.Z.O + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } +} + +/** + * The index of [this] in the values list. + */ +public val SecondClassHierarchy.Z.ordinal: Int + get() = SecondClassHierarchy_ZSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val SecondClassHierarchy.Z.name: String + get() = SecondClassHierarchy_ZSealedEnum.nameOf(this) + +/** + * A list of all [SecondClassHierarchy.Z] objects. + */ +public val SecondClassHierarchy.Z.Companion.values: List + get() = SecondClassHierarchy_ZSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [SecondClassHierarchy.Z] + */ +public val SecondClassHierarchy.Z.Companion.sealedEnum: SecondClassHierarchy_ZSealedEnum + get() = SecondClassHierarchy_ZSealedEnum + +/** + * Returns the [SecondClassHierarchy.Z] object for the given [name]. + * + * If the given name doesn't correspond to any [SecondClassHierarchy.Z], an + * [IllegalArgumentException] will be thrown. + */ +public fun SecondClassHierarchy.Z.Companion.valueOf(name: String): SecondClassHierarchy.Z = + SecondClassHierarchy_ZSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for first hierarchy A generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for first hierarchy A generates correct code.approved new file mode 100644 index 00000000..75881e36 --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for first hierarchy A generates correct code.approved @@ -0,0 +1,104 @@ +package com.livefront.sealedenum.compilation.hierarchy + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [FirstInterfaceHierarchy.A] + */ +public enum class FirstInterfaceHierarchy_AEnum() { + FirstInterfaceHierarchy_A_B_C, +} + +/** + * The isomorphic [FirstInterfaceHierarchy_AEnum] for [this]. + */ +public val FirstInterfaceHierarchy.A.`enum`: FirstInterfaceHierarchy_AEnum + get() = FirstInterfaceHierarchy_ASealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [FirstInterfaceHierarchy.A] for [this]. + */ +public val FirstInterfaceHierarchy_AEnum.sealedObject: FirstInterfaceHierarchy.A + get() = FirstInterfaceHierarchy_ASealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [FirstInterfaceHierarchy.A] + */ +public object FirstInterfaceHierarchy_ASealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + FirstInterfaceHierarchy.A.B.C + ) + } + + + public override val enumClass: KClass + get() = FirstInterfaceHierarchy_AEnum::class + + public override fun ordinalOf(obj: FirstInterfaceHierarchy.A): Int = when (obj) { + is FirstInterfaceHierarchy.A.B.C -> 0 + } + + public override fun nameOf(obj: FirstInterfaceHierarchy.A): String = when (obj) { + is FirstInterfaceHierarchy.A.B.C -> "FirstInterfaceHierarchy_A_B_C" + } + + public override fun valueOf(name: String): FirstInterfaceHierarchy.A = when (name) { + "FirstInterfaceHierarchy_A_B_C" -> FirstInterfaceHierarchy.A.B.C + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: FirstInterfaceHierarchy.A): + FirstInterfaceHierarchy_AEnum = when (obj) { + is FirstInterfaceHierarchy.A.B.C -> + FirstInterfaceHierarchy_AEnum.FirstInterfaceHierarchy_A_B_C + } + + public override fun enumToSealedObject(`enum`: FirstInterfaceHierarchy_AEnum): + FirstInterfaceHierarchy.A = when (enum) { + FirstInterfaceHierarchy_AEnum.FirstInterfaceHierarchy_A_B_C -> FirstInterfaceHierarchy.A.B.C + } +} + +/** + * The index of [this] in the values list. + */ +public val FirstInterfaceHierarchy.A.ordinal: Int + get() = FirstInterfaceHierarchy_ASealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val FirstInterfaceHierarchy.A.name: String + get() = FirstInterfaceHierarchy_ASealedEnum.nameOf(this) + +/** + * A list of all [FirstInterfaceHierarchy.A] objects. + */ +public val FirstInterfaceHierarchy.A.Companion.values: List + get() = FirstInterfaceHierarchy_ASealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [FirstInterfaceHierarchy.A] + */ +public val FirstInterfaceHierarchy.A.Companion.sealedEnum: FirstInterfaceHierarchy_ASealedEnum + get() = FirstInterfaceHierarchy_ASealedEnum + +/** + * Returns the [FirstInterfaceHierarchy.A] object for the given [name]. + * + * If the given name doesn't correspond to any [FirstInterfaceHierarchy.A], an + * [IllegalArgumentException] will be thrown. + */ +public fun FirstInterfaceHierarchy.A.Companion.valueOf(name: String): FirstInterfaceHierarchy.A = + FirstInterfaceHierarchy_ASealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for first hierarchy B generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for first hierarchy B generates correct code.approved new file mode 100644 index 00000000..0f7c181a --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for first hierarchy B generates correct code.approved @@ -0,0 +1,105 @@ +package com.livefront.sealedenum.compilation.hierarchy + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [FirstInterfaceHierarchy.A.B] + */ +public enum class FirstInterfaceHierarchy_A_BEnum() { + FirstInterfaceHierarchy_A_B_C, +} + +/** + * The isomorphic [FirstInterfaceHierarchy_A_BEnum] for [this]. + */ +public val FirstInterfaceHierarchy.A.B.`enum`: FirstInterfaceHierarchy_A_BEnum + get() = FirstInterfaceHierarchy_A_BSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [FirstInterfaceHierarchy.A.B] for [this]. + */ +public val FirstInterfaceHierarchy_A_BEnum.sealedObject: FirstInterfaceHierarchy.A.B + get() = FirstInterfaceHierarchy_A_BSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [FirstInterfaceHierarchy.A.B] + */ +public object FirstInterfaceHierarchy_A_BSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + FirstInterfaceHierarchy.A.B.C + ) + } + + + public override val enumClass: KClass + get() = FirstInterfaceHierarchy_A_BEnum::class + + public override fun ordinalOf(obj: FirstInterfaceHierarchy.A.B): Int = when (obj) { + is FirstInterfaceHierarchy.A.B.C -> 0 + } + + public override fun nameOf(obj: FirstInterfaceHierarchy.A.B): String = when (obj) { + is FirstInterfaceHierarchy.A.B.C -> "FirstInterfaceHierarchy_A_B_C" + } + + public override fun valueOf(name: String): FirstInterfaceHierarchy.A.B = when (name) { + "FirstInterfaceHierarchy_A_B_C" -> FirstInterfaceHierarchy.A.B.C + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: FirstInterfaceHierarchy.A.B): + FirstInterfaceHierarchy_A_BEnum = when (obj) { + is FirstInterfaceHierarchy.A.B.C -> + FirstInterfaceHierarchy_A_BEnum.FirstInterfaceHierarchy_A_B_C + } + + public override fun enumToSealedObject(`enum`: FirstInterfaceHierarchy_A_BEnum): + FirstInterfaceHierarchy.A.B = when (enum) { + FirstInterfaceHierarchy_A_BEnum.FirstInterfaceHierarchy_A_B_C -> + FirstInterfaceHierarchy.A.B.C + } +} + +/** + * The index of [this] in the values list. + */ +public val FirstInterfaceHierarchy.A.B.ordinal: Int + get() = FirstInterfaceHierarchy_A_BSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val FirstInterfaceHierarchy.A.B.name: String + get() = FirstInterfaceHierarchy_A_BSealedEnum.nameOf(this) + +/** + * A list of all [FirstInterfaceHierarchy.A.B] objects. + */ +public val FirstInterfaceHierarchy.A.B.Companion.values: List + get() = FirstInterfaceHierarchy_A_BSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [FirstInterfaceHierarchy.A.B] + */ +public val FirstInterfaceHierarchy.A.B.Companion.sealedEnum: FirstInterfaceHierarchy_A_BSealedEnum + get() = FirstInterfaceHierarchy_A_BSealedEnum + +/** + * Returns the [FirstInterfaceHierarchy.A.B] object for the given [name]. + * + * If the given name doesn't correspond to any [FirstInterfaceHierarchy.A.B], an + * [IllegalArgumentException] will be thrown. + */ +public fun FirstInterfaceHierarchy.A.B.Companion.valueOf(name: String): FirstInterfaceHierarchy.A.B + = FirstInterfaceHierarchy_A_BSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for second hierarchy A generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for second hierarchy A generates correct code.approved new file mode 100644 index 00000000..9037a0a0 --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for second hierarchy A generates correct code.approved @@ -0,0 +1,90 @@ +package com.livefront.sealedenum.compilation.hierarchy + +import com.livefront.sealedenum.SealedEnum +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List + +/** + * An implementation of [SealedEnum] for the sealed class [SecondInterfaceHierarchy.A] + */ +public object SecondInterfaceHierarchy_ASealedEnum : SealedEnum { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + SecondInterfaceHierarchy.A.B, + SecondInterfaceHierarchy.A.C.D, + SecondInterfaceHierarchy.A.C.E, + SecondInterfaceHierarchy.A.C.F.G, + SecondInterfaceHierarchy.A.C.H.I, + SecondInterfaceHierarchy.A.J.K, + SecondInterfaceHierarchy.A.L + ) + } + + + public override fun ordinalOf(obj: SecondInterfaceHierarchy.A): Int = when (obj) { + is SecondInterfaceHierarchy.A.B -> 0 + is SecondInterfaceHierarchy.A.C.D -> 1 + is SecondInterfaceHierarchy.A.C.E -> 2 + is SecondInterfaceHierarchy.A.C.F.G -> 3 + is SecondInterfaceHierarchy.A.C.H.I -> 4 + is SecondInterfaceHierarchy.A.J.K -> 5 + is SecondInterfaceHierarchy.A.L -> 6 + } + + public override fun nameOf(obj: SecondInterfaceHierarchy.A): String = when (obj) { + is SecondInterfaceHierarchy.A.B -> "SecondInterfaceHierarchy_A_B" + is SecondInterfaceHierarchy.A.C.D -> "SecondInterfaceHierarchy_A_C_D" + is SecondInterfaceHierarchy.A.C.E -> "SecondInterfaceHierarchy_A_C_E" + is SecondInterfaceHierarchy.A.C.F.G -> "SecondInterfaceHierarchy_A_C_F_G" + is SecondInterfaceHierarchy.A.C.H.I -> "SecondInterfaceHierarchy_A_C_H_I" + is SecondInterfaceHierarchy.A.J.K -> "SecondInterfaceHierarchy_A_J_K" + is SecondInterfaceHierarchy.A.L -> "SecondInterfaceHierarchy_A_L" + } + + public override fun valueOf(name: String): SecondInterfaceHierarchy.A = when (name) { + "SecondInterfaceHierarchy_A_B" -> SecondInterfaceHierarchy.A.B + "SecondInterfaceHierarchy_A_C_D" -> SecondInterfaceHierarchy.A.C.D + "SecondInterfaceHierarchy_A_C_E" -> SecondInterfaceHierarchy.A.C.E + "SecondInterfaceHierarchy_A_C_F_G" -> SecondInterfaceHierarchy.A.C.F.G + "SecondInterfaceHierarchy_A_C_H_I" -> SecondInterfaceHierarchy.A.C.H.I + "SecondInterfaceHierarchy_A_J_K" -> SecondInterfaceHierarchy.A.J.K + "SecondInterfaceHierarchy_A_L" -> SecondInterfaceHierarchy.A.L + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } +} + +/** + * The index of [this] in the values list. + */ +public val SecondInterfaceHierarchy.A.ordinal: Int + get() = SecondInterfaceHierarchy_ASealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val SecondInterfaceHierarchy.A.name: String + get() = SecondInterfaceHierarchy_ASealedEnum.nameOf(this) + +/** + * A list of all [SecondInterfaceHierarchy.A] objects. + */ +public val SecondInterfaceHierarchy.A.Companion.values: List + get() = SecondInterfaceHierarchy_ASealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [SecondInterfaceHierarchy.A] + */ +public val SecondInterfaceHierarchy.A.Companion.sealedEnum: SecondInterfaceHierarchy_ASealedEnum + get() = SecondInterfaceHierarchy_ASealedEnum + +/** + * Returns the [SecondInterfaceHierarchy.A] object for the given [name]. + * + * If the given name doesn't correspond to any [SecondInterfaceHierarchy.A], an + * [IllegalArgumentException] will be thrown. + */ +public fun SecondInterfaceHierarchy.A.Companion.valueOf(name: String): SecondInterfaceHierarchy.A = + SecondInterfaceHierarchy_ASealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for second hierarchy C generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for second hierarchy C generates correct code.approved new file mode 100644 index 00000000..7f06c9bf --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for second hierarchy C generates correct code.approved @@ -0,0 +1,78 @@ +package com.livefront.sealedenum.compilation.hierarchy + +import com.livefront.sealedenum.SealedEnum +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List + +/** + * An implementation of [SealedEnum] for the sealed class [SecondInterfaceHierarchy.A.C] + */ +public object SecondInterfaceHierarchy_A_CSealedEnum : SealedEnum { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + SecondInterfaceHierarchy.A.C.D, + SecondInterfaceHierarchy.A.C.E, + SecondInterfaceHierarchy.A.C.F.G, + SecondInterfaceHierarchy.A.C.H.I + ) + } + + + public override fun ordinalOf(obj: SecondInterfaceHierarchy.A.C): Int = when (obj) { + is SecondInterfaceHierarchy.A.C.D -> 0 + is SecondInterfaceHierarchy.A.C.E -> 1 + is SecondInterfaceHierarchy.A.C.F.G -> 2 + is SecondInterfaceHierarchy.A.C.H.I -> 3 + } + + public override fun nameOf(obj: SecondInterfaceHierarchy.A.C): String = when (obj) { + is SecondInterfaceHierarchy.A.C.D -> "SecondInterfaceHierarchy_A_C_D" + is SecondInterfaceHierarchy.A.C.E -> "SecondInterfaceHierarchy_A_C_E" + is SecondInterfaceHierarchy.A.C.F.G -> "SecondInterfaceHierarchy_A_C_F_G" + is SecondInterfaceHierarchy.A.C.H.I -> "SecondInterfaceHierarchy_A_C_H_I" + } + + public override fun valueOf(name: String): SecondInterfaceHierarchy.A.C = when (name) { + "SecondInterfaceHierarchy_A_C_D" -> SecondInterfaceHierarchy.A.C.D + "SecondInterfaceHierarchy_A_C_E" -> SecondInterfaceHierarchy.A.C.E + "SecondInterfaceHierarchy_A_C_F_G" -> SecondInterfaceHierarchy.A.C.F.G + "SecondInterfaceHierarchy_A_C_H_I" -> SecondInterfaceHierarchy.A.C.H.I + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } +} + +/** + * The index of [this] in the values list. + */ +public val SecondInterfaceHierarchy.A.C.ordinal: Int + get() = SecondInterfaceHierarchy_A_CSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val SecondInterfaceHierarchy.A.C.name: String + get() = SecondInterfaceHierarchy_A_CSealedEnum.nameOf(this) + +/** + * A list of all [SecondInterfaceHierarchy.A.C] objects. + */ +public val SecondInterfaceHierarchy.A.C.Companion.values: List + get() = SecondInterfaceHierarchy_A_CSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [SecondInterfaceHierarchy.A.C] + */ +public val SecondInterfaceHierarchy.A.C.Companion.sealedEnum: SecondInterfaceHierarchy_A_CSealedEnum + get() = SecondInterfaceHierarchy_A_CSealedEnum + +/** + * Returns the [SecondInterfaceHierarchy.A.C] object for the given [name]. + * + * If the given name doesn't correspond to any [SecondInterfaceHierarchy.A.C], an + * [IllegalArgumentException] will be thrown. + */ +public fun SecondInterfaceHierarchy.A.C.Companion.valueOf(name: String): + SecondInterfaceHierarchy.A.C = SecondInterfaceHierarchy_A_CSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for second hierarchy F generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for second hierarchy F generates correct code.approved new file mode 100644 index 00000000..c5ba52b6 --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for second hierarchy F generates correct code.approved @@ -0,0 +1,68 @@ +package com.livefront.sealedenum.compilation.hierarchy + +import com.livefront.sealedenum.SealedEnum +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List + +/** + * An implementation of [SealedEnum] for the sealed class [SecondInterfaceHierarchy.A.C.F] + */ +public object SecondInterfaceHierarchy_A_C_FSealedEnum : SealedEnum + { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + SecondInterfaceHierarchy.A.C.F.G + ) + } + + + public override fun ordinalOf(obj: SecondInterfaceHierarchy.A.C.F): Int = when (obj) { + is SecondInterfaceHierarchy.A.C.F.G -> 0 + } + + public override fun nameOf(obj: SecondInterfaceHierarchy.A.C.F): String = when (obj) { + is SecondInterfaceHierarchy.A.C.F.G -> "SecondInterfaceHierarchy_A_C_F_G" + } + + public override fun valueOf(name: String): SecondInterfaceHierarchy.A.C.F = when (name) { + "SecondInterfaceHierarchy_A_C_F_G" -> SecondInterfaceHierarchy.A.C.F.G + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } +} + +/** + * The index of [this] in the values list. + */ +public val SecondInterfaceHierarchy.A.C.F.ordinal: Int + get() = SecondInterfaceHierarchy_A_C_FSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val SecondInterfaceHierarchy.A.C.F.name: String + get() = SecondInterfaceHierarchy_A_C_FSealedEnum.nameOf(this) + +/** + * A list of all [SecondInterfaceHierarchy.A.C.F] objects. + */ +public val SecondInterfaceHierarchy.A.C.F.Companion.values: List + get() = SecondInterfaceHierarchy_A_C_FSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [SecondInterfaceHierarchy.A.C.F] + */ +public val SecondInterfaceHierarchy.A.C.F.Companion.sealedEnum: + SecondInterfaceHierarchy_A_C_FSealedEnum + get() = SecondInterfaceHierarchy_A_C_FSealedEnum + +/** + * Returns the [SecondInterfaceHierarchy.A.C.F] object for the given [name]. + * + * If the given name doesn't correspond to any [SecondInterfaceHierarchy.A.C.F], an + * [IllegalArgumentException] will be thrown. + */ +public fun SecondInterfaceHierarchy.A.C.F.Companion.valueOf(name: String): + SecondInterfaceHierarchy.A.C.F = SecondInterfaceHierarchy_A_C_FSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for second hierarchy H generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for second hierarchy H generates correct code.approved new file mode 100644 index 00000000..20d4f6d6 --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for second hierarchy H generates correct code.approved @@ -0,0 +1,68 @@ +package com.livefront.sealedenum.compilation.hierarchy + +import com.livefront.sealedenum.SealedEnum +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List + +/** + * An implementation of [SealedEnum] for the sealed class [SecondInterfaceHierarchy.A.C.H] + */ +public object SecondInterfaceHierarchy_A_C_HSealedEnum : SealedEnum + { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + SecondInterfaceHierarchy.A.C.H.I + ) + } + + + public override fun ordinalOf(obj: SecondInterfaceHierarchy.A.C.H): Int = when (obj) { + is SecondInterfaceHierarchy.A.C.H.I -> 0 + } + + public override fun nameOf(obj: SecondInterfaceHierarchy.A.C.H): String = when (obj) { + is SecondInterfaceHierarchy.A.C.H.I -> "SecondInterfaceHierarchy_A_C_H_I" + } + + public override fun valueOf(name: String): SecondInterfaceHierarchy.A.C.H = when (name) { + "SecondInterfaceHierarchy_A_C_H_I" -> SecondInterfaceHierarchy.A.C.H.I + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } +} + +/** + * The index of [this] in the values list. + */ +public val SecondInterfaceHierarchy.A.C.H.ordinal: Int + get() = SecondInterfaceHierarchy_A_C_HSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val SecondInterfaceHierarchy.A.C.H.name: String + get() = SecondInterfaceHierarchy_A_C_HSealedEnum.nameOf(this) + +/** + * A list of all [SecondInterfaceHierarchy.A.C.H] objects. + */ +public val SecondInterfaceHierarchy.A.C.H.Companion.values: List + get() = SecondInterfaceHierarchy_A_C_HSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [SecondInterfaceHierarchy.A.C.H] + */ +public val SecondInterfaceHierarchy.A.C.H.Companion.sealedEnum: + SecondInterfaceHierarchy_A_C_HSealedEnum + get() = SecondInterfaceHierarchy_A_C_HSealedEnum + +/** + * Returns the [SecondInterfaceHierarchy.A.C.H] object for the given [name]. + * + * If the given name doesn't correspond to any [SecondInterfaceHierarchy.A.C.H], an + * [IllegalArgumentException] will be thrown. + */ +public fun SecondInterfaceHierarchy.A.C.H.Companion.valueOf(name: String): + SecondInterfaceHierarchy.A.C.H = SecondInterfaceHierarchy_A_C_HSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for second hierarchy J generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for second hierarchy J generates correct code.approved new file mode 100644 index 00000000..385c07af --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for second hierarchy J generates correct code.approved @@ -0,0 +1,66 @@ +package com.livefront.sealedenum.compilation.hierarchy + +import com.livefront.sealedenum.SealedEnum +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List + +/** + * An implementation of [SealedEnum] for the sealed class [SecondInterfaceHierarchy.A.J] + */ +public object SecondInterfaceHierarchy_A_JSealedEnum : SealedEnum { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + SecondInterfaceHierarchy.A.J.K + ) + } + + + public override fun ordinalOf(obj: SecondInterfaceHierarchy.A.J): Int = when (obj) { + is SecondInterfaceHierarchy.A.J.K -> 0 + } + + public override fun nameOf(obj: SecondInterfaceHierarchy.A.J): String = when (obj) { + is SecondInterfaceHierarchy.A.J.K -> "SecondInterfaceHierarchy_A_J_K" + } + + public override fun valueOf(name: String): SecondInterfaceHierarchy.A.J = when (name) { + "SecondInterfaceHierarchy_A_J_K" -> SecondInterfaceHierarchy.A.J.K + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } +} + +/** + * The index of [this] in the values list. + */ +public val SecondInterfaceHierarchy.A.J.ordinal: Int + get() = SecondInterfaceHierarchy_A_JSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val SecondInterfaceHierarchy.A.J.name: String + get() = SecondInterfaceHierarchy_A_JSealedEnum.nameOf(this) + +/** + * A list of all [SecondInterfaceHierarchy.A.J] objects. + */ +public val SecondInterfaceHierarchy.A.J.Companion.values: List + get() = SecondInterfaceHierarchy_A_JSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [SecondInterfaceHierarchy.A.J] + */ +public val SecondInterfaceHierarchy.A.J.Companion.sealedEnum: SecondInterfaceHierarchy_A_JSealedEnum + get() = SecondInterfaceHierarchy_A_JSealedEnum + +/** + * Returns the [SecondInterfaceHierarchy.A.J] object for the given [name]. + * + * If the given name doesn't correspond to any [SecondInterfaceHierarchy.A.J], an + * [IllegalArgumentException] will be thrown. + */ +public fun SecondInterfaceHierarchy.A.J.Companion.valueOf(name: String): + SecondInterfaceHierarchy.A.J = SecondInterfaceHierarchy_A_JSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/ksp/NestedObjectsWithSameName.kt b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/ksp/NestedObjectsWithSameName.kt index 586c9c3e..eb3ed22d 100644 --- a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/ksp/NestedObjectsWithSameName.kt +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/ksp/NestedObjectsWithSameName.kt @@ -1,7 +1,6 @@ package com.livefront.sealedenum.compilation.ksp import com.livefront.sealedenum.GenSealedEnum -import org.intellij.lang.annotations.Language @Suppress("UtilityClassWithPublicConstructor") class NestedObjectsWithSameName { @@ -12,115 +11,3 @@ class NestedObjectsWithSameName { } } } - -@Language("kotlin") -val nestedObjectsWithSameNameEmptySealedClassGenerated = """ -package com.livefront.sealedenum.compilation.ksp - -import com.livefront.sealedenum.EnumForSealedEnumProvider -import com.livefront.sealedenum.SealedEnum -import com.livefront.sealedenum.SealedEnumWithEnumProvider -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List -import kotlin.reflect.KClass - -/** - * An isomorphic enum for the sealed class [NestedObjectsWithSameName.Companion.EmptySealedClass] - */ -public enum class NestedObjectsWithSameName_Companion_EmptySealedClassEnum() - -/** - * The isomorphic [NestedObjectsWithSameName_Companion_EmptySealedClassEnum] for [this]. - */ -public val NestedObjectsWithSameName.Companion.EmptySealedClass.`enum`: - NestedObjectsWithSameName_Companion_EmptySealedClassEnum - get() = NestedObjectsWithSameName_Companion_EmptySealedClassSealedEnum.sealedObjectToEnum(this) - -/** - * The isomorphic [NestedObjectsWithSameName.Companion.EmptySealedClass] for [this]. - */ -public val NestedObjectsWithSameName_Companion_EmptySealedClassEnum.sealedObject: - NestedObjectsWithSameName.Companion.EmptySealedClass - get() = NestedObjectsWithSameName_Companion_EmptySealedClassSealedEnum.enumToSealedObject(this) - -/** - * An implementation of [SealedEnum] for the sealed class - * [NestedObjectsWithSameName.Companion.EmptySealedClass] - */ -public object NestedObjectsWithSameName_Companion_EmptySealedClassSealedEnum : - SealedEnum, - SealedEnumWithEnumProvider, - EnumForSealedEnumProvider - { - public override val values: List by - lazy(mode = LazyThreadSafetyMode.PUBLICATION) { - emptyList() - } - - - public override val enumClass: KClass - get() = NestedObjectsWithSameName_Companion_EmptySealedClassEnum::class - - public override fun ordinalOf(obj: NestedObjectsWithSameName.Companion.EmptySealedClass): Int = - throw - AssertionError("Constructing a EmptySealedClass is impossible, since it has no sealed subclasses") - - public override fun nameOf(obj: NestedObjectsWithSameName.Companion.EmptySealedClass): String = - throw - AssertionError("Constructing a EmptySealedClass is impossible, since it has no sealed subclasses") - - public override fun valueOf(name: String): NestedObjectsWithSameName.Companion.EmptySealedClass - = throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - - public override - fun sealedObjectToEnum(obj: NestedObjectsWithSameName.Companion.EmptySealedClass): - NestedObjectsWithSameName_Companion_EmptySealedClassEnum = throw - AssertionError("Constructing a EmptySealedClass is impossible, since it has no sealed subclasses") - - public override - fun enumToSealedObject(`enum`: NestedObjectsWithSameName_Companion_EmptySealedClassEnum): - NestedObjectsWithSameName.Companion.EmptySealedClass = throw - AssertionError("Constructing a EmptySealedClass is impossible, since it has no sealed subclasses") -} - -/** - * The index of [this] in the values list. - */ -public val NestedObjectsWithSameName.Companion.EmptySealedClass.ordinal: Int - get() = NestedObjectsWithSameName_Companion_EmptySealedClassSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val NestedObjectsWithSameName.Companion.EmptySealedClass.name: String - get() = NestedObjectsWithSameName_Companion_EmptySealedClassSealedEnum.nameOf(this) - -/** - * A list of all [NestedObjectsWithSameName.Companion.EmptySealedClass] objects. - */ -public val NestedObjectsWithSameName.Companion.EmptySealedClass.Companion.values: - List - get() = NestedObjectsWithSameName_Companion_EmptySealedClassSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class - * [NestedObjectsWithSameName.Companion.EmptySealedClass] - */ -public val NestedObjectsWithSameName.Companion.EmptySealedClass.Companion.sealedEnum: - NestedObjectsWithSameName_Companion_EmptySealedClassSealedEnum - get() = NestedObjectsWithSameName_Companion_EmptySealedClassSealedEnum - -/** - * Returns the [NestedObjectsWithSameName.Companion.EmptySealedClass] object for the given [name]. - * - * If the given name doesn't correspond to any - * [NestedObjectsWithSameName.Companion.EmptySealedClass], an [IllegalArgumentException] will be - * thrown. - */ -public fun NestedObjectsWithSameName.Companion.EmptySealedClass.Companion.valueOf(name: String): - NestedObjectsWithSameName.Companion.EmptySealedClass = - NestedObjectsWithSameName_Companion_EmptySealedClassSealedEnum.valueOf(name) - -""".trimIndent() diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/ksp/NestedObjectsWithSameNameTests.compilation generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/ksp/NestedObjectsWithSameNameTests.compilation generates correct code.approved new file mode 100644 index 00000000..48f1a710 --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/ksp/NestedObjectsWithSameNameTests.compilation generates correct code.approved @@ -0,0 +1,107 @@ +package com.livefront.sealedenum.compilation.ksp + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [NestedObjectsWithSameName.Companion.EmptySealedClass] + */ +public enum class NestedObjectsWithSameName_Companion_EmptySealedClassEnum() + +/** + * The isomorphic [NestedObjectsWithSameName_Companion_EmptySealedClassEnum] for [this]. + */ +public val NestedObjectsWithSameName.Companion.EmptySealedClass.`enum`: + NestedObjectsWithSameName_Companion_EmptySealedClassEnum + get() = NestedObjectsWithSameName_Companion_EmptySealedClassSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [NestedObjectsWithSameName.Companion.EmptySealedClass] for [this]. + */ +public val NestedObjectsWithSameName_Companion_EmptySealedClassEnum.sealedObject: + NestedObjectsWithSameName.Companion.EmptySealedClass + get() = NestedObjectsWithSameName_Companion_EmptySealedClassSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class + * [NestedObjectsWithSameName.Companion.EmptySealedClass] + */ +public object NestedObjectsWithSameName_Companion_EmptySealedClassSealedEnum : + SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider + { + public override val values: List by + lazy(mode = LazyThreadSafetyMode.PUBLICATION) { + emptyList() + } + + + public override val enumClass: KClass + get() = NestedObjectsWithSameName_Companion_EmptySealedClassEnum::class + + public override fun ordinalOf(obj: NestedObjectsWithSameName.Companion.EmptySealedClass): Int = + throw + AssertionError("Constructing a EmptySealedClass is impossible, since it has no sealed subclasses") + + public override fun nameOf(obj: NestedObjectsWithSameName.Companion.EmptySealedClass): String = + throw + AssertionError("Constructing a EmptySealedClass is impossible, since it has no sealed subclasses") + + public override fun valueOf(name: String): NestedObjectsWithSameName.Companion.EmptySealedClass + = throw IllegalArgumentException("""No sealed enum constant $name""") + + public override + fun sealedObjectToEnum(obj: NestedObjectsWithSameName.Companion.EmptySealedClass): + NestedObjectsWithSameName_Companion_EmptySealedClassEnum = throw + AssertionError("Constructing a EmptySealedClass is impossible, since it has no sealed subclasses") + + public override + fun enumToSealedObject(`enum`: NestedObjectsWithSameName_Companion_EmptySealedClassEnum): + NestedObjectsWithSameName.Companion.EmptySealedClass = throw + AssertionError("Constructing a EmptySealedClass is impossible, since it has no sealed subclasses") +} + +/** + * The index of [this] in the values list. + */ +public val NestedObjectsWithSameName.Companion.EmptySealedClass.ordinal: Int + get() = NestedObjectsWithSameName_Companion_EmptySealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val NestedObjectsWithSameName.Companion.EmptySealedClass.name: String + get() = NestedObjectsWithSameName_Companion_EmptySealedClassSealedEnum.nameOf(this) + +/** + * A list of all [NestedObjectsWithSameName.Companion.EmptySealedClass] objects. + */ +public val NestedObjectsWithSameName.Companion.EmptySealedClass.Companion.values: + List + get() = NestedObjectsWithSameName_Companion_EmptySealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class + * [NestedObjectsWithSameName.Companion.EmptySealedClass] + */ +public val NestedObjectsWithSameName.Companion.EmptySealedClass.Companion.sealedEnum: + NestedObjectsWithSameName_Companion_EmptySealedClassSealedEnum + get() = NestedObjectsWithSameName_Companion_EmptySealedClassSealedEnum + +/** + * Returns the [NestedObjectsWithSameName.Companion.EmptySealedClass] object for the given [name]. + * + * If the given name doesn't correspond to any + * [NestedObjectsWithSameName.Companion.EmptySealedClass], an [IllegalArgumentException] will be + * thrown. + */ +public fun NestedObjectsWithSameName.Companion.EmptySealedClass.Companion.valueOf(name: String): + NestedObjectsWithSameName.Companion.EmptySealedClass = + NestedObjectsWithSameName_Companion_EmptySealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/ksp/NestedObjectsWithSameNameTests.kt b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/ksp/NestedObjectsWithSameNameTests.kt index bbf5adff..f41510da 100644 --- a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/ksp/NestedObjectsWithSameNameTests.kt +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/ksp/NestedObjectsWithSameNameTests.kt @@ -1,11 +1,14 @@ package com.livefront.sealedenum.compilation.ksp +import com.livefront.sealedenum.testing.SealedEnumApprovalsExtension +import com.livefront.sealedenum.testing.assertApprovedGeneratedFile import com.livefront.sealedenum.testing.assertCompiles -import com.livefront.sealedenum.testing.assertGeneratedFileMatches import com.livefront.sealedenum.testing.compile import com.livefront.sealedenum.testing.getSourceFile +import com.oneeyedmen.okeydoke.Approver import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith /** * Verifies that a sealed class in a companion object (or more precisely, an annotation that appears on a nested object @@ -17,6 +20,7 @@ import org.junit.jupiter.api.Test * * @see sealed-enum/issues/60 */ +@ExtendWith(SealedEnumApprovalsExtension::class) class NestedObjectsWithSameNameTests { @Test fun `empty sealed class`() { @@ -45,14 +49,10 @@ class NestedObjectsWithSameNameTests { } @Test - fun `compilation generates correct code`() { + fun Approver.`compilation generates correct code`() { val result = compile(getSourceFile("compilation", "ksp", "NestedObjectsWithSameName.kt")) assertCompiles(result) - assertGeneratedFileMatches( - "NestedObjectsWithSameName.Companion.EmptySealedClass_SealedEnum.kt", - nestedObjectsWithSameNameEmptySealedClassGenerated, - result - ) + assertApprovedGeneratedFile("NestedObjectsWithSameName.Companion.EmptySealedClass_SealedEnum.kt", result) } } diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/NestedClassTests.compilation for inside one class generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/NestedClassTests.compilation for inside one class generates correct code.approved new file mode 100644 index 00000000..53a9d1b0 --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/NestedClassTests.compilation for inside one class generates correct code.approved @@ -0,0 +1,79 @@ +package com.livefront.sealedenum.compilation.location + +import com.livefront.sealedenum.SealedEnum +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List + +/** + * An implementation of [SealedEnum] for the sealed class [OuterClass.InsideOneClassSealedClass] + */ +public object OuterClass_InsideOneClassSealedClassSealedEnum : + SealedEnum { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + OuterClass.InsideOneClassSealedClass.FirstObject, + OuterClass.InsideOneClassSealedClass.SecondObject + ) + } + + + public override fun ordinalOf(obj: OuterClass.InsideOneClassSealedClass): Int = when (obj) { + is OuterClass.InsideOneClassSealedClass.FirstObject -> 0 + is OuterClass.InsideOneClassSealedClass.SecondObject -> 1 + } + + public override fun nameOf(obj: OuterClass.InsideOneClassSealedClass): String = when (obj) { + is OuterClass.InsideOneClassSealedClass.FirstObject -> + "OuterClass_InsideOneClassSealedClass_FirstObject" + is OuterClass.InsideOneClassSealedClass.SecondObject -> + "OuterClass_InsideOneClassSealedClass_SecondObject" + } + + public override fun valueOf(name: String): OuterClass.InsideOneClassSealedClass = when (name) { + "OuterClass_InsideOneClassSealedClass_FirstObject" -> + OuterClass.InsideOneClassSealedClass.FirstObject + "OuterClass_InsideOneClassSealedClass_SecondObject" -> + OuterClass.InsideOneClassSealedClass.SecondObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } +} + +/** + * The index of [this] in the values list. + */ +public val OuterClass.InsideOneClassSealedClass.ordinal: Int + get() = OuterClass_InsideOneClassSealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val OuterClass.InsideOneClassSealedClass.name: String + get() = OuterClass_InsideOneClassSealedClassSealedEnum.nameOf(this) + +/** + * A list of all [OuterClass.InsideOneClassSealedClass] objects. + */ +public val OuterClass.InsideOneClassSealedClass.Companion.values: + List + get() = OuterClass_InsideOneClassSealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class + * [OuterClass.InsideOneClassSealedClass] + */ +public val OuterClass.InsideOneClassSealedClass.Companion.sealedEnum: + OuterClass_InsideOneClassSealedClassSealedEnum + get() = OuterClass_InsideOneClassSealedClassSealedEnum + +/** + * Returns the [OuterClass.InsideOneClassSealedClass] object for the given [name]. + * + * If the given name doesn't correspond to any [OuterClass.InsideOneClassSealedClass], an + * [IllegalArgumentException] will be thrown. + */ +public fun OuterClass.InsideOneClassSealedClass.Companion.valueOf(name: String): + OuterClass.InsideOneClassSealedClass = + OuterClass_InsideOneClassSealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/NestedClassTests.compilation for inside two classes generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/NestedClassTests.compilation for inside two classes generates correct code.approved new file mode 100644 index 00000000..211c0b88 --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/NestedClassTests.compilation for inside two classes generates correct code.approved @@ -0,0 +1,87 @@ +package com.livefront.sealedenum.compilation.location + +import com.livefront.sealedenum.SealedEnum +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List + +/** + * An implementation of [SealedEnum] for the sealed class + * [FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass] + */ +public object FirstOuterClass_SecondOuterClass_InsideTwoClassesSealedClassSealedEnum : + SealedEnum { + public override val values: List + by lazy(mode = LazyThreadSafetyMode.PUBLICATION) { + listOf( + FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass.FirstObject, + FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass.SecondObject + ) + } + + + public override + fun ordinalOf(obj: FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass): Int = + when (obj) { + is FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass.FirstObject -> 0 + is FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass.SecondObject -> 1 + } + + public override fun nameOf(obj: FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass): + String = when (obj) { + is FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass.FirstObject -> + "FirstOuterClass_SecondOuterClass_InsideTwoClassesSealedClass_FirstObject" + is FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass.SecondObject -> + "FirstOuterClass_SecondOuterClass_InsideTwoClassesSealedClass_SecondObject" + } + + public override fun valueOf(name: String): + FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass = when (name) { + "FirstOuterClass_SecondOuterClass_InsideTwoClassesSealedClass_FirstObject" -> + FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass.FirstObject + "FirstOuterClass_SecondOuterClass_InsideTwoClassesSealedClass_SecondObject" -> + FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass.SecondObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } +} + +/** + * The index of [this] in the values list. + */ +public val FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass.ordinal: Int + get() = FirstOuterClass_SecondOuterClass_InsideTwoClassesSealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass.name: String + get() = FirstOuterClass_SecondOuterClass_InsideTwoClassesSealedClassSealedEnum.nameOf(this) + +/** + * A list of all [FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass] objects. + */ +public val FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass.Companion.values: + List + get() = FirstOuterClass_SecondOuterClass_InsideTwoClassesSealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class + * [FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass] + */ +public val FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass.Companion.sealedEnum: + FirstOuterClass_SecondOuterClass_InsideTwoClassesSealedClassSealedEnum + get() = FirstOuterClass_SecondOuterClass_InsideTwoClassesSealedClassSealedEnum + +/** + * Returns the [FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass] object for the given + * [name]. + * + * If the given name doesn't correspond to any + * [FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass], an [IllegalArgumentException] will + * be thrown. + */ +public + fun FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass.Companion.valueOf(name: String): + FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass = + FirstOuterClass_SecondOuterClass_InsideTwoClassesSealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/OutsideSealedClassTests.compilation for alpha outside sealed class generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/OutsideSealedClassTests.compilation for alpha outside sealed class generates correct code.approved new file mode 100644 index 00000000..2a959b9a --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/OutsideSealedClassTests.compilation for alpha outside sealed class generates correct code.approved @@ -0,0 +1,103 @@ +package com.livefront.sealedenum.compilation.location + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [AlphaOutsideSealedClass] + */ +public enum class AlphaOutsideSealedClassEnum() { + AlphaFirstObject, +} + +/** + * The isomorphic [AlphaOutsideSealedClassEnum] for [this]. + */ +public val AlphaOutsideSealedClass.`enum`: AlphaOutsideSealedClassEnum + get() = AlphaOutsideSealedClassSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [AlphaOutsideSealedClass] for [this]. + */ +public val AlphaOutsideSealedClassEnum.sealedObject: AlphaOutsideSealedClass + get() = AlphaOutsideSealedClassSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [AlphaOutsideSealedClass] + */ +public object AlphaOutsideSealedClassSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + AlphaFirstObject + ) + } + + + public override val enumClass: KClass + get() = AlphaOutsideSealedClassEnum::class + + public override fun ordinalOf(obj: AlphaOutsideSealedClass): Int = when (obj) { + is AlphaFirstObject -> 0 + } + + public override fun nameOf(obj: AlphaOutsideSealedClass): String = when (obj) { + is AlphaFirstObject -> "AlphaFirstObject" + } + + public override fun valueOf(name: String): AlphaOutsideSealedClass = when (name) { + "AlphaFirstObject" -> AlphaFirstObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: AlphaOutsideSealedClass): + AlphaOutsideSealedClassEnum = when (obj) { + is AlphaFirstObject -> AlphaOutsideSealedClassEnum.AlphaFirstObject + } + + public override fun enumToSealedObject(`enum`: AlphaOutsideSealedClassEnum): + AlphaOutsideSealedClass = when (enum) { + AlphaOutsideSealedClassEnum.AlphaFirstObject -> AlphaFirstObject + } +} + +/** + * The index of [this] in the values list. + */ +public val AlphaOutsideSealedClass.ordinal: Int + get() = AlphaOutsideSealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val AlphaOutsideSealedClass.name: String + get() = AlphaOutsideSealedClassSealedEnum.nameOf(this) + +/** + * A list of all [AlphaOutsideSealedClass] objects. + */ +public val AlphaOutsideSealedClass.Companion.values: List + get() = AlphaOutsideSealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [AlphaOutsideSealedClass] + */ +public val AlphaOutsideSealedClass.Companion.sealedEnum: AlphaOutsideSealedClassSealedEnum + get() = AlphaOutsideSealedClassSealedEnum + +/** + * Returns the [AlphaOutsideSealedClass] object for the given [name]. + * + * If the given name doesn't correspond to any [AlphaOutsideSealedClass], an + * [IllegalArgumentException] will be thrown. + */ +public fun AlphaOutsideSealedClass.Companion.valueOf(name: String): AlphaOutsideSealedClass = + AlphaOutsideSealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/OutsideSealedClassTests.compilation for beta outside sealed class generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/OutsideSealedClassTests.compilation for beta outside sealed class generates correct code.approved new file mode 100644 index 00000000..a9457b5d --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/OutsideSealedClassTests.compilation for beta outside sealed class generates correct code.approved @@ -0,0 +1,124 @@ +package com.livefront.sealedenum.compilation.location + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [BetaOutsideSealedClass] + */ +public enum class BetaOutsideSealedClassEnum() { + BetaFirstObject, + BetaFourthObject, + BetaSecondObject, + BetaThirdObject, +} + +/** + * The isomorphic [BetaOutsideSealedClassEnum] for [this]. + */ +public val BetaOutsideSealedClass.`enum`: BetaOutsideSealedClassEnum + get() = BetaOutsideSealedClassSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [BetaOutsideSealedClass] for [this]. + */ +public val BetaOutsideSealedClassEnum.sealedObject: BetaOutsideSealedClass + get() = BetaOutsideSealedClassSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [BetaOutsideSealedClass] + */ +public object BetaOutsideSealedClassSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + BetaFirstObject, + BetaFourthObject, + BetaSecondObject, + BetaThirdObject + ) + } + + + public override val enumClass: KClass + get() = BetaOutsideSealedClassEnum::class + + public override fun ordinalOf(obj: BetaOutsideSealedClass): Int = when (obj) { + is BetaFirstObject -> 0 + is BetaFourthObject -> 1 + is BetaSecondObject -> 2 + is BetaThirdObject -> 3 + } + + public override fun nameOf(obj: BetaOutsideSealedClass): String = when (obj) { + is BetaFirstObject -> "BetaFirstObject" + is BetaFourthObject -> "BetaFourthObject" + is BetaSecondObject -> "BetaSecondObject" + is BetaThirdObject -> "BetaThirdObject" + } + + public override fun valueOf(name: String): BetaOutsideSealedClass = when (name) { + "BetaFirstObject" -> BetaFirstObject + "BetaFourthObject" -> BetaFourthObject + "BetaSecondObject" -> BetaSecondObject + "BetaThirdObject" -> BetaThirdObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: BetaOutsideSealedClass): BetaOutsideSealedClassEnum + = when (obj) { + is BetaFirstObject -> BetaOutsideSealedClassEnum.BetaFirstObject + is BetaFourthObject -> BetaOutsideSealedClassEnum.BetaFourthObject + is BetaSecondObject -> BetaOutsideSealedClassEnum.BetaSecondObject + is BetaThirdObject -> BetaOutsideSealedClassEnum.BetaThirdObject + } + + public override fun enumToSealedObject(`enum`: BetaOutsideSealedClassEnum): + BetaOutsideSealedClass = when (enum) { + BetaOutsideSealedClassEnum.BetaFirstObject -> BetaFirstObject + BetaOutsideSealedClassEnum.BetaFourthObject -> BetaFourthObject + BetaOutsideSealedClassEnum.BetaSecondObject -> BetaSecondObject + BetaOutsideSealedClassEnum.BetaThirdObject -> BetaThirdObject + } +} + +/** + * The index of [this] in the values list. + */ +public val BetaOutsideSealedClass.ordinal: Int + get() = BetaOutsideSealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val BetaOutsideSealedClass.name: String + get() = BetaOutsideSealedClassSealedEnum.nameOf(this) + +/** + * A list of all [BetaOutsideSealedClass] objects. + */ +public val BetaOutsideSealedClass.Companion.values: List + get() = BetaOutsideSealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [BetaOutsideSealedClass] + */ +public val BetaOutsideSealedClass.Companion.sealedEnum: BetaOutsideSealedClassSealedEnum + get() = BetaOutsideSealedClassSealedEnum + +/** + * Returns the [BetaOutsideSealedClass] object for the given [name]. + * + * If the given name doesn't correspond to any [BetaOutsideSealedClass], an + * [IllegalArgumentException] will be thrown. + */ +public fun BetaOutsideSealedClass.Companion.valueOf(name: String): BetaOutsideSealedClass = + BetaOutsideSealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/OutsideSealedClassTests.compilation for delta outside sealed class generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/OutsideSealedClassTests.compilation for delta outside sealed class generates correct code.approved new file mode 100644 index 00000000..2c876ec1 --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/OutsideSealedClassTests.compilation for delta outside sealed class generates correct code.approved @@ -0,0 +1,112 @@ +package com.livefront.sealedenum.compilation.location + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [DeltaOutsideSealedClass] + */ +public enum class DeltaOutsideSealedClassEnum() { + DeltaOutsideSealedClass_DeltaObject, + DeltaObject, +} + +/** + * The isomorphic [DeltaOutsideSealedClassEnum] for [this]. + */ +public val DeltaOutsideSealedClass.`enum`: DeltaOutsideSealedClassEnum + get() = DeltaOutsideSealedClassSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [DeltaOutsideSealedClass] for [this]. + */ +public val DeltaOutsideSealedClassEnum.sealedObject: DeltaOutsideSealedClass + get() = DeltaOutsideSealedClassSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [DeltaOutsideSealedClass] + */ +public object DeltaOutsideSealedClassSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + DeltaOutsideSealedClass.DeltaObject, + DeltaObject + ) + } + + + public override val enumClass: KClass + get() = DeltaOutsideSealedClassEnum::class + + public override fun ordinalOf(obj: DeltaOutsideSealedClass): Int = when (obj) { + is DeltaOutsideSealedClass.DeltaObject -> 0 + is DeltaObject -> 1 + } + + public override fun nameOf(obj: DeltaOutsideSealedClass): String = when (obj) { + is DeltaOutsideSealedClass.DeltaObject -> "DeltaOutsideSealedClass_DeltaObject" + is DeltaObject -> "DeltaObject" + } + + public override fun valueOf(name: String): DeltaOutsideSealedClass = when (name) { + "DeltaOutsideSealedClass_DeltaObject" -> DeltaOutsideSealedClass.DeltaObject + "DeltaObject" -> DeltaObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: DeltaOutsideSealedClass): + DeltaOutsideSealedClassEnum = when (obj) { + is DeltaOutsideSealedClass.DeltaObject -> + DeltaOutsideSealedClassEnum.DeltaOutsideSealedClass_DeltaObject + is DeltaObject -> DeltaOutsideSealedClassEnum.DeltaObject + } + + public override fun enumToSealedObject(`enum`: DeltaOutsideSealedClassEnum): + DeltaOutsideSealedClass = when (enum) { + DeltaOutsideSealedClassEnum.DeltaOutsideSealedClass_DeltaObject -> + DeltaOutsideSealedClass.DeltaObject + DeltaOutsideSealedClassEnum.DeltaObject -> DeltaObject + } +} + +/** + * The index of [this] in the values list. + */ +public val DeltaOutsideSealedClass.ordinal: Int + get() = DeltaOutsideSealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val DeltaOutsideSealedClass.name: String + get() = DeltaOutsideSealedClassSealedEnum.nameOf(this) + +/** + * A list of all [DeltaOutsideSealedClass] objects. + */ +public val DeltaOutsideSealedClass.Companion.values: List + get() = DeltaOutsideSealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [DeltaOutsideSealedClass] + */ +public val DeltaOutsideSealedClass.Companion.sealedEnum: DeltaOutsideSealedClassSealedEnum + get() = DeltaOutsideSealedClassSealedEnum + +/** + * Returns the [DeltaOutsideSealedClass] object for the given [name]. + * + * If the given name doesn't correspond to any [DeltaOutsideSealedClass], an + * [IllegalArgumentException] will be thrown. + */ +public fun DeltaOutsideSealedClass.Companion.valueOf(name: String): DeltaOutsideSealedClass = + DeltaOutsideSealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/OutsideSealedClassTests.compilation for gamma outside sealed class generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/OutsideSealedClassTests.compilation for gamma outside sealed class generates correct code.approved new file mode 100644 index 00000000..cfefeaf6 --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/OutsideSealedClassTests.compilation for gamma outside sealed class generates correct code.approved @@ -0,0 +1,126 @@ +package com.livefront.sealedenum.compilation.location + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [GammaOutsideSealedClass] + */ +public enum class GammaOutsideSealedClassEnum() { + GammaOutsideSealedClass_GammaSecondObject, + GammaFirstObject, + GammaFourthObject, + GammaThirdObject, +} + +/** + * The isomorphic [GammaOutsideSealedClassEnum] for [this]. + */ +public val GammaOutsideSealedClass.`enum`: GammaOutsideSealedClassEnum + get() = GammaOutsideSealedClassSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [GammaOutsideSealedClass] for [this]. + */ +public val GammaOutsideSealedClassEnum.sealedObject: GammaOutsideSealedClass + get() = GammaOutsideSealedClassSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [GammaOutsideSealedClass] + */ +public object GammaOutsideSealedClassSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + GammaOutsideSealedClass.GammaSecondObject, + GammaFirstObject, + GammaFourthObject, + GammaThirdObject + ) + } + + + public override val enumClass: KClass + get() = GammaOutsideSealedClassEnum::class + + public override fun ordinalOf(obj: GammaOutsideSealedClass): Int = when (obj) { + is GammaOutsideSealedClass.GammaSecondObject -> 0 + is GammaFirstObject -> 1 + is GammaFourthObject -> 2 + is GammaThirdObject -> 3 + } + + public override fun nameOf(obj: GammaOutsideSealedClass): String = when (obj) { + is GammaOutsideSealedClass.GammaSecondObject -> "GammaOutsideSealedClass_GammaSecondObject" + is GammaFirstObject -> "GammaFirstObject" + is GammaFourthObject -> "GammaFourthObject" + is GammaThirdObject -> "GammaThirdObject" + } + + public override fun valueOf(name: String): GammaOutsideSealedClass = when (name) { + "GammaOutsideSealedClass_GammaSecondObject" -> GammaOutsideSealedClass.GammaSecondObject + "GammaFirstObject" -> GammaFirstObject + "GammaFourthObject" -> GammaFourthObject + "GammaThirdObject" -> GammaThirdObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: GammaOutsideSealedClass): + GammaOutsideSealedClassEnum = when (obj) { + is GammaOutsideSealedClass.GammaSecondObject -> + GammaOutsideSealedClassEnum.GammaOutsideSealedClass_GammaSecondObject + is GammaFirstObject -> GammaOutsideSealedClassEnum.GammaFirstObject + is GammaFourthObject -> GammaOutsideSealedClassEnum.GammaFourthObject + is GammaThirdObject -> GammaOutsideSealedClassEnum.GammaThirdObject + } + + public override fun enumToSealedObject(`enum`: GammaOutsideSealedClassEnum): + GammaOutsideSealedClass = when (enum) { + GammaOutsideSealedClassEnum.GammaOutsideSealedClass_GammaSecondObject -> + GammaOutsideSealedClass.GammaSecondObject + GammaOutsideSealedClassEnum.GammaFirstObject -> GammaFirstObject + GammaOutsideSealedClassEnum.GammaFourthObject -> GammaFourthObject + GammaOutsideSealedClassEnum.GammaThirdObject -> GammaThirdObject + } +} + +/** + * The index of [this] in the values list. + */ +public val GammaOutsideSealedClass.ordinal: Int + get() = GammaOutsideSealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val GammaOutsideSealedClass.name: String + get() = GammaOutsideSealedClassSealedEnum.nameOf(this) + +/** + * A list of all [GammaOutsideSealedClass] objects. + */ +public val GammaOutsideSealedClass.Companion.values: List + get() = GammaOutsideSealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [GammaOutsideSealedClass] + */ +public val GammaOutsideSealedClass.Companion.sealedEnum: GammaOutsideSealedClassSealedEnum + get() = GammaOutsideSealedClassSealedEnum + +/** + * Returns the [GammaOutsideSealedClass] object for the given [name]. + * + * If the given name doesn't correspond to any [GammaOutsideSealedClass], an + * [IllegalArgumentException] will be thrown. + */ +public fun GammaOutsideSealedClass.Companion.valueOf(name: String): GammaOutsideSealedClass = + GammaOutsideSealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/SplitAcrossFilesSealedClassTests.compilation for objects split across files generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/SplitAcrossFilesSealedClassTests.compilation for objects split across files generates correct code.approved new file mode 100644 index 00000000..f79e5314 --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/SplitAcrossFilesSealedClassTests.compilation for objects split across files generates correct code.approved @@ -0,0 +1,117 @@ +package com.livefront.sealedenum.compilation.location + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [SplitAcrossFilesSealedClass] + */ +public enum class SplitAcrossFilesSealedClassEnum() { + SplitAcrossFilesSubclassA, + SplitAcrossFilesSubclassB, + SplitAcrossFilesSubclassC, +} + +/** + * The isomorphic [SplitAcrossFilesSealedClassEnum] for [this]. + */ +public val SplitAcrossFilesSealedClass.`enum`: SplitAcrossFilesSealedClassEnum + get() = SplitAcrossFilesSealedClassSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [SplitAcrossFilesSealedClass] for [this]. + */ +public val SplitAcrossFilesSealedClassEnum.sealedObject: SplitAcrossFilesSealedClass + get() = SplitAcrossFilesSealedClassSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [SplitAcrossFilesSealedClass] + */ +public object SplitAcrossFilesSealedClassSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + SplitAcrossFilesSubclassA, + SplitAcrossFilesSubclassB, + SplitAcrossFilesSubclassC + ) + } + + + public override val enumClass: KClass + get() = SplitAcrossFilesSealedClassEnum::class + + public override fun ordinalOf(obj: SplitAcrossFilesSealedClass): Int = when (obj) { + is SplitAcrossFilesSubclassA -> 0 + is SplitAcrossFilesSubclassB -> 1 + is SplitAcrossFilesSubclassC -> 2 + } + + public override fun nameOf(obj: SplitAcrossFilesSealedClass): String = when (obj) { + is SplitAcrossFilesSubclassA -> "SplitAcrossFilesSubclassA" + is SplitAcrossFilesSubclassB -> "SplitAcrossFilesSubclassB" + is SplitAcrossFilesSubclassC -> "SplitAcrossFilesSubclassC" + } + + public override fun valueOf(name: String): SplitAcrossFilesSealedClass = when (name) { + "SplitAcrossFilesSubclassA" -> SplitAcrossFilesSubclassA + "SplitAcrossFilesSubclassB" -> SplitAcrossFilesSubclassB + "SplitAcrossFilesSubclassC" -> SplitAcrossFilesSubclassC + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: SplitAcrossFilesSealedClass): + SplitAcrossFilesSealedClassEnum = when (obj) { + is SplitAcrossFilesSubclassA -> SplitAcrossFilesSealedClassEnum.SplitAcrossFilesSubclassA + is SplitAcrossFilesSubclassB -> SplitAcrossFilesSealedClassEnum.SplitAcrossFilesSubclassB + is SplitAcrossFilesSubclassC -> SplitAcrossFilesSealedClassEnum.SplitAcrossFilesSubclassC + } + + public override fun enumToSealedObject(`enum`: SplitAcrossFilesSealedClassEnum): + SplitAcrossFilesSealedClass = when (enum) { + SplitAcrossFilesSealedClassEnum.SplitAcrossFilesSubclassA -> SplitAcrossFilesSubclassA + SplitAcrossFilesSealedClassEnum.SplitAcrossFilesSubclassB -> SplitAcrossFilesSubclassB + SplitAcrossFilesSealedClassEnum.SplitAcrossFilesSubclassC -> SplitAcrossFilesSubclassC + } +} + +/** + * The index of [this] in the values list. + */ +public val SplitAcrossFilesSealedClass.ordinal: Int + get() = SplitAcrossFilesSealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val SplitAcrossFilesSealedClass.name: String + get() = SplitAcrossFilesSealedClassSealedEnum.nameOf(this) + +/** + * A list of all [SplitAcrossFilesSealedClass] objects. + */ +public val SplitAcrossFilesSealedClass.Companion.values: List + get() = SplitAcrossFilesSealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [SplitAcrossFilesSealedClass] + */ +public val SplitAcrossFilesSealedClass.Companion.sealedEnum: SplitAcrossFilesSealedClassSealedEnum + get() = SplitAcrossFilesSealedClassSealedEnum + +/** + * Returns the [SplitAcrossFilesSealedClass] object for the given [name]. + * + * If the given name doesn't correspond to any [SplitAcrossFilesSealedClass], an + * [IllegalArgumentException] will be thrown. + */ +public fun SplitAcrossFilesSealedClass.Companion.valueOf(name: String): SplitAcrossFilesSealedClass + = SplitAcrossFilesSealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/traversal/TraversalOrderTests.compilation generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/traversal/TraversalOrderTests.compilation generates correct code.approved new file mode 100644 index 00000000..5736f294 --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/traversal/TraversalOrderTests.compilation generates correct code.approved @@ -0,0 +1,728 @@ +package com.livefront.sealedenum.compilation.traversal + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [Tree] + */ +public enum class TreeLevelOrderEnum() { + Tree_A, + Tree_K, + Tree_T, + Tree_L_S, + Tree_B_C_D, + Tree_B_C_E, + Tree_B_C_J, + Tree_L_M_N, + Tree_L_M_O, + Tree_L_P_Q, + Tree_L_P_R, + Tree_B_C_F_G, + Tree_B_C_F_H, + Tree_B_C_F_I, +} + +/** + * The isomorphic [TreeLevelOrderEnum] for [this]. + */ +public val Tree.levelOrderEnum: TreeLevelOrderEnum + get() = TreeLevelOrderSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [Tree] for [this]. + */ +public val TreeLevelOrderEnum.sealedObject: Tree + get() = TreeLevelOrderSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [Tree] + */ +public object TreeLevelOrderSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = LazyThreadSafetyMode.PUBLICATION) { + listOf( + Tree.A, + Tree.K, + Tree.T, + Tree.L.S, + Tree.B.C.D, + Tree.B.C.E, + Tree.B.C.J, + Tree.L.M.N, + Tree.L.M.O, + Tree.L.P.Q, + Tree.L.P.R, + Tree.B.C.F.G, + Tree.B.C.F.H, + Tree.B.C.F.I + ) + } + + + public override val enumClass: KClass + get() = TreeLevelOrderEnum::class + + public override fun ordinalOf(obj: Tree): Int = when (obj) { + is Tree.A -> 0 + is Tree.K -> 1 + is Tree.T -> 2 + is Tree.L.S -> 3 + is Tree.B.C.D -> 4 + is Tree.B.C.E -> 5 + is Tree.B.C.J -> 6 + is Tree.L.M.N -> 7 + is Tree.L.M.O -> 8 + is Tree.L.P.Q -> 9 + is Tree.L.P.R -> 10 + is Tree.B.C.F.G -> 11 + is Tree.B.C.F.H -> 12 + is Tree.B.C.F.I -> 13 + } + + public override fun nameOf(obj: Tree): String = when (obj) { + is Tree.A -> "Tree_A" + is Tree.K -> "Tree_K" + is Tree.T -> "Tree_T" + is Tree.L.S -> "Tree_L_S" + is Tree.B.C.D -> "Tree_B_C_D" + is Tree.B.C.E -> "Tree_B_C_E" + is Tree.B.C.J -> "Tree_B_C_J" + is Tree.L.M.N -> "Tree_L_M_N" + is Tree.L.M.O -> "Tree_L_M_O" + is Tree.L.P.Q -> "Tree_L_P_Q" + is Tree.L.P.R -> "Tree_L_P_R" + is Tree.B.C.F.G -> "Tree_B_C_F_G" + is Tree.B.C.F.H -> "Tree_B_C_F_H" + is Tree.B.C.F.I -> "Tree_B_C_F_I" + } + + public override fun valueOf(name: String): Tree = when (name) { + "Tree_A" -> Tree.A + "Tree_K" -> Tree.K + "Tree_T" -> Tree.T + "Tree_L_S" -> Tree.L.S + "Tree_B_C_D" -> Tree.B.C.D + "Tree_B_C_E" -> Tree.B.C.E + "Tree_B_C_J" -> Tree.B.C.J + "Tree_L_M_N" -> Tree.L.M.N + "Tree_L_M_O" -> Tree.L.M.O + "Tree_L_P_Q" -> Tree.L.P.Q + "Tree_L_P_R" -> Tree.L.P.R + "Tree_B_C_F_G" -> Tree.B.C.F.G + "Tree_B_C_F_H" -> Tree.B.C.F.H + "Tree_B_C_F_I" -> Tree.B.C.F.I + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: Tree): TreeLevelOrderEnum = when (obj) { + is Tree.A -> TreeLevelOrderEnum.Tree_A + is Tree.K -> TreeLevelOrderEnum.Tree_K + is Tree.T -> TreeLevelOrderEnum.Tree_T + is Tree.L.S -> TreeLevelOrderEnum.Tree_L_S + is Tree.B.C.D -> TreeLevelOrderEnum.Tree_B_C_D + is Tree.B.C.E -> TreeLevelOrderEnum.Tree_B_C_E + is Tree.B.C.J -> TreeLevelOrderEnum.Tree_B_C_J + is Tree.L.M.N -> TreeLevelOrderEnum.Tree_L_M_N + is Tree.L.M.O -> TreeLevelOrderEnum.Tree_L_M_O + is Tree.L.P.Q -> TreeLevelOrderEnum.Tree_L_P_Q + is Tree.L.P.R -> TreeLevelOrderEnum.Tree_L_P_R + is Tree.B.C.F.G -> TreeLevelOrderEnum.Tree_B_C_F_G + is Tree.B.C.F.H -> TreeLevelOrderEnum.Tree_B_C_F_H + is Tree.B.C.F.I -> TreeLevelOrderEnum.Tree_B_C_F_I + } + + public override fun enumToSealedObject(`enum`: TreeLevelOrderEnum): Tree = when (enum) { + TreeLevelOrderEnum.Tree_A -> Tree.A + TreeLevelOrderEnum.Tree_K -> Tree.K + TreeLevelOrderEnum.Tree_T -> Tree.T + TreeLevelOrderEnum.Tree_L_S -> Tree.L.S + TreeLevelOrderEnum.Tree_B_C_D -> Tree.B.C.D + TreeLevelOrderEnum.Tree_B_C_E -> Tree.B.C.E + TreeLevelOrderEnum.Tree_B_C_J -> Tree.B.C.J + TreeLevelOrderEnum.Tree_L_M_N -> Tree.L.M.N + TreeLevelOrderEnum.Tree_L_M_O -> Tree.L.M.O + TreeLevelOrderEnum.Tree_L_P_Q -> Tree.L.P.Q + TreeLevelOrderEnum.Tree_L_P_R -> Tree.L.P.R + TreeLevelOrderEnum.Tree_B_C_F_G -> Tree.B.C.F.G + TreeLevelOrderEnum.Tree_B_C_F_H -> Tree.B.C.F.H + TreeLevelOrderEnum.Tree_B_C_F_I -> Tree.B.C.F.I + } +} + +/** + * The index of [this] in the values list. + */ +public val Tree.levelOrderOrdinal: Int + get() = TreeLevelOrderSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val Tree.levelOrderName: String + get() = TreeLevelOrderSealedEnum.nameOf(this) + +/** + * A list of all [Tree] objects. + */ +public val Tree.Companion.levelOrderValues: List + get() = TreeLevelOrderSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [Tree] + */ +public val Tree.Companion.levelOrderSealedEnum: TreeLevelOrderSealedEnum + get() = TreeLevelOrderSealedEnum + +/** + * Returns the [Tree] object for the given [name]. + * + * If the given name doesn't correspond to any [Tree], an [IllegalArgumentException] will be thrown. + */ +public fun Tree.Companion.levelOrderValueOf(name: String): Tree = + TreeLevelOrderSealedEnum.valueOf(name) + +/** + * An isomorphic enum for the sealed class [Tree] + */ +public enum class TreePostOrderEnum() { + Tree_B_C_F_G, + Tree_B_C_F_H, + Tree_B_C_F_I, + Tree_B_C_D, + Tree_B_C_E, + Tree_B_C_J, + Tree_L_M_N, + Tree_L_M_O, + Tree_L_P_Q, + Tree_L_P_R, + Tree_L_S, + Tree_A, + Tree_K, + Tree_T, +} + +/** + * The isomorphic [TreePostOrderEnum] for [this]. + */ +public val Tree.postOrderEnum: TreePostOrderEnum + get() = TreePostOrderSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [Tree] for [this]. + */ +public val TreePostOrderEnum.sealedObject: Tree + get() = TreePostOrderSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [Tree] + */ +public object TreePostOrderSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = LazyThreadSafetyMode.PUBLICATION) { + listOf( + Tree.B.C.F.G, + Tree.B.C.F.H, + Tree.B.C.F.I, + Tree.B.C.D, + Tree.B.C.E, + Tree.B.C.J, + Tree.L.M.N, + Tree.L.M.O, + Tree.L.P.Q, + Tree.L.P.R, + Tree.L.S, + Tree.A, + Tree.K, + Tree.T + ) + } + + + public override val enumClass: KClass + get() = TreePostOrderEnum::class + + public override fun ordinalOf(obj: Tree): Int = when (obj) { + is Tree.B.C.F.G -> 0 + is Tree.B.C.F.H -> 1 + is Tree.B.C.F.I -> 2 + is Tree.B.C.D -> 3 + is Tree.B.C.E -> 4 + is Tree.B.C.J -> 5 + is Tree.L.M.N -> 6 + is Tree.L.M.O -> 7 + is Tree.L.P.Q -> 8 + is Tree.L.P.R -> 9 + is Tree.L.S -> 10 + is Tree.A -> 11 + is Tree.K -> 12 + is Tree.T -> 13 + } + + public override fun nameOf(obj: Tree): String = when (obj) { + is Tree.B.C.F.G -> "Tree_B_C_F_G" + is Tree.B.C.F.H -> "Tree_B_C_F_H" + is Tree.B.C.F.I -> "Tree_B_C_F_I" + is Tree.B.C.D -> "Tree_B_C_D" + is Tree.B.C.E -> "Tree_B_C_E" + is Tree.B.C.J -> "Tree_B_C_J" + is Tree.L.M.N -> "Tree_L_M_N" + is Tree.L.M.O -> "Tree_L_M_O" + is Tree.L.P.Q -> "Tree_L_P_Q" + is Tree.L.P.R -> "Tree_L_P_R" + is Tree.L.S -> "Tree_L_S" + is Tree.A -> "Tree_A" + is Tree.K -> "Tree_K" + is Tree.T -> "Tree_T" + } + + public override fun valueOf(name: String): Tree = when (name) { + "Tree_B_C_F_G" -> Tree.B.C.F.G + "Tree_B_C_F_H" -> Tree.B.C.F.H + "Tree_B_C_F_I" -> Tree.B.C.F.I + "Tree_B_C_D" -> Tree.B.C.D + "Tree_B_C_E" -> Tree.B.C.E + "Tree_B_C_J" -> Tree.B.C.J + "Tree_L_M_N" -> Tree.L.M.N + "Tree_L_M_O" -> Tree.L.M.O + "Tree_L_P_Q" -> Tree.L.P.Q + "Tree_L_P_R" -> Tree.L.P.R + "Tree_L_S" -> Tree.L.S + "Tree_A" -> Tree.A + "Tree_K" -> Tree.K + "Tree_T" -> Tree.T + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: Tree): TreePostOrderEnum = when (obj) { + is Tree.B.C.F.G -> TreePostOrderEnum.Tree_B_C_F_G + is Tree.B.C.F.H -> TreePostOrderEnum.Tree_B_C_F_H + is Tree.B.C.F.I -> TreePostOrderEnum.Tree_B_C_F_I + is Tree.B.C.D -> TreePostOrderEnum.Tree_B_C_D + is Tree.B.C.E -> TreePostOrderEnum.Tree_B_C_E + is Tree.B.C.J -> TreePostOrderEnum.Tree_B_C_J + is Tree.L.M.N -> TreePostOrderEnum.Tree_L_M_N + is Tree.L.M.O -> TreePostOrderEnum.Tree_L_M_O + is Tree.L.P.Q -> TreePostOrderEnum.Tree_L_P_Q + is Tree.L.P.R -> TreePostOrderEnum.Tree_L_P_R + is Tree.L.S -> TreePostOrderEnum.Tree_L_S + is Tree.A -> TreePostOrderEnum.Tree_A + is Tree.K -> TreePostOrderEnum.Tree_K + is Tree.T -> TreePostOrderEnum.Tree_T + } + + public override fun enumToSealedObject(`enum`: TreePostOrderEnum): Tree = when (enum) { + TreePostOrderEnum.Tree_B_C_F_G -> Tree.B.C.F.G + TreePostOrderEnum.Tree_B_C_F_H -> Tree.B.C.F.H + TreePostOrderEnum.Tree_B_C_F_I -> Tree.B.C.F.I + TreePostOrderEnum.Tree_B_C_D -> Tree.B.C.D + TreePostOrderEnum.Tree_B_C_E -> Tree.B.C.E + TreePostOrderEnum.Tree_B_C_J -> Tree.B.C.J + TreePostOrderEnum.Tree_L_M_N -> Tree.L.M.N + TreePostOrderEnum.Tree_L_M_O -> Tree.L.M.O + TreePostOrderEnum.Tree_L_P_Q -> Tree.L.P.Q + TreePostOrderEnum.Tree_L_P_R -> Tree.L.P.R + TreePostOrderEnum.Tree_L_S -> Tree.L.S + TreePostOrderEnum.Tree_A -> Tree.A + TreePostOrderEnum.Tree_K -> Tree.K + TreePostOrderEnum.Tree_T -> Tree.T + } +} + +/** + * The index of [this] in the values list. + */ +public val Tree.postOrderOrdinal: Int + get() = TreePostOrderSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val Tree.postOrderName: String + get() = TreePostOrderSealedEnum.nameOf(this) + +/** + * A list of all [Tree] objects. + */ +public val Tree.Companion.postOrderValues: List + get() = TreePostOrderSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [Tree] + */ +public val Tree.Companion.postOrderSealedEnum: TreePostOrderSealedEnum + get() = TreePostOrderSealedEnum + +/** + * Returns the [Tree] object for the given [name]. + * + * If the given name doesn't correspond to any [Tree], an [IllegalArgumentException] will be thrown. + */ +public fun Tree.Companion.postOrderValueOf(name: String): Tree = + TreePostOrderSealedEnum.valueOf(name) + +/** + * An isomorphic enum for the sealed class [Tree] + */ +public enum class TreeInOrderEnum() { + Tree_A, + Tree_B_C_D, + Tree_B_C_E, + Tree_B_C_F_G, + Tree_B_C_F_H, + Tree_B_C_F_I, + Tree_B_C_J, + Tree_K, + Tree_L_M_N, + Tree_L_M_O, + Tree_L_P_Q, + Tree_L_P_R, + Tree_L_S, + Tree_T, +} + +/** + * The isomorphic [TreeInOrderEnum] for [this]. + */ +public val Tree.inOrderEnum: TreeInOrderEnum + get() = TreeInOrderSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [Tree] for [this]. + */ +public val TreeInOrderEnum.sealedObject: Tree + get() = TreeInOrderSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [Tree] + */ +public object TreeInOrderSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = LazyThreadSafetyMode.PUBLICATION) { + listOf( + Tree.A, + Tree.B.C.D, + Tree.B.C.E, + Tree.B.C.F.G, + Tree.B.C.F.H, + Tree.B.C.F.I, + Tree.B.C.J, + Tree.K, + Tree.L.M.N, + Tree.L.M.O, + Tree.L.P.Q, + Tree.L.P.R, + Tree.L.S, + Tree.T + ) + } + + + public override val enumClass: KClass + get() = TreeInOrderEnum::class + + public override fun ordinalOf(obj: Tree): Int = when (obj) { + is Tree.A -> 0 + is Tree.B.C.D -> 1 + is Tree.B.C.E -> 2 + is Tree.B.C.F.G -> 3 + is Tree.B.C.F.H -> 4 + is Tree.B.C.F.I -> 5 + is Tree.B.C.J -> 6 + is Tree.K -> 7 + is Tree.L.M.N -> 8 + is Tree.L.M.O -> 9 + is Tree.L.P.Q -> 10 + is Tree.L.P.R -> 11 + is Tree.L.S -> 12 + is Tree.T -> 13 + } + + public override fun nameOf(obj: Tree): String = when (obj) { + is Tree.A -> "Tree_A" + is Tree.B.C.D -> "Tree_B_C_D" + is Tree.B.C.E -> "Tree_B_C_E" + is Tree.B.C.F.G -> "Tree_B_C_F_G" + is Tree.B.C.F.H -> "Tree_B_C_F_H" + is Tree.B.C.F.I -> "Tree_B_C_F_I" + is Tree.B.C.J -> "Tree_B_C_J" + is Tree.K -> "Tree_K" + is Tree.L.M.N -> "Tree_L_M_N" + is Tree.L.M.O -> "Tree_L_M_O" + is Tree.L.P.Q -> "Tree_L_P_Q" + is Tree.L.P.R -> "Tree_L_P_R" + is Tree.L.S -> "Tree_L_S" + is Tree.T -> "Tree_T" + } + + public override fun valueOf(name: String): Tree = when (name) { + "Tree_A" -> Tree.A + "Tree_B_C_D" -> Tree.B.C.D + "Tree_B_C_E" -> Tree.B.C.E + "Tree_B_C_F_G" -> Tree.B.C.F.G + "Tree_B_C_F_H" -> Tree.B.C.F.H + "Tree_B_C_F_I" -> Tree.B.C.F.I + "Tree_B_C_J" -> Tree.B.C.J + "Tree_K" -> Tree.K + "Tree_L_M_N" -> Tree.L.M.N + "Tree_L_M_O" -> Tree.L.M.O + "Tree_L_P_Q" -> Tree.L.P.Q + "Tree_L_P_R" -> Tree.L.P.R + "Tree_L_S" -> Tree.L.S + "Tree_T" -> Tree.T + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: Tree): TreeInOrderEnum = when (obj) { + is Tree.A -> TreeInOrderEnum.Tree_A + is Tree.B.C.D -> TreeInOrderEnum.Tree_B_C_D + is Tree.B.C.E -> TreeInOrderEnum.Tree_B_C_E + is Tree.B.C.F.G -> TreeInOrderEnum.Tree_B_C_F_G + is Tree.B.C.F.H -> TreeInOrderEnum.Tree_B_C_F_H + is Tree.B.C.F.I -> TreeInOrderEnum.Tree_B_C_F_I + is Tree.B.C.J -> TreeInOrderEnum.Tree_B_C_J + is Tree.K -> TreeInOrderEnum.Tree_K + is Tree.L.M.N -> TreeInOrderEnum.Tree_L_M_N + is Tree.L.M.O -> TreeInOrderEnum.Tree_L_M_O + is Tree.L.P.Q -> TreeInOrderEnum.Tree_L_P_Q + is Tree.L.P.R -> TreeInOrderEnum.Tree_L_P_R + is Tree.L.S -> TreeInOrderEnum.Tree_L_S + is Tree.T -> TreeInOrderEnum.Tree_T + } + + public override fun enumToSealedObject(`enum`: TreeInOrderEnum): Tree = when (enum) { + TreeInOrderEnum.Tree_A -> Tree.A + TreeInOrderEnum.Tree_B_C_D -> Tree.B.C.D + TreeInOrderEnum.Tree_B_C_E -> Tree.B.C.E + TreeInOrderEnum.Tree_B_C_F_G -> Tree.B.C.F.G + TreeInOrderEnum.Tree_B_C_F_H -> Tree.B.C.F.H + TreeInOrderEnum.Tree_B_C_F_I -> Tree.B.C.F.I + TreeInOrderEnum.Tree_B_C_J -> Tree.B.C.J + TreeInOrderEnum.Tree_K -> Tree.K + TreeInOrderEnum.Tree_L_M_N -> Tree.L.M.N + TreeInOrderEnum.Tree_L_M_O -> Tree.L.M.O + TreeInOrderEnum.Tree_L_P_Q -> Tree.L.P.Q + TreeInOrderEnum.Tree_L_P_R -> Tree.L.P.R + TreeInOrderEnum.Tree_L_S -> Tree.L.S + TreeInOrderEnum.Tree_T -> Tree.T + } +} + +/** + * The index of [this] in the values list. + */ +public val Tree.inOrderOrdinal: Int + get() = TreeInOrderSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val Tree.inOrderName: String + get() = TreeInOrderSealedEnum.nameOf(this) + +/** + * A list of all [Tree] objects. + */ +public val Tree.Companion.inOrderValues: List + get() = TreeInOrderSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [Tree] + */ +public val Tree.Companion.inOrderSealedEnum: TreeInOrderSealedEnum + get() = TreeInOrderSealedEnum + +/** + * Returns the [Tree] object for the given [name]. + * + * If the given name doesn't correspond to any [Tree], an [IllegalArgumentException] will be thrown. + */ +public fun Tree.Companion.inOrderValueOf(name: String): Tree = TreeInOrderSealedEnum.valueOf(name) + +/** + * An isomorphic enum for the sealed class [Tree] + */ +public enum class TreePreOrderEnum() { + Tree_A, + Tree_K, + Tree_T, + Tree_B_C_D, + Tree_B_C_E, + Tree_B_C_J, + Tree_B_C_F_G, + Tree_B_C_F_H, + Tree_B_C_F_I, + Tree_L_S, + Tree_L_M_N, + Tree_L_M_O, + Tree_L_P_Q, + Tree_L_P_R, +} + +/** + * The isomorphic [TreePreOrderEnum] for [this]. + */ +public val Tree.preOrderEnum: TreePreOrderEnum + get() = TreePreOrderSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [Tree] for [this]. + */ +public val TreePreOrderEnum.sealedObject: Tree + get() = TreePreOrderSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [Tree] + */ +public object TreePreOrderSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = LazyThreadSafetyMode.PUBLICATION) { + listOf( + Tree.A, + Tree.K, + Tree.T, + Tree.B.C.D, + Tree.B.C.E, + Tree.B.C.J, + Tree.B.C.F.G, + Tree.B.C.F.H, + Tree.B.C.F.I, + Tree.L.S, + Tree.L.M.N, + Tree.L.M.O, + Tree.L.P.Q, + Tree.L.P.R + ) + } + + + public override val enumClass: KClass + get() = TreePreOrderEnum::class + + public override fun ordinalOf(obj: Tree): Int = when (obj) { + is Tree.A -> 0 + is Tree.K -> 1 + is Tree.T -> 2 + is Tree.B.C.D -> 3 + is Tree.B.C.E -> 4 + is Tree.B.C.J -> 5 + is Tree.B.C.F.G -> 6 + is Tree.B.C.F.H -> 7 + is Tree.B.C.F.I -> 8 + is Tree.L.S -> 9 + is Tree.L.M.N -> 10 + is Tree.L.M.O -> 11 + is Tree.L.P.Q -> 12 + is Tree.L.P.R -> 13 + } + + public override fun nameOf(obj: Tree): String = when (obj) { + is Tree.A -> "Tree_A" + is Tree.K -> "Tree_K" + is Tree.T -> "Tree_T" + is Tree.B.C.D -> "Tree_B_C_D" + is Tree.B.C.E -> "Tree_B_C_E" + is Tree.B.C.J -> "Tree_B_C_J" + is Tree.B.C.F.G -> "Tree_B_C_F_G" + is Tree.B.C.F.H -> "Tree_B_C_F_H" + is Tree.B.C.F.I -> "Tree_B_C_F_I" + is Tree.L.S -> "Tree_L_S" + is Tree.L.M.N -> "Tree_L_M_N" + is Tree.L.M.O -> "Tree_L_M_O" + is Tree.L.P.Q -> "Tree_L_P_Q" + is Tree.L.P.R -> "Tree_L_P_R" + } + + public override fun valueOf(name: String): Tree = when (name) { + "Tree_A" -> Tree.A + "Tree_K" -> Tree.K + "Tree_T" -> Tree.T + "Tree_B_C_D" -> Tree.B.C.D + "Tree_B_C_E" -> Tree.B.C.E + "Tree_B_C_J" -> Tree.B.C.J + "Tree_B_C_F_G" -> Tree.B.C.F.G + "Tree_B_C_F_H" -> Tree.B.C.F.H + "Tree_B_C_F_I" -> Tree.B.C.F.I + "Tree_L_S" -> Tree.L.S + "Tree_L_M_N" -> Tree.L.M.N + "Tree_L_M_O" -> Tree.L.M.O + "Tree_L_P_Q" -> Tree.L.P.Q + "Tree_L_P_R" -> Tree.L.P.R + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: Tree): TreePreOrderEnum = when (obj) { + is Tree.A -> TreePreOrderEnum.Tree_A + is Tree.K -> TreePreOrderEnum.Tree_K + is Tree.T -> TreePreOrderEnum.Tree_T + is Tree.B.C.D -> TreePreOrderEnum.Tree_B_C_D + is Tree.B.C.E -> TreePreOrderEnum.Tree_B_C_E + is Tree.B.C.J -> TreePreOrderEnum.Tree_B_C_J + is Tree.B.C.F.G -> TreePreOrderEnum.Tree_B_C_F_G + is Tree.B.C.F.H -> TreePreOrderEnum.Tree_B_C_F_H + is Tree.B.C.F.I -> TreePreOrderEnum.Tree_B_C_F_I + is Tree.L.S -> TreePreOrderEnum.Tree_L_S + is Tree.L.M.N -> TreePreOrderEnum.Tree_L_M_N + is Tree.L.M.O -> TreePreOrderEnum.Tree_L_M_O + is Tree.L.P.Q -> TreePreOrderEnum.Tree_L_P_Q + is Tree.L.P.R -> TreePreOrderEnum.Tree_L_P_R + } + + public override fun enumToSealedObject(`enum`: TreePreOrderEnum): Tree = when (enum) { + TreePreOrderEnum.Tree_A -> Tree.A + TreePreOrderEnum.Tree_K -> Tree.K + TreePreOrderEnum.Tree_T -> Tree.T + TreePreOrderEnum.Tree_B_C_D -> Tree.B.C.D + TreePreOrderEnum.Tree_B_C_E -> Tree.B.C.E + TreePreOrderEnum.Tree_B_C_J -> Tree.B.C.J + TreePreOrderEnum.Tree_B_C_F_G -> Tree.B.C.F.G + TreePreOrderEnum.Tree_B_C_F_H -> Tree.B.C.F.H + TreePreOrderEnum.Tree_B_C_F_I -> Tree.B.C.F.I + TreePreOrderEnum.Tree_L_S -> Tree.L.S + TreePreOrderEnum.Tree_L_M_N -> Tree.L.M.N + TreePreOrderEnum.Tree_L_M_O -> Tree.L.M.O + TreePreOrderEnum.Tree_L_P_Q -> Tree.L.P.Q + TreePreOrderEnum.Tree_L_P_R -> Tree.L.P.R + } +} + +/** + * The index of [this] in the values list. + */ +public val Tree.preOrderOrdinal: Int + get() = TreePreOrderSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val Tree.preOrderName: String + get() = TreePreOrderSealedEnum.nameOf(this) + +/** + * A list of all [Tree] objects. + */ +public val Tree.Companion.preOrderValues: List + get() = TreePreOrderSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [Tree] + */ +public val Tree.Companion.preOrderSealedEnum: TreePreOrderSealedEnum + get() = TreePreOrderSealedEnum + +/** + * Returns the [Tree] object for the given [name]. + * + * If the given name doesn't correspond to any [Tree], an [IllegalArgumentException] will be thrown. + */ +public fun Tree.Companion.preOrderValueOf(name: String): Tree = TreePreOrderSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/usecases/EnvironmentsSealedEnumTests.compilation generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/usecases/EnvironmentsSealedEnumTests.compilation generates correct code.approved new file mode 100644 index 00000000..c55e6208 --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/usecases/EnvironmentsSealedEnumTests.compilation generates correct code.approved @@ -0,0 +1,124 @@ +package com.livefront.sealedenum.compilation.usecases + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [Environments] + */ +public enum class EnvironmentsEnum( + sealedObject: Environments, +) : Uri by sealedObject { + Environments_Http_Livefront(com.livefront.sealedenum.compilation.usecases.Environments.Http.Livefront), + Environments_Http_Google(com.livefront.sealedenum.compilation.usecases.Environments.Http.Google), + Environments_Https_Livefront(com.livefront.sealedenum.compilation.usecases.Environments.Https.Livefront), + Environments_Https_Google(com.livefront.sealedenum.compilation.usecases.Environments.Https.Google), +} + +/** + * The isomorphic [EnvironmentsEnum] for [this]. + */ +public val Environments.`enum`: EnvironmentsEnum + get() = EnvironmentsSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [Environments] for [this]. + */ +public val EnvironmentsEnum.sealedObject: Environments + get() = EnvironmentsSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [Environments] + */ +public object EnvironmentsSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + Environments.Http.Livefront, + Environments.Http.Google, + Environments.Https.Livefront, + Environments.Https.Google + ) + } + + + public override val enumClass: KClass + get() = EnvironmentsEnum::class + + public override fun ordinalOf(obj: Environments): Int = when (obj) { + is Environments.Http.Livefront -> 0 + is Environments.Http.Google -> 1 + is Environments.Https.Livefront -> 2 + is Environments.Https.Google -> 3 + } + + public override fun nameOf(obj: Environments): String = when (obj) { + is Environments.Http.Livefront -> "Environments_Http_Livefront" + is Environments.Http.Google -> "Environments_Http_Google" + is Environments.Https.Livefront -> "Environments_Https_Livefront" + is Environments.Https.Google -> "Environments_Https_Google" + } + + public override fun valueOf(name: String): Environments = when (name) { + "Environments_Http_Livefront" -> Environments.Http.Livefront + "Environments_Http_Google" -> Environments.Http.Google + "Environments_Https_Livefront" -> Environments.Https.Livefront + "Environments_Https_Google" -> Environments.Https.Google + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: Environments): EnvironmentsEnum = when (obj) { + is Environments.Http.Livefront -> EnvironmentsEnum.Environments_Http_Livefront + is Environments.Http.Google -> EnvironmentsEnum.Environments_Http_Google + is Environments.Https.Livefront -> EnvironmentsEnum.Environments_Https_Livefront + is Environments.Https.Google -> EnvironmentsEnum.Environments_Https_Google + } + + public override fun enumToSealedObject(`enum`: EnvironmentsEnum): Environments = when (enum) { + EnvironmentsEnum.Environments_Http_Livefront -> Environments.Http.Livefront + EnvironmentsEnum.Environments_Http_Google -> Environments.Http.Google + EnvironmentsEnum.Environments_Https_Livefront -> Environments.Https.Livefront + EnvironmentsEnum.Environments_Https_Google -> Environments.Https.Google + } +} + +/** + * The index of [this] in the values list. + */ +public val Environments.ordinal: Int + get() = EnvironmentsSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val Environments.name: String + get() = EnvironmentsSealedEnum.nameOf(this) + +/** + * A list of all [Environments] objects. + */ +public val Environments.Companion.values: List + get() = EnvironmentsSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [Environments] + */ +public val Environments.Companion.sealedEnum: EnvironmentsSealedEnum + get() = EnvironmentsSealedEnum + +/** + * Returns the [Environments] object for the given [name]. + * + * If the given name doesn't correspond to any [Environments], an [IllegalArgumentException] will be + * thrown. + */ +public fun Environments.Companion.valueOf(name: String): Environments = + EnvironmentsSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/usecases/FlagTests.compilation generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/usecases/FlagTests.compilation generates correct code.approved new file mode 100644 index 00000000..9d596a92 --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/usecases/FlagTests.compilation generates correct code.approved @@ -0,0 +1,104 @@ +package com.livefront.sealedenum.compilation.usecases + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [Flag] + */ +public enum class FlagEnum() { + Flag_FirstFlag, + Flag_SecondFlag, +} + +/** + * The isomorphic [FlagEnum] for [this]. + */ +public val Flag.`enum`: FlagEnum + get() = FlagSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [Flag] for [this]. + */ +public val FlagEnum.sealedObject: Flag + get() = FlagSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [Flag] + */ +public object FlagSealedEnum : SealedEnum, SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = LazyThreadSafetyMode.PUBLICATION) { + listOf( + Flag.FirstFlag, + Flag.SecondFlag + ) + } + + + public override val enumClass: KClass + get() = FlagEnum::class + + public override fun ordinalOf(obj: Flag): Int = when (obj) { + is Flag.FirstFlag -> 0 + is Flag.SecondFlag -> 1 + } + + public override fun nameOf(obj: Flag): String = when (obj) { + is Flag.FirstFlag -> "Flag_FirstFlag" + is Flag.SecondFlag -> "Flag_SecondFlag" + } + + public override fun valueOf(name: String): Flag = when (name) { + "Flag_FirstFlag" -> Flag.FirstFlag + "Flag_SecondFlag" -> Flag.SecondFlag + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: Flag): FlagEnum = when (obj) { + is Flag.FirstFlag -> FlagEnum.Flag_FirstFlag + is Flag.SecondFlag -> FlagEnum.Flag_SecondFlag + } + + public override fun enumToSealedObject(`enum`: FlagEnum): Flag = when (enum) { + FlagEnum.Flag_FirstFlag -> Flag.FirstFlag + FlagEnum.Flag_SecondFlag -> Flag.SecondFlag + } +} + +/** + * The index of [this] in the values list. + */ +public val Flag.ordinal: Int + get() = FlagSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val Flag.name: String + get() = FlagSealedEnum.nameOf(this) + +/** + * A list of all [Flag] objects. + */ +public val Flag.Companion.values: List + get() = FlagSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [Flag] + */ +public val Flag.Companion.sealedEnum: FlagSealedEnum + get() = FlagSealedEnum + +/** + * Returns the [Flag] object for the given [name]. + * + * If the given name doesn't correspond to any [Flag], an [IllegalArgumentException] will be thrown. + */ +public fun Flag.Companion.valueOf(name: String): Flag = FlagSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/visibility/Internal.compilation generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/visibility/Internal.compilation generates correct code.approved new file mode 100644 index 00000000..f4c98cb3 --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/visibility/Internal.compilation generates correct code.approved @@ -0,0 +1,112 @@ +package com.livefront.sealedenum.compilation.visibility + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [InternalSealedClass] + */ +internal enum class InternalSealedClassEnum() { + InternalSealedClass_FirstObject, + InternalSealedClass_SecondObject, +} + +/** + * The isomorphic [InternalSealedClassEnum] for [this]. + */ +internal val InternalSealedClass.`enum`: InternalSealedClassEnum + get() = InternalSealedClassSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [InternalSealedClass] for [this]. + */ +internal val InternalSealedClassEnum.sealedObject: InternalSealedClass + get() = InternalSealedClassSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [InternalSealedClass] + */ +internal object InternalSealedClassSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + InternalSealedClass.FirstObject, + InternalSealedClass.SecondObject + ) + } + + + public override val enumClass: KClass + get() = InternalSealedClassEnum::class + + public override fun ordinalOf(obj: InternalSealedClass): Int = when (obj) { + is InternalSealedClass.FirstObject -> 0 + is InternalSealedClass.SecondObject -> 1 + } + + public override fun nameOf(obj: InternalSealedClass): String = when (obj) { + is InternalSealedClass.FirstObject -> "InternalSealedClass_FirstObject" + is InternalSealedClass.SecondObject -> "InternalSealedClass_SecondObject" + } + + public override fun valueOf(name: String): InternalSealedClass = when (name) { + "InternalSealedClass_FirstObject" -> InternalSealedClass.FirstObject + "InternalSealedClass_SecondObject" -> InternalSealedClass.SecondObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: InternalSealedClass): InternalSealedClassEnum = when + (obj) { + is InternalSealedClass.FirstObject -> + InternalSealedClassEnum.InternalSealedClass_FirstObject + is InternalSealedClass.SecondObject -> + InternalSealedClassEnum.InternalSealedClass_SecondObject + } + + public override fun enumToSealedObject(`enum`: InternalSealedClassEnum): InternalSealedClass = + when (enum) { + InternalSealedClassEnum.InternalSealedClass_FirstObject -> InternalSealedClass.FirstObject + InternalSealedClassEnum.InternalSealedClass_SecondObject -> InternalSealedClass.SecondObject + } +} + +/** + * The index of [this] in the values list. + */ +internal val InternalSealedClass.ordinal: Int + get() = InternalSealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +internal val InternalSealedClass.name: String + get() = InternalSealedClassSealedEnum.nameOf(this) + +/** + * A list of all [InternalSealedClass] objects. + */ +internal val InternalSealedClass.Companion.values: List + get() = InternalSealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [InternalSealedClass] + */ +internal val InternalSealedClass.Companion.sealedEnum: InternalSealedClassSealedEnum + get() = InternalSealedClassSealedEnum + +/** + * Returns the [InternalSealedClass] object for the given [name]. + * + * If the given name doesn't correspond to any [InternalSealedClass], an [IllegalArgumentException] + * will be thrown. + */ +internal fun InternalSealedClass.Companion.valueOf(name: String): InternalSealedClass = + InternalSealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/visibility/InternalCompanion.compilation generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/visibility/InternalCompanion.compilation generates correct code.approved new file mode 100644 index 00000000..1de30b79 --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/visibility/InternalCompanion.compilation generates correct code.approved @@ -0,0 +1,115 @@ +package com.livefront.sealedenum.compilation.visibility + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [InternalCompanionSealedClass] + */ +public enum class InternalCompanionSealedClassEnum() { + InternalCompanionSealedClass_FirstObject, + InternalCompanionSealedClass_SecondObject, +} + +/** + * The isomorphic [InternalCompanionSealedClassEnum] for [this]. + */ +public val InternalCompanionSealedClass.`enum`: InternalCompanionSealedClassEnum + get() = InternalCompanionSealedClassSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [InternalCompanionSealedClass] for [this]. + */ +public val InternalCompanionSealedClassEnum.sealedObject: InternalCompanionSealedClass + get() = InternalCompanionSealedClassSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [InternalCompanionSealedClass] + */ +public object InternalCompanionSealedClassSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + InternalCompanionSealedClass.FirstObject, + InternalCompanionSealedClass.SecondObject + ) + } + + + public override val enumClass: KClass + get() = InternalCompanionSealedClassEnum::class + + public override fun ordinalOf(obj: InternalCompanionSealedClass): Int = when (obj) { + is InternalCompanionSealedClass.FirstObject -> 0 + is InternalCompanionSealedClass.SecondObject -> 1 + } + + public override fun nameOf(obj: InternalCompanionSealedClass): String = when (obj) { + is InternalCompanionSealedClass.FirstObject -> "InternalCompanionSealedClass_FirstObject" + is InternalCompanionSealedClass.SecondObject -> "InternalCompanionSealedClass_SecondObject" + } + + public override fun valueOf(name: String): InternalCompanionSealedClass = when (name) { + "InternalCompanionSealedClass_FirstObject" -> InternalCompanionSealedClass.FirstObject + "InternalCompanionSealedClass_SecondObject" -> InternalCompanionSealedClass.SecondObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: InternalCompanionSealedClass): + InternalCompanionSealedClassEnum = when (obj) { + is InternalCompanionSealedClass.FirstObject -> + InternalCompanionSealedClassEnum.InternalCompanionSealedClass_FirstObject + is InternalCompanionSealedClass.SecondObject -> + InternalCompanionSealedClassEnum.InternalCompanionSealedClass_SecondObject + } + + public override fun enumToSealedObject(`enum`: InternalCompanionSealedClassEnum): + InternalCompanionSealedClass = when (enum) { + InternalCompanionSealedClassEnum.InternalCompanionSealedClass_FirstObject -> + InternalCompanionSealedClass.FirstObject + InternalCompanionSealedClassEnum.InternalCompanionSealedClass_SecondObject -> + InternalCompanionSealedClass.SecondObject + } +} + +/** + * The index of [this] in the values list. + */ +public val InternalCompanionSealedClass.ordinal: Int + get() = InternalCompanionSealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val InternalCompanionSealedClass.name: String + get() = InternalCompanionSealedClassSealedEnum.nameOf(this) + +/** + * A list of all [InternalCompanionSealedClass] objects. + */ +internal val InternalCompanionSealedClass.Companion.values: List + get() = InternalCompanionSealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [InternalCompanionSealedClass] + */ +internal val InternalCompanionSealedClass.Companion.sealedEnum: + InternalCompanionSealedClassSealedEnum + get() = InternalCompanionSealedClassSealedEnum + +/** + * Returns the [InternalCompanionSealedClass] object for the given [name]. + * + * If the given name doesn't correspond to any [InternalCompanionSealedClass], an + * [IllegalArgumentException] will be thrown. + */ +internal fun InternalCompanionSealedClass.Companion.valueOf(name: String): + InternalCompanionSealedClass = InternalCompanionSealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/visibility/InternalObjects.compilation generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/visibility/InternalObjects.compilation generates correct code.approved new file mode 100644 index 00000000..23c4f0d3 --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/visibility/InternalObjects.compilation generates correct code.approved @@ -0,0 +1,125 @@ +package com.livefront.sealedenum.compilation.visibility + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [InternalObjectsSealedClass] + */ +public enum class InternalObjectsSealedClassEnum() { + InternalObjectsSealedClass_FirstObject, + InternalObjectsSealedClass_SecondObject, + InternalObjectsSealedClass_InnerSealedClass_ThirdObject, +} + +/** + * The isomorphic [InternalObjectsSealedClassEnum] for [this]. + */ +public val InternalObjectsSealedClass.`enum`: InternalObjectsSealedClassEnum + get() = InternalObjectsSealedClassSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [InternalObjectsSealedClass] for [this]. + */ +public val InternalObjectsSealedClassEnum.sealedObject: InternalObjectsSealedClass + get() = InternalObjectsSealedClassSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [InternalObjectsSealedClass] + */ +public object InternalObjectsSealedClassSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + InternalObjectsSealedClass.FirstObject, + InternalObjectsSealedClass.SecondObject, + InternalObjectsSealedClass.InnerSealedClass.ThirdObject + ) + } + + + public override val enumClass: KClass + get() = InternalObjectsSealedClassEnum::class + + public override fun ordinalOf(obj: InternalObjectsSealedClass): Int = when (obj) { + is InternalObjectsSealedClass.FirstObject -> 0 + is InternalObjectsSealedClass.SecondObject -> 1 + is InternalObjectsSealedClass.InnerSealedClass.ThirdObject -> 2 + } + + public override fun nameOf(obj: InternalObjectsSealedClass): String = when (obj) { + is InternalObjectsSealedClass.FirstObject -> "InternalObjectsSealedClass_FirstObject" + is InternalObjectsSealedClass.SecondObject -> "InternalObjectsSealedClass_SecondObject" + is InternalObjectsSealedClass.InnerSealedClass.ThirdObject -> + "InternalObjectsSealedClass_InnerSealedClass_ThirdObject" + } + + public override fun valueOf(name: String): InternalObjectsSealedClass = when (name) { + "InternalObjectsSealedClass_FirstObject" -> InternalObjectsSealedClass.FirstObject + "InternalObjectsSealedClass_SecondObject" -> InternalObjectsSealedClass.SecondObject + "InternalObjectsSealedClass_InnerSealedClass_ThirdObject" -> + InternalObjectsSealedClass.InnerSealedClass.ThirdObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: InternalObjectsSealedClass): + InternalObjectsSealedClassEnum = when (obj) { + is InternalObjectsSealedClass.FirstObject -> + InternalObjectsSealedClassEnum.InternalObjectsSealedClass_FirstObject + is InternalObjectsSealedClass.SecondObject -> + InternalObjectsSealedClassEnum.InternalObjectsSealedClass_SecondObject + is InternalObjectsSealedClass.InnerSealedClass.ThirdObject -> + InternalObjectsSealedClassEnum.InternalObjectsSealedClass_InnerSealedClass_ThirdObject + } + + public override fun enumToSealedObject(`enum`: InternalObjectsSealedClassEnum): + InternalObjectsSealedClass = when (enum) { + InternalObjectsSealedClassEnum.InternalObjectsSealedClass_FirstObject -> + InternalObjectsSealedClass.FirstObject + InternalObjectsSealedClassEnum.InternalObjectsSealedClass_SecondObject -> + InternalObjectsSealedClass.SecondObject + InternalObjectsSealedClassEnum.InternalObjectsSealedClass_InnerSealedClass_ThirdObject -> + InternalObjectsSealedClass.InnerSealedClass.ThirdObject + } +} + +/** + * The index of [this] in the values list. + */ +public val InternalObjectsSealedClass.ordinal: Int + get() = InternalObjectsSealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val InternalObjectsSealedClass.name: String + get() = InternalObjectsSealedClassSealedEnum.nameOf(this) + +/** + * A list of all [InternalObjectsSealedClass] objects. + */ +public val InternalObjectsSealedClass.Companion.values: List + get() = InternalObjectsSealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [InternalObjectsSealedClass] + */ +public val InternalObjectsSealedClass.Companion.sealedEnum: InternalObjectsSealedClassSealedEnum + get() = InternalObjectsSealedClassSealedEnum + +/** + * Returns the [InternalObjectsSealedClass] object for the given [name]. + * + * If the given name doesn't correspond to any [InternalObjectsSealedClass], an + * [IllegalArgumentException] will be thrown. + */ +public fun InternalObjectsSealedClass.Companion.valueOf(name: String): InternalObjectsSealedClass = + InternalObjectsSealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/visibility/InternalSealedAndCompanion.compilation generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/visibility/InternalSealedAndCompanion.compilation generates correct code.approved new file mode 100644 index 00000000..efd15a6b --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/visibility/InternalSealedAndCompanion.compilation generates correct code.approved @@ -0,0 +1,125 @@ +package com.livefront.sealedenum.compilation.visibility + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [InternalSealedAndCompanionSealedClass] + */ +internal enum class InternalSealedAndCompanionSealedClassEnum() { + InternalSealedAndCompanionSealedClass_FirstObject, + InternalSealedAndCompanionSealedClass_SecondObject, +} + +/** + * The isomorphic [InternalSealedAndCompanionSealedClassEnum] for [this]. + */ +internal val InternalSealedAndCompanionSealedClass.`enum`: InternalSealedAndCompanionSealedClassEnum + get() = InternalSealedAndCompanionSealedClassSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [InternalSealedAndCompanionSealedClass] for [this]. + */ +internal val InternalSealedAndCompanionSealedClassEnum.sealedObject: + InternalSealedAndCompanionSealedClass + get() = InternalSealedAndCompanionSealedClassSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [InternalSealedAndCompanionSealedClass] + */ +internal object InternalSealedAndCompanionSealedClassSealedEnum : + SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider + { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + InternalSealedAndCompanionSealedClass.FirstObject, + InternalSealedAndCompanionSealedClass.SecondObject + ) + } + + + public override val enumClass: KClass + get() = InternalSealedAndCompanionSealedClassEnum::class + + public override fun ordinalOf(obj: InternalSealedAndCompanionSealedClass): Int = when (obj) { + is InternalSealedAndCompanionSealedClass.FirstObject -> 0 + is InternalSealedAndCompanionSealedClass.SecondObject -> 1 + } + + public override fun nameOf(obj: InternalSealedAndCompanionSealedClass): String = when (obj) { + is InternalSealedAndCompanionSealedClass.FirstObject -> + "InternalSealedAndCompanionSealedClass_FirstObject" + is InternalSealedAndCompanionSealedClass.SecondObject -> + "InternalSealedAndCompanionSealedClass_SecondObject" + } + + public override fun valueOf(name: String): InternalSealedAndCompanionSealedClass = when (name) { + "InternalSealedAndCompanionSealedClass_FirstObject" -> + InternalSealedAndCompanionSealedClass.FirstObject + "InternalSealedAndCompanionSealedClass_SecondObject" -> + InternalSealedAndCompanionSealedClass.SecondObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: InternalSealedAndCompanionSealedClass): + InternalSealedAndCompanionSealedClassEnum = when (obj) { + is InternalSealedAndCompanionSealedClass.FirstObject -> + InternalSealedAndCompanionSealedClassEnum.InternalSealedAndCompanionSealedClass_FirstObject + is InternalSealedAndCompanionSealedClass.SecondObject -> + InternalSealedAndCompanionSealedClassEnum.InternalSealedAndCompanionSealedClass_SecondObject + } + + public override fun enumToSealedObject(`enum`: InternalSealedAndCompanionSealedClassEnum): + InternalSealedAndCompanionSealedClass = when (enum) { + InternalSealedAndCompanionSealedClassEnum.InternalSealedAndCompanionSealedClass_FirstObject -> + InternalSealedAndCompanionSealedClass.FirstObject + InternalSealedAndCompanionSealedClassEnum.InternalSealedAndCompanionSealedClass_SecondObject -> + InternalSealedAndCompanionSealedClass.SecondObject + } +} + +/** + * The index of [this] in the values list. + */ +internal val InternalSealedAndCompanionSealedClass.ordinal: Int + get() = InternalSealedAndCompanionSealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +internal val InternalSealedAndCompanionSealedClass.name: String + get() = InternalSealedAndCompanionSealedClassSealedEnum.nameOf(this) + +/** + * A list of all [InternalSealedAndCompanionSealedClass] objects. + */ +internal val InternalSealedAndCompanionSealedClass.Companion.values: + List + get() = InternalSealedAndCompanionSealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class + * [InternalSealedAndCompanionSealedClass] + */ +internal val InternalSealedAndCompanionSealedClass.Companion.sealedEnum: + InternalSealedAndCompanionSealedClassSealedEnum + get() = InternalSealedAndCompanionSealedClassSealedEnum + +/** + * Returns the [InternalSealedAndCompanionSealedClass] object for the given [name]. + * + * If the given name doesn't correspond to any [InternalSealedAndCompanionSealedClass], an + * [IllegalArgumentException] will be thrown. + */ +internal fun InternalSealedAndCompanionSealedClass.Companion.valueOf(name: String): + InternalSealedAndCompanionSealedClass = + InternalSealedAndCompanionSealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/visibility/PrivateInterfaceSealedClassTests.compilation generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/visibility/PrivateInterfaceSealedClassTests.compilation generates correct code.approved new file mode 100644 index 00000000..770c8dfa --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/visibility/PrivateInterfaceSealedClassTests.compilation generates correct code.approved @@ -0,0 +1,114 @@ +package com.livefront.sealedenum.compilation.visibility + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [PrivateInterfaceSealedClass] + */ +public enum class PrivateInterfaceSealedClassEnum() { + PrivateInterfaceSealedClass_FirstObject, + PrivateInterfaceSealedClass_SecondObject, +} + +/** + * The isomorphic [PrivateInterfaceSealedClassEnum] for [this]. + */ +public val PrivateInterfaceSealedClass.`enum`: PrivateInterfaceSealedClassEnum + get() = PrivateInterfaceSealedClassSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [PrivateInterfaceSealedClass] for [this]. + */ +public val PrivateInterfaceSealedClassEnum.sealedObject: PrivateInterfaceSealedClass + get() = PrivateInterfaceSealedClassSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [PrivateInterfaceSealedClass] + */ +public object PrivateInterfaceSealedClassSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + PrivateInterfaceSealedClass.FirstObject, + PrivateInterfaceSealedClass.SecondObject + ) + } + + + public override val enumClass: KClass + get() = PrivateInterfaceSealedClassEnum::class + + public override fun ordinalOf(obj: PrivateInterfaceSealedClass): Int = when (obj) { + is PrivateInterfaceSealedClass.FirstObject -> 0 + is PrivateInterfaceSealedClass.SecondObject -> 1 + } + + public override fun nameOf(obj: PrivateInterfaceSealedClass): String = when (obj) { + is PrivateInterfaceSealedClass.FirstObject -> "PrivateInterfaceSealedClass_FirstObject" + is PrivateInterfaceSealedClass.SecondObject -> "PrivateInterfaceSealedClass_SecondObject" + } + + public override fun valueOf(name: String): PrivateInterfaceSealedClass = when (name) { + "PrivateInterfaceSealedClass_FirstObject" -> PrivateInterfaceSealedClass.FirstObject + "PrivateInterfaceSealedClass_SecondObject" -> PrivateInterfaceSealedClass.SecondObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: PrivateInterfaceSealedClass): + PrivateInterfaceSealedClassEnum = when (obj) { + is PrivateInterfaceSealedClass.FirstObject -> + PrivateInterfaceSealedClassEnum.PrivateInterfaceSealedClass_FirstObject + is PrivateInterfaceSealedClass.SecondObject -> + PrivateInterfaceSealedClassEnum.PrivateInterfaceSealedClass_SecondObject + } + + public override fun enumToSealedObject(`enum`: PrivateInterfaceSealedClassEnum): + PrivateInterfaceSealedClass = when (enum) { + PrivateInterfaceSealedClassEnum.PrivateInterfaceSealedClass_FirstObject -> + PrivateInterfaceSealedClass.FirstObject + PrivateInterfaceSealedClassEnum.PrivateInterfaceSealedClass_SecondObject -> + PrivateInterfaceSealedClass.SecondObject + } +} + +/** + * The index of [this] in the values list. + */ +public val PrivateInterfaceSealedClass.ordinal: Int + get() = PrivateInterfaceSealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val PrivateInterfaceSealedClass.name: String + get() = PrivateInterfaceSealedClassSealedEnum.nameOf(this) + +/** + * A list of all [PrivateInterfaceSealedClass] objects. + */ +public val PrivateInterfaceSealedClass.Companion.values: List + get() = PrivateInterfaceSealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [PrivateInterfaceSealedClass] + */ +public val PrivateInterfaceSealedClass.Companion.sealedEnum: PrivateInterfaceSealedClassSealedEnum + get() = PrivateInterfaceSealedClassSealedEnum + +/** + * Returns the [PrivateInterfaceSealedClass] object for the given [name]. + * + * If the given name doesn't correspond to any [PrivateInterfaceSealedClass], an + * [IllegalArgumentException] will be thrown. + */ +public fun PrivateInterfaceSealedClass.Companion.valueOf(name: String): PrivateInterfaceSealedClass + = PrivateInterfaceSealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/visibility/ProtectedInterfaceSealedClassWithDifferentPackageBaseClassTests.compilation generates correct code.approved b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/visibility/ProtectedInterfaceSealedClassWithDifferentPackageBaseClassTests.compilation generates correct code.approved new file mode 100644 index 00000000..533889ee --- /dev/null +++ b/processing-tests/ksp-tests/src/test/kotlin/com/livefront/sealedenum/compilation/visibility/ProtectedInterfaceSealedClassWithDifferentPackageBaseClassTests.compilation generates correct code.approved @@ -0,0 +1,176 @@ +package com.livefront.sealedenum.compilation.visibility + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class + * [ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass] + */ +public enum class + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassEnum() + { + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClass_FirstObject, + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClass_SecondObject, +} + +/** + * The isomorphic + * [ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassEnum] for + * [this]. + */ +public + val ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.`enum`: + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassEnum + get() = + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic + * [ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass] for + * [this]. + */ +public + val ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassEnum.sealedObject: + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass + get() = + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class + * [ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass] + */ +public object + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassSealedEnum + : + SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider + { + public override val values: + List + by lazy(mode = LazyThreadSafetyMode.PUBLICATION) { + listOf( + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.FirstObject, + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.SecondObject + ) + } + + + public override val enumClass: + KClass + get() = + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassEnum::class + + public override + fun ordinalOf(obj: ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass): + Int = when (obj) { + is + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.FirstObject -> + 0 + is + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.SecondObject -> + 1 + } + + public override + fun nameOf(obj: ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass): + String = when (obj) { + is + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.FirstObject -> + "ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClass_FirstObject" + is + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.SecondObject -> + "ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClass_SecondObject" + } + + public override fun valueOf(name: String): + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass + = when (name) { + "ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClass_FirstObject" -> + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.FirstObject + "ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClass_SecondObject" -> + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.SecondObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override + fun sealedObjectToEnum(obj: ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass): + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassEnum + = when (obj) { + is + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.FirstObject -> + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassEnum.ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClass_FirstObject + is + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.SecondObject -> + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassEnum.ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClass_SecondObject + } + + public override + fun enumToSealedObject(`enum`: ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassEnum): + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass + = when (enum) { + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassEnum.ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClass_FirstObject -> + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.FirstObject + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassEnum.ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClass_SecondObject -> + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.SecondObject + } +} + +/** + * The index of [this] in the values list. + */ +public + val ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.ordinal: + Int + get() = + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public + val ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.name: + String + get() = + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassSealedEnum.nameOf(this) + +/** + * A list of all + * [ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass] objects. + */ +public + val ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.Companion.values: + List + get() = + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class + * [ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass] + */ +public + val ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.Companion.sealedEnum: + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassSealedEnum + get() = + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassSealedEnum + +/** + * Returns the + * [ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass] object for + * the given [name]. + * + * If the given name doesn't correspond to any + * [ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass], an + * [IllegalArgumentException] will be thrown. + */ +public + fun ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.Companion.valueOf(name: String): + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass = + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/build.gradle.kts b/processing-tests/processor-tests/build.gradle.kts index e92d0935..de6a43ea 100644 --- a/processing-tests/processor-tests/build.gradle.kts +++ b/processing-tests/processor-tests/build.gradle.kts @@ -33,6 +33,7 @@ detekt { dependencies { testImplementation(libs.junit.jupiter) testImplementation(libs.kotlinCompileTesting.base) + testImplementation(libs.okeyDoke) testImplementation(kotlin("reflect")) testImplementation(projects.runtime) testImplementation(projects.processor) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/basic/EmptySealedClassTests.compilation generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/basic/EmptySealedClassTests.compilation generates correct code.approved new file mode 100644 index 00000000..7f1bcf18 --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/basic/EmptySealedClassTests.compilation generates correct code.approved @@ -0,0 +1,91 @@ +package com.livefront.sealedenum.compilation.basic + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [EmptySealedClass] + */ +public enum class EmptySealedClassEnum() + +/** + * The isomorphic [EmptySealedClassEnum] for [this]. + */ +public val EmptySealedClass.`enum`: EmptySealedClassEnum + get() = EmptySealedClassSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [EmptySealedClass] for [this]. + */ +public val EmptySealedClassEnum.sealedObject: EmptySealedClass + get() = EmptySealedClassSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [EmptySealedClass] + */ +public object EmptySealedClassSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + emptyList() + } + + + public override val enumClass: KClass + get() = EmptySealedClassEnum::class + + public override fun ordinalOf(obj: EmptySealedClass): Int = throw + AssertionError("Constructing a EmptySealedClass is impossible, since it has no sealed subclasses") + + public override fun nameOf(obj: EmptySealedClass): String = throw + AssertionError("Constructing a EmptySealedClass is impossible, since it has no sealed subclasses") + + public override fun valueOf(name: String): EmptySealedClass = throw + IllegalArgumentException("""No sealed enum constant $name""") + + public override fun sealedObjectToEnum(obj: EmptySealedClass): EmptySealedClassEnum = throw + AssertionError("Constructing a EmptySealedClass is impossible, since it has no sealed subclasses") + + public override fun enumToSealedObject(`enum`: EmptySealedClassEnum): EmptySealedClass = throw + AssertionError("Constructing a EmptySealedClass is impossible, since it has no sealed subclasses") +} + +/** + * The index of [this] in the values list. + */ +public val EmptySealedClass.ordinal: Int + get() = EmptySealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val EmptySealedClass.name: String + get() = EmptySealedClassSealedEnum.nameOf(this) + +/** + * A list of all [EmptySealedClass] objects. + */ +public val EmptySealedClass.Companion.values: List + get() = EmptySealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [EmptySealedClass] + */ +public val EmptySealedClass.Companion.sealedEnum: EmptySealedClassSealedEnum + get() = EmptySealedClassSealedEnum + +/** + * Returns the [EmptySealedClass] object for the given [name]. + * + * If the given name doesn't correspond to any [EmptySealedClass], an [IllegalArgumentException] + * will be thrown. + */ +public fun EmptySealedClass.Companion.valueOf(name: String): EmptySealedClass = + EmptySealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/basic/EmptySealedInterfaceTests.compilation generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/basic/EmptySealedInterfaceTests.compilation generates correct code.approved new file mode 100644 index 00000000..3aa7e18c --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/basic/EmptySealedInterfaceTests.compilation generates correct code.approved @@ -0,0 +1,93 @@ +package com.livefront.sealedenum.compilation.basic + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [EmptySealedInterface] + */ +public enum class EmptySealedInterfaceEnum() + +/** + * The isomorphic [EmptySealedInterfaceEnum] for [this]. + */ +public val EmptySealedInterface.`enum`: EmptySealedInterfaceEnum + get() = EmptySealedInterfaceSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [EmptySealedInterface] for [this]. + */ +public val EmptySealedInterfaceEnum.sealedObject: EmptySealedInterface + get() = EmptySealedInterfaceSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [EmptySealedInterface] + */ +public object EmptySealedInterfaceSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + emptyList() + } + + + public override val enumClass: KClass + get() = EmptySealedInterfaceEnum::class + + public override fun ordinalOf(obj: EmptySealedInterface): Int = throw + AssertionError("Constructing a EmptySealedInterface is impossible, since it has no sealed subclasses") + + public override fun nameOf(obj: EmptySealedInterface): String = throw + AssertionError("Constructing a EmptySealedInterface is impossible, since it has no sealed subclasses") + + public override fun valueOf(name: String): EmptySealedInterface = throw + IllegalArgumentException("""No sealed enum constant $name""") + + public override fun sealedObjectToEnum(obj: EmptySealedInterface): EmptySealedInterfaceEnum = + throw + AssertionError("Constructing a EmptySealedInterface is impossible, since it has no sealed subclasses") + + public override fun enumToSealedObject(`enum`: EmptySealedInterfaceEnum): EmptySealedInterface = + throw + AssertionError("Constructing a EmptySealedInterface is impossible, since it has no sealed subclasses") +} + +/** + * The index of [this] in the values list. + */ +public val EmptySealedInterface.ordinal: Int + get() = EmptySealedInterfaceSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val EmptySealedInterface.name: String + get() = EmptySealedInterfaceSealedEnum.nameOf(this) + +/** + * A list of all [EmptySealedInterface] objects. + */ +public val EmptySealedInterface.Companion.values: List + get() = EmptySealedInterfaceSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [EmptySealedInterface] + */ +public val EmptySealedInterface.Companion.sealedEnum: EmptySealedInterfaceSealedEnum + get() = EmptySealedInterfaceSealedEnum + +/** + * Returns the [EmptySealedInterface] object for the given [name]. + * + * If the given name doesn't correspond to any [EmptySealedInterface], an [IllegalArgumentException] + * will be thrown. + */ +public fun EmptySealedInterface.Companion.valueOf(name: String): EmptySealedInterface = + EmptySealedInterfaceSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/basic/OneObjectSealedClassTests.compilation generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/basic/OneObjectSealedClassTests.compilation generates correct code.approved new file mode 100644 index 00000000..8a33f7bc --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/basic/OneObjectSealedClassTests.compilation generates correct code.approved @@ -0,0 +1,105 @@ +package com.livefront.sealedenum.compilation.basic + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [OneObjectSealedClass] + */ +public enum class OneObjectSealedClassEnum() { + OneObjectSealedClass_FirstObject, +} + +/** + * The isomorphic [OneObjectSealedClassEnum] for [this]. + */ +public val OneObjectSealedClass.`enum`: OneObjectSealedClassEnum + get() = OneObjectSealedClassSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [OneObjectSealedClass] for [this]. + */ +public val OneObjectSealedClassEnum.sealedObject: OneObjectSealedClass + get() = OneObjectSealedClassSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [OneObjectSealedClass] + */ +public object OneObjectSealedClassSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + OneObjectSealedClass.FirstObject + ) + } + + + public override val enumClass: KClass + get() = OneObjectSealedClassEnum::class + + public override fun ordinalOf(obj: OneObjectSealedClass): Int = when (obj) { + is OneObjectSealedClass.FirstObject -> 0 + } + + public override fun nameOf(obj: OneObjectSealedClass): String = when (obj) { + is OneObjectSealedClass.FirstObject -> "OneObjectSealedClass_FirstObject" + } + + public override fun valueOf(name: String): OneObjectSealedClass = when (name) { + "OneObjectSealedClass_FirstObject" -> OneObjectSealedClass.FirstObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: OneObjectSealedClass): OneObjectSealedClassEnum = + when (obj) { + is OneObjectSealedClass.FirstObject -> + OneObjectSealedClassEnum.OneObjectSealedClass_FirstObject + } + + public override fun enumToSealedObject(`enum`: OneObjectSealedClassEnum): OneObjectSealedClass = + when (enum) { + OneObjectSealedClassEnum.OneObjectSealedClass_FirstObject -> + OneObjectSealedClass.FirstObject + } +} + +/** + * The index of [this] in the values list. + */ +public val OneObjectSealedClass.ordinal: Int + get() = OneObjectSealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val OneObjectSealedClass.name: String + get() = OneObjectSealedClassSealedEnum.nameOf(this) + +/** + * A list of all [OneObjectSealedClass] objects. + */ +public val OneObjectSealedClass.Companion.values: List + get() = OneObjectSealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [OneObjectSealedClass] + */ +public val OneObjectSealedClass.Companion.sealedEnum: OneObjectSealedClassSealedEnum + get() = OneObjectSealedClassSealedEnum + +/** + * Returns the [OneObjectSealedClass] object for the given [name]. + * + * If the given name doesn't correspond to any [OneObjectSealedClass], an [IllegalArgumentException] + * will be thrown. + */ +public fun OneObjectSealedClass.Companion.valueOf(name: String): OneObjectSealedClass = + OneObjectSealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/basic/OneObjectSealedInterfaceTests.compilation generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/basic/OneObjectSealedInterfaceTests.compilation generates correct code.approved new file mode 100644 index 00000000..d082d543 --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/basic/OneObjectSealedInterfaceTests.compilation generates correct code.approved @@ -0,0 +1,105 @@ +package com.livefront.sealedenum.compilation.basic + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [OneObjectSealedInterface] + */ +public enum class OneObjectSealedInterfaceEnum() { + OneObjectSealedInterface_FirstObject, +} + +/** + * The isomorphic [OneObjectSealedInterfaceEnum] for [this]. + */ +public val OneObjectSealedInterface.`enum`: OneObjectSealedInterfaceEnum + get() = OneObjectSealedInterfaceSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [OneObjectSealedInterface] for [this]. + */ +public val OneObjectSealedInterfaceEnum.sealedObject: OneObjectSealedInterface + get() = OneObjectSealedInterfaceSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [OneObjectSealedInterface] + */ +public object OneObjectSealedInterfaceSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + OneObjectSealedInterface.FirstObject + ) + } + + + public override val enumClass: KClass + get() = OneObjectSealedInterfaceEnum::class + + public override fun ordinalOf(obj: OneObjectSealedInterface): Int = when (obj) { + is OneObjectSealedInterface.FirstObject -> 0 + } + + public override fun nameOf(obj: OneObjectSealedInterface): String = when (obj) { + is OneObjectSealedInterface.FirstObject -> "OneObjectSealedInterface_FirstObject" + } + + public override fun valueOf(name: String): OneObjectSealedInterface = when (name) { + "OneObjectSealedInterface_FirstObject" -> OneObjectSealedInterface.FirstObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: OneObjectSealedInterface): + OneObjectSealedInterfaceEnum = when (obj) { + is OneObjectSealedInterface.FirstObject -> + OneObjectSealedInterfaceEnum.OneObjectSealedInterface_FirstObject + } + + public override fun enumToSealedObject(`enum`: OneObjectSealedInterfaceEnum): + OneObjectSealedInterface = when (enum) { + OneObjectSealedInterfaceEnum.OneObjectSealedInterface_FirstObject -> + OneObjectSealedInterface.FirstObject + } +} + +/** + * The index of [this] in the values list. + */ +public val OneObjectSealedInterface.ordinal: Int + get() = OneObjectSealedInterfaceSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val OneObjectSealedInterface.name: String + get() = OneObjectSealedInterfaceSealedEnum.nameOf(this) + +/** + * A list of all [OneObjectSealedInterface] objects. + */ +public val OneObjectSealedInterface.Companion.values: List + get() = OneObjectSealedInterfaceSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [OneObjectSealedInterface] + */ +public val OneObjectSealedInterface.Companion.sealedEnum: OneObjectSealedInterfaceSealedEnum + get() = OneObjectSealedInterfaceSealedEnum + +/** + * Returns the [OneObjectSealedInterface] object for the given [name]. + * + * If the given name doesn't correspond to any [OneObjectSealedInterface], an + * [IllegalArgumentException] will be thrown. + */ +public fun OneObjectSealedInterface.Companion.valueOf(name: String): OneObjectSealedInterface = + OneObjectSealedInterfaceSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/basic/TwoObjectSealedClassTests.compilation generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/basic/TwoObjectSealedClassTests.compilation generates correct code.approved new file mode 100644 index 00000000..f387ad6f --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/basic/TwoObjectSealedClassTests.compilation generates correct code.approved @@ -0,0 +1,114 @@ +package com.livefront.sealedenum.compilation.basic + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [TwoObjectSealedClass] + */ +public enum class TwoObjectSealedClassEnum() { + TwoObjectSealedClass_FirstObject, + TwoObjectSealedClass_SecondObject, +} + +/** + * The isomorphic [TwoObjectSealedClassEnum] for [this]. + */ +public val TwoObjectSealedClass.`enum`: TwoObjectSealedClassEnum + get() = TwoObjectSealedClassSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [TwoObjectSealedClass] for [this]. + */ +public val TwoObjectSealedClassEnum.sealedObject: TwoObjectSealedClass + get() = TwoObjectSealedClassSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [TwoObjectSealedClass] + */ +public object TwoObjectSealedClassSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + TwoObjectSealedClass.FirstObject, + TwoObjectSealedClass.SecondObject + ) + } + + + public override val enumClass: KClass + get() = TwoObjectSealedClassEnum::class + + public override fun ordinalOf(obj: TwoObjectSealedClass): Int = when (obj) { + is TwoObjectSealedClass.FirstObject -> 0 + is TwoObjectSealedClass.SecondObject -> 1 + } + + public override fun nameOf(obj: TwoObjectSealedClass): String = when (obj) { + is TwoObjectSealedClass.FirstObject -> "TwoObjectSealedClass_FirstObject" + is TwoObjectSealedClass.SecondObject -> "TwoObjectSealedClass_SecondObject" + } + + public override fun valueOf(name: String): TwoObjectSealedClass = when (name) { + "TwoObjectSealedClass_FirstObject" -> TwoObjectSealedClass.FirstObject + "TwoObjectSealedClass_SecondObject" -> TwoObjectSealedClass.SecondObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: TwoObjectSealedClass): TwoObjectSealedClassEnum = + when (obj) { + is TwoObjectSealedClass.FirstObject -> + TwoObjectSealedClassEnum.TwoObjectSealedClass_FirstObject + is TwoObjectSealedClass.SecondObject -> + TwoObjectSealedClassEnum.TwoObjectSealedClass_SecondObject + } + + public override fun enumToSealedObject(`enum`: TwoObjectSealedClassEnum): TwoObjectSealedClass = + when (enum) { + TwoObjectSealedClassEnum.TwoObjectSealedClass_FirstObject -> + TwoObjectSealedClass.FirstObject + TwoObjectSealedClassEnum.TwoObjectSealedClass_SecondObject -> + TwoObjectSealedClass.SecondObject + } +} + +/** + * The index of [this] in the values list. + */ +public val TwoObjectSealedClass.ordinal: Int + get() = TwoObjectSealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val TwoObjectSealedClass.name: String + get() = TwoObjectSealedClassSealedEnum.nameOf(this) + +/** + * A list of all [TwoObjectSealedClass] objects. + */ +public val TwoObjectSealedClass.Companion.values: List + get() = TwoObjectSealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [TwoObjectSealedClass] + */ +public val TwoObjectSealedClass.Companion.sealedEnum: TwoObjectSealedClassSealedEnum + get() = TwoObjectSealedClassSealedEnum + +/** + * Returns the [TwoObjectSealedClass] object for the given [name]. + * + * If the given name doesn't correspond to any [TwoObjectSealedClass], an [IllegalArgumentException] + * will be thrown. + */ +public fun TwoObjectSealedClass.Companion.valueOf(name: String): TwoObjectSealedClass = + TwoObjectSealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/basic/TwoObjectSealedInterfaceTests.compilation generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/basic/TwoObjectSealedInterfaceTests.compilation generates correct code.approved new file mode 100644 index 00000000..5e68ea07 --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/basic/TwoObjectSealedInterfaceTests.compilation generates correct code.approved @@ -0,0 +1,114 @@ +package com.livefront.sealedenum.compilation.basic + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [TwoObjectSealedInterface] + */ +public enum class TwoObjectSealedInterfaceEnum() { + TwoObjectSealedInterface_FirstObject, + TwoObjectSealedInterface_SecondObject, +} + +/** + * The isomorphic [TwoObjectSealedInterfaceEnum] for [this]. + */ +public val TwoObjectSealedInterface.`enum`: TwoObjectSealedInterfaceEnum + get() = TwoObjectSealedInterfaceSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [TwoObjectSealedInterface] for [this]. + */ +public val TwoObjectSealedInterfaceEnum.sealedObject: TwoObjectSealedInterface + get() = TwoObjectSealedInterfaceSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [TwoObjectSealedInterface] + */ +public object TwoObjectSealedInterfaceSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + TwoObjectSealedInterface.FirstObject, + TwoObjectSealedInterface.SecondObject + ) + } + + + public override val enumClass: KClass + get() = TwoObjectSealedInterfaceEnum::class + + public override fun ordinalOf(obj: TwoObjectSealedInterface): Int = when (obj) { + is TwoObjectSealedInterface.FirstObject -> 0 + is TwoObjectSealedInterface.SecondObject -> 1 + } + + public override fun nameOf(obj: TwoObjectSealedInterface): String = when (obj) { + is TwoObjectSealedInterface.FirstObject -> "TwoObjectSealedInterface_FirstObject" + is TwoObjectSealedInterface.SecondObject -> "TwoObjectSealedInterface_SecondObject" + } + + public override fun valueOf(name: String): TwoObjectSealedInterface = when (name) { + "TwoObjectSealedInterface_FirstObject" -> TwoObjectSealedInterface.FirstObject + "TwoObjectSealedInterface_SecondObject" -> TwoObjectSealedInterface.SecondObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: TwoObjectSealedInterface): + TwoObjectSealedInterfaceEnum = when (obj) { + is TwoObjectSealedInterface.FirstObject -> + TwoObjectSealedInterfaceEnum.TwoObjectSealedInterface_FirstObject + is TwoObjectSealedInterface.SecondObject -> + TwoObjectSealedInterfaceEnum.TwoObjectSealedInterface_SecondObject + } + + public override fun enumToSealedObject(`enum`: TwoObjectSealedInterfaceEnum): + TwoObjectSealedInterface = when (enum) { + TwoObjectSealedInterfaceEnum.TwoObjectSealedInterface_FirstObject -> + TwoObjectSealedInterface.FirstObject + TwoObjectSealedInterfaceEnum.TwoObjectSealedInterface_SecondObject -> + TwoObjectSealedInterface.SecondObject + } +} + +/** + * The index of [this] in the values list. + */ +public val TwoObjectSealedInterface.ordinal: Int + get() = TwoObjectSealedInterfaceSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val TwoObjectSealedInterface.name: String + get() = TwoObjectSealedInterfaceSealedEnum.nameOf(this) + +/** + * A list of all [TwoObjectSealedInterface] objects. + */ +public val TwoObjectSealedInterface.Companion.values: List + get() = TwoObjectSealedInterfaceSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [TwoObjectSealedInterface] + */ +public val TwoObjectSealedInterface.Companion.sealedEnum: TwoObjectSealedInterfaceSealedEnum + get() = TwoObjectSealedInterfaceSealedEnum + +/** + * Returns the [TwoObjectSealedInterface] object for the given [name]. + * + * If the given name doesn't correspond to any [TwoObjectSealedInterface], an + * [IllegalArgumentException] will be thrown. + */ +public fun TwoObjectSealedInterface.Companion.valueOf(name: String): TwoObjectSealedInterface = + TwoObjectSealedInterfaceSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/GenericSealedClassTests.compilation for limited type parameter generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/GenericSealedClassTests.compilation for limited type parameter generates correct code.approved new file mode 100644 index 00000000..4e029fa1 --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/GenericSealedClassTests.compilation for limited type parameter generates correct code.approved @@ -0,0 +1,122 @@ +package com.livefront.sealedenum.compilation.generics + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [LimitedTypeParameterSealedClass] + */ +public enum class LimitedTypeParameterSealedClassEnum() { + LimitedTypeParameterSealedClass_FirstObject, + LimitedTypeParameterSealedClass_SecondObject, +} + +/** + * The isomorphic [LimitedTypeParameterSealedClassEnum] for [this]. + */ +public val LimitedTypeParameterSealedClass<*, *>.`enum`: LimitedTypeParameterSealedClassEnum + get() = LimitedTypeParameterSealedClassSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [LimitedTypeParameterSealedClass] for [this]. + */ +public val LimitedTypeParameterSealedClassEnum.sealedObject: LimitedTypeParameterSealedClass<*, *> + get() = LimitedTypeParameterSealedClassSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [LimitedTypeParameterSealedClass] + */ +public object LimitedTypeParameterSealedClassSealedEnum : + SealedEnum>, + SealedEnumWithEnumProvider, LimitedTypeParameterSealedClassEnum>, + EnumForSealedEnumProvider, LimitedTypeParameterSealedClassEnum> + { + public override val values: List> by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + LimitedTypeParameterSealedClass.FirstObject, + LimitedTypeParameterSealedClass.SecondObject + ) + } + + + public override val enumClass: KClass + get() = LimitedTypeParameterSealedClassEnum::class + + public override fun ordinalOf(obj: LimitedTypeParameterSealedClass<*, *>): Int = when (obj) { + is LimitedTypeParameterSealedClass.FirstObject -> 0 + is LimitedTypeParameterSealedClass.SecondObject -> 1 + } + + public override fun nameOf(obj: LimitedTypeParameterSealedClass<*, *>): String = when (obj) { + is LimitedTypeParameterSealedClass.FirstObject -> + "LimitedTypeParameterSealedClass_FirstObject" + is LimitedTypeParameterSealedClass.SecondObject -> + "LimitedTypeParameterSealedClass_SecondObject" + } + + public override fun valueOf(name: String): LimitedTypeParameterSealedClass<*, *> = when (name) { + "LimitedTypeParameterSealedClass_FirstObject" -> LimitedTypeParameterSealedClass.FirstObject + "LimitedTypeParameterSealedClass_SecondObject" -> + LimitedTypeParameterSealedClass.SecondObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: LimitedTypeParameterSealedClass<*, *>): + LimitedTypeParameterSealedClassEnum = when (obj) { + is LimitedTypeParameterSealedClass.FirstObject -> + LimitedTypeParameterSealedClassEnum.LimitedTypeParameterSealedClass_FirstObject + is LimitedTypeParameterSealedClass.SecondObject -> + LimitedTypeParameterSealedClassEnum.LimitedTypeParameterSealedClass_SecondObject + } + + public override fun enumToSealedObject(`enum`: LimitedTypeParameterSealedClassEnum): + LimitedTypeParameterSealedClass<*, *> = when (enum) { + LimitedTypeParameterSealedClassEnum.LimitedTypeParameterSealedClass_FirstObject -> + LimitedTypeParameterSealedClass.FirstObject + LimitedTypeParameterSealedClassEnum.LimitedTypeParameterSealedClass_SecondObject -> + LimitedTypeParameterSealedClass.SecondObject + } +} + +/** + * The index of [this] in the values list. + */ +public val LimitedTypeParameterSealedClass<*, *>.ordinal: Int + get() = LimitedTypeParameterSealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val LimitedTypeParameterSealedClass<*, *>.name: String + get() = LimitedTypeParameterSealedClassSealedEnum.nameOf(this) + +/** + * A list of all [LimitedTypeParameterSealedClass] objects. + */ +public val LimitedTypeParameterSealedClass.LimitedType.values: + List> + get() = LimitedTypeParameterSealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [LimitedTypeParameterSealedClass] + */ +public val LimitedTypeParameterSealedClass.LimitedType.sealedEnum: + LimitedTypeParameterSealedClassSealedEnum + get() = LimitedTypeParameterSealedClassSealedEnum + +/** + * Returns the [LimitedTypeParameterSealedClass] object for the given [name]. + * + * If the given name doesn't correspond to any [LimitedTypeParameterSealedClass], an + * [IllegalArgumentException] will be thrown. + */ +public fun LimitedTypeParameterSealedClass.LimitedType.valueOf(name: String): + LimitedTypeParameterSealedClass<*, *> = + LimitedTypeParameterSealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/GenericSealedClassTests.compilation for multiple bounds sealed class generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/GenericSealedClassTests.compilation for multiple bounds sealed class generates correct code.approved new file mode 100644 index 00000000..36522d71 --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/GenericSealedClassTests.compilation for multiple bounds sealed class generates correct code.approved @@ -0,0 +1,105 @@ +package com.livefront.sealedenum.compilation.generics + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [MultipleBoundsSealedClass] + */ +public enum class MultipleBoundsSealedClassEnum() { + MultipleBoundsSealedClass_FirstObject, +} + +/** + * The isomorphic [MultipleBoundsSealedClassEnum] for [this]. + */ +public val MultipleBoundsSealedClass<*>.`enum`: MultipleBoundsSealedClassEnum + get() = MultipleBoundsSealedClassSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [MultipleBoundsSealedClass] for [this]. + */ +public val MultipleBoundsSealedClassEnum.sealedObject: MultipleBoundsSealedClass<*> + get() = MultipleBoundsSealedClassSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [MultipleBoundsSealedClass] + */ +public object MultipleBoundsSealedClassSealedEnum : SealedEnum>, + SealedEnumWithEnumProvider, MultipleBoundsSealedClassEnum>, + EnumForSealedEnumProvider, MultipleBoundsSealedClassEnum> { + public override val values: List> by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + MultipleBoundsSealedClass.FirstObject + ) + } + + + public override val enumClass: KClass + get() = MultipleBoundsSealedClassEnum::class + + public override fun ordinalOf(obj: MultipleBoundsSealedClass<*>): Int = when (obj) { + is MultipleBoundsSealedClass.FirstObject -> 0 + } + + public override fun nameOf(obj: MultipleBoundsSealedClass<*>): String = when (obj) { + is MultipleBoundsSealedClass.FirstObject -> "MultipleBoundsSealedClass_FirstObject" + } + + public override fun valueOf(name: String): MultipleBoundsSealedClass<*> = when (name) { + "MultipleBoundsSealedClass_FirstObject" -> MultipleBoundsSealedClass.FirstObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: MultipleBoundsSealedClass<*>): + MultipleBoundsSealedClassEnum = when (obj) { + is MultipleBoundsSealedClass.FirstObject -> + MultipleBoundsSealedClassEnum.MultipleBoundsSealedClass_FirstObject + } + + public override fun enumToSealedObject(`enum`: MultipleBoundsSealedClassEnum): + MultipleBoundsSealedClass<*> = when (enum) { + MultipleBoundsSealedClassEnum.MultipleBoundsSealedClass_FirstObject -> + MultipleBoundsSealedClass.FirstObject + } +} + +/** + * The index of [this] in the values list. + */ +public val MultipleBoundsSealedClass<*>.ordinal: Int + get() = MultipleBoundsSealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val MultipleBoundsSealedClass<*>.name: String + get() = MultipleBoundsSealedClassSealedEnum.nameOf(this) + +/** + * A list of all [MultipleBoundsSealedClass] objects. + */ +public val MultipleBoundsSealedClass.Companion.values: List> + get() = MultipleBoundsSealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [MultipleBoundsSealedClass] + */ +public val MultipleBoundsSealedClass.Companion.sealedEnum: MultipleBoundsSealedClassSealedEnum + get() = MultipleBoundsSealedClassSealedEnum + +/** + * Returns the [MultipleBoundsSealedClass] object for the given [name]. + * + * If the given name doesn't correspond to any [MultipleBoundsSealedClass], an + * [IllegalArgumentException] will be thrown. + */ +public fun MultipleBoundsSealedClass.Companion.valueOf(name: String): MultipleBoundsSealedClass<*> = + MultipleBoundsSealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/GenericSealedClassTests.compilation for one type parameter generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/GenericSealedClassTests.compilation for one type parameter generates correct code.approved new file mode 100644 index 00000000..02456492 --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/GenericSealedClassTests.compilation for one type parameter generates correct code.approved @@ -0,0 +1,123 @@ +package com.livefront.sealedenum.compilation.generics + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [OneTypeParameterSealedClass] + */ +public enum class OneTypeParameterSealedClassEnum() { + OneTypeParameterSealedClass_FirstObject, + OneTypeParameterSealedClass_SecondObject, + OneTypeParameterSealedClass_ThirdObject, +} + +/** + * The isomorphic [OneTypeParameterSealedClassEnum] for [this]. + */ +public val OneTypeParameterSealedClass<*>.`enum`: OneTypeParameterSealedClassEnum + get() = OneTypeParameterSealedClassSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [OneTypeParameterSealedClass] for [this]. + */ +public val OneTypeParameterSealedClassEnum.sealedObject: OneTypeParameterSealedClass<*> + get() = OneTypeParameterSealedClassSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [OneTypeParameterSealedClass] + */ +public object OneTypeParameterSealedClassSealedEnum : SealedEnum>, + SealedEnumWithEnumProvider, OneTypeParameterSealedClassEnum>, + EnumForSealedEnumProvider, OneTypeParameterSealedClassEnum> { + public override val values: List> by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + OneTypeParameterSealedClass.FirstObject, + OneTypeParameterSealedClass.SecondObject, + OneTypeParameterSealedClass.ThirdObject + ) + } + + + public override val enumClass: KClass + get() = OneTypeParameterSealedClassEnum::class + + public override fun ordinalOf(obj: OneTypeParameterSealedClass<*>): Int = when (obj) { + is OneTypeParameterSealedClass.FirstObject -> 0 + is OneTypeParameterSealedClass.SecondObject -> 1 + is OneTypeParameterSealedClass.ThirdObject -> 2 + } + + public override fun nameOf(obj: OneTypeParameterSealedClass<*>): String = when (obj) { + is OneTypeParameterSealedClass.FirstObject -> "OneTypeParameterSealedClass_FirstObject" + is OneTypeParameterSealedClass.SecondObject -> "OneTypeParameterSealedClass_SecondObject" + is OneTypeParameterSealedClass.ThirdObject -> "OneTypeParameterSealedClass_ThirdObject" + } + + public override fun valueOf(name: String): OneTypeParameterSealedClass<*> = when (name) { + "OneTypeParameterSealedClass_FirstObject" -> OneTypeParameterSealedClass.FirstObject + "OneTypeParameterSealedClass_SecondObject" -> OneTypeParameterSealedClass.SecondObject + "OneTypeParameterSealedClass_ThirdObject" -> OneTypeParameterSealedClass.ThirdObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: OneTypeParameterSealedClass<*>): + OneTypeParameterSealedClassEnum = when (obj) { + is OneTypeParameterSealedClass.FirstObject -> + OneTypeParameterSealedClassEnum.OneTypeParameterSealedClass_FirstObject + is OneTypeParameterSealedClass.SecondObject -> + OneTypeParameterSealedClassEnum.OneTypeParameterSealedClass_SecondObject + is OneTypeParameterSealedClass.ThirdObject -> + OneTypeParameterSealedClassEnum.OneTypeParameterSealedClass_ThirdObject + } + + public override fun enumToSealedObject(`enum`: OneTypeParameterSealedClassEnum): + OneTypeParameterSealedClass<*> = when (enum) { + OneTypeParameterSealedClassEnum.OneTypeParameterSealedClass_FirstObject -> + OneTypeParameterSealedClass.FirstObject + OneTypeParameterSealedClassEnum.OneTypeParameterSealedClass_SecondObject -> + OneTypeParameterSealedClass.SecondObject + OneTypeParameterSealedClassEnum.OneTypeParameterSealedClass_ThirdObject -> + OneTypeParameterSealedClass.ThirdObject + } +} + +/** + * The index of [this] in the values list. + */ +public val OneTypeParameterSealedClass<*>.ordinal: Int + get() = OneTypeParameterSealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val OneTypeParameterSealedClass<*>.name: String + get() = OneTypeParameterSealedClassSealedEnum.nameOf(this) + +/** + * A list of all [OneTypeParameterSealedClass] objects. + */ +public val OneTypeParameterSealedClass.OneType.values: List> + get() = OneTypeParameterSealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [OneTypeParameterSealedClass] + */ +public val OneTypeParameterSealedClass.OneType.sealedEnum: OneTypeParameterSealedClassSealedEnum + get() = OneTypeParameterSealedClassSealedEnum + +/** + * Returns the [OneTypeParameterSealedClass] object for the given [name]. + * + * If the given name doesn't correspond to any [OneTypeParameterSealedClass], an + * [IllegalArgumentException] will be thrown. + */ +public fun OneTypeParameterSealedClass.OneType.valueOf(name: String): OneTypeParameterSealedClass<*> + = OneTypeParameterSealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/GenericSealedClassTests.compilation for two type parameter generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/GenericSealedClassTests.compilation for two type parameter generates correct code.approved new file mode 100644 index 00000000..61f50f53 --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/GenericSealedClassTests.compilation for two type parameter generates correct code.approved @@ -0,0 +1,115 @@ +package com.livefront.sealedenum.compilation.generics + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [TwoTypeParameterSealedClass] + */ +public enum class TwoTypeParameterSealedClassEnum() { + TwoTypeParameterSealedClass_FirstObject, + TwoTypeParameterSealedClass_SecondObject, +} + +/** + * The isomorphic [TwoTypeParameterSealedClassEnum] for [this]. + */ +public val TwoTypeParameterSealedClass<*, *>.`enum`: TwoTypeParameterSealedClassEnum + get() = TwoTypeParameterSealedClassSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [TwoTypeParameterSealedClass] for [this]. + */ +public val TwoTypeParameterSealedClassEnum.sealedObject: TwoTypeParameterSealedClass<*, *> + get() = TwoTypeParameterSealedClassSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [TwoTypeParameterSealedClass] + */ +public object TwoTypeParameterSealedClassSealedEnum : SealedEnum>, + SealedEnumWithEnumProvider, TwoTypeParameterSealedClassEnum>, + EnumForSealedEnumProvider, TwoTypeParameterSealedClassEnum> + { + public override val values: List> by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + TwoTypeParameterSealedClass.FirstObject, + TwoTypeParameterSealedClass.SecondObject + ) + } + + + public override val enumClass: KClass + get() = TwoTypeParameterSealedClassEnum::class + + public override fun ordinalOf(obj: TwoTypeParameterSealedClass<*, *>): Int = when (obj) { + is TwoTypeParameterSealedClass.FirstObject -> 0 + is TwoTypeParameterSealedClass.SecondObject -> 1 + } + + public override fun nameOf(obj: TwoTypeParameterSealedClass<*, *>): String = when (obj) { + is TwoTypeParameterSealedClass.FirstObject -> "TwoTypeParameterSealedClass_FirstObject" + is TwoTypeParameterSealedClass.SecondObject -> "TwoTypeParameterSealedClass_SecondObject" + } + + public override fun valueOf(name: String): TwoTypeParameterSealedClass<*, *> = when (name) { + "TwoTypeParameterSealedClass_FirstObject" -> TwoTypeParameterSealedClass.FirstObject + "TwoTypeParameterSealedClass_SecondObject" -> TwoTypeParameterSealedClass.SecondObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: TwoTypeParameterSealedClass<*, *>): + TwoTypeParameterSealedClassEnum = when (obj) { + is TwoTypeParameterSealedClass.FirstObject -> + TwoTypeParameterSealedClassEnum.TwoTypeParameterSealedClass_FirstObject + is TwoTypeParameterSealedClass.SecondObject -> + TwoTypeParameterSealedClassEnum.TwoTypeParameterSealedClass_SecondObject + } + + public override fun enumToSealedObject(`enum`: TwoTypeParameterSealedClassEnum): + TwoTypeParameterSealedClass<*, *> = when (enum) { + TwoTypeParameterSealedClassEnum.TwoTypeParameterSealedClass_FirstObject -> + TwoTypeParameterSealedClass.FirstObject + TwoTypeParameterSealedClassEnum.TwoTypeParameterSealedClass_SecondObject -> + TwoTypeParameterSealedClass.SecondObject + } +} + +/** + * The index of [this] in the values list. + */ +public val TwoTypeParameterSealedClass<*, *>.ordinal: Int + get() = TwoTypeParameterSealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val TwoTypeParameterSealedClass<*, *>.name: String + get() = TwoTypeParameterSealedClassSealedEnum.nameOf(this) + +/** + * A list of all [TwoTypeParameterSealedClass] objects. + */ +public val TwoTypeParameterSealedClass.TwoType.values: List> + get() = TwoTypeParameterSealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [TwoTypeParameterSealedClass] + */ +public val TwoTypeParameterSealedClass.TwoType.sealedEnum: TwoTypeParameterSealedClassSealedEnum + get() = TwoTypeParameterSealedClassSealedEnum + +/** + * Returns the [TwoTypeParameterSealedClass] object for the given [name]. + * + * If the given name doesn't correspond to any [TwoTypeParameterSealedClass], an + * [IllegalArgumentException] will be thrown. + */ +public fun TwoTypeParameterSealedClass.TwoType.valueOf(name: String): + TwoTypeParameterSealedClass<*, *> = TwoTypeParameterSealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithAbstractBaseClassesTests.compilation for covariant type generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithAbstractBaseClassesTests.compilation for covariant type generates correct code.approved new file mode 100644 index 00000000..34e1b65f --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithAbstractBaseClassesTests.compilation for covariant type generates correct code.approved @@ -0,0 +1,107 @@ +package com.livefront.sealedenum.compilation.generics + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [SealedEnumWithAbstractBaseClassesCovariantType] + */ +public enum class SealedEnumWithAbstractBaseClassesCovariantTypeEnum( + sealedObject: SealedEnumWithAbstractBaseClassesCovariantType<*>, +) : BaseClassInterface3> by sealedObject + +/** + * The isomorphic [SealedEnumWithAbstractBaseClassesCovariantTypeEnum] for [this]. + */ +public val SealedEnumWithAbstractBaseClassesCovariantType<*>.`enum`: + SealedEnumWithAbstractBaseClassesCovariantTypeEnum + get() = SealedEnumWithAbstractBaseClassesCovariantTypeSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [SealedEnumWithAbstractBaseClassesCovariantType] for [this]. + */ +public val SealedEnumWithAbstractBaseClassesCovariantTypeEnum.sealedObject: + SealedEnumWithAbstractBaseClassesCovariantType<*> + get() = SealedEnumWithAbstractBaseClassesCovariantTypeSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class + * [SealedEnumWithAbstractBaseClassesCovariantType] + */ +public object SealedEnumWithAbstractBaseClassesCovariantTypeSealedEnum : + SealedEnum>, + SealedEnumWithEnumProvider, SealedEnumWithAbstractBaseClassesCovariantTypeEnum>, + EnumForSealedEnumProvider, SealedEnumWithAbstractBaseClassesCovariantTypeEnum> + { + public override val values: List> by lazy(mode + = LazyThreadSafetyMode.PUBLICATION) { + emptyList() + } + + + public override val enumClass: KClass + get() = SealedEnumWithAbstractBaseClassesCovariantTypeEnum::class + + public override fun ordinalOf(obj: SealedEnumWithAbstractBaseClassesCovariantType<*>): Int = + throw + AssertionError("Constructing a SealedEnumWithAbstractBaseClassesCovariantType is impossible, since it has no sealed subclasses") + + public override fun nameOf(obj: SealedEnumWithAbstractBaseClassesCovariantType<*>): String = + throw + AssertionError("Constructing a SealedEnumWithAbstractBaseClassesCovariantType is impossible, since it has no sealed subclasses") + + public override fun valueOf(name: String): SealedEnumWithAbstractBaseClassesCovariantType<*> = + throw IllegalArgumentException("""No sealed enum constant $name""") + + public override fun sealedObjectToEnum(obj: SealedEnumWithAbstractBaseClassesCovariantType<*>): + SealedEnumWithAbstractBaseClassesCovariantTypeEnum = throw + AssertionError("Constructing a SealedEnumWithAbstractBaseClassesCovariantType is impossible, since it has no sealed subclasses") + + public override + fun enumToSealedObject(`enum`: SealedEnumWithAbstractBaseClassesCovariantTypeEnum): + SealedEnumWithAbstractBaseClassesCovariantType<*> = throw + AssertionError("Constructing a SealedEnumWithAbstractBaseClassesCovariantType is impossible, since it has no sealed subclasses") +} + +/** + * The index of [this] in the values list. + */ +public val SealedEnumWithAbstractBaseClassesCovariantType<*>.ordinal: Int + get() = SealedEnumWithAbstractBaseClassesCovariantTypeSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val SealedEnumWithAbstractBaseClassesCovariantType<*>.name: String + get() = SealedEnumWithAbstractBaseClassesCovariantTypeSealedEnum.nameOf(this) + +/** + * A list of all [SealedEnumWithAbstractBaseClassesCovariantType] objects. + */ +public val SealedEnumWithAbstractBaseClassesCovariantType.Companion.values: + List> + get() = SealedEnumWithAbstractBaseClassesCovariantTypeSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class + * [SealedEnumWithAbstractBaseClassesCovariantType] + */ +public val SealedEnumWithAbstractBaseClassesCovariantType.Companion.sealedEnum: + SealedEnumWithAbstractBaseClassesCovariantTypeSealedEnum + get() = SealedEnumWithAbstractBaseClassesCovariantTypeSealedEnum + +/** + * Returns the [SealedEnumWithAbstractBaseClassesCovariantType] object for the given [name]. + * + * If the given name doesn't correspond to any [SealedEnumWithAbstractBaseClassesCovariantType], an + * [IllegalArgumentException] will be thrown. + */ +public fun SealedEnumWithAbstractBaseClassesCovariantType.Companion.valueOf(name: String): + SealedEnumWithAbstractBaseClassesCovariantType<*> = + SealedEnumWithAbstractBaseClassesCovariantTypeSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithAbstractBaseClassesTests.compilation for invariant type generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithAbstractBaseClassesTests.compilation for invariant type generates correct code.approved new file mode 100644 index 00000000..f232deda --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithAbstractBaseClassesTests.compilation for invariant type generates correct code.approved @@ -0,0 +1,103 @@ +package com.livefront.sealedenum.compilation.generics + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Any +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [SealedEnumWithAbstractBaseClasses] + */ +public enum class SealedEnumWithAbstractBaseClassesEnum( + sealedObject: SealedEnumWithAbstractBaseClasses, +) : BaseClassInterface2 by sealedObject, BaseClassInterface1> by + sealedObject + +/** + * The isomorphic [SealedEnumWithAbstractBaseClassesEnum] for [this]. + */ +public val SealedEnumWithAbstractBaseClasses.`enum`: SealedEnumWithAbstractBaseClassesEnum + get() = SealedEnumWithAbstractBaseClassesSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [SealedEnumWithAbstractBaseClasses] for [this]. + */ +public val SealedEnumWithAbstractBaseClassesEnum.sealedObject: SealedEnumWithAbstractBaseClasses + get() = SealedEnumWithAbstractBaseClassesSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [SealedEnumWithAbstractBaseClasses] + */ +public object SealedEnumWithAbstractBaseClassesSealedEnum : + SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider + { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + emptyList() + } + + + public override val enumClass: KClass + get() = SealedEnumWithAbstractBaseClassesEnum::class + + public override fun ordinalOf(obj: SealedEnumWithAbstractBaseClasses): Int = throw + AssertionError("Constructing a SealedEnumWithAbstractBaseClasses is impossible, since it has no sealed subclasses") + + public override fun nameOf(obj: SealedEnumWithAbstractBaseClasses): String = throw + AssertionError("Constructing a SealedEnumWithAbstractBaseClasses is impossible, since it has no sealed subclasses") + + public override fun valueOf(name: String): SealedEnumWithAbstractBaseClasses = throw + IllegalArgumentException("""No sealed enum constant $name""") + + public override fun sealedObjectToEnum(obj: SealedEnumWithAbstractBaseClasses): + SealedEnumWithAbstractBaseClassesEnum = throw + AssertionError("Constructing a SealedEnumWithAbstractBaseClasses is impossible, since it has no sealed subclasses") + + public override fun enumToSealedObject(`enum`: SealedEnumWithAbstractBaseClassesEnum): + SealedEnumWithAbstractBaseClasses = throw + AssertionError("Constructing a SealedEnumWithAbstractBaseClasses is impossible, since it has no sealed subclasses") +} + +/** + * The index of [this] in the values list. + */ +public val SealedEnumWithAbstractBaseClasses.ordinal: Int + get() = SealedEnumWithAbstractBaseClassesSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val SealedEnumWithAbstractBaseClasses.name: String + get() = SealedEnumWithAbstractBaseClassesSealedEnum.nameOf(this) + +/** + * A list of all [SealedEnumWithAbstractBaseClasses] objects. + */ +public val SealedEnumWithAbstractBaseClasses.Companion.values: + List + get() = SealedEnumWithAbstractBaseClassesSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class + * [SealedEnumWithAbstractBaseClasses] + */ +public val SealedEnumWithAbstractBaseClasses.Companion.sealedEnum: + SealedEnumWithAbstractBaseClassesSealedEnum + get() = SealedEnumWithAbstractBaseClassesSealedEnum + +/** + * Returns the [SealedEnumWithAbstractBaseClasses] object for the given [name]. + * + * If the given name doesn't correspond to any [SealedEnumWithAbstractBaseClasses], an + * [IllegalArgumentException] will be thrown. + */ +public fun SealedEnumWithAbstractBaseClasses.Companion.valueOf(name: String): + SealedEnumWithAbstractBaseClasses = + SealedEnumWithAbstractBaseClassesSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithInterfacesTests.compilation for empty sealed class generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithInterfacesTests.compilation for empty sealed class generates correct code.approved new file mode 100644 index 00000000..730e4bc9 --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithInterfacesTests.compilation for empty sealed class generates correct code.approved @@ -0,0 +1,97 @@ +package com.livefront.sealedenum.compilation.generics + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [EmptySealedClassWithInterface] + */ +public enum class EmptySealedClassWithInterfaceEnum( + sealedObject: EmptySealedClassWithInterface, +) : TestInterface by sealedObject + +/** + * The isomorphic [EmptySealedClassWithInterfaceEnum] for [this]. + */ +public val EmptySealedClassWithInterface.`enum`: EmptySealedClassWithInterfaceEnum + get() = EmptySealedClassWithInterfaceSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [EmptySealedClassWithInterface] for [this]. + */ +public val EmptySealedClassWithInterfaceEnum.sealedObject: EmptySealedClassWithInterface + get() = EmptySealedClassWithInterfaceSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [EmptySealedClassWithInterface] + */ +public object EmptySealedClassWithInterfaceSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider + { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + emptyList() + } + + + public override val enumClass: KClass + get() = EmptySealedClassWithInterfaceEnum::class + + public override fun ordinalOf(obj: EmptySealedClassWithInterface): Int = throw + AssertionError("Constructing a EmptySealedClassWithInterface is impossible, since it has no sealed subclasses") + + public override fun nameOf(obj: EmptySealedClassWithInterface): String = throw + AssertionError("Constructing a EmptySealedClassWithInterface is impossible, since it has no sealed subclasses") + + public override fun valueOf(name: String): EmptySealedClassWithInterface = throw + IllegalArgumentException("""No sealed enum constant $name""") + + public override fun sealedObjectToEnum(obj: EmptySealedClassWithInterface): + EmptySealedClassWithInterfaceEnum = throw + AssertionError("Constructing a EmptySealedClassWithInterface is impossible, since it has no sealed subclasses") + + public override fun enumToSealedObject(`enum`: EmptySealedClassWithInterfaceEnum): + EmptySealedClassWithInterface = throw + AssertionError("Constructing a EmptySealedClassWithInterface is impossible, since it has no sealed subclasses") +} + +/** + * The index of [this] in the values list. + */ +public val EmptySealedClassWithInterface.ordinal: Int + get() = EmptySealedClassWithInterfaceSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val EmptySealedClassWithInterface.name: String + get() = EmptySealedClassWithInterfaceSealedEnum.nameOf(this) + +/** + * A list of all [EmptySealedClassWithInterface] objects. + */ +public val EmptySealedClassWithInterface.Companion.values: List + get() = EmptySealedClassWithInterfaceSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [EmptySealedClassWithInterface] + */ +public val EmptySealedClassWithInterface.Companion.sealedEnum: + EmptySealedClassWithInterfaceSealedEnum + get() = EmptySealedClassWithInterfaceSealedEnum + +/** + * Returns the [EmptySealedClassWithInterface] object for the given [name]. + * + * If the given name doesn't correspond to any [EmptySealedClassWithInterface], an + * [IllegalArgumentException] will be thrown. + */ +public fun EmptySealedClassWithInterface.Companion.valueOf(name: String): + EmptySealedClassWithInterface = EmptySealedClassWithInterfaceSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithInterfacesTests.compilation for one object sealed class generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithInterfacesTests.compilation for one object sealed class generates correct code.approved new file mode 100644 index 00000000..f261136a --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithInterfacesTests.compilation for one object sealed class generates correct code.approved @@ -0,0 +1,115 @@ +package com.livefront.sealedenum.compilation.generics + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [OneObjectSealedClassWithInterface] + */ +public enum class OneObjectSealedClassWithInterfaceEnum( + sealedObject: OneObjectSealedClassWithInterface, +) : TestInterface by sealedObject { + OneObjectSealedClassWithInterface_FirstObject(com.livefront.sealedenum.compilation.generics.OneObjectSealedClassWithInterface.FirstObject), +} + +/** + * The isomorphic [OneObjectSealedClassWithInterfaceEnum] for [this]. + */ +public val OneObjectSealedClassWithInterface.`enum`: OneObjectSealedClassWithInterfaceEnum + get() = OneObjectSealedClassWithInterfaceSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [OneObjectSealedClassWithInterface] for [this]. + */ +public val OneObjectSealedClassWithInterfaceEnum.sealedObject: OneObjectSealedClassWithInterface + get() = OneObjectSealedClassWithInterfaceSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [OneObjectSealedClassWithInterface] + */ +public object OneObjectSealedClassWithInterfaceSealedEnum : + SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider + { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + OneObjectSealedClassWithInterface.FirstObject + ) + } + + + public override val enumClass: KClass + get() = OneObjectSealedClassWithInterfaceEnum::class + + public override fun ordinalOf(obj: OneObjectSealedClassWithInterface): Int = when (obj) { + is OneObjectSealedClassWithInterface.FirstObject -> 0 + } + + public override fun nameOf(obj: OneObjectSealedClassWithInterface): String = when (obj) { + is OneObjectSealedClassWithInterface.FirstObject -> + "OneObjectSealedClassWithInterface_FirstObject" + } + + public override fun valueOf(name: String): OneObjectSealedClassWithInterface = when (name) { + "OneObjectSealedClassWithInterface_FirstObject" -> + OneObjectSealedClassWithInterface.FirstObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: OneObjectSealedClassWithInterface): + OneObjectSealedClassWithInterfaceEnum = when (obj) { + is OneObjectSealedClassWithInterface.FirstObject -> + OneObjectSealedClassWithInterfaceEnum.OneObjectSealedClassWithInterface_FirstObject + } + + public override fun enumToSealedObject(`enum`: OneObjectSealedClassWithInterfaceEnum): + OneObjectSealedClassWithInterface = when (enum) { + OneObjectSealedClassWithInterfaceEnum.OneObjectSealedClassWithInterface_FirstObject -> + OneObjectSealedClassWithInterface.FirstObject + } +} + +/** + * The index of [this] in the values list. + */ +public val OneObjectSealedClassWithInterface.ordinal: Int + get() = OneObjectSealedClassWithInterfaceSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val OneObjectSealedClassWithInterface.name: String + get() = OneObjectSealedClassWithInterfaceSealedEnum.nameOf(this) + +/** + * A list of all [OneObjectSealedClassWithInterface] objects. + */ +public val OneObjectSealedClassWithInterface.Companion.values: + List + get() = OneObjectSealedClassWithInterfaceSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class + * [OneObjectSealedClassWithInterface] + */ +public val OneObjectSealedClassWithInterface.Companion.sealedEnum: + OneObjectSealedClassWithInterfaceSealedEnum + get() = OneObjectSealedClassWithInterfaceSealedEnum + +/** + * Returns the [OneObjectSealedClassWithInterface] object for the given [name]. + * + * If the given name doesn't correspond to any [OneObjectSealedClassWithInterface], an + * [IllegalArgumentException] will be thrown. + */ +public fun OneObjectSealedClassWithInterface.Companion.valueOf(name: String): + OneObjectSealedClassWithInterface = + OneObjectSealedClassWithInterfaceSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithInterfacesTests.compilation for sealed class with getter interface generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithInterfacesTests.compilation for sealed class with getter interface generates correct code.approved new file mode 100644 index 00000000..5a50bd5f --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithInterfacesTests.compilation for sealed class with getter interface generates correct code.approved @@ -0,0 +1,110 @@ +package com.livefront.sealedenum.compilation.generics + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [SealedClassWithGetterInterface] + */ +public enum class SealedClassWithGetterInterfaceEnum( + sealedObject: SealedClassWithGetterInterface, +) : TestGetterInterface by sealedObject { + SealedClassWithGetterInterface_FirstObject(com.livefront.sealedenum.compilation.generics.SealedClassWithGetterInterface.FirstObject), +} + +/** + * The isomorphic [SealedClassWithGetterInterfaceEnum] for [this]. + */ +public val SealedClassWithGetterInterface.`enum`: SealedClassWithGetterInterfaceEnum + get() = SealedClassWithGetterInterfaceSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [SealedClassWithGetterInterface] for [this]. + */ +public val SealedClassWithGetterInterfaceEnum.sealedObject: SealedClassWithGetterInterface + get() = SealedClassWithGetterInterfaceSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [SealedClassWithGetterInterface] + */ +public object SealedClassWithGetterInterfaceSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider + { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + SealedClassWithGetterInterface.FirstObject + ) + } + + + public override val enumClass: KClass + get() = SealedClassWithGetterInterfaceEnum::class + + public override fun ordinalOf(obj: SealedClassWithGetterInterface): Int = when (obj) { + is SealedClassWithGetterInterface.FirstObject -> 0 + } + + public override fun nameOf(obj: SealedClassWithGetterInterface): String = when (obj) { + is SealedClassWithGetterInterface.FirstObject -> + "SealedClassWithGetterInterface_FirstObject" + } + + public override fun valueOf(name: String): SealedClassWithGetterInterface = when (name) { + "SealedClassWithGetterInterface_FirstObject" -> SealedClassWithGetterInterface.FirstObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: SealedClassWithGetterInterface): + SealedClassWithGetterInterfaceEnum = when (obj) { + is SealedClassWithGetterInterface.FirstObject -> + SealedClassWithGetterInterfaceEnum.SealedClassWithGetterInterface_FirstObject + } + + public override fun enumToSealedObject(`enum`: SealedClassWithGetterInterfaceEnum): + SealedClassWithGetterInterface = when (enum) { + SealedClassWithGetterInterfaceEnum.SealedClassWithGetterInterface_FirstObject -> + SealedClassWithGetterInterface.FirstObject + } +} + +/** + * The index of [this] in the values list. + */ +public val SealedClassWithGetterInterface.ordinal: Int + get() = SealedClassWithGetterInterfaceSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val SealedClassWithGetterInterface.name: String + get() = SealedClassWithGetterInterfaceSealedEnum.nameOf(this) + +/** + * A list of all [SealedClassWithGetterInterface] objects. + */ +public val SealedClassWithGetterInterface.Companion.values: List + get() = SealedClassWithGetterInterfaceSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [SealedClassWithGetterInterface] + */ +public val SealedClassWithGetterInterface.Companion.sealedEnum: + SealedClassWithGetterInterfaceSealedEnum + get() = SealedClassWithGetterInterfaceSealedEnum + +/** + * Returns the [SealedClassWithGetterInterface] object for the given [name]. + * + * If the given name doesn't correspond to any [SealedClassWithGetterInterface], an + * [IllegalArgumentException] will be thrown. + */ +public fun SealedClassWithGetterInterface.Companion.valueOf(name: String): + SealedClassWithGetterInterface = SealedClassWithGetterInterfaceSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithInterfacesTests.compilation for two object sealed class generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithInterfacesTests.compilation for two object sealed class generates correct code.approved new file mode 100644 index 00000000..0dc39bae --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/generics/SealedEnumWithInterfacesTests.compilation for two object sealed class generates correct code.approved @@ -0,0 +1,132 @@ +package com.livefront.sealedenum.compilation.generics + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [TwoObjectSealedClassWithGenericInterface] + */ +public enum class TwoObjectSealedClassWithGenericInterfaceEnum( + sealedObject: TwoObjectSealedClassWithGenericInterface, +) : TestGenericInterface by sealedObject { + TwoObjectSealedClassWithGenericInterface_FirstObject(com.livefront.sealedenum.compilation.generics.TwoObjectSealedClassWithGenericInterface.FirstObject), + TwoObjectSealedClassWithGenericInterface_SecondObject(com.livefront.sealedenum.compilation.generics.TwoObjectSealedClassWithGenericInterface.SecondObject), +} + +/** + * The isomorphic [TwoObjectSealedClassWithGenericInterfaceEnum] for [this]. + */ +public val TwoObjectSealedClassWithGenericInterface.`enum`: + TwoObjectSealedClassWithGenericInterfaceEnum + get() = TwoObjectSealedClassWithGenericInterfaceSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [TwoObjectSealedClassWithGenericInterface] for [this]. + */ +public val TwoObjectSealedClassWithGenericInterfaceEnum.sealedObject: + TwoObjectSealedClassWithGenericInterface + get() = TwoObjectSealedClassWithGenericInterfaceSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [TwoObjectSealedClassWithGenericInterface] + */ +public object TwoObjectSealedClassWithGenericInterfaceSealedEnum : + SealedEnum>, + SealedEnumWithEnumProvider, TwoObjectSealedClassWithGenericInterfaceEnum>, + EnumForSealedEnumProvider, TwoObjectSealedClassWithGenericInterfaceEnum> + { + public override val values: List> by + lazy(mode = LazyThreadSafetyMode.PUBLICATION) { + listOf( + TwoObjectSealedClassWithGenericInterface.FirstObject, + TwoObjectSealedClassWithGenericInterface.SecondObject + ) + } + + + public override val enumClass: KClass + get() = TwoObjectSealedClassWithGenericInterfaceEnum::class + + public override fun ordinalOf(obj: TwoObjectSealedClassWithGenericInterface): Int + = when (obj) { + is TwoObjectSealedClassWithGenericInterface.FirstObject -> 0 + is TwoObjectSealedClassWithGenericInterface.SecondObject -> 1 + } + + public override fun nameOf(obj: TwoObjectSealedClassWithGenericInterface): String + = when (obj) { + is TwoObjectSealedClassWithGenericInterface.FirstObject -> + "TwoObjectSealedClassWithGenericInterface_FirstObject" + is TwoObjectSealedClassWithGenericInterface.SecondObject -> + "TwoObjectSealedClassWithGenericInterface_SecondObject" + } + + public override fun valueOf(name: String): + TwoObjectSealedClassWithGenericInterface = when (name) { + "TwoObjectSealedClassWithGenericInterface_FirstObject" -> + TwoObjectSealedClassWithGenericInterface.FirstObject + "TwoObjectSealedClassWithGenericInterface_SecondObject" -> + TwoObjectSealedClassWithGenericInterface.SecondObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override + fun sealedObjectToEnum(obj: TwoObjectSealedClassWithGenericInterface): + TwoObjectSealedClassWithGenericInterfaceEnum = when (obj) { + is TwoObjectSealedClassWithGenericInterface.FirstObject -> + TwoObjectSealedClassWithGenericInterfaceEnum.TwoObjectSealedClassWithGenericInterface_FirstObject + is TwoObjectSealedClassWithGenericInterface.SecondObject -> + TwoObjectSealedClassWithGenericInterfaceEnum.TwoObjectSealedClassWithGenericInterface_SecondObject + } + + public override fun enumToSealedObject(`enum`: TwoObjectSealedClassWithGenericInterfaceEnum): + TwoObjectSealedClassWithGenericInterface = when (enum) { + TwoObjectSealedClassWithGenericInterfaceEnum.TwoObjectSealedClassWithGenericInterface_FirstObject -> + TwoObjectSealedClassWithGenericInterface.FirstObject + TwoObjectSealedClassWithGenericInterfaceEnum.TwoObjectSealedClassWithGenericInterface_SecondObject -> + TwoObjectSealedClassWithGenericInterface.SecondObject + } +} + +/** + * The index of [this] in the values list. + */ +public val TwoObjectSealedClassWithGenericInterface.ordinal: Int + get() = TwoObjectSealedClassWithGenericInterfaceSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val TwoObjectSealedClassWithGenericInterface.name: String + get() = TwoObjectSealedClassWithGenericInterfaceSealedEnum.nameOf(this) + +/** + * A list of all [TwoObjectSealedClassWithGenericInterface] objects. + */ +public val TwoObjectSealedClassWithGenericInterface.Companion.values: + List> + get() = TwoObjectSealedClassWithGenericInterfaceSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class + * [TwoObjectSealedClassWithGenericInterface] + */ +public val TwoObjectSealedClassWithGenericInterface.Companion.sealedEnum: + TwoObjectSealedClassWithGenericInterfaceSealedEnum + get() = TwoObjectSealedClassWithGenericInterfaceSealedEnum + +/** + * Returns the [TwoObjectSealedClassWithGenericInterface] object for the given [name]. + * + * If the given name doesn't correspond to any [TwoObjectSealedClassWithGenericInterface], an + * [IllegalArgumentException] will be thrown. + */ +public fun TwoObjectSealedClassWithGenericInterface.Companion.valueOf(name: String): + TwoObjectSealedClassWithGenericInterface = + TwoObjectSealedClassWithGenericInterfaceSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for first hierarchy A generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for first hierarchy A generates correct code.approved new file mode 100644 index 00000000..f8dfb5d3 --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for first hierarchy A generates correct code.approved @@ -0,0 +1,103 @@ +package com.livefront.sealedenum.compilation.hierarchy + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [FirstClassHierarchy.A] + */ +public enum class FirstClassHierarchy_AEnum() { + FirstClassHierarchy_A_B_C, +} + +/** + * The isomorphic [FirstClassHierarchy_AEnum] for [this]. + */ +public val FirstClassHierarchy.A.`enum`: FirstClassHierarchy_AEnum + get() = FirstClassHierarchy_ASealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [FirstClassHierarchy.A] for [this]. + */ +public val FirstClassHierarchy_AEnum.sealedObject: FirstClassHierarchy.A + get() = FirstClassHierarchy_ASealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [FirstClassHierarchy.A] + */ +public object FirstClassHierarchy_ASealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + FirstClassHierarchy.A.B.C + ) + } + + + public override val enumClass: KClass + get() = FirstClassHierarchy_AEnum::class + + public override fun ordinalOf(obj: FirstClassHierarchy.A): Int = when (obj) { + is FirstClassHierarchy.A.B.C -> 0 + } + + public override fun nameOf(obj: FirstClassHierarchy.A): String = when (obj) { + is FirstClassHierarchy.A.B.C -> "FirstClassHierarchy_A_B_C" + } + + public override fun valueOf(name: String): FirstClassHierarchy.A = when (name) { + "FirstClassHierarchy_A_B_C" -> FirstClassHierarchy.A.B.C + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: FirstClassHierarchy.A): FirstClassHierarchy_AEnum = + when (obj) { + is FirstClassHierarchy.A.B.C -> FirstClassHierarchy_AEnum.FirstClassHierarchy_A_B_C + } + + public override fun enumToSealedObject(`enum`: FirstClassHierarchy_AEnum): FirstClassHierarchy.A + = when (enum) { + FirstClassHierarchy_AEnum.FirstClassHierarchy_A_B_C -> FirstClassHierarchy.A.B.C + } +} + +/** + * The index of [this] in the values list. + */ +public val FirstClassHierarchy.A.ordinal: Int + get() = FirstClassHierarchy_ASealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val FirstClassHierarchy.A.name: String + get() = FirstClassHierarchy_ASealedEnum.nameOf(this) + +/** + * A list of all [FirstClassHierarchy.A] objects. + */ +public val FirstClassHierarchy.A.Companion.values: List + get() = FirstClassHierarchy_ASealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [FirstClassHierarchy.A] + */ +public val FirstClassHierarchy.A.Companion.sealedEnum: FirstClassHierarchy_ASealedEnum + get() = FirstClassHierarchy_ASealedEnum + +/** + * Returns the [FirstClassHierarchy.A] object for the given [name]. + * + * If the given name doesn't correspond to any [FirstClassHierarchy.A], an + * [IllegalArgumentException] will be thrown. + */ +public fun FirstClassHierarchy.A.Companion.valueOf(name: String): FirstClassHierarchy.A = + FirstClassHierarchy_ASealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for first hierarchy B generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for first hierarchy B generates correct code.approved new file mode 100644 index 00000000..9bfd16fe --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for first hierarchy B generates correct code.approved @@ -0,0 +1,103 @@ +package com.livefront.sealedenum.compilation.hierarchy + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [FirstClassHierarchy.A.B] + */ +public enum class FirstClassHierarchy_A_BEnum() { + FirstClassHierarchy_A_B_C, +} + +/** + * The isomorphic [FirstClassHierarchy_A_BEnum] for [this]. + */ +public val FirstClassHierarchy.A.B.`enum`: FirstClassHierarchy_A_BEnum + get() = FirstClassHierarchy_A_BSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [FirstClassHierarchy.A.B] for [this]. + */ +public val FirstClassHierarchy_A_BEnum.sealedObject: FirstClassHierarchy.A.B + get() = FirstClassHierarchy_A_BSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [FirstClassHierarchy.A.B] + */ +public object FirstClassHierarchy_A_BSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + FirstClassHierarchy.A.B.C + ) + } + + + public override val enumClass: KClass + get() = FirstClassHierarchy_A_BEnum::class + + public override fun ordinalOf(obj: FirstClassHierarchy.A.B): Int = when (obj) { + is FirstClassHierarchy.A.B.C -> 0 + } + + public override fun nameOf(obj: FirstClassHierarchy.A.B): String = when (obj) { + is FirstClassHierarchy.A.B.C -> "FirstClassHierarchy_A_B_C" + } + + public override fun valueOf(name: String): FirstClassHierarchy.A.B = when (name) { + "FirstClassHierarchy_A_B_C" -> FirstClassHierarchy.A.B.C + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: FirstClassHierarchy.A.B): + FirstClassHierarchy_A_BEnum = when (obj) { + is FirstClassHierarchy.A.B.C -> FirstClassHierarchy_A_BEnum.FirstClassHierarchy_A_B_C + } + + public override fun enumToSealedObject(`enum`: FirstClassHierarchy_A_BEnum): + FirstClassHierarchy.A.B = when (enum) { + FirstClassHierarchy_A_BEnum.FirstClassHierarchy_A_B_C -> FirstClassHierarchy.A.B.C + } +} + +/** + * The index of [this] in the values list. + */ +public val FirstClassHierarchy.A.B.ordinal: Int + get() = FirstClassHierarchy_A_BSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val FirstClassHierarchy.A.B.name: String + get() = FirstClassHierarchy_A_BSealedEnum.nameOf(this) + +/** + * A list of all [FirstClassHierarchy.A.B] objects. + */ +public val FirstClassHierarchy.A.B.Companion.values: List + get() = FirstClassHierarchy_A_BSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [FirstClassHierarchy.A.B] + */ +public val FirstClassHierarchy.A.B.Companion.sealedEnum: FirstClassHierarchy_A_BSealedEnum + get() = FirstClassHierarchy_A_BSealedEnum + +/** + * Returns the [FirstClassHierarchy.A.B] object for the given [name]. + * + * If the given name doesn't correspond to any [FirstClassHierarchy.A.B], an + * [IllegalArgumentException] will be thrown. + */ +public fun FirstClassHierarchy.A.B.Companion.valueOf(name: String): FirstClassHierarchy.A.B = + FirstClassHierarchy_A_BSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for second hierarchy Q generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for second hierarchy Q generates correct code.approved new file mode 100644 index 00000000..1dcd3819 --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for second hierarchy Q generates correct code.approved @@ -0,0 +1,66 @@ +package com.livefront.sealedenum.compilation.hierarchy + +import com.livefront.sealedenum.SealedEnum +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List + +/** + * An implementation of [SealedEnum] for the sealed class [SecondClassHierarchy.Z.Q] + */ +public object SecondClassHierarchy_Z_QSealedEnum : SealedEnum { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + SecondClassHierarchy.Z.Q.P + ) + } + + + public override fun ordinalOf(obj: SecondClassHierarchy.Z.Q): Int = when (obj) { + is SecondClassHierarchy.Z.Q.P -> 0 + } + + public override fun nameOf(obj: SecondClassHierarchy.Z.Q): String = when (obj) { + is SecondClassHierarchy.Z.Q.P -> "SecondClassHierarchy_Z_Q_P" + } + + public override fun valueOf(name: String): SecondClassHierarchy.Z.Q = when (name) { + "SecondClassHierarchy_Z_Q_P" -> SecondClassHierarchy.Z.Q.P + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } +} + +/** + * The index of [this] in the values list. + */ +public val SecondClassHierarchy.Z.Q.ordinal: Int + get() = SecondClassHierarchy_Z_QSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val SecondClassHierarchy.Z.Q.name: String + get() = SecondClassHierarchy_Z_QSealedEnum.nameOf(this) + +/** + * A list of all [SecondClassHierarchy.Z.Q] objects. + */ +public val SecondClassHierarchy.Z.Q.Companion.values: List + get() = SecondClassHierarchy_Z_QSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [SecondClassHierarchy.Z.Q] + */ +public val SecondClassHierarchy.Z.Q.Companion.sealedEnum: SecondClassHierarchy_Z_QSealedEnum + get() = SecondClassHierarchy_Z_QSealedEnum + +/** + * Returns the [SecondClassHierarchy.Z.Q] object for the given [name]. + * + * If the given name doesn't correspond to any [SecondClassHierarchy.Z.Q], an + * [IllegalArgumentException] will be thrown. + */ +public fun SecondClassHierarchy.Z.Q.Companion.valueOf(name: String): SecondClassHierarchy.Z.Q = + SecondClassHierarchy_Z_QSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for second hierarchy S generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for second hierarchy S generates correct code.approved new file mode 100644 index 00000000..5a74be38 --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for second hierarchy S generates correct code.approved @@ -0,0 +1,66 @@ +package com.livefront.sealedenum.compilation.hierarchy + +import com.livefront.sealedenum.SealedEnum +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List + +/** + * An implementation of [SealedEnum] for the sealed class [SecondClassHierarchy.Z.X.S] + */ +public object SecondClassHierarchy_Z_X_SSealedEnum : SealedEnum { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + SecondClassHierarchy.Z.X.S.R + ) + } + + + public override fun ordinalOf(obj: SecondClassHierarchy.Z.X.S): Int = when (obj) { + is SecondClassHierarchy.Z.X.S.R -> 0 + } + + public override fun nameOf(obj: SecondClassHierarchy.Z.X.S): String = when (obj) { + is SecondClassHierarchy.Z.X.S.R -> "SecondClassHierarchy_Z_X_S_R" + } + + public override fun valueOf(name: String): SecondClassHierarchy.Z.X.S = when (name) { + "SecondClassHierarchy_Z_X_S_R" -> SecondClassHierarchy.Z.X.S.R + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } +} + +/** + * The index of [this] in the values list. + */ +public val SecondClassHierarchy.Z.X.S.ordinal: Int + get() = SecondClassHierarchy_Z_X_SSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val SecondClassHierarchy.Z.X.S.name: String + get() = SecondClassHierarchy_Z_X_SSealedEnum.nameOf(this) + +/** + * A list of all [SecondClassHierarchy.Z.X.S] objects. + */ +public val SecondClassHierarchy.Z.X.S.Companion.values: List + get() = SecondClassHierarchy_Z_X_SSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [SecondClassHierarchy.Z.X.S] + */ +public val SecondClassHierarchy.Z.X.S.Companion.sealedEnum: SecondClassHierarchy_Z_X_SSealedEnum + get() = SecondClassHierarchy_Z_X_SSealedEnum + +/** + * Returns the [SecondClassHierarchy.Z.X.S] object for the given [name]. + * + * If the given name doesn't correspond to any [SecondClassHierarchy.Z.X.S], an + * [IllegalArgumentException] will be thrown. + */ +public fun SecondClassHierarchy.Z.X.S.Companion.valueOf(name: String): SecondClassHierarchy.Z.X.S = + SecondClassHierarchy_Z_X_SSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for second hierarchy U generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for second hierarchy U generates correct code.approved new file mode 100644 index 00000000..166e0908 --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for second hierarchy U generates correct code.approved @@ -0,0 +1,66 @@ +package com.livefront.sealedenum.compilation.hierarchy + +import com.livefront.sealedenum.SealedEnum +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List + +/** + * An implementation of [SealedEnum] for the sealed class [SecondClassHierarchy.Z.X.U] + */ +public object SecondClassHierarchy_Z_X_USealedEnum : SealedEnum { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + SecondClassHierarchy.Z.X.U.T + ) + } + + + public override fun ordinalOf(obj: SecondClassHierarchy.Z.X.U): Int = when (obj) { + is SecondClassHierarchy.Z.X.U.T -> 0 + } + + public override fun nameOf(obj: SecondClassHierarchy.Z.X.U): String = when (obj) { + is SecondClassHierarchy.Z.X.U.T -> "SecondClassHierarchy_Z_X_U_T" + } + + public override fun valueOf(name: String): SecondClassHierarchy.Z.X.U = when (name) { + "SecondClassHierarchy_Z_X_U_T" -> SecondClassHierarchy.Z.X.U.T + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } +} + +/** + * The index of [this] in the values list. + */ +public val SecondClassHierarchy.Z.X.U.ordinal: Int + get() = SecondClassHierarchy_Z_X_USealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val SecondClassHierarchy.Z.X.U.name: String + get() = SecondClassHierarchy_Z_X_USealedEnum.nameOf(this) + +/** + * A list of all [SecondClassHierarchy.Z.X.U] objects. + */ +public val SecondClassHierarchy.Z.X.U.Companion.values: List + get() = SecondClassHierarchy_Z_X_USealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [SecondClassHierarchy.Z.X.U] + */ +public val SecondClassHierarchy.Z.X.U.Companion.sealedEnum: SecondClassHierarchy_Z_X_USealedEnum + get() = SecondClassHierarchy_Z_X_USealedEnum + +/** + * Returns the [SecondClassHierarchy.Z.X.U] object for the given [name]. + * + * If the given name doesn't correspond to any [SecondClassHierarchy.Z.X.U], an + * [IllegalArgumentException] will be thrown. + */ +public fun SecondClassHierarchy.Z.X.U.Companion.valueOf(name: String): SecondClassHierarchy.Z.X.U = + SecondClassHierarchy_Z_X_USealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for second hierarchy X generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for second hierarchy X generates correct code.approved new file mode 100644 index 00000000..a5204887 --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for second hierarchy X generates correct code.approved @@ -0,0 +1,78 @@ +package com.livefront.sealedenum.compilation.hierarchy + +import com.livefront.sealedenum.SealedEnum +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List + +/** + * An implementation of [SealedEnum] for the sealed class [SecondClassHierarchy.Z.X] + */ +public object SecondClassHierarchy_Z_XSealedEnum : SealedEnum { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + SecondClassHierarchy.Z.X.W, + SecondClassHierarchy.Z.X.V, + SecondClassHierarchy.Z.X.U.T, + SecondClassHierarchy.Z.X.S.R + ) + } + + + public override fun ordinalOf(obj: SecondClassHierarchy.Z.X): Int = when (obj) { + is SecondClassHierarchy.Z.X.W -> 0 + is SecondClassHierarchy.Z.X.V -> 1 + is SecondClassHierarchy.Z.X.U.T -> 2 + is SecondClassHierarchy.Z.X.S.R -> 3 + } + + public override fun nameOf(obj: SecondClassHierarchy.Z.X): String = when (obj) { + is SecondClassHierarchy.Z.X.W -> "SecondClassHierarchy_Z_X_W" + is SecondClassHierarchy.Z.X.V -> "SecondClassHierarchy_Z_X_V" + is SecondClassHierarchy.Z.X.U.T -> "SecondClassHierarchy_Z_X_U_T" + is SecondClassHierarchy.Z.X.S.R -> "SecondClassHierarchy_Z_X_S_R" + } + + public override fun valueOf(name: String): SecondClassHierarchy.Z.X = when (name) { + "SecondClassHierarchy_Z_X_W" -> SecondClassHierarchy.Z.X.W + "SecondClassHierarchy_Z_X_V" -> SecondClassHierarchy.Z.X.V + "SecondClassHierarchy_Z_X_U_T" -> SecondClassHierarchy.Z.X.U.T + "SecondClassHierarchy_Z_X_S_R" -> SecondClassHierarchy.Z.X.S.R + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } +} + +/** + * The index of [this] in the values list. + */ +public val SecondClassHierarchy.Z.X.ordinal: Int + get() = SecondClassHierarchy_Z_XSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val SecondClassHierarchy.Z.X.name: String + get() = SecondClassHierarchy_Z_XSealedEnum.nameOf(this) + +/** + * A list of all [SecondClassHierarchy.Z.X] objects. + */ +public val SecondClassHierarchy.Z.X.Companion.values: List + get() = SecondClassHierarchy_Z_XSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [SecondClassHierarchy.Z.X] + */ +public val SecondClassHierarchy.Z.X.Companion.sealedEnum: SecondClassHierarchy_Z_XSealedEnum + get() = SecondClassHierarchy_Z_XSealedEnum + +/** + * Returns the [SecondClassHierarchy.Z.X] object for the given [name]. + * + * If the given name doesn't correspond to any [SecondClassHierarchy.Z.X], an + * [IllegalArgumentException] will be thrown. + */ +public fun SecondClassHierarchy.Z.X.Companion.valueOf(name: String): SecondClassHierarchy.Z.X = + SecondClassHierarchy_Z_XSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for second hierarchy Z generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for second hierarchy Z generates correct code.approved new file mode 100644 index 00000000..7a677833 --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedClassHierarchyTests.compilation for second hierarchy Z generates correct code.approved @@ -0,0 +1,90 @@ +package com.livefront.sealedenum.compilation.hierarchy + +import com.livefront.sealedenum.SealedEnum +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List + +/** + * An implementation of [SealedEnum] for the sealed class [SecondClassHierarchy.Z] + */ +public object SecondClassHierarchy_ZSealedEnum : SealedEnum { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + SecondClassHierarchy.Z.Y, + SecondClassHierarchy.Z.X.W, + SecondClassHierarchy.Z.X.V, + SecondClassHierarchy.Z.X.U.T, + SecondClassHierarchy.Z.X.S.R, + SecondClassHierarchy.Z.Q.P, + SecondClassHierarchy.Z.O + ) + } + + + public override fun ordinalOf(obj: SecondClassHierarchy.Z): Int = when (obj) { + is SecondClassHierarchy.Z.Y -> 0 + is SecondClassHierarchy.Z.X.W -> 1 + is SecondClassHierarchy.Z.X.V -> 2 + is SecondClassHierarchy.Z.X.U.T -> 3 + is SecondClassHierarchy.Z.X.S.R -> 4 + is SecondClassHierarchy.Z.Q.P -> 5 + is SecondClassHierarchy.Z.O -> 6 + } + + public override fun nameOf(obj: SecondClassHierarchy.Z): String = when (obj) { + is SecondClassHierarchy.Z.Y -> "SecondClassHierarchy_Z_Y" + is SecondClassHierarchy.Z.X.W -> "SecondClassHierarchy_Z_X_W" + is SecondClassHierarchy.Z.X.V -> "SecondClassHierarchy_Z_X_V" + is SecondClassHierarchy.Z.X.U.T -> "SecondClassHierarchy_Z_X_U_T" + is SecondClassHierarchy.Z.X.S.R -> "SecondClassHierarchy_Z_X_S_R" + is SecondClassHierarchy.Z.Q.P -> "SecondClassHierarchy_Z_Q_P" + is SecondClassHierarchy.Z.O -> "SecondClassHierarchy_Z_O" + } + + public override fun valueOf(name: String): SecondClassHierarchy.Z = when (name) { + "SecondClassHierarchy_Z_Y" -> SecondClassHierarchy.Z.Y + "SecondClassHierarchy_Z_X_W" -> SecondClassHierarchy.Z.X.W + "SecondClassHierarchy_Z_X_V" -> SecondClassHierarchy.Z.X.V + "SecondClassHierarchy_Z_X_U_T" -> SecondClassHierarchy.Z.X.U.T + "SecondClassHierarchy_Z_X_S_R" -> SecondClassHierarchy.Z.X.S.R + "SecondClassHierarchy_Z_Q_P" -> SecondClassHierarchy.Z.Q.P + "SecondClassHierarchy_Z_O" -> SecondClassHierarchy.Z.O + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } +} + +/** + * The index of [this] in the values list. + */ +public val SecondClassHierarchy.Z.ordinal: Int + get() = SecondClassHierarchy_ZSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val SecondClassHierarchy.Z.name: String + get() = SecondClassHierarchy_ZSealedEnum.nameOf(this) + +/** + * A list of all [SecondClassHierarchy.Z] objects. + */ +public val SecondClassHierarchy.Z.Companion.values: List + get() = SecondClassHierarchy_ZSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [SecondClassHierarchy.Z] + */ +public val SecondClassHierarchy.Z.Companion.sealedEnum: SecondClassHierarchy_ZSealedEnum + get() = SecondClassHierarchy_ZSealedEnum + +/** + * Returns the [SecondClassHierarchy.Z] object for the given [name]. + * + * If the given name doesn't correspond to any [SecondClassHierarchy.Z], an + * [IllegalArgumentException] will be thrown. + */ +public fun SecondClassHierarchy.Z.Companion.valueOf(name: String): SecondClassHierarchy.Z = + SecondClassHierarchy_ZSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for first hierarchy A generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for first hierarchy A generates correct code.approved new file mode 100644 index 00000000..75881e36 --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for first hierarchy A generates correct code.approved @@ -0,0 +1,104 @@ +package com.livefront.sealedenum.compilation.hierarchy + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [FirstInterfaceHierarchy.A] + */ +public enum class FirstInterfaceHierarchy_AEnum() { + FirstInterfaceHierarchy_A_B_C, +} + +/** + * The isomorphic [FirstInterfaceHierarchy_AEnum] for [this]. + */ +public val FirstInterfaceHierarchy.A.`enum`: FirstInterfaceHierarchy_AEnum + get() = FirstInterfaceHierarchy_ASealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [FirstInterfaceHierarchy.A] for [this]. + */ +public val FirstInterfaceHierarchy_AEnum.sealedObject: FirstInterfaceHierarchy.A + get() = FirstInterfaceHierarchy_ASealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [FirstInterfaceHierarchy.A] + */ +public object FirstInterfaceHierarchy_ASealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + FirstInterfaceHierarchy.A.B.C + ) + } + + + public override val enumClass: KClass + get() = FirstInterfaceHierarchy_AEnum::class + + public override fun ordinalOf(obj: FirstInterfaceHierarchy.A): Int = when (obj) { + is FirstInterfaceHierarchy.A.B.C -> 0 + } + + public override fun nameOf(obj: FirstInterfaceHierarchy.A): String = when (obj) { + is FirstInterfaceHierarchy.A.B.C -> "FirstInterfaceHierarchy_A_B_C" + } + + public override fun valueOf(name: String): FirstInterfaceHierarchy.A = when (name) { + "FirstInterfaceHierarchy_A_B_C" -> FirstInterfaceHierarchy.A.B.C + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: FirstInterfaceHierarchy.A): + FirstInterfaceHierarchy_AEnum = when (obj) { + is FirstInterfaceHierarchy.A.B.C -> + FirstInterfaceHierarchy_AEnum.FirstInterfaceHierarchy_A_B_C + } + + public override fun enumToSealedObject(`enum`: FirstInterfaceHierarchy_AEnum): + FirstInterfaceHierarchy.A = when (enum) { + FirstInterfaceHierarchy_AEnum.FirstInterfaceHierarchy_A_B_C -> FirstInterfaceHierarchy.A.B.C + } +} + +/** + * The index of [this] in the values list. + */ +public val FirstInterfaceHierarchy.A.ordinal: Int + get() = FirstInterfaceHierarchy_ASealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val FirstInterfaceHierarchy.A.name: String + get() = FirstInterfaceHierarchy_ASealedEnum.nameOf(this) + +/** + * A list of all [FirstInterfaceHierarchy.A] objects. + */ +public val FirstInterfaceHierarchy.A.Companion.values: List + get() = FirstInterfaceHierarchy_ASealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [FirstInterfaceHierarchy.A] + */ +public val FirstInterfaceHierarchy.A.Companion.sealedEnum: FirstInterfaceHierarchy_ASealedEnum + get() = FirstInterfaceHierarchy_ASealedEnum + +/** + * Returns the [FirstInterfaceHierarchy.A] object for the given [name]. + * + * If the given name doesn't correspond to any [FirstInterfaceHierarchy.A], an + * [IllegalArgumentException] will be thrown. + */ +public fun FirstInterfaceHierarchy.A.Companion.valueOf(name: String): FirstInterfaceHierarchy.A = + FirstInterfaceHierarchy_ASealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for first hierarchy B generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for first hierarchy B generates correct code.approved new file mode 100644 index 00000000..0f7c181a --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for first hierarchy B generates correct code.approved @@ -0,0 +1,105 @@ +package com.livefront.sealedenum.compilation.hierarchy + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [FirstInterfaceHierarchy.A.B] + */ +public enum class FirstInterfaceHierarchy_A_BEnum() { + FirstInterfaceHierarchy_A_B_C, +} + +/** + * The isomorphic [FirstInterfaceHierarchy_A_BEnum] for [this]. + */ +public val FirstInterfaceHierarchy.A.B.`enum`: FirstInterfaceHierarchy_A_BEnum + get() = FirstInterfaceHierarchy_A_BSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [FirstInterfaceHierarchy.A.B] for [this]. + */ +public val FirstInterfaceHierarchy_A_BEnum.sealedObject: FirstInterfaceHierarchy.A.B + get() = FirstInterfaceHierarchy_A_BSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [FirstInterfaceHierarchy.A.B] + */ +public object FirstInterfaceHierarchy_A_BSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + FirstInterfaceHierarchy.A.B.C + ) + } + + + public override val enumClass: KClass + get() = FirstInterfaceHierarchy_A_BEnum::class + + public override fun ordinalOf(obj: FirstInterfaceHierarchy.A.B): Int = when (obj) { + is FirstInterfaceHierarchy.A.B.C -> 0 + } + + public override fun nameOf(obj: FirstInterfaceHierarchy.A.B): String = when (obj) { + is FirstInterfaceHierarchy.A.B.C -> "FirstInterfaceHierarchy_A_B_C" + } + + public override fun valueOf(name: String): FirstInterfaceHierarchy.A.B = when (name) { + "FirstInterfaceHierarchy_A_B_C" -> FirstInterfaceHierarchy.A.B.C + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: FirstInterfaceHierarchy.A.B): + FirstInterfaceHierarchy_A_BEnum = when (obj) { + is FirstInterfaceHierarchy.A.B.C -> + FirstInterfaceHierarchy_A_BEnum.FirstInterfaceHierarchy_A_B_C + } + + public override fun enumToSealedObject(`enum`: FirstInterfaceHierarchy_A_BEnum): + FirstInterfaceHierarchy.A.B = when (enum) { + FirstInterfaceHierarchy_A_BEnum.FirstInterfaceHierarchy_A_B_C -> + FirstInterfaceHierarchy.A.B.C + } +} + +/** + * The index of [this] in the values list. + */ +public val FirstInterfaceHierarchy.A.B.ordinal: Int + get() = FirstInterfaceHierarchy_A_BSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val FirstInterfaceHierarchy.A.B.name: String + get() = FirstInterfaceHierarchy_A_BSealedEnum.nameOf(this) + +/** + * A list of all [FirstInterfaceHierarchy.A.B] objects. + */ +public val FirstInterfaceHierarchy.A.B.Companion.values: List + get() = FirstInterfaceHierarchy_A_BSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [FirstInterfaceHierarchy.A.B] + */ +public val FirstInterfaceHierarchy.A.B.Companion.sealedEnum: FirstInterfaceHierarchy_A_BSealedEnum + get() = FirstInterfaceHierarchy_A_BSealedEnum + +/** + * Returns the [FirstInterfaceHierarchy.A.B] object for the given [name]. + * + * If the given name doesn't correspond to any [FirstInterfaceHierarchy.A.B], an + * [IllegalArgumentException] will be thrown. + */ +public fun FirstInterfaceHierarchy.A.B.Companion.valueOf(name: String): FirstInterfaceHierarchy.A.B + = FirstInterfaceHierarchy_A_BSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for second hierarchy A generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for second hierarchy A generates correct code.approved new file mode 100644 index 00000000..9037a0a0 --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for second hierarchy A generates correct code.approved @@ -0,0 +1,90 @@ +package com.livefront.sealedenum.compilation.hierarchy + +import com.livefront.sealedenum.SealedEnum +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List + +/** + * An implementation of [SealedEnum] for the sealed class [SecondInterfaceHierarchy.A] + */ +public object SecondInterfaceHierarchy_ASealedEnum : SealedEnum { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + SecondInterfaceHierarchy.A.B, + SecondInterfaceHierarchy.A.C.D, + SecondInterfaceHierarchy.A.C.E, + SecondInterfaceHierarchy.A.C.F.G, + SecondInterfaceHierarchy.A.C.H.I, + SecondInterfaceHierarchy.A.J.K, + SecondInterfaceHierarchy.A.L + ) + } + + + public override fun ordinalOf(obj: SecondInterfaceHierarchy.A): Int = when (obj) { + is SecondInterfaceHierarchy.A.B -> 0 + is SecondInterfaceHierarchy.A.C.D -> 1 + is SecondInterfaceHierarchy.A.C.E -> 2 + is SecondInterfaceHierarchy.A.C.F.G -> 3 + is SecondInterfaceHierarchy.A.C.H.I -> 4 + is SecondInterfaceHierarchy.A.J.K -> 5 + is SecondInterfaceHierarchy.A.L -> 6 + } + + public override fun nameOf(obj: SecondInterfaceHierarchy.A): String = when (obj) { + is SecondInterfaceHierarchy.A.B -> "SecondInterfaceHierarchy_A_B" + is SecondInterfaceHierarchy.A.C.D -> "SecondInterfaceHierarchy_A_C_D" + is SecondInterfaceHierarchy.A.C.E -> "SecondInterfaceHierarchy_A_C_E" + is SecondInterfaceHierarchy.A.C.F.G -> "SecondInterfaceHierarchy_A_C_F_G" + is SecondInterfaceHierarchy.A.C.H.I -> "SecondInterfaceHierarchy_A_C_H_I" + is SecondInterfaceHierarchy.A.J.K -> "SecondInterfaceHierarchy_A_J_K" + is SecondInterfaceHierarchy.A.L -> "SecondInterfaceHierarchy_A_L" + } + + public override fun valueOf(name: String): SecondInterfaceHierarchy.A = when (name) { + "SecondInterfaceHierarchy_A_B" -> SecondInterfaceHierarchy.A.B + "SecondInterfaceHierarchy_A_C_D" -> SecondInterfaceHierarchy.A.C.D + "SecondInterfaceHierarchy_A_C_E" -> SecondInterfaceHierarchy.A.C.E + "SecondInterfaceHierarchy_A_C_F_G" -> SecondInterfaceHierarchy.A.C.F.G + "SecondInterfaceHierarchy_A_C_H_I" -> SecondInterfaceHierarchy.A.C.H.I + "SecondInterfaceHierarchy_A_J_K" -> SecondInterfaceHierarchy.A.J.K + "SecondInterfaceHierarchy_A_L" -> SecondInterfaceHierarchy.A.L + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } +} + +/** + * The index of [this] in the values list. + */ +public val SecondInterfaceHierarchy.A.ordinal: Int + get() = SecondInterfaceHierarchy_ASealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val SecondInterfaceHierarchy.A.name: String + get() = SecondInterfaceHierarchy_ASealedEnum.nameOf(this) + +/** + * A list of all [SecondInterfaceHierarchy.A] objects. + */ +public val SecondInterfaceHierarchy.A.Companion.values: List + get() = SecondInterfaceHierarchy_ASealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [SecondInterfaceHierarchy.A] + */ +public val SecondInterfaceHierarchy.A.Companion.sealedEnum: SecondInterfaceHierarchy_ASealedEnum + get() = SecondInterfaceHierarchy_ASealedEnum + +/** + * Returns the [SecondInterfaceHierarchy.A] object for the given [name]. + * + * If the given name doesn't correspond to any [SecondInterfaceHierarchy.A], an + * [IllegalArgumentException] will be thrown. + */ +public fun SecondInterfaceHierarchy.A.Companion.valueOf(name: String): SecondInterfaceHierarchy.A = + SecondInterfaceHierarchy_ASealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for second hierarchy C generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for second hierarchy C generates correct code.approved new file mode 100644 index 00000000..7f06c9bf --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for second hierarchy C generates correct code.approved @@ -0,0 +1,78 @@ +package com.livefront.sealedenum.compilation.hierarchy + +import com.livefront.sealedenum.SealedEnum +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List + +/** + * An implementation of [SealedEnum] for the sealed class [SecondInterfaceHierarchy.A.C] + */ +public object SecondInterfaceHierarchy_A_CSealedEnum : SealedEnum { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + SecondInterfaceHierarchy.A.C.D, + SecondInterfaceHierarchy.A.C.E, + SecondInterfaceHierarchy.A.C.F.G, + SecondInterfaceHierarchy.A.C.H.I + ) + } + + + public override fun ordinalOf(obj: SecondInterfaceHierarchy.A.C): Int = when (obj) { + is SecondInterfaceHierarchy.A.C.D -> 0 + is SecondInterfaceHierarchy.A.C.E -> 1 + is SecondInterfaceHierarchy.A.C.F.G -> 2 + is SecondInterfaceHierarchy.A.C.H.I -> 3 + } + + public override fun nameOf(obj: SecondInterfaceHierarchy.A.C): String = when (obj) { + is SecondInterfaceHierarchy.A.C.D -> "SecondInterfaceHierarchy_A_C_D" + is SecondInterfaceHierarchy.A.C.E -> "SecondInterfaceHierarchy_A_C_E" + is SecondInterfaceHierarchy.A.C.F.G -> "SecondInterfaceHierarchy_A_C_F_G" + is SecondInterfaceHierarchy.A.C.H.I -> "SecondInterfaceHierarchy_A_C_H_I" + } + + public override fun valueOf(name: String): SecondInterfaceHierarchy.A.C = when (name) { + "SecondInterfaceHierarchy_A_C_D" -> SecondInterfaceHierarchy.A.C.D + "SecondInterfaceHierarchy_A_C_E" -> SecondInterfaceHierarchy.A.C.E + "SecondInterfaceHierarchy_A_C_F_G" -> SecondInterfaceHierarchy.A.C.F.G + "SecondInterfaceHierarchy_A_C_H_I" -> SecondInterfaceHierarchy.A.C.H.I + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } +} + +/** + * The index of [this] in the values list. + */ +public val SecondInterfaceHierarchy.A.C.ordinal: Int + get() = SecondInterfaceHierarchy_A_CSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val SecondInterfaceHierarchy.A.C.name: String + get() = SecondInterfaceHierarchy_A_CSealedEnum.nameOf(this) + +/** + * A list of all [SecondInterfaceHierarchy.A.C] objects. + */ +public val SecondInterfaceHierarchy.A.C.Companion.values: List + get() = SecondInterfaceHierarchy_A_CSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [SecondInterfaceHierarchy.A.C] + */ +public val SecondInterfaceHierarchy.A.C.Companion.sealedEnum: SecondInterfaceHierarchy_A_CSealedEnum + get() = SecondInterfaceHierarchy_A_CSealedEnum + +/** + * Returns the [SecondInterfaceHierarchy.A.C] object for the given [name]. + * + * If the given name doesn't correspond to any [SecondInterfaceHierarchy.A.C], an + * [IllegalArgumentException] will be thrown. + */ +public fun SecondInterfaceHierarchy.A.C.Companion.valueOf(name: String): + SecondInterfaceHierarchy.A.C = SecondInterfaceHierarchy_A_CSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for second hierarchy F generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for second hierarchy F generates correct code.approved new file mode 100644 index 00000000..c5ba52b6 --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for second hierarchy F generates correct code.approved @@ -0,0 +1,68 @@ +package com.livefront.sealedenum.compilation.hierarchy + +import com.livefront.sealedenum.SealedEnum +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List + +/** + * An implementation of [SealedEnum] for the sealed class [SecondInterfaceHierarchy.A.C.F] + */ +public object SecondInterfaceHierarchy_A_C_FSealedEnum : SealedEnum + { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + SecondInterfaceHierarchy.A.C.F.G + ) + } + + + public override fun ordinalOf(obj: SecondInterfaceHierarchy.A.C.F): Int = when (obj) { + is SecondInterfaceHierarchy.A.C.F.G -> 0 + } + + public override fun nameOf(obj: SecondInterfaceHierarchy.A.C.F): String = when (obj) { + is SecondInterfaceHierarchy.A.C.F.G -> "SecondInterfaceHierarchy_A_C_F_G" + } + + public override fun valueOf(name: String): SecondInterfaceHierarchy.A.C.F = when (name) { + "SecondInterfaceHierarchy_A_C_F_G" -> SecondInterfaceHierarchy.A.C.F.G + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } +} + +/** + * The index of [this] in the values list. + */ +public val SecondInterfaceHierarchy.A.C.F.ordinal: Int + get() = SecondInterfaceHierarchy_A_C_FSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val SecondInterfaceHierarchy.A.C.F.name: String + get() = SecondInterfaceHierarchy_A_C_FSealedEnum.nameOf(this) + +/** + * A list of all [SecondInterfaceHierarchy.A.C.F] objects. + */ +public val SecondInterfaceHierarchy.A.C.F.Companion.values: List + get() = SecondInterfaceHierarchy_A_C_FSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [SecondInterfaceHierarchy.A.C.F] + */ +public val SecondInterfaceHierarchy.A.C.F.Companion.sealedEnum: + SecondInterfaceHierarchy_A_C_FSealedEnum + get() = SecondInterfaceHierarchy_A_C_FSealedEnum + +/** + * Returns the [SecondInterfaceHierarchy.A.C.F] object for the given [name]. + * + * If the given name doesn't correspond to any [SecondInterfaceHierarchy.A.C.F], an + * [IllegalArgumentException] will be thrown. + */ +public fun SecondInterfaceHierarchy.A.C.F.Companion.valueOf(name: String): + SecondInterfaceHierarchy.A.C.F = SecondInterfaceHierarchy_A_C_FSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for second hierarchy H generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for second hierarchy H generates correct code.approved new file mode 100644 index 00000000..20d4f6d6 --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for second hierarchy H generates correct code.approved @@ -0,0 +1,68 @@ +package com.livefront.sealedenum.compilation.hierarchy + +import com.livefront.sealedenum.SealedEnum +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List + +/** + * An implementation of [SealedEnum] for the sealed class [SecondInterfaceHierarchy.A.C.H] + */ +public object SecondInterfaceHierarchy_A_C_HSealedEnum : SealedEnum + { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + SecondInterfaceHierarchy.A.C.H.I + ) + } + + + public override fun ordinalOf(obj: SecondInterfaceHierarchy.A.C.H): Int = when (obj) { + is SecondInterfaceHierarchy.A.C.H.I -> 0 + } + + public override fun nameOf(obj: SecondInterfaceHierarchy.A.C.H): String = when (obj) { + is SecondInterfaceHierarchy.A.C.H.I -> "SecondInterfaceHierarchy_A_C_H_I" + } + + public override fun valueOf(name: String): SecondInterfaceHierarchy.A.C.H = when (name) { + "SecondInterfaceHierarchy_A_C_H_I" -> SecondInterfaceHierarchy.A.C.H.I + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } +} + +/** + * The index of [this] in the values list. + */ +public val SecondInterfaceHierarchy.A.C.H.ordinal: Int + get() = SecondInterfaceHierarchy_A_C_HSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val SecondInterfaceHierarchy.A.C.H.name: String + get() = SecondInterfaceHierarchy_A_C_HSealedEnum.nameOf(this) + +/** + * A list of all [SecondInterfaceHierarchy.A.C.H] objects. + */ +public val SecondInterfaceHierarchy.A.C.H.Companion.values: List + get() = SecondInterfaceHierarchy_A_C_HSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [SecondInterfaceHierarchy.A.C.H] + */ +public val SecondInterfaceHierarchy.A.C.H.Companion.sealedEnum: + SecondInterfaceHierarchy_A_C_HSealedEnum + get() = SecondInterfaceHierarchy_A_C_HSealedEnum + +/** + * Returns the [SecondInterfaceHierarchy.A.C.H] object for the given [name]. + * + * If the given name doesn't correspond to any [SecondInterfaceHierarchy.A.C.H], an + * [IllegalArgumentException] will be thrown. + */ +public fun SecondInterfaceHierarchy.A.C.H.Companion.valueOf(name: String): + SecondInterfaceHierarchy.A.C.H = SecondInterfaceHierarchy_A_C_HSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for second hierarchy J generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for second hierarchy J generates correct code.approved new file mode 100644 index 00000000..385c07af --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/hierarchy/SealedInterfaceHierarchyTests.compilation for second hierarchy J generates correct code.approved @@ -0,0 +1,66 @@ +package com.livefront.sealedenum.compilation.hierarchy + +import com.livefront.sealedenum.SealedEnum +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List + +/** + * An implementation of [SealedEnum] for the sealed class [SecondInterfaceHierarchy.A.J] + */ +public object SecondInterfaceHierarchy_A_JSealedEnum : SealedEnum { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + SecondInterfaceHierarchy.A.J.K + ) + } + + + public override fun ordinalOf(obj: SecondInterfaceHierarchy.A.J): Int = when (obj) { + is SecondInterfaceHierarchy.A.J.K -> 0 + } + + public override fun nameOf(obj: SecondInterfaceHierarchy.A.J): String = when (obj) { + is SecondInterfaceHierarchy.A.J.K -> "SecondInterfaceHierarchy_A_J_K" + } + + public override fun valueOf(name: String): SecondInterfaceHierarchy.A.J = when (name) { + "SecondInterfaceHierarchy_A_J_K" -> SecondInterfaceHierarchy.A.J.K + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } +} + +/** + * The index of [this] in the values list. + */ +public val SecondInterfaceHierarchy.A.J.ordinal: Int + get() = SecondInterfaceHierarchy_A_JSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val SecondInterfaceHierarchy.A.J.name: String + get() = SecondInterfaceHierarchy_A_JSealedEnum.nameOf(this) + +/** + * A list of all [SecondInterfaceHierarchy.A.J] objects. + */ +public val SecondInterfaceHierarchy.A.J.Companion.values: List + get() = SecondInterfaceHierarchy_A_JSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [SecondInterfaceHierarchy.A.J] + */ +public val SecondInterfaceHierarchy.A.J.Companion.sealedEnum: SecondInterfaceHierarchy_A_JSealedEnum + get() = SecondInterfaceHierarchy_A_JSealedEnum + +/** + * Returns the [SecondInterfaceHierarchy.A.J] object for the given [name]. + * + * If the given name doesn't correspond to any [SecondInterfaceHierarchy.A.J], an + * [IllegalArgumentException] will be thrown. + */ +public fun SecondInterfaceHierarchy.A.J.Companion.valueOf(name: String): + SecondInterfaceHierarchy.A.J = SecondInterfaceHierarchy_A_JSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/kitchensink/JavaBaseClasses.kt b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/kitchensink/JavaBaseClasses.kt index 01d73edd..edcdd43f 100644 --- a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/kitchensink/JavaBaseClasses.kt +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/kitchensink/JavaBaseClasses.kt @@ -1,7 +1,6 @@ package com.livefront.sealedenum.compilation.kitchensink import com.livefront.sealedenum.GenSealedEnum -import org.intellij.lang.annotations.Language interface KotlinInterface1 @@ -37,131 +36,3 @@ sealed class JavaBaseClassesSealedClass> : @GenSealedEnum(generateEnum = true) companion object } - -@Language("kotlin") -val javaBaseClassesSealedClassGenerated = """ -package com.livefront.sealedenum.compilation.kitchensink - -import com.livefront.sealedenum.EnumForSealedEnumProvider -import com.livefront.sealedenum.SealedEnum -import com.livefront.sealedenum.SealedEnumWithEnumProvider -import kotlin.Double -import kotlin.Int -import kotlin.LazyThreadSafetyMode -import kotlin.String -import kotlin.collections.List -import kotlin.reflect.KClass - -/** - * An isomorphic enum for the sealed class [JavaBaseClassesSealedClass] - */ -public enum class JavaBaseClassesSealedClassEnum( - sealedObject: JavaBaseClassesSealedClass<*>, -) : KotlinInterface5 by sealedObject, JavaInterface3 by sealedObject, - KotlinInterface4 by sealedObject, KotlinInterface6 by sealedObject, - JavaInterface2> by sealedObject, - JavaInterface5>>>>> - by sealedObject, KotlinInterface2 by sealedObject, JavaInterface1 by sealedObject, - KotlinInterface1 by sealedObject, KotlinInterface3> by sealedObject, - JavaInterface4 by sealedObject { - JavaBaseClassesSealedClass_FirstObject(com.livefront.sealedenum.compilation.kitchensink.JavaBaseClassesSealedClass.FirstObject), - JavaBaseClassesSealedClass_SecondObject(com.livefront.sealedenum.compilation.kitchensink.JavaBaseClassesSealedClass.SecondObject), -} - -/** - * The isomorphic [JavaBaseClassesSealedClassEnum] for [this]. - */ -public val JavaBaseClassesSealedClass<*>.`enum`: JavaBaseClassesSealedClassEnum - get() = JavaBaseClassesSealedClassSealedEnum.sealedObjectToEnum(this) - -/** - * The isomorphic [JavaBaseClassesSealedClass] for [this]. - */ -public val JavaBaseClassesSealedClassEnum.sealedObject: JavaBaseClassesSealedClass<*> - get() = JavaBaseClassesSealedClassSealedEnum.enumToSealedObject(this) - -/** - * An implementation of [SealedEnum] for the sealed class [JavaBaseClassesSealedClass] - */ -public object JavaBaseClassesSealedClassSealedEnum : SealedEnum>, - SealedEnumWithEnumProvider, JavaBaseClassesSealedClassEnum>, - EnumForSealedEnumProvider, JavaBaseClassesSealedClassEnum> { - public override val values: List> by lazy(mode = - LazyThreadSafetyMode.PUBLICATION) { - listOf( - JavaBaseClassesSealedClass.FirstObject, - JavaBaseClassesSealedClass.SecondObject - ) - } - - - public override val enumClass: KClass - get() = JavaBaseClassesSealedClassEnum::class - - public override fun ordinalOf(obj: JavaBaseClassesSealedClass<*>): Int = when (obj) { - is JavaBaseClassesSealedClass.FirstObject -> 0 - is JavaBaseClassesSealedClass.SecondObject -> 1 - } - - public override fun nameOf(obj: JavaBaseClassesSealedClass<*>): String = when (obj) { - is JavaBaseClassesSealedClass.FirstObject -> "JavaBaseClassesSealedClass_FirstObject" - is JavaBaseClassesSealedClass.SecondObject -> "JavaBaseClassesSealedClass_SecondObject" - } - - public override fun valueOf(name: String): JavaBaseClassesSealedClass<*> = when (name) { - "JavaBaseClassesSealedClass_FirstObject" -> JavaBaseClassesSealedClass.FirstObject - "JavaBaseClassesSealedClass_SecondObject" -> JavaBaseClassesSealedClass.SecondObject - else -> throw IllegalArgumentException(""${'"'}No sealed enum constant ${'$'}name""${'"'}) - } - - public override fun sealedObjectToEnum(obj: JavaBaseClassesSealedClass<*>): - JavaBaseClassesSealedClassEnum = when (obj) { - is JavaBaseClassesSealedClass.FirstObject -> - JavaBaseClassesSealedClassEnum.JavaBaseClassesSealedClass_FirstObject - is JavaBaseClassesSealedClass.SecondObject -> - JavaBaseClassesSealedClassEnum.JavaBaseClassesSealedClass_SecondObject - } - - public override fun enumToSealedObject(`enum`: JavaBaseClassesSealedClassEnum): - JavaBaseClassesSealedClass<*> = when (enum) { - JavaBaseClassesSealedClassEnum.JavaBaseClassesSealedClass_FirstObject -> - JavaBaseClassesSealedClass.FirstObject - JavaBaseClassesSealedClassEnum.JavaBaseClassesSealedClass_SecondObject -> - JavaBaseClassesSealedClass.SecondObject - } -} - -/** - * The index of [this] in the values list. - */ -public val JavaBaseClassesSealedClass<*>.ordinal: Int - get() = JavaBaseClassesSealedClassSealedEnum.ordinalOf(this) - -/** - * The name of [this] for use with valueOf. - */ -public val JavaBaseClassesSealedClass<*>.name: String - get() = JavaBaseClassesSealedClassSealedEnum.nameOf(this) - -/** - * A list of all [JavaBaseClassesSealedClass] objects. - */ -public val JavaBaseClassesSealedClass.Companion.values: List> - get() = JavaBaseClassesSealedClassSealedEnum.values - -/** - * Returns an implementation of [SealedEnum] for the sealed class [JavaBaseClassesSealedClass] - */ -public val JavaBaseClassesSealedClass.Companion.sealedEnum: JavaBaseClassesSealedClassSealedEnum - get() = JavaBaseClassesSealedClassSealedEnum - -/** - * Returns the [JavaBaseClassesSealedClass] object for the given [name]. - * - * If the given name doesn't correspond to any [JavaBaseClassesSealedClass], an - * [IllegalArgumentException] will be thrown. - */ -public fun JavaBaseClassesSealedClass.Companion.valueOf(name: String): JavaBaseClassesSealedClass<*> - = JavaBaseClassesSealedClassSealedEnum.valueOf(name) - -""".trimIndent() diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/kitchensink/JavaBaseClassesTests.compilation generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/kitchensink/JavaBaseClassesTests.compilation generates correct code.approved new file mode 100644 index 00000000..7ce49129 --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/kitchensink/JavaBaseClassesTests.compilation generates correct code.approved @@ -0,0 +1,123 @@ +package com.livefront.sealedenum.compilation.kitchensink + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Double +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [JavaBaseClassesSealedClass] + */ +public enum class JavaBaseClassesSealedClassEnum( + sealedObject: JavaBaseClassesSealedClass<*>, +) : KotlinInterface5 by sealedObject, JavaInterface3 by sealedObject, + KotlinInterface4 by sealedObject, KotlinInterface6 by sealedObject, + JavaInterface2> by sealedObject, + JavaInterface5>>>>> + by sealedObject, KotlinInterface2 by sealedObject, JavaInterface1 by sealedObject, + KotlinInterface1 by sealedObject, KotlinInterface3> by sealedObject, + JavaInterface4 by sealedObject { + JavaBaseClassesSealedClass_FirstObject(com.livefront.sealedenum.compilation.kitchensink.JavaBaseClassesSealedClass.FirstObject), + JavaBaseClassesSealedClass_SecondObject(com.livefront.sealedenum.compilation.kitchensink.JavaBaseClassesSealedClass.SecondObject), +} + +/** + * The isomorphic [JavaBaseClassesSealedClassEnum] for [this]. + */ +public val JavaBaseClassesSealedClass<*>.`enum`: JavaBaseClassesSealedClassEnum + get() = JavaBaseClassesSealedClassSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [JavaBaseClassesSealedClass] for [this]. + */ +public val JavaBaseClassesSealedClassEnum.sealedObject: JavaBaseClassesSealedClass<*> + get() = JavaBaseClassesSealedClassSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [JavaBaseClassesSealedClass] + */ +public object JavaBaseClassesSealedClassSealedEnum : SealedEnum>, + SealedEnumWithEnumProvider, JavaBaseClassesSealedClassEnum>, + EnumForSealedEnumProvider, JavaBaseClassesSealedClassEnum> { + public override val values: List> by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + JavaBaseClassesSealedClass.FirstObject, + JavaBaseClassesSealedClass.SecondObject + ) + } + + + public override val enumClass: KClass + get() = JavaBaseClassesSealedClassEnum::class + + public override fun ordinalOf(obj: JavaBaseClassesSealedClass<*>): Int = when (obj) { + is JavaBaseClassesSealedClass.FirstObject -> 0 + is JavaBaseClassesSealedClass.SecondObject -> 1 + } + + public override fun nameOf(obj: JavaBaseClassesSealedClass<*>): String = when (obj) { + is JavaBaseClassesSealedClass.FirstObject -> "JavaBaseClassesSealedClass_FirstObject" + is JavaBaseClassesSealedClass.SecondObject -> "JavaBaseClassesSealedClass_SecondObject" + } + + public override fun valueOf(name: String): JavaBaseClassesSealedClass<*> = when (name) { + "JavaBaseClassesSealedClass_FirstObject" -> JavaBaseClassesSealedClass.FirstObject + "JavaBaseClassesSealedClass_SecondObject" -> JavaBaseClassesSealedClass.SecondObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: JavaBaseClassesSealedClass<*>): + JavaBaseClassesSealedClassEnum = when (obj) { + is JavaBaseClassesSealedClass.FirstObject -> + JavaBaseClassesSealedClassEnum.JavaBaseClassesSealedClass_FirstObject + is JavaBaseClassesSealedClass.SecondObject -> + JavaBaseClassesSealedClassEnum.JavaBaseClassesSealedClass_SecondObject + } + + public override fun enumToSealedObject(`enum`: JavaBaseClassesSealedClassEnum): + JavaBaseClassesSealedClass<*> = when (enum) { + JavaBaseClassesSealedClassEnum.JavaBaseClassesSealedClass_FirstObject -> + JavaBaseClassesSealedClass.FirstObject + JavaBaseClassesSealedClassEnum.JavaBaseClassesSealedClass_SecondObject -> + JavaBaseClassesSealedClass.SecondObject + } +} + +/** + * The index of [this] in the values list. + */ +public val JavaBaseClassesSealedClass<*>.ordinal: Int + get() = JavaBaseClassesSealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val JavaBaseClassesSealedClass<*>.name: String + get() = JavaBaseClassesSealedClassSealedEnum.nameOf(this) + +/** + * A list of all [JavaBaseClassesSealedClass] objects. + */ +public val JavaBaseClassesSealedClass.Companion.values: List> + get() = JavaBaseClassesSealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [JavaBaseClassesSealedClass] + */ +public val JavaBaseClassesSealedClass.Companion.sealedEnum: JavaBaseClassesSealedClassSealedEnum + get() = JavaBaseClassesSealedClassSealedEnum + +/** + * Returns the [JavaBaseClassesSealedClass] object for the given [name]. + * + * If the given name doesn't correspond to any [JavaBaseClassesSealedClass], an + * [IllegalArgumentException] will be thrown. + */ +public fun JavaBaseClassesSealedClass.Companion.valueOf(name: String): JavaBaseClassesSealedClass<*> + = JavaBaseClassesSealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/kitchensink/JavaBaseClassesTests.kt b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/kitchensink/JavaBaseClassesTests.kt index 8e382a4c..98cdf7e5 100644 --- a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/kitchensink/JavaBaseClassesTests.kt +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/kitchensink/JavaBaseClassesTests.kt @@ -1,16 +1,20 @@ package com.livefront.sealedenum.compilation.kitchensink +import com.livefront.sealedenum.testing.SealedEnumApprovalsExtension +import com.livefront.sealedenum.testing.assertApprovedGeneratedFile import com.livefront.sealedenum.testing.assertCompiles -import com.livefront.sealedenum.testing.assertGeneratedFileMatches import com.livefront.sealedenum.testing.compile import com.livefront.sealedenum.testing.getSourceFile +import com.oneeyedmen.okeydoke.Approver import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith import kotlin.reflect.KTypeProjection import kotlin.reflect.full.createType import kotlin.reflect.full.isSubtypeOf +@ExtendWith(SealedEnumApprovalsExtension::class) class JavaBaseClassesTests { @Suppress("LongMethod") @@ -149,7 +153,7 @@ class JavaBaseClassesTests { } @Test - fun `compilation generates correct code`() { + fun Approver.`compilation generates correct code`() { val result = compile( getSourceFile("compilation", "kitchensink", "JavaInterface1.java"), getSourceFile("compilation", "kitchensink", "JavaInterface2.java"), @@ -162,10 +166,6 @@ class JavaBaseClassesTests { ) assertCompiles(result) - assertGeneratedFileMatches( - "JavaBaseClassesSealedClass_SealedEnum.kt", - javaBaseClassesSealedClassGenerated, - result - ) + assertApprovedGeneratedFile("JavaBaseClassesSealedClass_SealedEnum.kt", result) } } diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/NestedClassTests.compilation for inside one class generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/NestedClassTests.compilation for inside one class generates correct code.approved new file mode 100644 index 00000000..53a9d1b0 --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/NestedClassTests.compilation for inside one class generates correct code.approved @@ -0,0 +1,79 @@ +package com.livefront.sealedenum.compilation.location + +import com.livefront.sealedenum.SealedEnum +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List + +/** + * An implementation of [SealedEnum] for the sealed class [OuterClass.InsideOneClassSealedClass] + */ +public object OuterClass_InsideOneClassSealedClassSealedEnum : + SealedEnum { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + OuterClass.InsideOneClassSealedClass.FirstObject, + OuterClass.InsideOneClassSealedClass.SecondObject + ) + } + + + public override fun ordinalOf(obj: OuterClass.InsideOneClassSealedClass): Int = when (obj) { + is OuterClass.InsideOneClassSealedClass.FirstObject -> 0 + is OuterClass.InsideOneClassSealedClass.SecondObject -> 1 + } + + public override fun nameOf(obj: OuterClass.InsideOneClassSealedClass): String = when (obj) { + is OuterClass.InsideOneClassSealedClass.FirstObject -> + "OuterClass_InsideOneClassSealedClass_FirstObject" + is OuterClass.InsideOneClassSealedClass.SecondObject -> + "OuterClass_InsideOneClassSealedClass_SecondObject" + } + + public override fun valueOf(name: String): OuterClass.InsideOneClassSealedClass = when (name) { + "OuterClass_InsideOneClassSealedClass_FirstObject" -> + OuterClass.InsideOneClassSealedClass.FirstObject + "OuterClass_InsideOneClassSealedClass_SecondObject" -> + OuterClass.InsideOneClassSealedClass.SecondObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } +} + +/** + * The index of [this] in the values list. + */ +public val OuterClass.InsideOneClassSealedClass.ordinal: Int + get() = OuterClass_InsideOneClassSealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val OuterClass.InsideOneClassSealedClass.name: String + get() = OuterClass_InsideOneClassSealedClassSealedEnum.nameOf(this) + +/** + * A list of all [OuterClass.InsideOneClassSealedClass] objects. + */ +public val OuterClass.InsideOneClassSealedClass.Companion.values: + List + get() = OuterClass_InsideOneClassSealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class + * [OuterClass.InsideOneClassSealedClass] + */ +public val OuterClass.InsideOneClassSealedClass.Companion.sealedEnum: + OuterClass_InsideOneClassSealedClassSealedEnum + get() = OuterClass_InsideOneClassSealedClassSealedEnum + +/** + * Returns the [OuterClass.InsideOneClassSealedClass] object for the given [name]. + * + * If the given name doesn't correspond to any [OuterClass.InsideOneClassSealedClass], an + * [IllegalArgumentException] will be thrown. + */ +public fun OuterClass.InsideOneClassSealedClass.Companion.valueOf(name: String): + OuterClass.InsideOneClassSealedClass = + OuterClass_InsideOneClassSealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/NestedClassTests.compilation for inside two classes generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/NestedClassTests.compilation for inside two classes generates correct code.approved new file mode 100644 index 00000000..211c0b88 --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/NestedClassTests.compilation for inside two classes generates correct code.approved @@ -0,0 +1,87 @@ +package com.livefront.sealedenum.compilation.location + +import com.livefront.sealedenum.SealedEnum +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List + +/** + * An implementation of [SealedEnum] for the sealed class + * [FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass] + */ +public object FirstOuterClass_SecondOuterClass_InsideTwoClassesSealedClassSealedEnum : + SealedEnum { + public override val values: List + by lazy(mode = LazyThreadSafetyMode.PUBLICATION) { + listOf( + FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass.FirstObject, + FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass.SecondObject + ) + } + + + public override + fun ordinalOf(obj: FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass): Int = + when (obj) { + is FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass.FirstObject -> 0 + is FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass.SecondObject -> 1 + } + + public override fun nameOf(obj: FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass): + String = when (obj) { + is FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass.FirstObject -> + "FirstOuterClass_SecondOuterClass_InsideTwoClassesSealedClass_FirstObject" + is FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass.SecondObject -> + "FirstOuterClass_SecondOuterClass_InsideTwoClassesSealedClass_SecondObject" + } + + public override fun valueOf(name: String): + FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass = when (name) { + "FirstOuterClass_SecondOuterClass_InsideTwoClassesSealedClass_FirstObject" -> + FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass.FirstObject + "FirstOuterClass_SecondOuterClass_InsideTwoClassesSealedClass_SecondObject" -> + FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass.SecondObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } +} + +/** + * The index of [this] in the values list. + */ +public val FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass.ordinal: Int + get() = FirstOuterClass_SecondOuterClass_InsideTwoClassesSealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass.name: String + get() = FirstOuterClass_SecondOuterClass_InsideTwoClassesSealedClassSealedEnum.nameOf(this) + +/** + * A list of all [FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass] objects. + */ +public val FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass.Companion.values: + List + get() = FirstOuterClass_SecondOuterClass_InsideTwoClassesSealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class + * [FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass] + */ +public val FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass.Companion.sealedEnum: + FirstOuterClass_SecondOuterClass_InsideTwoClassesSealedClassSealedEnum + get() = FirstOuterClass_SecondOuterClass_InsideTwoClassesSealedClassSealedEnum + +/** + * Returns the [FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass] object for the given + * [name]. + * + * If the given name doesn't correspond to any + * [FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass], an [IllegalArgumentException] will + * be thrown. + */ +public + fun FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass.Companion.valueOf(name: String): + FirstOuterClass.SecondOuterClass.InsideTwoClassesSealedClass = + FirstOuterClass_SecondOuterClass_InsideTwoClassesSealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/OutsideSealedClassTests.compilation for alpha outside sealed class generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/OutsideSealedClassTests.compilation for alpha outside sealed class generates correct code.approved new file mode 100644 index 00000000..2a959b9a --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/OutsideSealedClassTests.compilation for alpha outside sealed class generates correct code.approved @@ -0,0 +1,103 @@ +package com.livefront.sealedenum.compilation.location + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [AlphaOutsideSealedClass] + */ +public enum class AlphaOutsideSealedClassEnum() { + AlphaFirstObject, +} + +/** + * The isomorphic [AlphaOutsideSealedClassEnum] for [this]. + */ +public val AlphaOutsideSealedClass.`enum`: AlphaOutsideSealedClassEnum + get() = AlphaOutsideSealedClassSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [AlphaOutsideSealedClass] for [this]. + */ +public val AlphaOutsideSealedClassEnum.sealedObject: AlphaOutsideSealedClass + get() = AlphaOutsideSealedClassSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [AlphaOutsideSealedClass] + */ +public object AlphaOutsideSealedClassSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + AlphaFirstObject + ) + } + + + public override val enumClass: KClass + get() = AlphaOutsideSealedClassEnum::class + + public override fun ordinalOf(obj: AlphaOutsideSealedClass): Int = when (obj) { + is AlphaFirstObject -> 0 + } + + public override fun nameOf(obj: AlphaOutsideSealedClass): String = when (obj) { + is AlphaFirstObject -> "AlphaFirstObject" + } + + public override fun valueOf(name: String): AlphaOutsideSealedClass = when (name) { + "AlphaFirstObject" -> AlphaFirstObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: AlphaOutsideSealedClass): + AlphaOutsideSealedClassEnum = when (obj) { + is AlphaFirstObject -> AlphaOutsideSealedClassEnum.AlphaFirstObject + } + + public override fun enumToSealedObject(`enum`: AlphaOutsideSealedClassEnum): + AlphaOutsideSealedClass = when (enum) { + AlphaOutsideSealedClassEnum.AlphaFirstObject -> AlphaFirstObject + } +} + +/** + * The index of [this] in the values list. + */ +public val AlphaOutsideSealedClass.ordinal: Int + get() = AlphaOutsideSealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val AlphaOutsideSealedClass.name: String + get() = AlphaOutsideSealedClassSealedEnum.nameOf(this) + +/** + * A list of all [AlphaOutsideSealedClass] objects. + */ +public val AlphaOutsideSealedClass.Companion.values: List + get() = AlphaOutsideSealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [AlphaOutsideSealedClass] + */ +public val AlphaOutsideSealedClass.Companion.sealedEnum: AlphaOutsideSealedClassSealedEnum + get() = AlphaOutsideSealedClassSealedEnum + +/** + * Returns the [AlphaOutsideSealedClass] object for the given [name]. + * + * If the given name doesn't correspond to any [AlphaOutsideSealedClass], an + * [IllegalArgumentException] will be thrown. + */ +public fun AlphaOutsideSealedClass.Companion.valueOf(name: String): AlphaOutsideSealedClass = + AlphaOutsideSealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/OutsideSealedClassTests.compilation for beta outside sealed class generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/OutsideSealedClassTests.compilation for beta outside sealed class generates correct code.approved new file mode 100644 index 00000000..a9457b5d --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/OutsideSealedClassTests.compilation for beta outside sealed class generates correct code.approved @@ -0,0 +1,124 @@ +package com.livefront.sealedenum.compilation.location + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [BetaOutsideSealedClass] + */ +public enum class BetaOutsideSealedClassEnum() { + BetaFirstObject, + BetaFourthObject, + BetaSecondObject, + BetaThirdObject, +} + +/** + * The isomorphic [BetaOutsideSealedClassEnum] for [this]. + */ +public val BetaOutsideSealedClass.`enum`: BetaOutsideSealedClassEnum + get() = BetaOutsideSealedClassSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [BetaOutsideSealedClass] for [this]. + */ +public val BetaOutsideSealedClassEnum.sealedObject: BetaOutsideSealedClass + get() = BetaOutsideSealedClassSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [BetaOutsideSealedClass] + */ +public object BetaOutsideSealedClassSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + BetaFirstObject, + BetaFourthObject, + BetaSecondObject, + BetaThirdObject + ) + } + + + public override val enumClass: KClass + get() = BetaOutsideSealedClassEnum::class + + public override fun ordinalOf(obj: BetaOutsideSealedClass): Int = when (obj) { + is BetaFirstObject -> 0 + is BetaFourthObject -> 1 + is BetaSecondObject -> 2 + is BetaThirdObject -> 3 + } + + public override fun nameOf(obj: BetaOutsideSealedClass): String = when (obj) { + is BetaFirstObject -> "BetaFirstObject" + is BetaFourthObject -> "BetaFourthObject" + is BetaSecondObject -> "BetaSecondObject" + is BetaThirdObject -> "BetaThirdObject" + } + + public override fun valueOf(name: String): BetaOutsideSealedClass = when (name) { + "BetaFirstObject" -> BetaFirstObject + "BetaFourthObject" -> BetaFourthObject + "BetaSecondObject" -> BetaSecondObject + "BetaThirdObject" -> BetaThirdObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: BetaOutsideSealedClass): BetaOutsideSealedClassEnum + = when (obj) { + is BetaFirstObject -> BetaOutsideSealedClassEnum.BetaFirstObject + is BetaFourthObject -> BetaOutsideSealedClassEnum.BetaFourthObject + is BetaSecondObject -> BetaOutsideSealedClassEnum.BetaSecondObject + is BetaThirdObject -> BetaOutsideSealedClassEnum.BetaThirdObject + } + + public override fun enumToSealedObject(`enum`: BetaOutsideSealedClassEnum): + BetaOutsideSealedClass = when (enum) { + BetaOutsideSealedClassEnum.BetaFirstObject -> BetaFirstObject + BetaOutsideSealedClassEnum.BetaFourthObject -> BetaFourthObject + BetaOutsideSealedClassEnum.BetaSecondObject -> BetaSecondObject + BetaOutsideSealedClassEnum.BetaThirdObject -> BetaThirdObject + } +} + +/** + * The index of [this] in the values list. + */ +public val BetaOutsideSealedClass.ordinal: Int + get() = BetaOutsideSealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val BetaOutsideSealedClass.name: String + get() = BetaOutsideSealedClassSealedEnum.nameOf(this) + +/** + * A list of all [BetaOutsideSealedClass] objects. + */ +public val BetaOutsideSealedClass.Companion.values: List + get() = BetaOutsideSealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [BetaOutsideSealedClass] + */ +public val BetaOutsideSealedClass.Companion.sealedEnum: BetaOutsideSealedClassSealedEnum + get() = BetaOutsideSealedClassSealedEnum + +/** + * Returns the [BetaOutsideSealedClass] object for the given [name]. + * + * If the given name doesn't correspond to any [BetaOutsideSealedClass], an + * [IllegalArgumentException] will be thrown. + */ +public fun BetaOutsideSealedClass.Companion.valueOf(name: String): BetaOutsideSealedClass = + BetaOutsideSealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/OutsideSealedClassTests.compilation for delta outside sealed class generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/OutsideSealedClassTests.compilation for delta outside sealed class generates correct code.approved new file mode 100644 index 00000000..2c876ec1 --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/OutsideSealedClassTests.compilation for delta outside sealed class generates correct code.approved @@ -0,0 +1,112 @@ +package com.livefront.sealedenum.compilation.location + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [DeltaOutsideSealedClass] + */ +public enum class DeltaOutsideSealedClassEnum() { + DeltaOutsideSealedClass_DeltaObject, + DeltaObject, +} + +/** + * The isomorphic [DeltaOutsideSealedClassEnum] for [this]. + */ +public val DeltaOutsideSealedClass.`enum`: DeltaOutsideSealedClassEnum + get() = DeltaOutsideSealedClassSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [DeltaOutsideSealedClass] for [this]. + */ +public val DeltaOutsideSealedClassEnum.sealedObject: DeltaOutsideSealedClass + get() = DeltaOutsideSealedClassSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [DeltaOutsideSealedClass] + */ +public object DeltaOutsideSealedClassSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + DeltaOutsideSealedClass.DeltaObject, + DeltaObject + ) + } + + + public override val enumClass: KClass + get() = DeltaOutsideSealedClassEnum::class + + public override fun ordinalOf(obj: DeltaOutsideSealedClass): Int = when (obj) { + is DeltaOutsideSealedClass.DeltaObject -> 0 + is DeltaObject -> 1 + } + + public override fun nameOf(obj: DeltaOutsideSealedClass): String = when (obj) { + is DeltaOutsideSealedClass.DeltaObject -> "DeltaOutsideSealedClass_DeltaObject" + is DeltaObject -> "DeltaObject" + } + + public override fun valueOf(name: String): DeltaOutsideSealedClass = when (name) { + "DeltaOutsideSealedClass_DeltaObject" -> DeltaOutsideSealedClass.DeltaObject + "DeltaObject" -> DeltaObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: DeltaOutsideSealedClass): + DeltaOutsideSealedClassEnum = when (obj) { + is DeltaOutsideSealedClass.DeltaObject -> + DeltaOutsideSealedClassEnum.DeltaOutsideSealedClass_DeltaObject + is DeltaObject -> DeltaOutsideSealedClassEnum.DeltaObject + } + + public override fun enumToSealedObject(`enum`: DeltaOutsideSealedClassEnum): + DeltaOutsideSealedClass = when (enum) { + DeltaOutsideSealedClassEnum.DeltaOutsideSealedClass_DeltaObject -> + DeltaOutsideSealedClass.DeltaObject + DeltaOutsideSealedClassEnum.DeltaObject -> DeltaObject + } +} + +/** + * The index of [this] in the values list. + */ +public val DeltaOutsideSealedClass.ordinal: Int + get() = DeltaOutsideSealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val DeltaOutsideSealedClass.name: String + get() = DeltaOutsideSealedClassSealedEnum.nameOf(this) + +/** + * A list of all [DeltaOutsideSealedClass] objects. + */ +public val DeltaOutsideSealedClass.Companion.values: List + get() = DeltaOutsideSealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [DeltaOutsideSealedClass] + */ +public val DeltaOutsideSealedClass.Companion.sealedEnum: DeltaOutsideSealedClassSealedEnum + get() = DeltaOutsideSealedClassSealedEnum + +/** + * Returns the [DeltaOutsideSealedClass] object for the given [name]. + * + * If the given name doesn't correspond to any [DeltaOutsideSealedClass], an + * [IllegalArgumentException] will be thrown. + */ +public fun DeltaOutsideSealedClass.Companion.valueOf(name: String): DeltaOutsideSealedClass = + DeltaOutsideSealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/OutsideSealedClassTests.compilation for gamma outside sealed class generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/OutsideSealedClassTests.compilation for gamma outside sealed class generates correct code.approved new file mode 100644 index 00000000..cfefeaf6 --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/OutsideSealedClassTests.compilation for gamma outside sealed class generates correct code.approved @@ -0,0 +1,126 @@ +package com.livefront.sealedenum.compilation.location + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [GammaOutsideSealedClass] + */ +public enum class GammaOutsideSealedClassEnum() { + GammaOutsideSealedClass_GammaSecondObject, + GammaFirstObject, + GammaFourthObject, + GammaThirdObject, +} + +/** + * The isomorphic [GammaOutsideSealedClassEnum] for [this]. + */ +public val GammaOutsideSealedClass.`enum`: GammaOutsideSealedClassEnum + get() = GammaOutsideSealedClassSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [GammaOutsideSealedClass] for [this]. + */ +public val GammaOutsideSealedClassEnum.sealedObject: GammaOutsideSealedClass + get() = GammaOutsideSealedClassSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [GammaOutsideSealedClass] + */ +public object GammaOutsideSealedClassSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + GammaOutsideSealedClass.GammaSecondObject, + GammaFirstObject, + GammaFourthObject, + GammaThirdObject + ) + } + + + public override val enumClass: KClass + get() = GammaOutsideSealedClassEnum::class + + public override fun ordinalOf(obj: GammaOutsideSealedClass): Int = when (obj) { + is GammaOutsideSealedClass.GammaSecondObject -> 0 + is GammaFirstObject -> 1 + is GammaFourthObject -> 2 + is GammaThirdObject -> 3 + } + + public override fun nameOf(obj: GammaOutsideSealedClass): String = when (obj) { + is GammaOutsideSealedClass.GammaSecondObject -> "GammaOutsideSealedClass_GammaSecondObject" + is GammaFirstObject -> "GammaFirstObject" + is GammaFourthObject -> "GammaFourthObject" + is GammaThirdObject -> "GammaThirdObject" + } + + public override fun valueOf(name: String): GammaOutsideSealedClass = when (name) { + "GammaOutsideSealedClass_GammaSecondObject" -> GammaOutsideSealedClass.GammaSecondObject + "GammaFirstObject" -> GammaFirstObject + "GammaFourthObject" -> GammaFourthObject + "GammaThirdObject" -> GammaThirdObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: GammaOutsideSealedClass): + GammaOutsideSealedClassEnum = when (obj) { + is GammaOutsideSealedClass.GammaSecondObject -> + GammaOutsideSealedClassEnum.GammaOutsideSealedClass_GammaSecondObject + is GammaFirstObject -> GammaOutsideSealedClassEnum.GammaFirstObject + is GammaFourthObject -> GammaOutsideSealedClassEnum.GammaFourthObject + is GammaThirdObject -> GammaOutsideSealedClassEnum.GammaThirdObject + } + + public override fun enumToSealedObject(`enum`: GammaOutsideSealedClassEnum): + GammaOutsideSealedClass = when (enum) { + GammaOutsideSealedClassEnum.GammaOutsideSealedClass_GammaSecondObject -> + GammaOutsideSealedClass.GammaSecondObject + GammaOutsideSealedClassEnum.GammaFirstObject -> GammaFirstObject + GammaOutsideSealedClassEnum.GammaFourthObject -> GammaFourthObject + GammaOutsideSealedClassEnum.GammaThirdObject -> GammaThirdObject + } +} + +/** + * The index of [this] in the values list. + */ +public val GammaOutsideSealedClass.ordinal: Int + get() = GammaOutsideSealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val GammaOutsideSealedClass.name: String + get() = GammaOutsideSealedClassSealedEnum.nameOf(this) + +/** + * A list of all [GammaOutsideSealedClass] objects. + */ +public val GammaOutsideSealedClass.Companion.values: List + get() = GammaOutsideSealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [GammaOutsideSealedClass] + */ +public val GammaOutsideSealedClass.Companion.sealedEnum: GammaOutsideSealedClassSealedEnum + get() = GammaOutsideSealedClassSealedEnum + +/** + * Returns the [GammaOutsideSealedClass] object for the given [name]. + * + * If the given name doesn't correspond to any [GammaOutsideSealedClass], an + * [IllegalArgumentException] will be thrown. + */ +public fun GammaOutsideSealedClass.Companion.valueOf(name: String): GammaOutsideSealedClass = + GammaOutsideSealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/SplitAcrossFilesSealedClassTests.compilation for objects split across files generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/SplitAcrossFilesSealedClassTests.compilation for objects split across files generates correct code.approved new file mode 100644 index 00000000..f79e5314 --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/location/SplitAcrossFilesSealedClassTests.compilation for objects split across files generates correct code.approved @@ -0,0 +1,117 @@ +package com.livefront.sealedenum.compilation.location + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [SplitAcrossFilesSealedClass] + */ +public enum class SplitAcrossFilesSealedClassEnum() { + SplitAcrossFilesSubclassA, + SplitAcrossFilesSubclassB, + SplitAcrossFilesSubclassC, +} + +/** + * The isomorphic [SplitAcrossFilesSealedClassEnum] for [this]. + */ +public val SplitAcrossFilesSealedClass.`enum`: SplitAcrossFilesSealedClassEnum + get() = SplitAcrossFilesSealedClassSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [SplitAcrossFilesSealedClass] for [this]. + */ +public val SplitAcrossFilesSealedClassEnum.sealedObject: SplitAcrossFilesSealedClass + get() = SplitAcrossFilesSealedClassSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [SplitAcrossFilesSealedClass] + */ +public object SplitAcrossFilesSealedClassSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + SplitAcrossFilesSubclassA, + SplitAcrossFilesSubclassB, + SplitAcrossFilesSubclassC + ) + } + + + public override val enumClass: KClass + get() = SplitAcrossFilesSealedClassEnum::class + + public override fun ordinalOf(obj: SplitAcrossFilesSealedClass): Int = when (obj) { + is SplitAcrossFilesSubclassA -> 0 + is SplitAcrossFilesSubclassB -> 1 + is SplitAcrossFilesSubclassC -> 2 + } + + public override fun nameOf(obj: SplitAcrossFilesSealedClass): String = when (obj) { + is SplitAcrossFilesSubclassA -> "SplitAcrossFilesSubclassA" + is SplitAcrossFilesSubclassB -> "SplitAcrossFilesSubclassB" + is SplitAcrossFilesSubclassC -> "SplitAcrossFilesSubclassC" + } + + public override fun valueOf(name: String): SplitAcrossFilesSealedClass = when (name) { + "SplitAcrossFilesSubclassA" -> SplitAcrossFilesSubclassA + "SplitAcrossFilesSubclassB" -> SplitAcrossFilesSubclassB + "SplitAcrossFilesSubclassC" -> SplitAcrossFilesSubclassC + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: SplitAcrossFilesSealedClass): + SplitAcrossFilesSealedClassEnum = when (obj) { + is SplitAcrossFilesSubclassA -> SplitAcrossFilesSealedClassEnum.SplitAcrossFilesSubclassA + is SplitAcrossFilesSubclassB -> SplitAcrossFilesSealedClassEnum.SplitAcrossFilesSubclassB + is SplitAcrossFilesSubclassC -> SplitAcrossFilesSealedClassEnum.SplitAcrossFilesSubclassC + } + + public override fun enumToSealedObject(`enum`: SplitAcrossFilesSealedClassEnum): + SplitAcrossFilesSealedClass = when (enum) { + SplitAcrossFilesSealedClassEnum.SplitAcrossFilesSubclassA -> SplitAcrossFilesSubclassA + SplitAcrossFilesSealedClassEnum.SplitAcrossFilesSubclassB -> SplitAcrossFilesSubclassB + SplitAcrossFilesSealedClassEnum.SplitAcrossFilesSubclassC -> SplitAcrossFilesSubclassC + } +} + +/** + * The index of [this] in the values list. + */ +public val SplitAcrossFilesSealedClass.ordinal: Int + get() = SplitAcrossFilesSealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val SplitAcrossFilesSealedClass.name: String + get() = SplitAcrossFilesSealedClassSealedEnum.nameOf(this) + +/** + * A list of all [SplitAcrossFilesSealedClass] objects. + */ +public val SplitAcrossFilesSealedClass.Companion.values: List + get() = SplitAcrossFilesSealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [SplitAcrossFilesSealedClass] + */ +public val SplitAcrossFilesSealedClass.Companion.sealedEnum: SplitAcrossFilesSealedClassSealedEnum + get() = SplitAcrossFilesSealedClassSealedEnum + +/** + * Returns the [SplitAcrossFilesSealedClass] object for the given [name]. + * + * If the given name doesn't correspond to any [SplitAcrossFilesSealedClass], an + * [IllegalArgumentException] will be thrown. + */ +public fun SplitAcrossFilesSealedClass.Companion.valueOf(name: String): SplitAcrossFilesSealedClass + = SplitAcrossFilesSealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/traversal/TraversalOrderTests.compilation generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/traversal/TraversalOrderTests.compilation generates correct code.approved new file mode 100644 index 00000000..5736f294 --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/traversal/TraversalOrderTests.compilation generates correct code.approved @@ -0,0 +1,728 @@ +package com.livefront.sealedenum.compilation.traversal + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [Tree] + */ +public enum class TreeLevelOrderEnum() { + Tree_A, + Tree_K, + Tree_T, + Tree_L_S, + Tree_B_C_D, + Tree_B_C_E, + Tree_B_C_J, + Tree_L_M_N, + Tree_L_M_O, + Tree_L_P_Q, + Tree_L_P_R, + Tree_B_C_F_G, + Tree_B_C_F_H, + Tree_B_C_F_I, +} + +/** + * The isomorphic [TreeLevelOrderEnum] for [this]. + */ +public val Tree.levelOrderEnum: TreeLevelOrderEnum + get() = TreeLevelOrderSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [Tree] for [this]. + */ +public val TreeLevelOrderEnum.sealedObject: Tree + get() = TreeLevelOrderSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [Tree] + */ +public object TreeLevelOrderSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = LazyThreadSafetyMode.PUBLICATION) { + listOf( + Tree.A, + Tree.K, + Tree.T, + Tree.L.S, + Tree.B.C.D, + Tree.B.C.E, + Tree.B.C.J, + Tree.L.M.N, + Tree.L.M.O, + Tree.L.P.Q, + Tree.L.P.R, + Tree.B.C.F.G, + Tree.B.C.F.H, + Tree.B.C.F.I + ) + } + + + public override val enumClass: KClass + get() = TreeLevelOrderEnum::class + + public override fun ordinalOf(obj: Tree): Int = when (obj) { + is Tree.A -> 0 + is Tree.K -> 1 + is Tree.T -> 2 + is Tree.L.S -> 3 + is Tree.B.C.D -> 4 + is Tree.B.C.E -> 5 + is Tree.B.C.J -> 6 + is Tree.L.M.N -> 7 + is Tree.L.M.O -> 8 + is Tree.L.P.Q -> 9 + is Tree.L.P.R -> 10 + is Tree.B.C.F.G -> 11 + is Tree.B.C.F.H -> 12 + is Tree.B.C.F.I -> 13 + } + + public override fun nameOf(obj: Tree): String = when (obj) { + is Tree.A -> "Tree_A" + is Tree.K -> "Tree_K" + is Tree.T -> "Tree_T" + is Tree.L.S -> "Tree_L_S" + is Tree.B.C.D -> "Tree_B_C_D" + is Tree.B.C.E -> "Tree_B_C_E" + is Tree.B.C.J -> "Tree_B_C_J" + is Tree.L.M.N -> "Tree_L_M_N" + is Tree.L.M.O -> "Tree_L_M_O" + is Tree.L.P.Q -> "Tree_L_P_Q" + is Tree.L.P.R -> "Tree_L_P_R" + is Tree.B.C.F.G -> "Tree_B_C_F_G" + is Tree.B.C.F.H -> "Tree_B_C_F_H" + is Tree.B.C.F.I -> "Tree_B_C_F_I" + } + + public override fun valueOf(name: String): Tree = when (name) { + "Tree_A" -> Tree.A + "Tree_K" -> Tree.K + "Tree_T" -> Tree.T + "Tree_L_S" -> Tree.L.S + "Tree_B_C_D" -> Tree.B.C.D + "Tree_B_C_E" -> Tree.B.C.E + "Tree_B_C_J" -> Tree.B.C.J + "Tree_L_M_N" -> Tree.L.M.N + "Tree_L_M_O" -> Tree.L.M.O + "Tree_L_P_Q" -> Tree.L.P.Q + "Tree_L_P_R" -> Tree.L.P.R + "Tree_B_C_F_G" -> Tree.B.C.F.G + "Tree_B_C_F_H" -> Tree.B.C.F.H + "Tree_B_C_F_I" -> Tree.B.C.F.I + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: Tree): TreeLevelOrderEnum = when (obj) { + is Tree.A -> TreeLevelOrderEnum.Tree_A + is Tree.K -> TreeLevelOrderEnum.Tree_K + is Tree.T -> TreeLevelOrderEnum.Tree_T + is Tree.L.S -> TreeLevelOrderEnum.Tree_L_S + is Tree.B.C.D -> TreeLevelOrderEnum.Tree_B_C_D + is Tree.B.C.E -> TreeLevelOrderEnum.Tree_B_C_E + is Tree.B.C.J -> TreeLevelOrderEnum.Tree_B_C_J + is Tree.L.M.N -> TreeLevelOrderEnum.Tree_L_M_N + is Tree.L.M.O -> TreeLevelOrderEnum.Tree_L_M_O + is Tree.L.P.Q -> TreeLevelOrderEnum.Tree_L_P_Q + is Tree.L.P.R -> TreeLevelOrderEnum.Tree_L_P_R + is Tree.B.C.F.G -> TreeLevelOrderEnum.Tree_B_C_F_G + is Tree.B.C.F.H -> TreeLevelOrderEnum.Tree_B_C_F_H + is Tree.B.C.F.I -> TreeLevelOrderEnum.Tree_B_C_F_I + } + + public override fun enumToSealedObject(`enum`: TreeLevelOrderEnum): Tree = when (enum) { + TreeLevelOrderEnum.Tree_A -> Tree.A + TreeLevelOrderEnum.Tree_K -> Tree.K + TreeLevelOrderEnum.Tree_T -> Tree.T + TreeLevelOrderEnum.Tree_L_S -> Tree.L.S + TreeLevelOrderEnum.Tree_B_C_D -> Tree.B.C.D + TreeLevelOrderEnum.Tree_B_C_E -> Tree.B.C.E + TreeLevelOrderEnum.Tree_B_C_J -> Tree.B.C.J + TreeLevelOrderEnum.Tree_L_M_N -> Tree.L.M.N + TreeLevelOrderEnum.Tree_L_M_O -> Tree.L.M.O + TreeLevelOrderEnum.Tree_L_P_Q -> Tree.L.P.Q + TreeLevelOrderEnum.Tree_L_P_R -> Tree.L.P.R + TreeLevelOrderEnum.Tree_B_C_F_G -> Tree.B.C.F.G + TreeLevelOrderEnum.Tree_B_C_F_H -> Tree.B.C.F.H + TreeLevelOrderEnum.Tree_B_C_F_I -> Tree.B.C.F.I + } +} + +/** + * The index of [this] in the values list. + */ +public val Tree.levelOrderOrdinal: Int + get() = TreeLevelOrderSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val Tree.levelOrderName: String + get() = TreeLevelOrderSealedEnum.nameOf(this) + +/** + * A list of all [Tree] objects. + */ +public val Tree.Companion.levelOrderValues: List + get() = TreeLevelOrderSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [Tree] + */ +public val Tree.Companion.levelOrderSealedEnum: TreeLevelOrderSealedEnum + get() = TreeLevelOrderSealedEnum + +/** + * Returns the [Tree] object for the given [name]. + * + * If the given name doesn't correspond to any [Tree], an [IllegalArgumentException] will be thrown. + */ +public fun Tree.Companion.levelOrderValueOf(name: String): Tree = + TreeLevelOrderSealedEnum.valueOf(name) + +/** + * An isomorphic enum for the sealed class [Tree] + */ +public enum class TreePostOrderEnum() { + Tree_B_C_F_G, + Tree_B_C_F_H, + Tree_B_C_F_I, + Tree_B_C_D, + Tree_B_C_E, + Tree_B_C_J, + Tree_L_M_N, + Tree_L_M_O, + Tree_L_P_Q, + Tree_L_P_R, + Tree_L_S, + Tree_A, + Tree_K, + Tree_T, +} + +/** + * The isomorphic [TreePostOrderEnum] for [this]. + */ +public val Tree.postOrderEnum: TreePostOrderEnum + get() = TreePostOrderSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [Tree] for [this]. + */ +public val TreePostOrderEnum.sealedObject: Tree + get() = TreePostOrderSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [Tree] + */ +public object TreePostOrderSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = LazyThreadSafetyMode.PUBLICATION) { + listOf( + Tree.B.C.F.G, + Tree.B.C.F.H, + Tree.B.C.F.I, + Tree.B.C.D, + Tree.B.C.E, + Tree.B.C.J, + Tree.L.M.N, + Tree.L.M.O, + Tree.L.P.Q, + Tree.L.P.R, + Tree.L.S, + Tree.A, + Tree.K, + Tree.T + ) + } + + + public override val enumClass: KClass + get() = TreePostOrderEnum::class + + public override fun ordinalOf(obj: Tree): Int = when (obj) { + is Tree.B.C.F.G -> 0 + is Tree.B.C.F.H -> 1 + is Tree.B.C.F.I -> 2 + is Tree.B.C.D -> 3 + is Tree.B.C.E -> 4 + is Tree.B.C.J -> 5 + is Tree.L.M.N -> 6 + is Tree.L.M.O -> 7 + is Tree.L.P.Q -> 8 + is Tree.L.P.R -> 9 + is Tree.L.S -> 10 + is Tree.A -> 11 + is Tree.K -> 12 + is Tree.T -> 13 + } + + public override fun nameOf(obj: Tree): String = when (obj) { + is Tree.B.C.F.G -> "Tree_B_C_F_G" + is Tree.B.C.F.H -> "Tree_B_C_F_H" + is Tree.B.C.F.I -> "Tree_B_C_F_I" + is Tree.B.C.D -> "Tree_B_C_D" + is Tree.B.C.E -> "Tree_B_C_E" + is Tree.B.C.J -> "Tree_B_C_J" + is Tree.L.M.N -> "Tree_L_M_N" + is Tree.L.M.O -> "Tree_L_M_O" + is Tree.L.P.Q -> "Tree_L_P_Q" + is Tree.L.P.R -> "Tree_L_P_R" + is Tree.L.S -> "Tree_L_S" + is Tree.A -> "Tree_A" + is Tree.K -> "Tree_K" + is Tree.T -> "Tree_T" + } + + public override fun valueOf(name: String): Tree = when (name) { + "Tree_B_C_F_G" -> Tree.B.C.F.G + "Tree_B_C_F_H" -> Tree.B.C.F.H + "Tree_B_C_F_I" -> Tree.B.C.F.I + "Tree_B_C_D" -> Tree.B.C.D + "Tree_B_C_E" -> Tree.B.C.E + "Tree_B_C_J" -> Tree.B.C.J + "Tree_L_M_N" -> Tree.L.M.N + "Tree_L_M_O" -> Tree.L.M.O + "Tree_L_P_Q" -> Tree.L.P.Q + "Tree_L_P_R" -> Tree.L.P.R + "Tree_L_S" -> Tree.L.S + "Tree_A" -> Tree.A + "Tree_K" -> Tree.K + "Tree_T" -> Tree.T + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: Tree): TreePostOrderEnum = when (obj) { + is Tree.B.C.F.G -> TreePostOrderEnum.Tree_B_C_F_G + is Tree.B.C.F.H -> TreePostOrderEnum.Tree_B_C_F_H + is Tree.B.C.F.I -> TreePostOrderEnum.Tree_B_C_F_I + is Tree.B.C.D -> TreePostOrderEnum.Tree_B_C_D + is Tree.B.C.E -> TreePostOrderEnum.Tree_B_C_E + is Tree.B.C.J -> TreePostOrderEnum.Tree_B_C_J + is Tree.L.M.N -> TreePostOrderEnum.Tree_L_M_N + is Tree.L.M.O -> TreePostOrderEnum.Tree_L_M_O + is Tree.L.P.Q -> TreePostOrderEnum.Tree_L_P_Q + is Tree.L.P.R -> TreePostOrderEnum.Tree_L_P_R + is Tree.L.S -> TreePostOrderEnum.Tree_L_S + is Tree.A -> TreePostOrderEnum.Tree_A + is Tree.K -> TreePostOrderEnum.Tree_K + is Tree.T -> TreePostOrderEnum.Tree_T + } + + public override fun enumToSealedObject(`enum`: TreePostOrderEnum): Tree = when (enum) { + TreePostOrderEnum.Tree_B_C_F_G -> Tree.B.C.F.G + TreePostOrderEnum.Tree_B_C_F_H -> Tree.B.C.F.H + TreePostOrderEnum.Tree_B_C_F_I -> Tree.B.C.F.I + TreePostOrderEnum.Tree_B_C_D -> Tree.B.C.D + TreePostOrderEnum.Tree_B_C_E -> Tree.B.C.E + TreePostOrderEnum.Tree_B_C_J -> Tree.B.C.J + TreePostOrderEnum.Tree_L_M_N -> Tree.L.M.N + TreePostOrderEnum.Tree_L_M_O -> Tree.L.M.O + TreePostOrderEnum.Tree_L_P_Q -> Tree.L.P.Q + TreePostOrderEnum.Tree_L_P_R -> Tree.L.P.R + TreePostOrderEnum.Tree_L_S -> Tree.L.S + TreePostOrderEnum.Tree_A -> Tree.A + TreePostOrderEnum.Tree_K -> Tree.K + TreePostOrderEnum.Tree_T -> Tree.T + } +} + +/** + * The index of [this] in the values list. + */ +public val Tree.postOrderOrdinal: Int + get() = TreePostOrderSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val Tree.postOrderName: String + get() = TreePostOrderSealedEnum.nameOf(this) + +/** + * A list of all [Tree] objects. + */ +public val Tree.Companion.postOrderValues: List + get() = TreePostOrderSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [Tree] + */ +public val Tree.Companion.postOrderSealedEnum: TreePostOrderSealedEnum + get() = TreePostOrderSealedEnum + +/** + * Returns the [Tree] object for the given [name]. + * + * If the given name doesn't correspond to any [Tree], an [IllegalArgumentException] will be thrown. + */ +public fun Tree.Companion.postOrderValueOf(name: String): Tree = + TreePostOrderSealedEnum.valueOf(name) + +/** + * An isomorphic enum for the sealed class [Tree] + */ +public enum class TreeInOrderEnum() { + Tree_A, + Tree_B_C_D, + Tree_B_C_E, + Tree_B_C_F_G, + Tree_B_C_F_H, + Tree_B_C_F_I, + Tree_B_C_J, + Tree_K, + Tree_L_M_N, + Tree_L_M_O, + Tree_L_P_Q, + Tree_L_P_R, + Tree_L_S, + Tree_T, +} + +/** + * The isomorphic [TreeInOrderEnum] for [this]. + */ +public val Tree.inOrderEnum: TreeInOrderEnum + get() = TreeInOrderSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [Tree] for [this]. + */ +public val TreeInOrderEnum.sealedObject: Tree + get() = TreeInOrderSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [Tree] + */ +public object TreeInOrderSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = LazyThreadSafetyMode.PUBLICATION) { + listOf( + Tree.A, + Tree.B.C.D, + Tree.B.C.E, + Tree.B.C.F.G, + Tree.B.C.F.H, + Tree.B.C.F.I, + Tree.B.C.J, + Tree.K, + Tree.L.M.N, + Tree.L.M.O, + Tree.L.P.Q, + Tree.L.P.R, + Tree.L.S, + Tree.T + ) + } + + + public override val enumClass: KClass + get() = TreeInOrderEnum::class + + public override fun ordinalOf(obj: Tree): Int = when (obj) { + is Tree.A -> 0 + is Tree.B.C.D -> 1 + is Tree.B.C.E -> 2 + is Tree.B.C.F.G -> 3 + is Tree.B.C.F.H -> 4 + is Tree.B.C.F.I -> 5 + is Tree.B.C.J -> 6 + is Tree.K -> 7 + is Tree.L.M.N -> 8 + is Tree.L.M.O -> 9 + is Tree.L.P.Q -> 10 + is Tree.L.P.R -> 11 + is Tree.L.S -> 12 + is Tree.T -> 13 + } + + public override fun nameOf(obj: Tree): String = when (obj) { + is Tree.A -> "Tree_A" + is Tree.B.C.D -> "Tree_B_C_D" + is Tree.B.C.E -> "Tree_B_C_E" + is Tree.B.C.F.G -> "Tree_B_C_F_G" + is Tree.B.C.F.H -> "Tree_B_C_F_H" + is Tree.B.C.F.I -> "Tree_B_C_F_I" + is Tree.B.C.J -> "Tree_B_C_J" + is Tree.K -> "Tree_K" + is Tree.L.M.N -> "Tree_L_M_N" + is Tree.L.M.O -> "Tree_L_M_O" + is Tree.L.P.Q -> "Tree_L_P_Q" + is Tree.L.P.R -> "Tree_L_P_R" + is Tree.L.S -> "Tree_L_S" + is Tree.T -> "Tree_T" + } + + public override fun valueOf(name: String): Tree = when (name) { + "Tree_A" -> Tree.A + "Tree_B_C_D" -> Tree.B.C.D + "Tree_B_C_E" -> Tree.B.C.E + "Tree_B_C_F_G" -> Tree.B.C.F.G + "Tree_B_C_F_H" -> Tree.B.C.F.H + "Tree_B_C_F_I" -> Tree.B.C.F.I + "Tree_B_C_J" -> Tree.B.C.J + "Tree_K" -> Tree.K + "Tree_L_M_N" -> Tree.L.M.N + "Tree_L_M_O" -> Tree.L.M.O + "Tree_L_P_Q" -> Tree.L.P.Q + "Tree_L_P_R" -> Tree.L.P.R + "Tree_L_S" -> Tree.L.S + "Tree_T" -> Tree.T + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: Tree): TreeInOrderEnum = when (obj) { + is Tree.A -> TreeInOrderEnum.Tree_A + is Tree.B.C.D -> TreeInOrderEnum.Tree_B_C_D + is Tree.B.C.E -> TreeInOrderEnum.Tree_B_C_E + is Tree.B.C.F.G -> TreeInOrderEnum.Tree_B_C_F_G + is Tree.B.C.F.H -> TreeInOrderEnum.Tree_B_C_F_H + is Tree.B.C.F.I -> TreeInOrderEnum.Tree_B_C_F_I + is Tree.B.C.J -> TreeInOrderEnum.Tree_B_C_J + is Tree.K -> TreeInOrderEnum.Tree_K + is Tree.L.M.N -> TreeInOrderEnum.Tree_L_M_N + is Tree.L.M.O -> TreeInOrderEnum.Tree_L_M_O + is Tree.L.P.Q -> TreeInOrderEnum.Tree_L_P_Q + is Tree.L.P.R -> TreeInOrderEnum.Tree_L_P_R + is Tree.L.S -> TreeInOrderEnum.Tree_L_S + is Tree.T -> TreeInOrderEnum.Tree_T + } + + public override fun enumToSealedObject(`enum`: TreeInOrderEnum): Tree = when (enum) { + TreeInOrderEnum.Tree_A -> Tree.A + TreeInOrderEnum.Tree_B_C_D -> Tree.B.C.D + TreeInOrderEnum.Tree_B_C_E -> Tree.B.C.E + TreeInOrderEnum.Tree_B_C_F_G -> Tree.B.C.F.G + TreeInOrderEnum.Tree_B_C_F_H -> Tree.B.C.F.H + TreeInOrderEnum.Tree_B_C_F_I -> Tree.B.C.F.I + TreeInOrderEnum.Tree_B_C_J -> Tree.B.C.J + TreeInOrderEnum.Tree_K -> Tree.K + TreeInOrderEnum.Tree_L_M_N -> Tree.L.M.N + TreeInOrderEnum.Tree_L_M_O -> Tree.L.M.O + TreeInOrderEnum.Tree_L_P_Q -> Tree.L.P.Q + TreeInOrderEnum.Tree_L_P_R -> Tree.L.P.R + TreeInOrderEnum.Tree_L_S -> Tree.L.S + TreeInOrderEnum.Tree_T -> Tree.T + } +} + +/** + * The index of [this] in the values list. + */ +public val Tree.inOrderOrdinal: Int + get() = TreeInOrderSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val Tree.inOrderName: String + get() = TreeInOrderSealedEnum.nameOf(this) + +/** + * A list of all [Tree] objects. + */ +public val Tree.Companion.inOrderValues: List + get() = TreeInOrderSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [Tree] + */ +public val Tree.Companion.inOrderSealedEnum: TreeInOrderSealedEnum + get() = TreeInOrderSealedEnum + +/** + * Returns the [Tree] object for the given [name]. + * + * If the given name doesn't correspond to any [Tree], an [IllegalArgumentException] will be thrown. + */ +public fun Tree.Companion.inOrderValueOf(name: String): Tree = TreeInOrderSealedEnum.valueOf(name) + +/** + * An isomorphic enum for the sealed class [Tree] + */ +public enum class TreePreOrderEnum() { + Tree_A, + Tree_K, + Tree_T, + Tree_B_C_D, + Tree_B_C_E, + Tree_B_C_J, + Tree_B_C_F_G, + Tree_B_C_F_H, + Tree_B_C_F_I, + Tree_L_S, + Tree_L_M_N, + Tree_L_M_O, + Tree_L_P_Q, + Tree_L_P_R, +} + +/** + * The isomorphic [TreePreOrderEnum] for [this]. + */ +public val Tree.preOrderEnum: TreePreOrderEnum + get() = TreePreOrderSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [Tree] for [this]. + */ +public val TreePreOrderEnum.sealedObject: Tree + get() = TreePreOrderSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [Tree] + */ +public object TreePreOrderSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = LazyThreadSafetyMode.PUBLICATION) { + listOf( + Tree.A, + Tree.K, + Tree.T, + Tree.B.C.D, + Tree.B.C.E, + Tree.B.C.J, + Tree.B.C.F.G, + Tree.B.C.F.H, + Tree.B.C.F.I, + Tree.L.S, + Tree.L.M.N, + Tree.L.M.O, + Tree.L.P.Q, + Tree.L.P.R + ) + } + + + public override val enumClass: KClass + get() = TreePreOrderEnum::class + + public override fun ordinalOf(obj: Tree): Int = when (obj) { + is Tree.A -> 0 + is Tree.K -> 1 + is Tree.T -> 2 + is Tree.B.C.D -> 3 + is Tree.B.C.E -> 4 + is Tree.B.C.J -> 5 + is Tree.B.C.F.G -> 6 + is Tree.B.C.F.H -> 7 + is Tree.B.C.F.I -> 8 + is Tree.L.S -> 9 + is Tree.L.M.N -> 10 + is Tree.L.M.O -> 11 + is Tree.L.P.Q -> 12 + is Tree.L.P.R -> 13 + } + + public override fun nameOf(obj: Tree): String = when (obj) { + is Tree.A -> "Tree_A" + is Tree.K -> "Tree_K" + is Tree.T -> "Tree_T" + is Tree.B.C.D -> "Tree_B_C_D" + is Tree.B.C.E -> "Tree_B_C_E" + is Tree.B.C.J -> "Tree_B_C_J" + is Tree.B.C.F.G -> "Tree_B_C_F_G" + is Tree.B.C.F.H -> "Tree_B_C_F_H" + is Tree.B.C.F.I -> "Tree_B_C_F_I" + is Tree.L.S -> "Tree_L_S" + is Tree.L.M.N -> "Tree_L_M_N" + is Tree.L.M.O -> "Tree_L_M_O" + is Tree.L.P.Q -> "Tree_L_P_Q" + is Tree.L.P.R -> "Tree_L_P_R" + } + + public override fun valueOf(name: String): Tree = when (name) { + "Tree_A" -> Tree.A + "Tree_K" -> Tree.K + "Tree_T" -> Tree.T + "Tree_B_C_D" -> Tree.B.C.D + "Tree_B_C_E" -> Tree.B.C.E + "Tree_B_C_J" -> Tree.B.C.J + "Tree_B_C_F_G" -> Tree.B.C.F.G + "Tree_B_C_F_H" -> Tree.B.C.F.H + "Tree_B_C_F_I" -> Tree.B.C.F.I + "Tree_L_S" -> Tree.L.S + "Tree_L_M_N" -> Tree.L.M.N + "Tree_L_M_O" -> Tree.L.M.O + "Tree_L_P_Q" -> Tree.L.P.Q + "Tree_L_P_R" -> Tree.L.P.R + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: Tree): TreePreOrderEnum = when (obj) { + is Tree.A -> TreePreOrderEnum.Tree_A + is Tree.K -> TreePreOrderEnum.Tree_K + is Tree.T -> TreePreOrderEnum.Tree_T + is Tree.B.C.D -> TreePreOrderEnum.Tree_B_C_D + is Tree.B.C.E -> TreePreOrderEnum.Tree_B_C_E + is Tree.B.C.J -> TreePreOrderEnum.Tree_B_C_J + is Tree.B.C.F.G -> TreePreOrderEnum.Tree_B_C_F_G + is Tree.B.C.F.H -> TreePreOrderEnum.Tree_B_C_F_H + is Tree.B.C.F.I -> TreePreOrderEnum.Tree_B_C_F_I + is Tree.L.S -> TreePreOrderEnum.Tree_L_S + is Tree.L.M.N -> TreePreOrderEnum.Tree_L_M_N + is Tree.L.M.O -> TreePreOrderEnum.Tree_L_M_O + is Tree.L.P.Q -> TreePreOrderEnum.Tree_L_P_Q + is Tree.L.P.R -> TreePreOrderEnum.Tree_L_P_R + } + + public override fun enumToSealedObject(`enum`: TreePreOrderEnum): Tree = when (enum) { + TreePreOrderEnum.Tree_A -> Tree.A + TreePreOrderEnum.Tree_K -> Tree.K + TreePreOrderEnum.Tree_T -> Tree.T + TreePreOrderEnum.Tree_B_C_D -> Tree.B.C.D + TreePreOrderEnum.Tree_B_C_E -> Tree.B.C.E + TreePreOrderEnum.Tree_B_C_J -> Tree.B.C.J + TreePreOrderEnum.Tree_B_C_F_G -> Tree.B.C.F.G + TreePreOrderEnum.Tree_B_C_F_H -> Tree.B.C.F.H + TreePreOrderEnum.Tree_B_C_F_I -> Tree.B.C.F.I + TreePreOrderEnum.Tree_L_S -> Tree.L.S + TreePreOrderEnum.Tree_L_M_N -> Tree.L.M.N + TreePreOrderEnum.Tree_L_M_O -> Tree.L.M.O + TreePreOrderEnum.Tree_L_P_Q -> Tree.L.P.Q + TreePreOrderEnum.Tree_L_P_R -> Tree.L.P.R + } +} + +/** + * The index of [this] in the values list. + */ +public val Tree.preOrderOrdinal: Int + get() = TreePreOrderSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val Tree.preOrderName: String + get() = TreePreOrderSealedEnum.nameOf(this) + +/** + * A list of all [Tree] objects. + */ +public val Tree.Companion.preOrderValues: List + get() = TreePreOrderSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [Tree] + */ +public val Tree.Companion.preOrderSealedEnum: TreePreOrderSealedEnum + get() = TreePreOrderSealedEnum + +/** + * Returns the [Tree] object for the given [name]. + * + * If the given name doesn't correspond to any [Tree], an [IllegalArgumentException] will be thrown. + */ +public fun Tree.Companion.preOrderValueOf(name: String): Tree = TreePreOrderSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/usecases/EnvironmentsSealedEnumTests.compilation generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/usecases/EnvironmentsSealedEnumTests.compilation generates correct code.approved new file mode 100644 index 00000000..c55e6208 --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/usecases/EnvironmentsSealedEnumTests.compilation generates correct code.approved @@ -0,0 +1,124 @@ +package com.livefront.sealedenum.compilation.usecases + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [Environments] + */ +public enum class EnvironmentsEnum( + sealedObject: Environments, +) : Uri by sealedObject { + Environments_Http_Livefront(com.livefront.sealedenum.compilation.usecases.Environments.Http.Livefront), + Environments_Http_Google(com.livefront.sealedenum.compilation.usecases.Environments.Http.Google), + Environments_Https_Livefront(com.livefront.sealedenum.compilation.usecases.Environments.Https.Livefront), + Environments_Https_Google(com.livefront.sealedenum.compilation.usecases.Environments.Https.Google), +} + +/** + * The isomorphic [EnvironmentsEnum] for [this]. + */ +public val Environments.`enum`: EnvironmentsEnum + get() = EnvironmentsSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [Environments] for [this]. + */ +public val EnvironmentsEnum.sealedObject: Environments + get() = EnvironmentsSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [Environments] + */ +public object EnvironmentsSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + Environments.Http.Livefront, + Environments.Http.Google, + Environments.Https.Livefront, + Environments.Https.Google + ) + } + + + public override val enumClass: KClass + get() = EnvironmentsEnum::class + + public override fun ordinalOf(obj: Environments): Int = when (obj) { + is Environments.Http.Livefront -> 0 + is Environments.Http.Google -> 1 + is Environments.Https.Livefront -> 2 + is Environments.Https.Google -> 3 + } + + public override fun nameOf(obj: Environments): String = when (obj) { + is Environments.Http.Livefront -> "Environments_Http_Livefront" + is Environments.Http.Google -> "Environments_Http_Google" + is Environments.Https.Livefront -> "Environments_Https_Livefront" + is Environments.Https.Google -> "Environments_Https_Google" + } + + public override fun valueOf(name: String): Environments = when (name) { + "Environments_Http_Livefront" -> Environments.Http.Livefront + "Environments_Http_Google" -> Environments.Http.Google + "Environments_Https_Livefront" -> Environments.Https.Livefront + "Environments_Https_Google" -> Environments.Https.Google + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: Environments): EnvironmentsEnum = when (obj) { + is Environments.Http.Livefront -> EnvironmentsEnum.Environments_Http_Livefront + is Environments.Http.Google -> EnvironmentsEnum.Environments_Http_Google + is Environments.Https.Livefront -> EnvironmentsEnum.Environments_Https_Livefront + is Environments.Https.Google -> EnvironmentsEnum.Environments_Https_Google + } + + public override fun enumToSealedObject(`enum`: EnvironmentsEnum): Environments = when (enum) { + EnvironmentsEnum.Environments_Http_Livefront -> Environments.Http.Livefront + EnvironmentsEnum.Environments_Http_Google -> Environments.Http.Google + EnvironmentsEnum.Environments_Https_Livefront -> Environments.Https.Livefront + EnvironmentsEnum.Environments_Https_Google -> Environments.Https.Google + } +} + +/** + * The index of [this] in the values list. + */ +public val Environments.ordinal: Int + get() = EnvironmentsSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val Environments.name: String + get() = EnvironmentsSealedEnum.nameOf(this) + +/** + * A list of all [Environments] objects. + */ +public val Environments.Companion.values: List + get() = EnvironmentsSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [Environments] + */ +public val Environments.Companion.sealedEnum: EnvironmentsSealedEnum + get() = EnvironmentsSealedEnum + +/** + * Returns the [Environments] object for the given [name]. + * + * If the given name doesn't correspond to any [Environments], an [IllegalArgumentException] will be + * thrown. + */ +public fun Environments.Companion.valueOf(name: String): Environments = + EnvironmentsSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/usecases/FlagTests.compilation generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/usecases/FlagTests.compilation generates correct code.approved new file mode 100644 index 00000000..9d596a92 --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/usecases/FlagTests.compilation generates correct code.approved @@ -0,0 +1,104 @@ +package com.livefront.sealedenum.compilation.usecases + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [Flag] + */ +public enum class FlagEnum() { + Flag_FirstFlag, + Flag_SecondFlag, +} + +/** + * The isomorphic [FlagEnum] for [this]. + */ +public val Flag.`enum`: FlagEnum + get() = FlagSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [Flag] for [this]. + */ +public val FlagEnum.sealedObject: Flag + get() = FlagSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [Flag] + */ +public object FlagSealedEnum : SealedEnum, SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = LazyThreadSafetyMode.PUBLICATION) { + listOf( + Flag.FirstFlag, + Flag.SecondFlag + ) + } + + + public override val enumClass: KClass + get() = FlagEnum::class + + public override fun ordinalOf(obj: Flag): Int = when (obj) { + is Flag.FirstFlag -> 0 + is Flag.SecondFlag -> 1 + } + + public override fun nameOf(obj: Flag): String = when (obj) { + is Flag.FirstFlag -> "Flag_FirstFlag" + is Flag.SecondFlag -> "Flag_SecondFlag" + } + + public override fun valueOf(name: String): Flag = when (name) { + "Flag_FirstFlag" -> Flag.FirstFlag + "Flag_SecondFlag" -> Flag.SecondFlag + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: Flag): FlagEnum = when (obj) { + is Flag.FirstFlag -> FlagEnum.Flag_FirstFlag + is Flag.SecondFlag -> FlagEnum.Flag_SecondFlag + } + + public override fun enumToSealedObject(`enum`: FlagEnum): Flag = when (enum) { + FlagEnum.Flag_FirstFlag -> Flag.FirstFlag + FlagEnum.Flag_SecondFlag -> Flag.SecondFlag + } +} + +/** + * The index of [this] in the values list. + */ +public val Flag.ordinal: Int + get() = FlagSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val Flag.name: String + get() = FlagSealedEnum.nameOf(this) + +/** + * A list of all [Flag] objects. + */ +public val Flag.Companion.values: List + get() = FlagSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [Flag] + */ +public val Flag.Companion.sealedEnum: FlagSealedEnum + get() = FlagSealedEnum + +/** + * Returns the [Flag] object for the given [name]. + * + * If the given name doesn't correspond to any [Flag], an [IllegalArgumentException] will be thrown. + */ +public fun Flag.Companion.valueOf(name: String): Flag = FlagSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/visibility/Internal.compilation generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/visibility/Internal.compilation generates correct code.approved new file mode 100644 index 00000000..f4c98cb3 --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/visibility/Internal.compilation generates correct code.approved @@ -0,0 +1,112 @@ +package com.livefront.sealedenum.compilation.visibility + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [InternalSealedClass] + */ +internal enum class InternalSealedClassEnum() { + InternalSealedClass_FirstObject, + InternalSealedClass_SecondObject, +} + +/** + * The isomorphic [InternalSealedClassEnum] for [this]. + */ +internal val InternalSealedClass.`enum`: InternalSealedClassEnum + get() = InternalSealedClassSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [InternalSealedClass] for [this]. + */ +internal val InternalSealedClassEnum.sealedObject: InternalSealedClass + get() = InternalSealedClassSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [InternalSealedClass] + */ +internal object InternalSealedClassSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + InternalSealedClass.FirstObject, + InternalSealedClass.SecondObject + ) + } + + + public override val enumClass: KClass + get() = InternalSealedClassEnum::class + + public override fun ordinalOf(obj: InternalSealedClass): Int = when (obj) { + is InternalSealedClass.FirstObject -> 0 + is InternalSealedClass.SecondObject -> 1 + } + + public override fun nameOf(obj: InternalSealedClass): String = when (obj) { + is InternalSealedClass.FirstObject -> "InternalSealedClass_FirstObject" + is InternalSealedClass.SecondObject -> "InternalSealedClass_SecondObject" + } + + public override fun valueOf(name: String): InternalSealedClass = when (name) { + "InternalSealedClass_FirstObject" -> InternalSealedClass.FirstObject + "InternalSealedClass_SecondObject" -> InternalSealedClass.SecondObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: InternalSealedClass): InternalSealedClassEnum = when + (obj) { + is InternalSealedClass.FirstObject -> + InternalSealedClassEnum.InternalSealedClass_FirstObject + is InternalSealedClass.SecondObject -> + InternalSealedClassEnum.InternalSealedClass_SecondObject + } + + public override fun enumToSealedObject(`enum`: InternalSealedClassEnum): InternalSealedClass = + when (enum) { + InternalSealedClassEnum.InternalSealedClass_FirstObject -> InternalSealedClass.FirstObject + InternalSealedClassEnum.InternalSealedClass_SecondObject -> InternalSealedClass.SecondObject + } +} + +/** + * The index of [this] in the values list. + */ +internal val InternalSealedClass.ordinal: Int + get() = InternalSealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +internal val InternalSealedClass.name: String + get() = InternalSealedClassSealedEnum.nameOf(this) + +/** + * A list of all [InternalSealedClass] objects. + */ +internal val InternalSealedClass.Companion.values: List + get() = InternalSealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [InternalSealedClass] + */ +internal val InternalSealedClass.Companion.sealedEnum: InternalSealedClassSealedEnum + get() = InternalSealedClassSealedEnum + +/** + * Returns the [InternalSealedClass] object for the given [name]. + * + * If the given name doesn't correspond to any [InternalSealedClass], an [IllegalArgumentException] + * will be thrown. + */ +internal fun InternalSealedClass.Companion.valueOf(name: String): InternalSealedClass = + InternalSealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/visibility/InternalCompanion.compilation generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/visibility/InternalCompanion.compilation generates correct code.approved new file mode 100644 index 00000000..1de30b79 --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/visibility/InternalCompanion.compilation generates correct code.approved @@ -0,0 +1,115 @@ +package com.livefront.sealedenum.compilation.visibility + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [InternalCompanionSealedClass] + */ +public enum class InternalCompanionSealedClassEnum() { + InternalCompanionSealedClass_FirstObject, + InternalCompanionSealedClass_SecondObject, +} + +/** + * The isomorphic [InternalCompanionSealedClassEnum] for [this]. + */ +public val InternalCompanionSealedClass.`enum`: InternalCompanionSealedClassEnum + get() = InternalCompanionSealedClassSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [InternalCompanionSealedClass] for [this]. + */ +public val InternalCompanionSealedClassEnum.sealedObject: InternalCompanionSealedClass + get() = InternalCompanionSealedClassSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [InternalCompanionSealedClass] + */ +public object InternalCompanionSealedClassSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + InternalCompanionSealedClass.FirstObject, + InternalCompanionSealedClass.SecondObject + ) + } + + + public override val enumClass: KClass + get() = InternalCompanionSealedClassEnum::class + + public override fun ordinalOf(obj: InternalCompanionSealedClass): Int = when (obj) { + is InternalCompanionSealedClass.FirstObject -> 0 + is InternalCompanionSealedClass.SecondObject -> 1 + } + + public override fun nameOf(obj: InternalCompanionSealedClass): String = when (obj) { + is InternalCompanionSealedClass.FirstObject -> "InternalCompanionSealedClass_FirstObject" + is InternalCompanionSealedClass.SecondObject -> "InternalCompanionSealedClass_SecondObject" + } + + public override fun valueOf(name: String): InternalCompanionSealedClass = when (name) { + "InternalCompanionSealedClass_FirstObject" -> InternalCompanionSealedClass.FirstObject + "InternalCompanionSealedClass_SecondObject" -> InternalCompanionSealedClass.SecondObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: InternalCompanionSealedClass): + InternalCompanionSealedClassEnum = when (obj) { + is InternalCompanionSealedClass.FirstObject -> + InternalCompanionSealedClassEnum.InternalCompanionSealedClass_FirstObject + is InternalCompanionSealedClass.SecondObject -> + InternalCompanionSealedClassEnum.InternalCompanionSealedClass_SecondObject + } + + public override fun enumToSealedObject(`enum`: InternalCompanionSealedClassEnum): + InternalCompanionSealedClass = when (enum) { + InternalCompanionSealedClassEnum.InternalCompanionSealedClass_FirstObject -> + InternalCompanionSealedClass.FirstObject + InternalCompanionSealedClassEnum.InternalCompanionSealedClass_SecondObject -> + InternalCompanionSealedClass.SecondObject + } +} + +/** + * The index of [this] in the values list. + */ +public val InternalCompanionSealedClass.ordinal: Int + get() = InternalCompanionSealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val InternalCompanionSealedClass.name: String + get() = InternalCompanionSealedClassSealedEnum.nameOf(this) + +/** + * A list of all [InternalCompanionSealedClass] objects. + */ +internal val InternalCompanionSealedClass.Companion.values: List + get() = InternalCompanionSealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [InternalCompanionSealedClass] + */ +internal val InternalCompanionSealedClass.Companion.sealedEnum: + InternalCompanionSealedClassSealedEnum + get() = InternalCompanionSealedClassSealedEnum + +/** + * Returns the [InternalCompanionSealedClass] object for the given [name]. + * + * If the given name doesn't correspond to any [InternalCompanionSealedClass], an + * [IllegalArgumentException] will be thrown. + */ +internal fun InternalCompanionSealedClass.Companion.valueOf(name: String): + InternalCompanionSealedClass = InternalCompanionSealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/visibility/InternalObjects.compilation generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/visibility/InternalObjects.compilation generates correct code.approved new file mode 100644 index 00000000..23c4f0d3 --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/visibility/InternalObjects.compilation generates correct code.approved @@ -0,0 +1,125 @@ +package com.livefront.sealedenum.compilation.visibility + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [InternalObjectsSealedClass] + */ +public enum class InternalObjectsSealedClassEnum() { + InternalObjectsSealedClass_FirstObject, + InternalObjectsSealedClass_SecondObject, + InternalObjectsSealedClass_InnerSealedClass_ThirdObject, +} + +/** + * The isomorphic [InternalObjectsSealedClassEnum] for [this]. + */ +public val InternalObjectsSealedClass.`enum`: InternalObjectsSealedClassEnum + get() = InternalObjectsSealedClassSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [InternalObjectsSealedClass] for [this]. + */ +public val InternalObjectsSealedClassEnum.sealedObject: InternalObjectsSealedClass + get() = InternalObjectsSealedClassSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [InternalObjectsSealedClass] + */ +public object InternalObjectsSealedClassSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + InternalObjectsSealedClass.FirstObject, + InternalObjectsSealedClass.SecondObject, + InternalObjectsSealedClass.InnerSealedClass.ThirdObject + ) + } + + + public override val enumClass: KClass + get() = InternalObjectsSealedClassEnum::class + + public override fun ordinalOf(obj: InternalObjectsSealedClass): Int = when (obj) { + is InternalObjectsSealedClass.FirstObject -> 0 + is InternalObjectsSealedClass.SecondObject -> 1 + is InternalObjectsSealedClass.InnerSealedClass.ThirdObject -> 2 + } + + public override fun nameOf(obj: InternalObjectsSealedClass): String = when (obj) { + is InternalObjectsSealedClass.FirstObject -> "InternalObjectsSealedClass_FirstObject" + is InternalObjectsSealedClass.SecondObject -> "InternalObjectsSealedClass_SecondObject" + is InternalObjectsSealedClass.InnerSealedClass.ThirdObject -> + "InternalObjectsSealedClass_InnerSealedClass_ThirdObject" + } + + public override fun valueOf(name: String): InternalObjectsSealedClass = when (name) { + "InternalObjectsSealedClass_FirstObject" -> InternalObjectsSealedClass.FirstObject + "InternalObjectsSealedClass_SecondObject" -> InternalObjectsSealedClass.SecondObject + "InternalObjectsSealedClass_InnerSealedClass_ThirdObject" -> + InternalObjectsSealedClass.InnerSealedClass.ThirdObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: InternalObjectsSealedClass): + InternalObjectsSealedClassEnum = when (obj) { + is InternalObjectsSealedClass.FirstObject -> + InternalObjectsSealedClassEnum.InternalObjectsSealedClass_FirstObject + is InternalObjectsSealedClass.SecondObject -> + InternalObjectsSealedClassEnum.InternalObjectsSealedClass_SecondObject + is InternalObjectsSealedClass.InnerSealedClass.ThirdObject -> + InternalObjectsSealedClassEnum.InternalObjectsSealedClass_InnerSealedClass_ThirdObject + } + + public override fun enumToSealedObject(`enum`: InternalObjectsSealedClassEnum): + InternalObjectsSealedClass = when (enum) { + InternalObjectsSealedClassEnum.InternalObjectsSealedClass_FirstObject -> + InternalObjectsSealedClass.FirstObject + InternalObjectsSealedClassEnum.InternalObjectsSealedClass_SecondObject -> + InternalObjectsSealedClass.SecondObject + InternalObjectsSealedClassEnum.InternalObjectsSealedClass_InnerSealedClass_ThirdObject -> + InternalObjectsSealedClass.InnerSealedClass.ThirdObject + } +} + +/** + * The index of [this] in the values list. + */ +public val InternalObjectsSealedClass.ordinal: Int + get() = InternalObjectsSealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val InternalObjectsSealedClass.name: String + get() = InternalObjectsSealedClassSealedEnum.nameOf(this) + +/** + * A list of all [InternalObjectsSealedClass] objects. + */ +public val InternalObjectsSealedClass.Companion.values: List + get() = InternalObjectsSealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [InternalObjectsSealedClass] + */ +public val InternalObjectsSealedClass.Companion.sealedEnum: InternalObjectsSealedClassSealedEnum + get() = InternalObjectsSealedClassSealedEnum + +/** + * Returns the [InternalObjectsSealedClass] object for the given [name]. + * + * If the given name doesn't correspond to any [InternalObjectsSealedClass], an + * [IllegalArgumentException] will be thrown. + */ +public fun InternalObjectsSealedClass.Companion.valueOf(name: String): InternalObjectsSealedClass = + InternalObjectsSealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/visibility/InternalSealedAndCompanion.compilation generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/visibility/InternalSealedAndCompanion.compilation generates correct code.approved new file mode 100644 index 00000000..efd15a6b --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/visibility/InternalSealedAndCompanion.compilation generates correct code.approved @@ -0,0 +1,125 @@ +package com.livefront.sealedenum.compilation.visibility + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [InternalSealedAndCompanionSealedClass] + */ +internal enum class InternalSealedAndCompanionSealedClassEnum() { + InternalSealedAndCompanionSealedClass_FirstObject, + InternalSealedAndCompanionSealedClass_SecondObject, +} + +/** + * The isomorphic [InternalSealedAndCompanionSealedClassEnum] for [this]. + */ +internal val InternalSealedAndCompanionSealedClass.`enum`: InternalSealedAndCompanionSealedClassEnum + get() = InternalSealedAndCompanionSealedClassSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [InternalSealedAndCompanionSealedClass] for [this]. + */ +internal val InternalSealedAndCompanionSealedClassEnum.sealedObject: + InternalSealedAndCompanionSealedClass + get() = InternalSealedAndCompanionSealedClassSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [InternalSealedAndCompanionSealedClass] + */ +internal object InternalSealedAndCompanionSealedClassSealedEnum : + SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider + { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + InternalSealedAndCompanionSealedClass.FirstObject, + InternalSealedAndCompanionSealedClass.SecondObject + ) + } + + + public override val enumClass: KClass + get() = InternalSealedAndCompanionSealedClassEnum::class + + public override fun ordinalOf(obj: InternalSealedAndCompanionSealedClass): Int = when (obj) { + is InternalSealedAndCompanionSealedClass.FirstObject -> 0 + is InternalSealedAndCompanionSealedClass.SecondObject -> 1 + } + + public override fun nameOf(obj: InternalSealedAndCompanionSealedClass): String = when (obj) { + is InternalSealedAndCompanionSealedClass.FirstObject -> + "InternalSealedAndCompanionSealedClass_FirstObject" + is InternalSealedAndCompanionSealedClass.SecondObject -> + "InternalSealedAndCompanionSealedClass_SecondObject" + } + + public override fun valueOf(name: String): InternalSealedAndCompanionSealedClass = when (name) { + "InternalSealedAndCompanionSealedClass_FirstObject" -> + InternalSealedAndCompanionSealedClass.FirstObject + "InternalSealedAndCompanionSealedClass_SecondObject" -> + InternalSealedAndCompanionSealedClass.SecondObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: InternalSealedAndCompanionSealedClass): + InternalSealedAndCompanionSealedClassEnum = when (obj) { + is InternalSealedAndCompanionSealedClass.FirstObject -> + InternalSealedAndCompanionSealedClassEnum.InternalSealedAndCompanionSealedClass_FirstObject + is InternalSealedAndCompanionSealedClass.SecondObject -> + InternalSealedAndCompanionSealedClassEnum.InternalSealedAndCompanionSealedClass_SecondObject + } + + public override fun enumToSealedObject(`enum`: InternalSealedAndCompanionSealedClassEnum): + InternalSealedAndCompanionSealedClass = when (enum) { + InternalSealedAndCompanionSealedClassEnum.InternalSealedAndCompanionSealedClass_FirstObject -> + InternalSealedAndCompanionSealedClass.FirstObject + InternalSealedAndCompanionSealedClassEnum.InternalSealedAndCompanionSealedClass_SecondObject -> + InternalSealedAndCompanionSealedClass.SecondObject + } +} + +/** + * The index of [this] in the values list. + */ +internal val InternalSealedAndCompanionSealedClass.ordinal: Int + get() = InternalSealedAndCompanionSealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +internal val InternalSealedAndCompanionSealedClass.name: String + get() = InternalSealedAndCompanionSealedClassSealedEnum.nameOf(this) + +/** + * A list of all [InternalSealedAndCompanionSealedClass] objects. + */ +internal val InternalSealedAndCompanionSealedClass.Companion.values: + List + get() = InternalSealedAndCompanionSealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class + * [InternalSealedAndCompanionSealedClass] + */ +internal val InternalSealedAndCompanionSealedClass.Companion.sealedEnum: + InternalSealedAndCompanionSealedClassSealedEnum + get() = InternalSealedAndCompanionSealedClassSealedEnum + +/** + * Returns the [InternalSealedAndCompanionSealedClass] object for the given [name]. + * + * If the given name doesn't correspond to any [InternalSealedAndCompanionSealedClass], an + * [IllegalArgumentException] will be thrown. + */ +internal fun InternalSealedAndCompanionSealedClass.Companion.valueOf(name: String): + InternalSealedAndCompanionSealedClass = + InternalSealedAndCompanionSealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/visibility/PrivateInterfaceSealedClassTests.compilation generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/visibility/PrivateInterfaceSealedClassTests.compilation generates correct code.approved new file mode 100644 index 00000000..770c8dfa --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/visibility/PrivateInterfaceSealedClassTests.compilation generates correct code.approved @@ -0,0 +1,114 @@ +package com.livefront.sealedenum.compilation.visibility + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class [PrivateInterfaceSealedClass] + */ +public enum class PrivateInterfaceSealedClassEnum() { + PrivateInterfaceSealedClass_FirstObject, + PrivateInterfaceSealedClass_SecondObject, +} + +/** + * The isomorphic [PrivateInterfaceSealedClassEnum] for [this]. + */ +public val PrivateInterfaceSealedClass.`enum`: PrivateInterfaceSealedClassEnum + get() = PrivateInterfaceSealedClassSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [PrivateInterfaceSealedClass] for [this]. + */ +public val PrivateInterfaceSealedClassEnum.sealedObject: PrivateInterfaceSealedClass + get() = PrivateInterfaceSealedClassSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class [PrivateInterfaceSealedClass] + */ +public object PrivateInterfaceSealedClassSealedEnum : SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider { + public override val values: List by lazy(mode = + LazyThreadSafetyMode.PUBLICATION) { + listOf( + PrivateInterfaceSealedClass.FirstObject, + PrivateInterfaceSealedClass.SecondObject + ) + } + + + public override val enumClass: KClass + get() = PrivateInterfaceSealedClassEnum::class + + public override fun ordinalOf(obj: PrivateInterfaceSealedClass): Int = when (obj) { + is PrivateInterfaceSealedClass.FirstObject -> 0 + is PrivateInterfaceSealedClass.SecondObject -> 1 + } + + public override fun nameOf(obj: PrivateInterfaceSealedClass): String = when (obj) { + is PrivateInterfaceSealedClass.FirstObject -> "PrivateInterfaceSealedClass_FirstObject" + is PrivateInterfaceSealedClass.SecondObject -> "PrivateInterfaceSealedClass_SecondObject" + } + + public override fun valueOf(name: String): PrivateInterfaceSealedClass = when (name) { + "PrivateInterfaceSealedClass_FirstObject" -> PrivateInterfaceSealedClass.FirstObject + "PrivateInterfaceSealedClass_SecondObject" -> PrivateInterfaceSealedClass.SecondObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override fun sealedObjectToEnum(obj: PrivateInterfaceSealedClass): + PrivateInterfaceSealedClassEnum = when (obj) { + is PrivateInterfaceSealedClass.FirstObject -> + PrivateInterfaceSealedClassEnum.PrivateInterfaceSealedClass_FirstObject + is PrivateInterfaceSealedClass.SecondObject -> + PrivateInterfaceSealedClassEnum.PrivateInterfaceSealedClass_SecondObject + } + + public override fun enumToSealedObject(`enum`: PrivateInterfaceSealedClassEnum): + PrivateInterfaceSealedClass = when (enum) { + PrivateInterfaceSealedClassEnum.PrivateInterfaceSealedClass_FirstObject -> + PrivateInterfaceSealedClass.FirstObject + PrivateInterfaceSealedClassEnum.PrivateInterfaceSealedClass_SecondObject -> + PrivateInterfaceSealedClass.SecondObject + } +} + +/** + * The index of [this] in the values list. + */ +public val PrivateInterfaceSealedClass.ordinal: Int + get() = PrivateInterfaceSealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val PrivateInterfaceSealedClass.name: String + get() = PrivateInterfaceSealedClassSealedEnum.nameOf(this) + +/** + * A list of all [PrivateInterfaceSealedClass] objects. + */ +public val PrivateInterfaceSealedClass.Companion.values: List + get() = PrivateInterfaceSealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class [PrivateInterfaceSealedClass] + */ +public val PrivateInterfaceSealedClass.Companion.sealedEnum: PrivateInterfaceSealedClassSealedEnum + get() = PrivateInterfaceSealedClassSealedEnum + +/** + * Returns the [PrivateInterfaceSealedClass] object for the given [name]. + * + * If the given name doesn't correspond to any [PrivateInterfaceSealedClass], an + * [IllegalArgumentException] will be thrown. + */ +public fun PrivateInterfaceSealedClass.Companion.valueOf(name: String): PrivateInterfaceSealedClass + = PrivateInterfaceSealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/visibility/ProtectedInterfaceSealedClassTests.compilation generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/visibility/ProtectedInterfaceSealedClassTests.compilation generates correct code.approved new file mode 100644 index 00000000..2d36655f --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/visibility/ProtectedInterfaceSealedClassTests.compilation generates correct code.approved @@ -0,0 +1,141 @@ +package com.livefront.sealedenum.compilation.visibility + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class + * [ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass] + */ +public enum class ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassEnum( + sealedObject: ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass, +) : JavaProtectedInterfaceBaseClass.ProtectedInterface by sealedObject { + ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClass_FirstObject(com.livefront.sealedenum.compilation.visibility.ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.FirstObject), + ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClass_SecondObject(com.livefront.sealedenum.compilation.visibility.ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.SecondObject), +} + +/** + * The isomorphic [ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassEnum] for [this]. + */ +public val ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.`enum`: + ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassEnum + get() = + ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic [ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass] for [this]. + */ +public val ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassEnum.sealedObject: + ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass + get() = + ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class + * [ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass] + */ +public object ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassSealedEnum : + SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider + { + public override val values: List by + lazy(mode = LazyThreadSafetyMode.PUBLICATION) { + listOf( + ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.FirstObject, + ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.SecondObject + ) + } + + + public override val enumClass: + KClass + get() = ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassEnum::class + + public override fun ordinalOf(obj: ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass): + Int = when (obj) { + is ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.FirstObject -> 0 + is ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.SecondObject -> 1 + } + + public override fun nameOf(obj: ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass): + String = when (obj) { + is ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.FirstObject -> + "ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClass_FirstObject" + is ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.SecondObject -> + "ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClass_SecondObject" + } + + public override fun valueOf(name: String): + ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass = when (name) { + "ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClass_FirstObject" -> + ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.FirstObject + "ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClass_SecondObject" -> + ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.SecondObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override + fun sealedObjectToEnum(obj: ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass): + ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassEnum = when (obj) { + is ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.FirstObject -> + ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassEnum.ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClass_FirstObject + is ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.SecondObject -> + ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassEnum.ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClass_SecondObject + } + + public override + fun enumToSealedObject(`enum`: ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassEnum): + ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass = when (enum) { + ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassEnum.ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClass_FirstObject -> + ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.FirstObject + ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassEnum.ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClass_SecondObject -> + ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.SecondObject + } +} + +/** + * The index of [this] in the values list. + */ +public val ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.ordinal: Int + get() = ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public val ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.name: String + get() = ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassSealedEnum.nameOf(this) + +/** + * A list of all [ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass] objects. + */ +public val ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.Companion.values: + List + get() = ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class + * [ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass] + */ +public val ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.Companion.sealedEnum: + ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassSealedEnum + get() = ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassSealedEnum + +/** + * Returns the [ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass] object for the given + * [name]. + * + * If the given name doesn't correspond to any + * [ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass], an [IllegalArgumentException] will be + * thrown. + */ +public + fun ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.Companion.valueOf(name: String): + ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass = + ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassSealedEnum.valueOf(name) diff --git a/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/visibility/ProtectedInterfaceSealedClassWithDifferentPackageBaseClassTests.compilation generates correct code.approved b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/visibility/ProtectedInterfaceSealedClassWithDifferentPackageBaseClassTests.compilation generates correct code.approved new file mode 100644 index 00000000..533889ee --- /dev/null +++ b/processing-tests/processor-tests/src/test/kotlin/com/livefront/sealedenum/compilation/visibility/ProtectedInterfaceSealedClassWithDifferentPackageBaseClassTests.compilation generates correct code.approved @@ -0,0 +1,176 @@ +package com.livefront.sealedenum.compilation.visibility + +import com.livefront.sealedenum.EnumForSealedEnumProvider +import com.livefront.sealedenum.SealedEnum +import com.livefront.sealedenum.SealedEnumWithEnumProvider +import kotlin.Int +import kotlin.LazyThreadSafetyMode +import kotlin.String +import kotlin.collections.List +import kotlin.reflect.KClass + +/** + * An isomorphic enum for the sealed class + * [ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass] + */ +public enum class + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassEnum() + { + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClass_FirstObject, + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClass_SecondObject, +} + +/** + * The isomorphic + * [ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassEnum] for + * [this]. + */ +public + val ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.`enum`: + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassEnum + get() = + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassSealedEnum.sealedObjectToEnum(this) + +/** + * The isomorphic + * [ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass] for + * [this]. + */ +public + val ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassEnum.sealedObject: + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass + get() = + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassSealedEnum.enumToSealedObject(this) + +/** + * An implementation of [SealedEnum] for the sealed class + * [ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass] + */ +public object + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassSealedEnum + : + SealedEnum, + SealedEnumWithEnumProvider, + EnumForSealedEnumProvider + { + public override val values: + List + by lazy(mode = LazyThreadSafetyMode.PUBLICATION) { + listOf( + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.FirstObject, + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.SecondObject + ) + } + + + public override val enumClass: + KClass + get() = + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassEnum::class + + public override + fun ordinalOf(obj: ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass): + Int = when (obj) { + is + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.FirstObject -> + 0 + is + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.SecondObject -> + 1 + } + + public override + fun nameOf(obj: ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass): + String = when (obj) { + is + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.FirstObject -> + "ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClass_FirstObject" + is + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.SecondObject -> + "ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClass_SecondObject" + } + + public override fun valueOf(name: String): + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass + = when (name) { + "ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClass_FirstObject" -> + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.FirstObject + "ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClass_SecondObject" -> + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.SecondObject + else -> throw IllegalArgumentException("""No sealed enum constant $name""") + } + + public override + fun sealedObjectToEnum(obj: ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass): + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassEnum + = when (obj) { + is + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.FirstObject -> + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassEnum.ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClass_FirstObject + is + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.SecondObject -> + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassEnum.ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClass_SecondObject + } + + public override + fun enumToSealedObject(`enum`: ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassEnum): + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass + = when (enum) { + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassEnum.ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClass_FirstObject -> + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.FirstObject + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassEnum.ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClass_SecondObject -> + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.SecondObject + } +} + +/** + * The index of [this] in the values list. + */ +public + val ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.ordinal: + Int + get() = + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassSealedEnum.ordinalOf(this) + +/** + * The name of [this] for use with valueOf. + */ +public + val ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.name: + String + get() = + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassSealedEnum.nameOf(this) + +/** + * A list of all + * [ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass] objects. + */ +public + val ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.Companion.values: + List + get() = + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassSealedEnum.values + +/** + * Returns an implementation of [SealedEnum] for the sealed class + * [ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass] + */ +public + val ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.Companion.sealedEnum: + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassSealedEnum + get() = + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassSealedEnum + +/** + * Returns the + * [ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass] object for + * the given [name]. + * + * If the given name doesn't correspond to any + * [ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass], an + * [IllegalArgumentException] will be thrown. + */ +public + fun ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.Companion.valueOf(name: String): + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass = + ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassSealedEnum.valueOf(name)