Optimization for finding delegating methods.
Optimize Dao Processor to not find Kotlin Boxed Delegating Methods if the Dao is not extending an class or implementing an interface.
Test: Baseline tests replicate compiler errors in DaoPrimitiveTest.kt
Bug: 169950251
Change-Id: I0cf8d34eced96f7513ffe020469e85b6a0e1e98f
diff --git a/room/compiler/src/main/kotlin/androidx/room/processor/DaoProcessor.kt b/room/compiler/src/main/kotlin/androidx/room/processor/DaoProcessor.kt
index 848239d..d6769c1 100644
--- a/room/compiler/src/main/kotlin/androidx/room/processor/DaoProcessor.kt
+++ b/room/compiler/src/main/kotlin/androidx/room/processor/DaoProcessor.kt
@@ -142,14 +142,21 @@
).process()
}
- // TODO (b/169950251): avoid going through the matching logic if the interface does not
- // extend another one
+ // Only try to find kotlin boxed delegating methods when the dao extends a class or
+ // implements an interface since otherwise there are no duplicated method generated by
+ // Kotlin.
val unannotatedMethods = methods[Any::class] ?: emptyList<XMethodElement>()
- val allAnnotatedMethods = methods.values.flatten() - unannotatedMethods
- val delegatingMethods = matchKotlinBoxedPrimitiveMethods(
- unannotatedMethods,
- annotatedMethods = allAnnotatedMethods
- )
+ val delegatingMethods =
+ if (element.superType != null ||
+ element.getSuperInterfaceElements().isNotEmpty()
+ ) {
+ matchKotlinBoxedPrimitiveMethods(
+ unannotatedMethods,
+ methods.values.flatten() - unannotatedMethods
+ )
+ } else {
+ emptyList()
+ }
val kotlinDefaultMethodDelegates = if (element.isInterface()) {
val allProcessedMethods =
@@ -181,16 +188,16 @@
null
}
- (unannotatedMethods - delegatingMethods.map { it.element }).forEach { method ->
- context.logger.e(method, ProcessorErrors.INVALID_ANNOTATION_COUNT_IN_DAO_METHOD)
- }
-
val type = declaredType.typeName
context.checker.notUnbound(
type, element,
ProcessorErrors.CANNOT_USE_UNBOUND_GENERICS_IN_DAO_CLASSES
)
+ (unannotatedMethods - delegatingMethods.map { it.element }).forEach { method ->
+ context.logger.e(method, ProcessorErrors.INVALID_ANNOTATION_COUNT_IN_DAO_METHOD)
+ }
+
return Dao(
element = element,
type = declaredType,