Merge "Remove XElement.asDeclaredType" into androidx-main
diff --git a/room/compiler-processing/src/main/java/androidx/room/compiler/processing/XElement.kt b/room/compiler-processing/src/main/java/androidx/room/compiler/processing/XElement.kt
index 0eef86b..77fc091 100644
--- a/room/compiler-processing/src/main/java/androidx/room/compiler/processing/XElement.kt
+++ b/room/compiler-processing/src/main/java/androidx/room/compiler/processing/XElement.kt
@@ -31,14 +31,6 @@
      * Returns the string representation of the Element's kind.
      */
     fun kindName(): String
-    /**
-     * Returns the [XDeclaredType] type of the current element, assuming it is an [XTypeElement].
-     * It is a shortcut for `asTypeElement().type`.
-     */
-    fun asDeclaredType(): XDeclaredType {
-        // this will be removed b/175417726
-        return (this as XTypeElement).type
-    }
 }
 
 /**
diff --git a/room/compiler-processing/src/test/java/androidx/room/compiler/processing/XProcessingEnvTest.kt b/room/compiler-processing/src/test/java/androidx/room/compiler/processing/XProcessingEnvTest.kt
index 2f92301..517f14c 100644
--- a/room/compiler-processing/src/test/java/androidx/room/compiler/processing/XProcessingEnvTest.kt
+++ b/room/compiler-processing/src/test/java/androidx/room/compiler/processing/XProcessingEnvTest.kt
@@ -116,7 +116,7 @@
             val element = it.processingEnv.requireTypeElement("foo.bar.Baz")
             assertThat(element.packageName).isEqualTo("foo.bar")
             assertThat(element.name).isEqualTo("Baz")
-            assertThat(element.asDeclaredType().typeName)
+            assertThat(element.className)
                 .isEqualTo(ClassName.get("foo.bar", "Baz"))
             assertThat(element.findPrimaryConstructor()).isNull()
             assertThat(element.getConstructors()).hasSize(1)
diff --git a/room/compiler/src/main/kotlin/androidx/room/processor/CustomConverterProcessor.kt b/room/compiler/src/main/kotlin/androidx/room/processor/CustomConverterProcessor.kt
index d8a4bc2..b7b237c 100644
--- a/room/compiler/src/main/kotlin/androidx/room/processor/CustomConverterProcessor.kt
+++ b/room/compiler/src/main/kotlin/androidx/room/processor/CustomConverterProcessor.kt
@@ -75,12 +75,10 @@
     fun process(): List<CustomTypeConverter> {
         // using element utils instead of MoreElements to include statics.
         val methods = element.getAllMethods()
-        val declaredType = element.asDeclaredType()
         val converterMethods = methods.filter {
             it.hasAnnotation(TypeConverter::class)
         }
-        val isProvidedConverter = declaredType.asTypeElement()
-            .hasAnnotation(ProvidedTypeConverter::class)
+        val isProvidedConverter = element.hasAnnotation(ProvidedTypeConverter::class)
         context.checker.check(converterMethods.isNotEmpty(), element, TYPE_CONVERTER_EMPTY_CLASS)
         val allStatic = converterMethods.all { it.isStatic() }
         val constructors = element.getConstructors()
@@ -96,7 +94,7 @@
         }
         return converterMethods.mapNotNull {
             processMethod(
-                container = declaredType,
+                container = element.type,
                 isContainerKotlinObject = isKotlinObjectDeclaration,
                 methodElement = it,
                 isProvidedConverter = isProvidedConverter
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 d6769c1..3eacaa3 100644
--- a/room/compiler/src/main/kotlin/androidx/room/processor/DaoProcessor.kt
+++ b/room/compiler/src/main/kotlin/androidx/room/processor/DaoProcessor.kt
@@ -57,7 +57,7 @@
             element, ProcessorErrors.DAO_MUST_BE_AN_ABSTRACT_CLASS_OR_AN_INTERFACE
         )
 
-        val declaredType = element.asDeclaredType()
+        val declaredType = element.type
         val allMethods = element.getAllMethods()
         val methods = allMethods
             .filter {
diff --git a/room/compiler/src/main/kotlin/androidx/room/processor/DatabaseProcessor.kt b/room/compiler/src/main/kotlin/androidx/room/processor/DatabaseProcessor.kt
index 1a276a2..c8f13ab 100644
--- a/room/compiler/src/main/kotlin/androidx/room/processor/DatabaseProcessor.kt
+++ b/room/compiler/src/main/kotlin/androidx/room/processor/DatabaseProcessor.kt
@@ -17,12 +17,11 @@
 package androidx.room.processor
 
 import androidx.room.SkipQueryVerification
-import androidx.room.ext.RoomTypeNames
 import androidx.room.compiler.processing.XAnnotationBox
 import androidx.room.compiler.processing.XElement
 import androidx.room.compiler.processing.XType
 import androidx.room.compiler.processing.XTypeElement
-import androidx.room.compiler.processing.isTypeElement
+import androidx.room.ext.RoomTypeNames
 import androidx.room.verifier.DatabaseVerificationErrors
 import androidx.room.verifier.DatabaseVerifier
 import androidx.room.vo.Dao
@@ -77,14 +76,12 @@
         }
         validateUniqueTableAndViewNames(element, entities, views)
 
-        val declaredType = element.asDeclaredType()
+        val declaredType = element.type
         val daoMethods = element.getAllMethods().filter {
             it.isAbstract()
         }.filterNot {
             // remove methods that belong to room
-            val containing = it.enclosingTypeElement
-            containing.isTypeElement() &&
-                containing.asDeclaredType().typeName == RoomTypeNames.ROOM_DB
+            it.enclosingTypeElement.className == RoomTypeNames.ROOM_DB
         }.map { executable ->
             // TODO when we add support for non Dao return types (e.g. database), this code needs
             // to change
diff --git a/room/compiler/src/main/kotlin/androidx/room/processor/PojoProcessor.kt b/room/compiler/src/main/kotlin/androidx/room/processor/PojoProcessor.kt
index 24b38ec..d56d3ce 100644
--- a/room/compiler/src/main/kotlin/androidx/room/processor/PojoProcessor.kt
+++ b/room/compiler/src/main/kotlin/androidx/room/processor/PojoProcessor.kt
@@ -115,7 +115,7 @@
     private fun doProcess(): Pojo {
         delegate.onPreProcess(element)
 
-        val declaredType = element.asDeclaredType()
+        val declaredType = element.type
         // TODO handle conflicts with super: b/35568142
         val allFields = element.getAllFieldsIncludingPrivateSupers()
             .filter {
diff --git a/room/compiler/src/main/kotlin/androidx/room/processor/autovalue/AutoValuePojoProcessorDelegate.kt b/room/compiler/src/main/kotlin/androidx/room/processor/autovalue/AutoValuePojoProcessorDelegate.kt
index 6ae275ffa..15ad354 100644
--- a/room/compiler/src/main/kotlin/androidx/room/processor/autovalue/AutoValuePojoProcessorDelegate.kt
+++ b/room/compiler/src/main/kotlin/androidx/room/processor/autovalue/AutoValuePojoProcessorDelegate.kt
@@ -40,7 +40,7 @@
 ) : PojoProcessor.Delegate {
 
     private val autoValueDeclaredType: XDeclaredType by lazy {
-        autoValueElement.asDeclaredType()
+        autoValueElement.type
     }
 
     override fun onPreProcess(element: XTypeElement) {
diff --git a/room/compiler/src/main/kotlin/androidx/room/vo/Constructor.kt b/room/compiler/src/main/kotlin/androidx/room/vo/Constructor.kt
index 338892d..6adaa3c 100644
--- a/room/compiler/src/main/kotlin/androidx/room/vo/Constructor.kt
+++ b/room/compiler/src/main/kotlin/androidx/room/vo/Constructor.kt
@@ -45,13 +45,13 @@
             element.isConstructor() -> {
                 builder.addStatement(
                     "$L = new $T($L)", outVar,
-                    element.enclosingTypeElement.asDeclaredType().typeName, args
+                    element.enclosingTypeElement.className, args
                 )
             }
             element.isMethod() -> {
                 builder.addStatement(
                     "$L = $T.$L($L)", outVar,
-                    element.enclosingTypeElement.asDeclaredType().typeName,
+                    element.enclosingTypeElement.className,
                     element.name, args
                 )
             }
diff --git a/room/compiler/src/main/kotlin/androidx/room/vo/RelationCollector.kt b/room/compiler/src/main/kotlin/androidx/room/vo/RelationCollector.kt
index 5aaf495..4c6b0c2 100644
--- a/room/compiler/src/main/kotlin/androidx/room/vo/RelationCollector.kt
+++ b/room/compiler/src/main/kotlin/androidx/room/vo/RelationCollector.kt
@@ -272,7 +272,7 @@
                     QueryParameter(
                         name = RelationCollectorMethodWriter.PARAM_MAP_VARIABLE,
                         sqlName = RelationCollectorMethodWriter.PARAM_MAP_VARIABLE,
-                        type = longSparseArrayElement.asDeclaredType(),
+                        type = longSparseArrayElement.type,
                         queryParamAdapter = LONG_SPARSE_ARRAY_KEY_QUERY_PARAM_ADAPTER
                     )
                 } else {
diff --git a/room/compiler/src/main/kotlin/androidx/room/writer/DaoWriter.kt b/room/compiler/src/main/kotlin/androidx/room/writer/DaoWriter.kt
index ee30de2..fe9c44d 100644
--- a/room/compiler/src/main/kotlin/androidx/room/writer/DaoWriter.kt
+++ b/room/compiler/src/main/kotlin/androidx/room/writer/DaoWriter.kt
@@ -72,7 +72,7 @@
     val processingEnv: XProcessingEnv
 ) :
     ClassWriter(dao.typeName) {
-    private val declaredDao = dao.element.asDeclaredType()
+    private val declaredDao = dao.element.type
 
     companion object {
         const val GET_LIST_OF_TYPE_CONVERTERS_METHOD = "getRequiredConverters"
diff --git a/room/compiler/src/test/kotlin/androidx/room/processor/BaseDaoTest.kt b/room/compiler/src/test/kotlin/androidx/room/processor/BaseDaoTest.kt
index fe49774..7b2bd76 100644
--- a/room/compiler/src/test/kotlin/androidx/room/processor/BaseDaoTest.kt
+++ b/room/compiler/src/test/kotlin/androidx/room/processor/BaseDaoTest.kt
@@ -184,7 +184,7 @@
             val daoElm = invocation.processingEnv.requireTypeElement("foo.bar.MyDao")
             val dbElm = invocation.context.processingEnv
                 .requireTypeElement(RoomTypeNames.ROOM_DB)
-            val dbType = dbElm.asDeclaredType()
+            val dbType = dbElm.type
             val processedDao = DaoProcessor(
                 invocation.context, daoElm, dbType, null
             ).process()
diff --git a/room/compiler/src/test/kotlin/androidx/room/processor/DaoProcessorTest.kt b/room/compiler/src/test/kotlin/androidx/room/processor/DaoProcessorTest.kt
index 0ecfafc..b1995f6 100644
--- a/room/compiler/src/test/kotlin/androidx/room/processor/DaoProcessorTest.kt
+++ b/room/compiler/src/test/kotlin/androidx/room/processor/DaoProcessorTest.kt
@@ -221,7 +221,7 @@
                 assertThat(
                     QueryMethodProcessor(
                         baseContext = daoProcessor.context,
-                        containing = dao.element.asDeclaredType(),
+                        containing = dao.element.type,
                         executableElement = it.element,
                         dbVerifier = null
                     ).context.logger.suppressedWarnings,
@@ -257,7 +257,7 @@
                 assertThat(
                     QueryMethodProcessor(
                         baseContext = daoProcessor.context,
-                        containing = dao.element.asDeclaredType(),
+                        containing = dao.element.type,
                         executableElement = it.element,
                         dbVerifier = null
                     ).context.logger.suppressedWarnings,
diff --git a/room/compiler/src/test/kotlin/androidx/room/processor/FieldProcessorTest.kt b/room/compiler/src/test/kotlin/androidx/room/processor/FieldProcessorTest.kt
index 0cba335..961298c 100644
--- a/room/compiler/src/test/kotlin/androidx/room/processor/FieldProcessorTest.kt
+++ b/room/compiler/src/test/kotlin/androidx/room/processor/FieldProcessorTest.kt
@@ -618,7 +618,7 @@
                                 ).context
                             val parser = FieldProcessor(
                                 baseContext = entityContext,
-                                containing = owner.asDeclaredType(),
+                                containing = owner.type,
                                 element = fieldElement!!,
                                 bindingScope = FieldProcessor.BindingScope.TWO_WAY,
                                 fieldParent = null,
diff --git a/room/compiler/src/test/kotlin/androidx/room/processor/InsertionMethodProcessorTest.kt b/room/compiler/src/test/kotlin/androidx/room/processor/InsertionMethodProcessorTest.kt
index fa09818..71f7bcb 100644
--- a/room/compiler/src/test/kotlin/androidx/room/processor/InsertionMethodProcessorTest.kt
+++ b/room/compiler/src/test/kotlin/androidx/room/processor/InsertionMethodProcessorTest.kt
@@ -875,7 +875,7 @@
                             }.first { it.second.isNotEmpty() }
                         val processor = InsertionMethodProcessor(
                             baseContext = invocation.context,
-                            containing = owner.asDeclaredType(),
+                            containing = owner.type,
                             executableElement = methods.first()
                         )
                         val processed = processor.process()
diff --git a/room/compiler/src/test/kotlin/androidx/room/processor/QueryMethodProcessorTest.kt b/room/compiler/src/test/kotlin/androidx/room/processor/QueryMethodProcessorTest.kt
index 7eadf4b..41042bb 100644
--- a/room/compiler/src/test/kotlin/androidx/room/processor/QueryMethodProcessorTest.kt
+++ b/room/compiler/src/test/kotlin/androidx/room/processor/QueryMethodProcessorTest.kt
@@ -1155,7 +1155,7 @@
                         }
                         val parser = QueryMethodProcessor(
                             baseContext = invocation.context,
-                            containing = owner.asDeclaredType(),
+                            containing = owner.type,
                             executableElement = methods.first(),
                             dbVerifier = verifier
                         )
diff --git a/room/compiler/src/test/kotlin/androidx/room/processor/RawQueryMethodProcessorTest.kt b/room/compiler/src/test/kotlin/androidx/room/processor/RawQueryMethodProcessorTest.kt
index 5dedc7f..b1104c5 100644
--- a/room/compiler/src/test/kotlin/androidx/room/processor/RawQueryMethodProcessorTest.kt
+++ b/room/compiler/src/test/kotlin/androidx/room/processor/RawQueryMethodProcessorTest.kt
@@ -220,7 +220,7 @@
             val daoFunctionElement = daoElement.getDeclaredMethods().first()
             RawQueryMethodProcessor(
                 baseContext = invocation.context,
-                containing = daoElement.asDeclaredType(),
+                containing = daoElement.type,
                 executableElement = daoFunctionElement
             ).process()
         }.failsToCompile().withErrorContaining(
@@ -355,7 +355,7 @@
                             }.first { it.second.isNotEmpty() }
                         val parser = RawQueryMethodProcessor(
                             baseContext = invocation.context,
-                            containing = owner.asDeclaredType(),
+                            containing = owner.type,
                             executableElement = methods.first()
                         )
                         val parsedQuery = parser.process()
diff --git a/room/compiler/src/test/kotlin/androidx/room/processor/ShortcutMethodProcessorTest.kt b/room/compiler/src/test/kotlin/androidx/room/processor/ShortcutMethodProcessorTest.kt
index a327534..2cd6906 100644
--- a/room/compiler/src/test/kotlin/androidx/room/processor/ShortcutMethodProcessorTest.kt
+++ b/room/compiler/src/test/kotlin/androidx/room/processor/ShortcutMethodProcessorTest.kt
@@ -533,7 +533,7 @@
                                 }.first { it.second.isNotEmpty() }
                             val processed = process(
                                 baseContext = invocation.context,
-                                containing = owner.asDeclaredType(),
+                                containing = owner.type,
                                 executableElement = methods.first()
                             )
                             handler(processed, invocation)
diff --git a/room/compiler/src/test/kotlin/androidx/room/processor/TransactionMethodProcessorTest.kt b/room/compiler/src/test/kotlin/androidx/room/processor/TransactionMethodProcessorTest.kt
index c9c543a..2ae21b5 100644
--- a/room/compiler/src/test/kotlin/androidx/room/processor/TransactionMethodProcessorTest.kt
+++ b/room/compiler/src/test/kotlin/androidx/room/processor/TransactionMethodProcessorTest.kt
@@ -263,7 +263,7 @@
                             }.first { it.second.isNotEmpty() }
                         val processor = TransactionMethodProcessor(
                             baseContext = invocation.context,
-                            containing = owner.asDeclaredType(),
+                            containing = owner.type,
                             executableElement = methods.first()
                         )
                         val processed = processor.process()
diff --git a/room/compiler/src/test/kotlin/androidx/room/solver/TypeAdapterStoreTest.kt b/room/compiler/src/test/kotlin/androidx/room/solver/TypeAdapterStoreTest.kt
index 3b8ff54..04d9d40e 100644
--- a/room/compiler/src/test/kotlin/androidx/room/solver/TypeAdapterStoreTest.kt
+++ b/room/compiler/src/test/kotlin/androidx/room/solver/TypeAdapterStoreTest.kt
@@ -329,7 +329,7 @@
             assertThat(publisherElement, notNullValue())
             assertThat(
                 RxQueryResultBinderProvider.getAll(invocation.context).any {
-                    it.matches(publisherElement.asDeclaredType())
+                    it.matches(publisherElement.type)
                 },
                 `is`(true)
             )
@@ -350,7 +350,7 @@
             assertThat(publisherElement, notNullValue())
             assertThat(
                 RxQueryResultBinderProvider.getAll(invocation.context).any {
-                    it.matches(publisherElement.asDeclaredType())
+                    it.matches(publisherElement.type)
                 },
                 `is`(true)
             )
@@ -375,7 +375,7 @@
                 assertThat(publisher, notNullValue())
                 assertThat(
                     RxQueryResultBinderProvider.getAll(invocation.context).any {
-                        it.matches(publisher.asDeclaredType())
+                        it.matches(publisher.type)
                     },
                     `is`(true)
                 )
@@ -396,7 +396,7 @@
                 val flowable = invocation.processingEnv.requireTypeElement(rxTypeClassName)
                 assertThat(
                     RxQueryResultBinderProvider.getAll(invocation.context).any {
-                        it.matches(flowable.asDeclaredType())
+                        it.matches(flowable.type)
                     },
                     `is`(true)
                 )
@@ -418,7 +418,7 @@
                 assertThat(observable, notNullValue())
                 assertThat(
                     RxQueryResultBinderProvider.getAll(invocation.context).any {
-                        it.matches(observable.asDeclaredType())
+                        it.matches(observable.type)
                     },
                     `is`(true)
                 )
@@ -438,7 +438,7 @@
                 assertThat(single, notNullValue())
                 assertThat(
                     RxCallableInsertMethodBinderProvider.getAll(invocation.context).any {
-                        it.matches(single.asDeclaredType())
+                        it.matches(single.type)
                     },
                     `is`(true)
                 )
@@ -456,7 +456,7 @@
                 val maybe = invocation.processingEnv.requireTypeElement(rxTypeClassName)
                 assertThat(
                     RxCallableInsertMethodBinderProvider.getAll(invocation.context).any {
-                        it.matches(maybe.asDeclaredType())
+                        it.matches(maybe.type)
                     },
                     `is`(true)
                 )
@@ -474,7 +474,7 @@
                 val completable = invocation.processingEnv.requireTypeElement(rxTypeClassName)
                 assertThat(
                     RxCallableInsertMethodBinderProvider.getAll(invocation.context).any {
-                        it.matches(completable.asDeclaredType())
+                        it.matches(completable.type)
                     },
                     `is`(true)
                 )
@@ -490,7 +490,7 @@
                 .requireTypeElement(GuavaUtilConcurrentTypeNames.LISTENABLE_FUTURE)
             assertThat(
                 GuavaListenableFutureInsertMethodBinderProvider(invocation.context).matches(
-                    future.asDeclaredType()
+                    future.type
                 ),
                 `is`(true)
             )
@@ -504,7 +504,7 @@
             assertThat(single, notNullValue())
             assertThat(
                 RxCallableDeleteOrUpdateMethodBinderProvider.getAll(invocation.context).any {
-                    it.matches(single.asDeclaredType())
+                    it.matches(single.type)
                 },
                 `is`(true)
             )
@@ -519,7 +519,7 @@
             assertThat(maybe, notNullValue())
             assertThat(
                 RxCallableDeleteOrUpdateMethodBinderProvider.getAll(invocation.context).any {
-                    it.matches(maybe.asDeclaredType())
+                    it.matches(maybe.type)
                 },
                 `is`(true)
             )
@@ -535,7 +535,7 @@
             assertThat(completable, notNullValue())
             assertThat(
                 RxCallableDeleteOrUpdateMethodBinderProvider.getAll(invocation.context).any {
-                    it.matches(completable.asDeclaredType())
+                    it.matches(completable.type)
                 },
                 `is`(true)
             )
@@ -552,7 +552,7 @@
             assertThat(future, notNullValue())
             assertThat(
                 GuavaListenableFutureDeleteOrUpdateMethodBinderProvider(invocation.context)
-                    .matches(future.asDeclaredType()),
+                    .matches(future.type),
                 `is`(true)
             )
         }
@@ -568,7 +568,7 @@
             assertThat(liveData, notNullValue())
             assertThat(
                 LiveDataQueryResultBinderProvider(invocation.context).matches(
-                    liveData.asDeclaredType()
+                    liveData.type
                 ),
                 `is`(true)
             )
@@ -622,7 +622,7 @@
             assertThat(dataSource, notNullValue())
             assertThat(
                 DataSourceQueryResultBinderProvider(invocation.context).matches(
-                    dataSource.asDeclaredType()
+                    dataSource.type
                 ),
                 `is`(true)
             )
@@ -642,7 +642,7 @@
             assertThat(dataSource, notNullValue())
             assertThat(
                 DataSourceQueryResultBinderProvider(invocation.context).matches(
-                    dataSource.asDeclaredType()
+                    dataSource.type
                 ),
                 `is`(true)
             )
@@ -658,7 +658,7 @@
             assertThat(pagedListProvider, notNullValue())
             assertThat(
                 DataSourceFactoryQueryResultBinderProvider(invocation.context).matches(
-                    pagedListProvider.asDeclaredType()
+                    pagedListProvider.type
                 ),
                 `is`(true)
             )
diff --git a/room/compiler/src/test/kotlin/androidx/room/solver/query/QueryWriterTest.kt b/room/compiler/src/test/kotlin/androidx/room/solver/query/QueryWriterTest.kt
index 877c24b..7c325d5 100644
--- a/room/compiler/src/test/kotlin/androidx/room/solver/query/QueryWriterTest.kt
+++ b/room/compiler/src/test/kotlin/androidx/room/solver/query/QueryWriterTest.kt
@@ -366,7 +366,7 @@
                             }.first { it.second.isNotEmpty() }
                         val parser = QueryMethodProcessor(
                             baseContext = invocation.context,
-                            containing = owner.asDeclaredType(),
+                            containing = owner.type,
                             executableElement = methods.first()
                         )
                         val method = parser.process()
diff --git a/room/compiler/src/test/kotlin/androidx/room/writer/DaoWriterTest.kt b/room/compiler/src/test/kotlin/androidx/room/writer/DaoWriterTest.kt
index 2a76a7d..b78e3b3 100644
--- a/room/compiler/src/test/kotlin/androidx/room/writer/DaoWriterTest.kt
+++ b/room/compiler/src/test/kotlin/androidx/room/writer/DaoWriterTest.kt
@@ -110,7 +110,7 @@
                             .firstOrNull()
                             ?: invocation.context.processingEnv
                                 .requireTypeElement(RoomTypeNames.ROOM_DB)
-                        val dbType = db.asDeclaredType()
+                        val dbType = db.type
                         val parser = DaoProcessor(
                             baseContext = invocation.context,
                             element = dao,