Skip to content

Commit

Permalink
Merge pull request #128 from livefront/av/class-to-kclass
Browse files Browse the repository at this point in the history
Convert Class to KClass
  • Loading branch information
alexvanyo authored Apr 7, 2023
2 parents b28e64e + 62af418 commit 12257ab
Show file tree
Hide file tree
Showing 38 changed files with 143 additions and 138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.squareup.kotlinpoet.TypeSpec
import com.squareup.kotlinpoet.asClassName
import com.squareup.kotlinpoet.buildCodeBlock
import javax.lang.model.element.TypeElement
import kotlin.reflect.KClass

/**
* A builder for a [SealedEnum] object for the given [sealedClass].
Expand Down Expand Up @@ -212,13 +213,13 @@ internal data class SealedEnumTypeSpec(
.build()

private fun createEnumClassGetter(enumForSealedEnum: ClassName): PropertySpec {
val parameterizedClass = Class::class.asClassName().parameterizedBy(enumForSealedEnum)
val parameterizedClass = KClass::class.asClassName().parameterizedBy(enumForSealedEnum)

return PropertySpec.builder("enumClass", parameterizedClass)
.addModifiers(KModifier.OVERRIDE)
.getter(
FunSpec.getterBuilder()
.addStatement("return %T::class.java", enumForSealedEnum)
.addStatement("return %T::class", enumForSealedEnum)
.build()
)
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ package com.livefront.sealedenum.compilation.basic
import com.livefront.sealedenum.EnumForSealedEnumProvider
import com.livefront.sealedenum.SealedEnum
import com.livefront.sealedenum.SealedEnumWithEnumProvider
import java.lang.Class
import kotlin.Int
import kotlin.String
import kotlin.collections.List
import kotlin.reflect.KClass
/**
* An isomorphic enum for the sealed class [EmptySealedClass]
Expand Down Expand Up @@ -46,8 +46,8 @@ public object EmptySealedClassSealedEnum : SealedEnum<EmptySealedClass>,
public override val values: List<EmptySealedClass> = emptyList()
public override val enumClass: Class<EmptySealedClassEnum>
get() = EmptySealedClassEnum::class.java
public override val enumClass: KClass<EmptySealedClassEnum>
get() = EmptySealedClassEnum::class
public override fun ordinalOf(obj: EmptySealedClass): Int = throw
AssertionError("Constructing a EmptySealedClass is impossible, since it has no sealed subclasses")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class EmptySealedClassTests {

@Test
fun `correct enum class`() {
assertEquals(EmptySealedClassEnum::class.java, EmptySealedClass.sealedEnum.enumClass)
assertEquals(EmptySealedClassEnum::class, EmptySealedClass.sealedEnum.enumClass)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ package com.livefront.sealedenum.compilation.basic
import com.livefront.sealedenum.EnumForSealedEnumProvider
import com.livefront.sealedenum.SealedEnum
import com.livefront.sealedenum.SealedEnumWithEnumProvider
import java.lang.Class
import kotlin.Int
import kotlin.String
import kotlin.collections.List
import kotlin.reflect.KClass
/**
* An isomorphic enum for the sealed class [EmptySealedInterface]
Expand Down Expand Up @@ -46,8 +46,8 @@ public object EmptySealedInterfaceSealedEnum : SealedEnum<EmptySealedInterface>,
public override val values: List<EmptySealedInterface> = emptyList()
public override val enumClass: Class<EmptySealedInterfaceEnum>
get() = EmptySealedInterfaceEnum::class.java
public override val enumClass: KClass<EmptySealedInterfaceEnum>
get() = EmptySealedInterfaceEnum::class
public override fun ordinalOf(obj: EmptySealedInterface): Int = throw
AssertionError("Constructing a EmptySealedInterface is impossible, since it has no sealed subclasses")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class EmptySealedInterfaceTests {

@Test
fun `correct enum class`() {
assertEquals(EmptySealedInterfaceEnum::class.java, EmptySealedInterface.sealedEnum.enumClass)
assertEquals(EmptySealedInterfaceEnum::class, EmptySealedInterface.sealedEnum.enumClass)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ package com.livefront.sealedenum.compilation.basic
import com.livefront.sealedenum.EnumForSealedEnumProvider
import com.livefront.sealedenum.SealedEnum
import com.livefront.sealedenum.SealedEnumWithEnumProvider
import java.lang.Class
import kotlin.Int
import kotlin.String
import kotlin.collections.List
import kotlin.reflect.KClass
/**
* An isomorphic enum for the sealed class [OneObjectSealedClass]
Expand Down Expand Up @@ -52,8 +52,8 @@ public object OneObjectSealedClassSealedEnum : SealedEnum<OneObjectSealedClass>,
)
public override val enumClass: Class<OneObjectSealedClassEnum>
get() = OneObjectSealedClassEnum::class.java
public override val enumClass: KClass<OneObjectSealedClassEnum>
get() = OneObjectSealedClassEnum::class
public override fun ordinalOf(obj: OneObjectSealedClass): Int = when (obj) {
OneObjectSealedClass.FirstObject -> 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class OneObjectSealedClassTests {

@Test
fun `correct enum class`() {
assertEquals(OneObjectSealedClassEnum::class.java, OneObjectSealedClass.sealedEnum.enumClass)
assertEquals(OneObjectSealedClassEnum::class, OneObjectSealedClass.sealedEnum.enumClass)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ package com.livefront.sealedenum.compilation.basic
import com.livefront.sealedenum.EnumForSealedEnumProvider
import com.livefront.sealedenum.SealedEnum
import com.livefront.sealedenum.SealedEnumWithEnumProvider
import java.lang.Class
import kotlin.Int
import kotlin.String
import kotlin.collections.List
import kotlin.reflect.KClass
/**
* An isomorphic enum for the sealed class [OneObjectSealedInterface]
Expand Down Expand Up @@ -52,8 +52,8 @@ public object OneObjectSealedInterfaceSealedEnum : SealedEnum<OneObjectSealedInt
)
public override val enumClass: Class<OneObjectSealedInterfaceEnum>
get() = OneObjectSealedInterfaceEnum::class.java
public override val enumClass: KClass<OneObjectSealedInterfaceEnum>
get() = OneObjectSealedInterfaceEnum::class
public override fun ordinalOf(obj: OneObjectSealedInterface): Int = when (obj) {
OneObjectSealedInterface.FirstObject -> 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class OneObjectSealedInterfaceTests {

@Test
fun `correct enum class`() {
assertEquals(OneObjectSealedInterfaceEnum::class.java, OneObjectSealedInterface.sealedEnum.enumClass)
assertEquals(OneObjectSealedInterfaceEnum::class, OneObjectSealedInterface.sealedEnum.enumClass)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ package com.livefront.sealedenum.compilation.basic
import com.livefront.sealedenum.EnumForSealedEnumProvider
import com.livefront.sealedenum.SealedEnum
import com.livefront.sealedenum.SealedEnumWithEnumProvider
import java.lang.Class
import kotlin.Int
import kotlin.String
import kotlin.collections.List
import kotlin.reflect.KClass
/**
* An isomorphic enum for the sealed class [TwoObjectSealedClass]
Expand Down Expand Up @@ -56,8 +56,8 @@ public object TwoObjectSealedClassSealedEnum : SealedEnum<TwoObjectSealedClass>,
)
public override val enumClass: Class<TwoObjectSealedClassEnum>
get() = TwoObjectSealedClassEnum::class.java
public override val enumClass: KClass<TwoObjectSealedClassEnum>
get() = TwoObjectSealedClassEnum::class
public override fun ordinalOf(obj: TwoObjectSealedClass): Int = when (obj) {
TwoObjectSealedClass.FirstObject -> 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class TwoObjectSealedClassTests {

@Test
fun `correct enum class`() {
assertEquals(TwoObjectSealedClassEnum::class.java, TwoObjectSealedClassSealedEnum.enumClass)
assertEquals(TwoObjectSealedClassEnum::class, TwoObjectSealedClassSealedEnum.enumClass)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ package com.livefront.sealedenum.compilation.basic
import com.livefront.sealedenum.EnumForSealedEnumProvider
import com.livefront.sealedenum.SealedEnum
import com.livefront.sealedenum.SealedEnumWithEnumProvider
import java.lang.Class
import kotlin.Int
import kotlin.String
import kotlin.collections.List
import kotlin.reflect.KClass
/**
* An isomorphic enum for the sealed class [TwoObjectSealedInterface]
Expand Down Expand Up @@ -56,8 +56,8 @@ public object TwoObjectSealedInterfaceSealedEnum : SealedEnum<TwoObjectSealedInt
)
public override val enumClass: Class<TwoObjectSealedInterfaceEnum>
get() = TwoObjectSealedInterfaceEnum::class.java
public override val enumClass: KClass<TwoObjectSealedInterfaceEnum>
get() = TwoObjectSealedInterfaceEnum::class
public override fun ordinalOf(obj: TwoObjectSealedInterface): Int = when (obj) {
TwoObjectSealedInterface.FirstObject -> 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class TwoObjectSealedInterfaceTests {

@Test
fun `correct enum class`() {
assertEquals(TwoObjectSealedInterfaceEnum::class.java, TwoObjectSealedInterface.sealedEnum.enumClass)
assertEquals(TwoObjectSealedInterfaceEnum::class, TwoObjectSealedInterface.sealedEnum.enumClass)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ package com.livefront.sealedenum.compilation.generics
import com.livefront.sealedenum.EnumForSealedEnumProvider
import com.livefront.sealedenum.SealedEnum
import com.livefront.sealedenum.SealedEnumWithEnumProvider
import java.lang.Class
import kotlin.Int
import kotlin.String
import kotlin.collections.List
import kotlin.reflect.KClass
/**
* An isomorphic enum for the sealed class [OneTypeParameterSealedClass]
Expand Down Expand Up @@ -62,8 +62,8 @@ public object OneTypeParameterSealedClassSealedEnum : SealedEnum<OneTypeParamete
)
public override val enumClass: Class<OneTypeParameterSealedClassEnum>
get() = OneTypeParameterSealedClassEnum::class.java
public override val enumClass: KClass<OneTypeParameterSealedClassEnum>
get() = OneTypeParameterSealedClassEnum::class
public override fun ordinalOf(obj: OneTypeParameterSealedClass<*>): Int = when (obj) {
OneTypeParameterSealedClass.FirstObject -> 0
Expand Down Expand Up @@ -158,10 +158,10 @@ package com.livefront.sealedenum.compilation.generics
import com.livefront.sealedenum.EnumForSealedEnumProvider
import com.livefront.sealedenum.SealedEnum
import com.livefront.sealedenum.SealedEnumWithEnumProvider
import java.lang.Class
import kotlin.Int
import kotlin.String
import kotlin.collections.List
import kotlin.reflect.KClass
/**
* An isomorphic enum for the sealed class [TwoTypeParameterSealedClass]
Expand Down Expand Up @@ -196,8 +196,8 @@ public object TwoTypeParameterSealedClassSealedEnum : SealedEnum<TwoTypeParamete
)
public override val enumClass: Class<TwoTypeParameterSealedClassEnum>
get() = TwoTypeParameterSealedClassEnum::class.java
public override val enumClass: KClass<TwoTypeParameterSealedClassEnum>
get() = TwoTypeParameterSealedClassEnum::class
public override fun ordinalOf(obj: TwoTypeParameterSealedClass<*, *>): Int = when (obj) {
TwoTypeParameterSealedClass.FirstObject -> 0
Expand Down Expand Up @@ -285,10 +285,10 @@ package com.livefront.sealedenum.compilation.generics
import com.livefront.sealedenum.EnumForSealedEnumProvider
import com.livefront.sealedenum.SealedEnum
import com.livefront.sealedenum.SealedEnumWithEnumProvider
import java.lang.Class
import kotlin.Int
import kotlin.String
import kotlin.collections.List
import kotlin.reflect.KClass
/**
* An isomorphic enum for the sealed class [LimitedTypeParameterSealedClass]
Expand Down Expand Up @@ -324,8 +324,8 @@ public object LimitedTypeParameterSealedClassSealedEnum :
)
public override val enumClass: Class<LimitedTypeParameterSealedClassEnum>
get() = LimitedTypeParameterSealedClassEnum::class.java
public override val enumClass: KClass<LimitedTypeParameterSealedClassEnum>
get() = LimitedTypeParameterSealedClassEnum::class
public override fun ordinalOf(obj: LimitedTypeParameterSealedClass<*, *>): Int = when (obj) {
LimitedTypeParameterSealedClass.FirstObject -> 0
Expand Down Expand Up @@ -420,10 +420,10 @@ package com.livefront.sealedenum.compilation.generics
import com.livefront.sealedenum.EnumForSealedEnumProvider
import com.livefront.sealedenum.SealedEnum
import com.livefront.sealedenum.SealedEnumWithEnumProvider
import java.lang.Class
import kotlin.Int
import kotlin.String
import kotlin.collections.List
import kotlin.reflect.KClass
/**
* An isomorphic enum for the sealed class [MultipleBoundsSealedClass]
Expand Down Expand Up @@ -455,8 +455,8 @@ public object MultipleBoundsSealedClassSealedEnum : SealedEnum<MultipleBoundsSea
)
public override val enumClass: Class<MultipleBoundsSealedClassEnum>
get() = MultipleBoundsSealedClassEnum::class.java
public override val enumClass: KClass<MultipleBoundsSealedClassEnum>
get() = MultipleBoundsSealedClassEnum::class
public override fun ordinalOf(obj: MultipleBoundsSealedClass<*>): Int = when (obj) {
MultipleBoundsSealedClass.FirstObject -> 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ package com.livefront.sealedenum.compilation.generics
import com.livefront.sealedenum.EnumForSealedEnumProvider
import com.livefront.sealedenum.SealedEnum
import com.livefront.sealedenum.SealedEnumWithEnumProvider
import java.lang.Class
import kotlin.Any
import kotlin.Int
import kotlin.String
import kotlin.collections.List
import kotlin.reflect.KClass
/**
* An isomorphic enum for the sealed class [SealedEnumWithAbstractBaseClasses]
Expand Down Expand Up @@ -64,8 +64,8 @@ public object SealedEnumWithAbstractBaseClassesSealedEnum :
public override val values: List<SealedEnumWithAbstractBaseClasses> = emptyList()
public override val enumClass: Class<SealedEnumWithAbstractBaseClassesEnum>
get() = SealedEnumWithAbstractBaseClassesEnum::class.java
public override val enumClass: KClass<SealedEnumWithAbstractBaseClassesEnum>
get() = SealedEnumWithAbstractBaseClassesEnum::class
public override fun ordinalOf(obj: SealedEnumWithAbstractBaseClasses): Int = throw
AssertionError("Constructing a SealedEnumWithAbstractBaseClasses is impossible, since it has no sealed subclasses")
Expand Down Expand Up @@ -140,10 +140,10 @@ package com.livefront.sealedenum.compilation.generics
import com.livefront.sealedenum.EnumForSealedEnumProvider
import com.livefront.sealedenum.SealedEnum
import com.livefront.sealedenum.SealedEnumWithEnumProvider
import java.lang.Class
import kotlin.Int
import kotlin.String
import kotlin.collections.List
import kotlin.reflect.KClass
/**
* An isomorphic enum for the sealed class [SealedEnumWithAbstractBaseClassesCovariantType]
Expand Down Expand Up @@ -179,8 +179,8 @@ public object SealedEnumWithAbstractBaseClassesCovariantTypeSealedEnum :
emptyList()
public override val enumClass: Class<SealedEnumWithAbstractBaseClassesCovariantTypeEnum>
get() = SealedEnumWithAbstractBaseClassesCovariantTypeEnum::class.java
public override val enumClass: KClass<SealedEnumWithAbstractBaseClassesCovariantTypeEnum>
get() = SealedEnumWithAbstractBaseClassesCovariantTypeEnum::class
public override fun ordinalOf(obj: SealedEnumWithAbstractBaseClassesCovariantType<*>): Int =
throw
Expand Down
Loading

0 comments on commit 12257ab

Please sign in to comment.