@@ -2,6 +2,7 @@ package dev.kord.codegen.ksp.annotations
22
33import com.google.devtools.ksp.isDefault
44import com.google.devtools.ksp.symbol.KSAnnotation
5+ import com.google.devtools.ksp.symbol.KSClassDeclaration
56import com.google.devtools.ksp.symbol.KSType
67import com.google.devtools.ksp.symbol.KSValueArgument
78import kotlin.reflect.KClass
@@ -74,11 +75,20 @@ public class AnnotationArguments<A : Annotation> private constructor(
7475 parameter.value as KSType ?
7576
7677 @JvmName(" getEnum" )
77- public inline operator fun <reified T : Enum <T >> get (parameter : KProperty1 <A , T >): T ? =
78- (parameter.value as KSType ? )?.let {
79- enumValueOf<T >(it.declaration.simpleName.asString())
78+ public inline operator fun <reified T : Enum <T >> get (parameter : KProperty1 <A , T >): T ? {
79+ val constant = parameter.value ? : return null
80+
81+ val name = when (constant) {
82+ // KSP V1
83+ is KSType -> constant.declaration.simpleName.asString()
84+ // KSP V2
85+ is KSClassDeclaration -> constant.simpleName.asString()
86+ else -> error(" Unexpected type of $constant " )
8087 }
8188
89+ return enumValueOf<T >(name)
90+ }
91+
8292 /* *
8393 * Returns the value of [parameter] as a [List] of [Numbers][Number] or `null` if it is the default value
8494 * (see [NonNullAnnotationArguments] for more information).
@@ -202,7 +212,7 @@ public class AnnotationArguments<A : Annotation> private constructor(
202212
203213 @JvmName(" getEnumArray" )
204214 public inline operator fun <reified T : Enum <T >> get (parameter : KProperty1 <A , Array <out T >>): List <T >? =
205- delegate[parameter]!!
215+ delegate[parameter]
206216
207217 public companion object {
208218 /* *
0 commit comments