Add TypeArgument check on PagingSource's Value arg

Throws compiler error message if the PagingSource's Value argument is of
java.util.Collection type

Bug: 192074940
Test: ./gradlew :room:room-compiler:test
Change-Id: I3416fb182d6b148a084ce2620c0ef56f269a33bb
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/processor/ProcessorErrors.kt b/room/room-compiler/src/main/kotlin/androidx/room/processor/ProcessorErrors.kt
index c520c32..c9b955e 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/processor/ProcessorErrors.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/processor/ProcessorErrors.kt
@@ -611,6 +611,9 @@
     val PAGING_SPECIFY_PAGING_SOURCE_TYPE = "For now, Room only supports PagingSource with Key of" +
         " type Int."
 
+    val PAGING_SPECIFY_PAGING_SOURCE_VALUE_TYPE = "For now, Room only supports PagingSource with" +
+        " Value that is not of Collection type."
+
     fun primaryKeyNull(field: String): String {
         return "You must annotate primary keys with @NonNull. \"$field\" is nullable. SQLite " +
             "considers this a " +
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/solver/binderprovider/PagingSourceQueryResultBinderProvider.kt b/room/room-compiler/src/main/kotlin/androidx/room/solver/binderprovider/PagingSourceQueryResultBinderProvider.kt
index ce3267f..45b5e5b 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/solver/binderprovider/PagingSourceQueryResultBinderProvider.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/solver/binderprovider/PagingSourceQueryResultBinderProvider.kt
@@ -69,6 +69,8 @@
     }
 
     override fun matches(declared: XType): Boolean {
+        val collectionTypeRaw = context.COMMON_TYPES.READONLY_COLLECTION.rawType
+
         if (pagingSourceType == null) {
             return false
         }
@@ -85,6 +87,10 @@
             context.logger.e(ProcessorErrors.PAGING_SPECIFY_PAGING_SOURCE_TYPE)
         }
 
+        if (collectionTypeRaw.isAssignableFrom(declared.typeArguments.last().rawType)) {
+            context.logger.e(ProcessorErrors.PAGING_SPECIFY_PAGING_SOURCE_VALUE_TYPE)
+        }
+
         return true
     }
 }
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/solver/TypeAdapterStoreTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/solver/TypeAdapterStoreTest.kt
index b881c96..4b7ebf6 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/solver/TypeAdapterStoreTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/solver/TypeAdapterStoreTest.kt
@@ -801,6 +801,89 @@
     }
 
     @Test
+    fun findPagingSourceJavaCollectionValue() {
+        runProcessorTest { invocation ->
+            val pagingSourceElement = invocation.processingEnv
+                .requireTypeElement(PagingSource::class)
+            val intType = invocation.processingEnv.requireType(Integer::class)
+            val collectionType = invocation.processingEnv.requireType("java.util.Collection")
+            val pagingSourceIntCollectionType = invocation.processingEnv
+                .getDeclaredType(pagingSourceElement, intType, collectionType)
+
+            assertThat(pagingSourceIntCollectionType).isNotNull()
+            assertThat(
+                PagingSourceQueryResultBinderProvider(invocation.context)
+                    .matches(pagingSourceIntCollectionType)
+            ).isTrue()
+            invocation.assertCompilationResult {
+                hasError(ProcessorErrors.PAGING_SPECIFY_PAGING_SOURCE_VALUE_TYPE)
+            }
+        }
+    }
+
+    @Test
+    fun findPagingSourceKotlinCollectionValue() {
+        runProcessorTest { invocation ->
+            val pagingSourceElement = invocation.processingEnv
+                .requireTypeElement(PagingSource::class)
+            val intType = invocation.processingEnv.requireType(Integer::class)
+            val kotlinCollectionType = invocation.processingEnv.requireType(Collection::class)
+            val pagingSourceIntCollectionType = invocation.processingEnv
+                .getDeclaredType(pagingSourceElement, intType, kotlinCollectionType)
+
+            assertThat(pagingSourceIntCollectionType).isNotNull()
+            assertThat(
+                PagingSourceQueryResultBinderProvider(invocation.context)
+                    .matches(pagingSourceIntCollectionType)
+            ).isTrue()
+            invocation.assertCompilationResult {
+                hasError(ProcessorErrors.PAGING_SPECIFY_PAGING_SOURCE_VALUE_TYPE)
+            }
+        }
+    }
+
+    @Test
+    fun findPagingSourceJavaListValue() {
+        runProcessorTest { invocation ->
+            val pagingSourceElement = invocation.processingEnv
+                .requireTypeElement(PagingSource::class)
+            val intType = invocation.processingEnv.requireType(Integer::class)
+            val javaListType = invocation.processingEnv.requireType("java.util.List")
+            val pagingSourceIntListType = invocation.processingEnv
+                .getDeclaredType(pagingSourceElement, intType, javaListType)
+            assertThat(pagingSourceIntListType).isNotNull()
+            assertThat(
+                PagingSourceQueryResultBinderProvider(invocation.context)
+                    .matches(pagingSourceIntListType)
+            ).isTrue()
+            invocation.assertCompilationResult {
+                hasError(ProcessorErrors.PAGING_SPECIFY_PAGING_SOURCE_VALUE_TYPE)
+            }
+        }
+    }
+
+    @Test
+    fun findPagingSourceKotlinMutableSetValue() {
+        runProcessorTest { invocation ->
+            val pagingSourceElement = invocation.processingEnv
+                .requireTypeElement(PagingSource::class)
+            val intType = invocation.processingEnv.requireType(Integer::class)
+            val mutableSetType = invocation.processingEnv.requireType(MutableSet::class)
+            val pagingSourceIntCollectionType = invocation.processingEnv
+                .getDeclaredType(pagingSourceElement, intType, mutableSetType)
+
+            assertThat(pagingSourceIntCollectionType).isNotNull()
+            assertThat(
+                PagingSourceQueryResultBinderProvider(invocation.context)
+                    .matches(pagingSourceIntCollectionType)
+            ).isTrue()
+            invocation.assertCompilationResult {
+                hasError(ProcessorErrors.PAGING_SPECIFY_PAGING_SOURCE_VALUE_TYPE)
+            }
+        }
+    }
+
+    @Test
     fun testNewPagingSourceBinder() {
         val inputSource =
             Source.java(