Merge "Investigating KSP Type Annotation possibility for Room support." into androidx-main
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XAnnotationTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XAnnotationTest.kt
index 78c6bf9..b25e8f1 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XAnnotationTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XAnnotationTest.kt
@@ -92,6 +92,67 @@
}
@Test
+ fun typeParameterAnnotationsOnFunction() {
+ val kotlinSource = Source.kotlin(
+ "foo.bar.Subject.kt",
+ """
+ package foo.bar
+ import kotlin.collections.*
+
+ @Target(AnnotationTarget.TYPE)
+ annotation class SomeAnnotation(val value: String)
+
+ class Subject {
+ fun myFunction(): Map<@SomeAnnotation("someString") Int, Int> {
+ return emptyMap()
+ }
+ }
+ """.trimIndent()
+ )
+ val javaSource = Source.java(
+ "foo.bar.Subject",
+ """
+ package foo.bar;
+ import java.lang.annotation.ElementType;
+ import java.lang.annotation.Target;
+ import java.util.Map;
+ import java.util.HashMap;
+
+ @Target(ElementType.TYPE_USE)
+ @interface SomeAnnotation {
+ String value();
+ }
+
+ class Subject {
+ Map<@SomeAnnotation("someString") Integer, Integer> myFunction() {
+ return new HashMap<>();
+ }
+ }
+ """.trimIndent()
+ )
+
+ listOf(javaSource, kotlinSource).forEach { source ->
+ runTest(
+ sources = listOf(source)
+ ) { invocation ->
+ if (!invocation.isKsp) return@runTest
+ val subject = invocation.processingEnv.requireTypeElement(
+ "foo.bar.Subject")
+ val method = subject.getMethodByJvmName("myFunction")
+ val firstArg = method.returnType.typeArguments.first()
+ val annotation = firstArg.getAllAnnotations().first()
+ assertThat(
+ annotation.name
+ ).isEqualTo("SomeAnnotation")
+
+ assertThat(
+ annotation.annotationValues.first().value
+ ).isEqualTo("someString")
+ }
+ }
+ }
+
+ @Test
fun readsAnnotationsDeclaredInSources() {
val source = Source.kotlin(
"MyClass.kt",