Skip to content

Commit 1ddec60

Browse files
authored
Merge branch 'google:main' into mapToJvmClassName
2 parents 83271ea + 6f7c046 commit 1ddec60

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

api/src/main/kotlin/com/google/devtools/ksp/utils.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,16 @@ private fun KSAnnotation.createInvocationHandler(clazz: Class<*>): InvocationHan
371371
}
372372
else -> {
373373
when {
374+
// Workaround for java annotation value array type
375+
// https://github.com/google/ksp/issues/1329
376+
method.returnType.isArray -> {
377+
if (result !is Array<*>) {
378+
val value = { result.asArray(method, clazz) }
379+
cache.getOrPut(Pair(method.returnType, value), value)
380+
} else {
381+
throw IllegalStateException("unhandled value type, $ExceptionMessage")
382+
}
383+
}
374384
method.returnType.isEnum -> {
375385
val value = { result.asEnum(method.returnType) }
376386
cache.getOrPut(Pair(method.returnType, result), value)
@@ -517,3 +527,6 @@ private fun List<KSType>.asClasses(proxyClass: Class<*>) = try {
517527
}
518528

519529
fun KSValueArgument.isDefault() = origin == Origin.SYNTHETIC
530+
531+
@KspExperimental
532+
private fun Any.asArray(method: Method, proxyClass: Class<*>) = listOf(this).asArray(method, proxyClass)

test-utils/testData/api/javaAnnotatedUtil.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
// Test: ParameterArraysTestAnnotationWithDefaultTest
3636
// IsPresent: class com.google.devtools.ksp.processor.ParameterArraysTestAnnotation
3737
// ByType: ParameterArraysTestAnnotation[booleanArrayValue=[true, false],byteArrayValue=[-2, 4],shortArrayValue=[-1, 2, 3],charArrayValue=[a, b, c],doubleArrayValue=[1.1, 2.2, 3.3],floatArrayValue=[1.0, 2.0, 3.3],intArrayValue=[1, 2, 4, 8, 16],longArrayValue=[1, 2, 4, 8, 16, 32],stringArrayValue=[first, second, third],kClassArrayValue=[class kotlin.Throwable, class com.google.devtools.ksp.processor.ParametersTestAnnotation],enumArrayValue=[VALUE1, VALUE2, VALUE1, VALUE2]]
38+
// Test: ParameterArraysTestAnnotationWithSingleAsArrayTest
39+
// IsPresent: class com.google.devtools.ksp.processor.ParameterArraysTestAnnotation
40+
// ByType: ParameterArraysTestAnnotation[booleanArrayValue=[true],byteArrayValue=[-2],shortArrayValue=[-1],charArrayValue=[a],doubleArrayValue=[1.1],floatArrayValue=[1.0],intArrayValue=[1],longArrayValue=[1],stringArrayValue=[first],kClassArrayValue=[class kotlin.Throwable],enumArrayValue=[VALUE1]]
3841
// Test: AnnotationWithinAnAnnotationTest
3942
// IsPresent: class com.google.devtools.ksp.processor.OuterAnnotation
4043
// ByType: com.google.devtools.ksp.processor.OuterAnnotation[innerAnnotation=com.google.devtools.ksp.processor.InnerAnnotation[value=hello from the other side]]
@@ -164,6 +167,22 @@ public class ParametersTestWithNegativeDefaultsAnnotationTest {}
164167
@Test
165168
public class ParameterArraysTestAnnotationWithDefaultTest {}
166169

170+
@ParameterArraysTestAnnotation(
171+
booleanArrayValue = true,
172+
byteArrayValue = -2,
173+
shortArrayValue = -1,
174+
charArrayValue = 'a',
175+
doubleArrayValue = 1.1,
176+
floatArrayValue = 1.0f,
177+
intArrayValue = 1,
178+
longArrayValue = 1L,
179+
stringArrayValue = "first",
180+
kClassArrayValue = java.lang.Throwable.class,
181+
enumArrayValue = TestEnum.VALUE1
182+
)
183+
@Test
184+
public class ParameterArraysTestAnnotationWithSingleAsArrayTest {}
185+
167186
@OuterAnnotation(innerAnnotation = @InnerAnnotation(value = "hello from the other side"))
168187
@Test
169188
public class AnnotationWithinAnAnnotationTest {}

0 commit comments

Comments
 (0)