Skip to content

Commit

Permalink
Get AnnotationByType's invocation handler supports java array value
Browse files Browse the repository at this point in the history
  • Loading branch information
larryxiao625 authored and neetopia committed Mar 3, 2023
1 parent 3b020dc commit d565abd
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions api/src/main/kotlin/com/google/devtools/ksp/utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,16 @@ private fun KSAnnotation.createInvocationHandler(clazz: Class<*>): InvocationHan
}
else -> {
when {
// Workaround for java annotation value array type
// https://github.com/google/ksp/issues/1329
method.returnType.isArray -> {
if (result !is Array<*>) {
val value = { result.asArray(method, clazz) }
cache.getOrPut(Pair(method.returnType, value), value)
} else {
throw IllegalStateException("unhandled value type, $ExceptionMessage")
}
}
method.returnType.isEnum -> {
val value = { result.asEnum(method.returnType) }
cache.getOrPut(Pair(method.returnType, result), value)
Expand Down Expand Up @@ -517,3 +527,6 @@ private fun List<KSType>.asClasses(proxyClass: Class<*>) = try {
}

fun KSValueArgument.isDefault() = origin == Origin.SYNTHETIC

@KspExperimental
private fun Any.asArray(method: Method, proxyClass: Class<*>) = listOf(this).asArray(method, proxyClass)

0 comments on commit d565abd

Please sign in to comment.