Merge "Fix KSTypeVarianceResolver for raw TypeName" into androidx-main am: c0fd42a878
Original change: https://android-review.googlesource.com/c/platform/frameworks/support/+/2595706
Change-Id: I7a5754f3a68ba21d327ba462994cc4eee89540e7
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KSTypeVarianceResolver.kt b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KSTypeVarianceResolver.kt
index 2687c5e..ca11a18 100644
--- a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KSTypeVarianceResolver.kt
+++ b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KSTypeVarianceResolver.kt
@@ -51,7 +51,9 @@
*/
@OptIn(KspExperimental::class)
fun applyTypeVariance(type: KSType, scope: KSTypeVarianceResolverScope?): KSType {
- if (type.isError || scope?.needsWildcardResolution == false) {
+ if (type.isError ||
+ resolver.isJavaRawType(type) ||
+ scope?.needsWildcardResolution == false) {
// There's nothing to resolve in this case, so just return the original type.
return type
}
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XTypeTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XTypeTest.kt
index 12b61d7..babbadec 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XTypeTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XTypeTest.kt
@@ -67,9 +67,11 @@
package foo.bar;
import java.io.InputStream;
import java.util.Set;
+ import java.util.List;
class Parent<InputStreamType extends InputStream> {
public void wildcardParam(Set<?> param1) {}
- public void rawTypeParam(Set param1) {}
+ public void rawParamType(Set param1) {}
+ public void rawParamTypeArgument(List<Set> param1) {}
}
""".trimIndent()
)
@@ -145,9 +147,42 @@
)
}
}
- type.typeElement!!.getMethodByJvmName("rawTypeParam").let { method ->
- val rawTypeParam = method.parameters.first()
- assertThat(rawTypeParam.type.typeArguments).isEmpty()
+ type.typeElement!!.getMethodByJvmName("rawParamType").let { method ->
+ val rawParamType = method.parameters.first()
+ assertThat(rawParamType.type.typeArguments).isEmpty()
+ assertThat(rawParamType.type.asTypeName().java).isEqualTo(
+ JClassName.get("java.util", "Set")
+ )
+ if (it.isKsp) {
+ assertThat(rawParamType.type.asTypeName().kotlin).isEqualTo(
+ KClassName("kotlin.collections", "MutableSet")
+ )
+ }
+ }
+ type.typeElement!!.getMethodByJvmName("rawParamTypeArgument").let { method ->
+ val rawParamTypeArgument = method.parameters.first()
+ assertThat(rawParamTypeArgument.type.asTypeName().java).isEqualTo(
+ JParameterizedTypeName.get(
+ JClassName.get("java.util", "List"),
+ JClassName.get("java.util", "Set"),
+ )
+ )
+ if (it.isKsp) {
+ assertThat(rawParamTypeArgument.type.asTypeName().kotlin).isEqualTo(
+ KClassName("kotlin.collections", "MutableList").parameterizedBy(
+ KClassName("kotlin.collections", "MutableSet")
+ )
+ )
+ }
+ val rawTypeArgument = rawParamTypeArgument.type.typeArguments.single()
+ assertThat(rawTypeArgument.asTypeName().java).isEqualTo(
+ JClassName.get("java.util", "Set")
+ )
+ if (it.isKsp) {
+ assertThat(rawTypeArgument.asTypeName().kotlin).isEqualTo(
+ KClassName("kotlin.collections", "MutableSet")
+ )
+ }
}
}
}