Skip to content

Commit

Permalink
Merge branch 'google:main' into mapToJvmClassName
Browse files Browse the repository at this point in the history
  • Loading branch information
bubenheimer committed Mar 8, 2023
2 parents 83271ea + 6f7c046 commit 1ddec60
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
13 changes: 13 additions & 0 deletions api/src/main/kotlin/com/google/devtools/ksp/utils.kt
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)
19 changes: 19 additions & 0 deletions test-utils/testData/api/javaAnnotatedUtil.kt
Expand Up @@ -35,6 +35,9 @@
// Test: ParameterArraysTestAnnotationWithDefaultTest
// IsPresent: class com.google.devtools.ksp.processor.ParameterArraysTestAnnotation
// 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]]
// Test: ParameterArraysTestAnnotationWithSingleAsArrayTest
// IsPresent: class com.google.devtools.ksp.processor.ParameterArraysTestAnnotation
// 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]]
// Test: AnnotationWithinAnAnnotationTest
// IsPresent: class com.google.devtools.ksp.processor.OuterAnnotation
// ByType: com.google.devtools.ksp.processor.OuterAnnotation[innerAnnotation=com.google.devtools.ksp.processor.InnerAnnotation[value=hello from the other side]]
Expand Down Expand Up @@ -164,6 +167,22 @@ public class ParametersTestWithNegativeDefaultsAnnotationTest {}
@Test
public class ParameterArraysTestAnnotationWithDefaultTest {}

@ParameterArraysTestAnnotation(
booleanArrayValue = true,
byteArrayValue = -2,
shortArrayValue = -1,
charArrayValue = 'a',
doubleArrayValue = 1.1,
floatArrayValue = 1.0f,
intArrayValue = 1,
longArrayValue = 1L,
stringArrayValue = "first",
kClassArrayValue = java.lang.Throwable.class,
enumArrayValue = TestEnum.VALUE1
)
@Test
public class ParameterArraysTestAnnotationWithSingleAsArrayTest {}

@OuterAnnotation(innerAnnotation = @InnerAnnotation(value = "hello from the other side"))
@Test
public class AnnotationWithinAnAnnotationTest {}
Expand Down

0 comments on commit 1ddec60

Please sign in to comment.