Allow primitive types in findTypeElement
This CL allows querying primitive types via the env.findTypeMirror API
rather than going through types.getPrimitiveType.
Even though it is a bit debateable, this greatly simplifies how
we need to handle primitives and allows us to remove access to
TypeKind for the most part.
I've also added another helper to get the ArrayType
Bug: 160323720
Test: existing test suite
Change-Id: I1afc59eef156ad5db146d60b9d151f8ad305143e
diff --git a/room/compiler/src/main/kotlin/androidx/room/ext/element_ext.kt b/room/compiler/src/main/kotlin/androidx/room/ext/element_ext.kt
index 57119b5..72b0117 100644
--- a/room/compiler/src/main/kotlin/androidx/room/ext/element_ext.kt
+++ b/room/compiler/src/main/kotlin/androidx/room/ext/element_ext.kt
@@ -25,6 +25,8 @@
import com.google.auto.common.MoreElements
import com.google.auto.common.MoreTypes
import isAssignableFrom
+import isDeclared
+import isNotNone
import java.lang.reflect.Proxy
import java.util.Locale
import javax.annotation.processing.ProcessingEnvironment
@@ -38,7 +40,6 @@
import javax.lang.model.element.VariableElement
import javax.lang.model.type.DeclaredType
import javax.lang.model.type.ExecutableType
-import javax.lang.model.type.TypeKind
import javax.lang.model.type.TypeMirror
import javax.lang.model.type.WildcardType
import javax.lang.model.util.ElementFilter
@@ -105,7 +106,7 @@
.filter { it is VariableElement }
.map { it as VariableElement }
.toSet()
- if (superclass.kind != TypeKind.NONE) {
+ if (superclass.isNotNone()) {
return myMembers + superclass.asTypeElement()
.getAllFieldsIncludingPrivateSupers(processingEnvironment)
} else {
@@ -118,7 +119,7 @@
val interfaceMethods = interfaces.flatMap {
it.asTypeElement().getAllMethodsIncludingSupers()
}
- return if (superclass.kind != TypeKind.NONE) {
+ return if (superclass.isNotNone()) {
myMethods + interfaceMethods + superclass.asTypeElement().getAllMethodsIncludingSupers()
} else {
myMethods + interfaceMethods
@@ -340,7 +341,7 @@
if (assignable) {
return true
}
- if (from.kind != TypeKind.DECLARED || to.kind != TypeKind.DECLARED) {
+ if (!from.isDeclared() || !to.isDeclared()) {
return false
}
val declaredFrom = MoreTypes.asDeclared(from)
diff --git a/room/compiler/src/main/kotlin/androidx/room/ext/processing_env_ext.kt b/room/compiler/src/main/kotlin/androidx/room/ext/processing_env_ext.kt
index 0e0626a..c9e7812 100644
--- a/room/compiler/src/main/kotlin/androidx/room/ext/processing_env_ext.kt
+++ b/room/compiler/src/main/kotlin/androidx/room/ext/processing_env_ext.kt
@@ -17,8 +17,11 @@
import com.google.auto.common.GeneratedAnnotations
import com.squareup.javapoet.TypeName
+import java.util.Locale
import javax.annotation.processing.ProcessingEnvironment
import javax.lang.model.element.TypeElement
+import javax.lang.model.type.ArrayType
+import javax.lang.model.type.TypeKind
import javax.lang.model.type.TypeMirror
import kotlin.reflect.KClass
@@ -87,7 +90,9 @@
*/
fun ProcessingEnvironment.requireTypeMirror(
qName: String
-): TypeMirror = requireTypeElement(qName).type
+): TypeMirror = checkNotNull(findTypeMirror(qName)) {
+ "couldn't find required type mirror $qName"
+}
/**
* Query a type mirror by KClass and return null if it does not exist
@@ -103,12 +108,25 @@
typeName: TypeName
): TypeMirror? = findTypeMirror(typeName.toString())
+private val PRIMITIVE_TYPE_MAPPING = TypeKind.values().filter {
+ it.isPrimitive
+}.associateBy {
+ it.name.toLowerCase(Locale.US)
+}
+
/**
* Query a type mirror by qualified name and return null if it does not exist
*/
fun ProcessingEnvironment.findTypeMirror(
qName: String
-): TypeMirror? = findTypeElement(qName)?.type
+): TypeMirror? {
+ // first check primitives. Even though it is less likely, it is fast to check and can avoid a
+ // call to the processor
+ PRIMITIVE_TYPE_MAPPING[qName]?.let {
+ return typeUtils.getPrimitiveType(it)
+ }
+ return findTypeElement(qName)?.type
+}
fun ProcessingEnvironment.getGeneratedAnnotation(): TypeElement? {
val element = GeneratedAnnotations.generatedAnnotation(elementUtils, sourceVersion)
@@ -117,4 +135,8 @@
} else {
null
}
-}
\ No newline at end of file
+}
+
+fun ProcessingEnvironment.getArrayType(typeName: TypeName): ArrayType {
+ return typeUtils.getArrayType(requireTypeMirror(typeName))
+}
diff --git a/room/compiler/src/main/kotlin/androidx/room/ext/type_mirror_ext.kt b/room/compiler/src/main/kotlin/androidx/room/ext/type_mirror_ext.kt
index ff2e46c..b5fa841 100644
--- a/room/compiler/src/main/kotlin/androidx/room/ext/type_mirror_ext.kt
+++ b/room/compiler/src/main/kotlin/androidx/room/ext/type_mirror_ext.kt
@@ -13,11 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+import androidx.room.ext.type
import com.google.auto.common.MoreTypes
import javax.lang.model.element.Element
import javax.lang.model.element.TypeElement
import javax.lang.model.type.ArrayType
import javax.lang.model.type.DeclaredType
+import javax.lang.model.type.PrimitiveType
import javax.lang.model.type.TypeKind
import javax.lang.model.type.TypeKind.ARRAY
import javax.lang.model.type.TypeKind.BOOLEAN
@@ -43,6 +45,11 @@
}
}
+fun TypeMirror.box(typeUtils: Types) = if (this.kind.isPrimitive) {
+ typeUtils.boxedClass(this as PrimitiveType).type
+} else {
+ this
+}
fun TypeMirror.asTypeElement(): TypeElement = MoreTypes.asTypeElement(this)
fun TypeMirror.asElement(): Element = MoreTypes.asElement(this)
diff --git a/room/compiler/src/main/kotlin/androidx/room/parser/SqlParser.kt b/room/compiler/src/main/kotlin/androidx/room/parser/SqlParser.kt
index 2843611..c542239 100644
--- a/room/compiler/src/main/kotlin/androidx/room/parser/SqlParser.kt
+++ b/room/compiler/src/main/kotlin/androidx/room/parser/SqlParser.kt
@@ -17,12 +17,13 @@
package androidx.room.parser
import androidx.room.ColumnInfo
+import androidx.room.ext.getArrayType
import androidx.room.ext.requireTypeMirror
-import androidx.room.ext.type
+import box
+import com.squareup.javapoet.TypeName
import org.antlr.v4.runtime.tree.ParseTree
import org.antlr.v4.runtime.tree.TerminalNode
import javax.annotation.processing.ProcessingEnvironment
-import javax.lang.model.type.TypeKind
import javax.lang.model.type.TypeMirror
@Suppress("FunctionName")
@@ -191,28 +192,25 @@
BLOB;
fun getTypeMirrors(env: ProcessingEnvironment): List<TypeMirror>? {
- val typeUtils = env.typeUtils
return when (this) {
TEXT -> listOf(env.requireTypeMirror("java.lang.String"))
INTEGER -> withBoxedTypes(
- env, TypeKind.INT, TypeKind.BYTE, TypeKind.CHAR,
- TypeKind.LONG, TypeKind.SHORT
+ env, TypeName.INT, TypeName.BYTE, TypeName.CHAR,
+ TypeName.LONG, TypeName.SHORT
)
- REAL -> withBoxedTypes(env, TypeKind.DOUBLE, TypeKind.FLOAT)
+ REAL -> withBoxedTypes(env, TypeName.DOUBLE, TypeName.FLOAT)
BLOB -> listOf(
- typeUtils.getArrayType(
- typeUtils.getPrimitiveType(TypeKind.BYTE)
- )
+ env.getArrayType(TypeName.BYTE)
)
else -> emptyList()
}
}
- private fun withBoxedTypes(env: ProcessingEnvironment, vararg primitives: TypeKind):
+ private fun withBoxedTypes(env: ProcessingEnvironment, vararg primitives: TypeName):
List<TypeMirror> {
return primitives.flatMap {
- val primitiveType = env.typeUtils.getPrimitiveType(it)
- listOf(primitiveType, env.typeUtils.boxedClass(primitiveType).type)
+ val primitiveType = env.requireTypeMirror(it)
+ listOf(primitiveType, primitiveType.box(env.typeUtils))
}
}
diff --git a/room/compiler/src/main/kotlin/androidx/room/solver/types/BoxedPrimitiveColumnTypeAdapter.kt b/room/compiler/src/main/kotlin/androidx/room/solver/types/BoxedPrimitiveColumnTypeAdapter.kt
index b3034af..29c636d 100644
--- a/room/compiler/src/main/kotlin/androidx/room/solver/types/BoxedPrimitiveColumnTypeAdapter.kt
+++ b/room/compiler/src/main/kotlin/androidx/room/solver/types/BoxedPrimitiveColumnTypeAdapter.kt
@@ -17,9 +17,8 @@
package androidx.room.solver.types
import androidx.room.ext.L
-import androidx.room.ext.type
import androidx.room.solver.CodeGenScope
-import asPrimitive
+import box
import javax.annotation.processing.ProcessingEnvironment
import javax.lang.model.type.TypeMirror
@@ -38,9 +37,8 @@
return primitiveAdapters.map {
BoxedPrimitiveColumnTypeAdapter(
- processingEnvironment.typeUtils
- .boxedClass(it.out.asPrimitive()).type,
- it
+ it.out.box(processingEnvironment.typeUtils),
+ it
)
}
}
diff --git a/room/compiler/src/main/kotlin/androidx/room/solver/types/ByteArrayColumnTypeAdapter.kt b/room/compiler/src/main/kotlin/androidx/room/solver/types/ByteArrayColumnTypeAdapter.kt
index 879a44e..5645a7b 100644
--- a/room/compiler/src/main/kotlin/androidx/room/solver/types/ByteArrayColumnTypeAdapter.kt
+++ b/room/compiler/src/main/kotlin/androidx/room/solver/types/ByteArrayColumnTypeAdapter.kt
@@ -17,13 +17,14 @@
package androidx.room.solver.types
import androidx.room.ext.L
+import androidx.room.ext.getArrayType
import androidx.room.parser.SQLTypeAffinity
import androidx.room.solver.CodeGenScope
+import com.squareup.javapoet.TypeName
import javax.annotation.processing.ProcessingEnvironment
-import javax.lang.model.type.TypeKind
class ByteArrayColumnTypeAdapter(env: ProcessingEnvironment) : ColumnTypeAdapter(
- out = env.typeUtils.getArrayType(env.typeUtils.getPrimitiveType(TypeKind.BYTE)),
+ out = env.getArrayType(TypeName.BYTE),
typeAffinity = SQLTypeAffinity.BLOB) {
override fun readFromCursor(
outVarName: String,
diff --git a/room/compiler/src/main/kotlin/androidx/room/solver/types/PrimitiveBooleanToIntConverter.kt b/room/compiler/src/main/kotlin/androidx/room/solver/types/PrimitiveBooleanToIntConverter.kt
index d1ee9e5..e2bfffe 100644
--- a/room/compiler/src/main/kotlin/androidx/room/solver/types/PrimitiveBooleanToIntConverter.kt
+++ b/room/compiler/src/main/kotlin/androidx/room/solver/types/PrimitiveBooleanToIntConverter.kt
@@ -17,18 +17,18 @@
package androidx.room.solver.types
import androidx.room.ext.L
+import androidx.room.ext.requireTypeMirror
import androidx.room.solver.CodeGenScope
+import com.squareup.javapoet.TypeName
import javax.annotation.processing.ProcessingEnvironment
-import javax.lang.model.type.TypeKind.BOOLEAN
-import javax.lang.model.type.TypeKind.INT
/**
* int to boolean adapter.
*/
object PrimitiveBooleanToIntConverter {
fun create(processingEnvironment: ProcessingEnvironment): List<TypeConverter> {
- val tBoolean = processingEnvironment.typeUtils.getPrimitiveType(BOOLEAN)
- val tInt = processingEnvironment.typeUtils.getPrimitiveType(INT)
+ val tBoolean = processingEnvironment.requireTypeMirror(TypeName.BOOLEAN)
+ val tInt = processingEnvironment.requireTypeMirror(TypeName.INT)
return listOf(
object : TypeConverter(tBoolean, tInt) {
override fun convert(
diff --git a/room/compiler/src/main/kotlin/androidx/room/solver/types/PrimitiveColumnTypeAdapter.kt b/room/compiler/src/main/kotlin/androidx/room/solver/types/PrimitiveColumnTypeAdapter.kt
index af7cb13..b2d7e5d 100644
--- a/room/compiler/src/main/kotlin/androidx/room/solver/types/PrimitiveColumnTypeAdapter.kt
+++ b/room/compiler/src/main/kotlin/androidx/room/solver/types/PrimitiveColumnTypeAdapter.kt
@@ -17,30 +17,30 @@
package androidx.room.solver.types
import androidx.room.ext.L
+import androidx.room.ext.requireTypeMirror
import androidx.room.ext.typeName
import androidx.room.parser.SQLTypeAffinity
import androidx.room.parser.SQLTypeAffinity.REAL
import androidx.room.solver.CodeGenScope
+import com.squareup.javapoet.TypeName.BYTE
+import com.squareup.javapoet.TypeName.CHAR
+import com.squareup.javapoet.TypeName.DOUBLE
+import com.squareup.javapoet.TypeName.FLOAT
+import com.squareup.javapoet.TypeName.INT
+import com.squareup.javapoet.TypeName.LONG
+import com.squareup.javapoet.TypeName.SHORT
import javax.annotation.processing.ProcessingEnvironment
-import javax.lang.model.type.PrimitiveType
-import javax.lang.model.type.TypeKind.BYTE
-import javax.lang.model.type.TypeKind.CHAR
-import javax.lang.model.type.TypeKind.DOUBLE
-import javax.lang.model.type.TypeKind.FLOAT
-import javax.lang.model.type.TypeKind.INT
-import javax.lang.model.type.TypeKind.LONG
-import javax.lang.model.type.TypeKind.SHORT
+import javax.lang.model.type.TypeMirror
/**
* Adapters for all primitives that has direct cursor mappings.
*/
open class PrimitiveColumnTypeAdapter(
- out: PrimitiveType,
+ out: TypeMirror,
val cursorGetter: String,
val stmtSetter: String,
typeAffinity: SQLTypeAffinity
-) :
- ColumnTypeAdapter(out, typeAffinity) {
+) : ColumnTypeAdapter(out, typeAffinity) {
val cast = if (cursorGetter == "get${out.typeName().toString().capitalize()}")
""
else
@@ -60,7 +60,7 @@
Triple(DOUBLE, "getDouble", "bindDouble")
).map {
PrimitiveColumnTypeAdapter(
- out = processingEnvironment.typeUtils.getPrimitiveType(it.first),
+ out = processingEnvironment.requireTypeMirror(it.first),
cursorGetter = it.second,
stmtSetter = it.third,
typeAffinity = when (it.first) {
diff --git a/room/compiler/src/test/kotlin/androidx/room/ext/ElementExtTest.kt b/room/compiler/src/test/kotlin/androidx/room/ext/ElementExtTest.kt
index 40c776e..f5a04c4 100644
--- a/room/compiler/src/test/kotlin/androidx/room/ext/ElementExtTest.kt
+++ b/room/compiler/src/test/kotlin/androidx/room/ext/ElementExtTest.kt
@@ -16,6 +16,7 @@
package androidx.room.ext
+import box
import com.google.common.truth.Truth.assertThat
import com.google.testing.compile.JavaFileObjects
import com.squareup.javapoet.ClassName
@@ -204,6 +205,32 @@
}.compilesWithoutError()
}
+ @Test
+ fun primitiveTypes() {
+ // check that we can also find primitive types from the common API
+ val primitiveTypeNames = listOf(
+ TypeName.BOOLEAN,
+ TypeName.BYTE,
+ TypeName.SHORT,
+ TypeName.INT,
+ TypeName.LONG,
+ TypeName.CHAR,
+ TypeName.FLOAT,
+ TypeName.DOUBLE
+ )
+ simpleRun { invocation ->
+ val processingEnv = invocation.processingEnv
+ primitiveTypeNames.forEach { primitiveTypeName ->
+ val typeMirror = processingEnv.requireTypeMirror(primitiveTypeName)
+ assertThat(typeMirror.kind.isPrimitive).isTrue()
+ assertThat(typeMirror.typeName()).isEqualTo(primitiveTypeName)
+ assertThat(
+ typeMirror.box(invocation.typeUtils).typeName()
+ ).isEqualTo(primitiveTypeName.box())
+ }
+ }.compilesWithoutError()
+ }
+
private fun assertThat(executables: Iterable<ExecutableElement>) = assertThat(
executables.map { it.simpleName.toString() }
)
diff --git a/room/compiler/src/test/kotlin/androidx/room/processor/EntityNameMatchingVariationsTest.kt b/room/compiler/src/test/kotlin/androidx/room/processor/EntityNameMatchingVariationsTest.kt
index ad7e072..0596817 100644
--- a/room/compiler/src/test/kotlin/androidx/room/processor/EntityNameMatchingVariationsTest.kt
+++ b/room/compiler/src/test/kotlin/androidx/room/processor/EntityNameMatchingVariationsTest.kt
@@ -16,11 +16,13 @@
package androidx.room.processor
+import androidx.room.ext.requireTypeMirror
import androidx.room.parser.SQLTypeAffinity
import androidx.room.vo.CallType
import androidx.room.vo.Field
import androidx.room.vo.FieldGetter
import androidx.room.vo.FieldSetter
+import com.squareup.javapoet.TypeName
import org.hamcrest.CoreMatchers.`is`
import org.hamcrest.MatcherAssert.assertThat
import org.junit.Test
@@ -62,7 +64,7 @@
assertThat(entity.type.toString(), `is`("foo.bar.MyEntity"))
assertThat(entity.fields.size, `is`(1))
val field = entity.fields.first()
- val intType = invocation.processingEnv.typeUtils.getPrimitiveType(INT)
+ val intType = invocation.processingEnv.requireTypeMirror(TypeName.INT)
assertThat(field, `is`(Field(
element = field.element,
name = fieldName,
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 f35bdf5..1bb2398 100644
--- a/room/compiler/src/test/kotlin/androidx/room/processor/FieldProcessorTest.kt
+++ b/room/compiler/src/test/kotlin/androidx/room/processor/FieldProcessorTest.kt
@@ -21,6 +21,7 @@
import androidx.room.ext.asTypeElement
import androidx.room.ext.asVariableElement
import androidx.room.ext.getAllFieldsIncludingPrivateSupers
+import androidx.room.ext.getArrayType
import androidx.room.ext.requireTypeMirror
import androidx.room.parser.Collate
import androidx.room.parser.SQLTypeAffinity
@@ -28,10 +29,12 @@
import androidx.room.testing.TestInvocation
import androidx.room.testing.TestProcessor
import androidx.room.vo.Field
+import box
import com.google.common.truth.Truth
import com.google.testing.compile.CompileTester
import com.google.testing.compile.JavaFileObjects
import com.google.testing.compile.JavaSourcesSubjectFactory
+import com.squareup.javapoet.TypeName
import org.hamcrest.CoreMatchers.`is`
import org.hamcrest.CoreMatchers.equalTo
import org.hamcrest.CoreMatchers.nullValue
@@ -42,8 +45,6 @@
import org.mockito.Mockito.mock
import simpleRun
import javax.lang.model.element.Element
-import javax.lang.model.type.TypeKind
-import javax.lang.model.type.TypeMirror
@Suppress("HasPlatformType")
@RunWith(JUnit4::class)
@@ -58,64 +59,54 @@
"""
const val ENTITY_SUFFIX = "}"
val ALL_PRIMITIVES = arrayListOf(
- TypeKind.INT,
- TypeKind.BYTE,
- TypeKind.SHORT,
- TypeKind.LONG,
- TypeKind.CHAR,
- TypeKind.FLOAT,
- TypeKind.DOUBLE)
+ TypeName.INT,
+ TypeName.BYTE,
+ TypeName.SHORT,
+ TypeName.LONG,
+ TypeName.CHAR,
+ TypeName.FLOAT,
+ TypeName.DOUBLE
+ )
val ARRAY_CONVERTER = JavaFileObjects.forSourceLines("foo.bar.MyConverter",
"""
package foo.bar;
import androidx.room.*;
public class MyConverter {
${ALL_PRIMITIVES.joinToString("\n") {
- val arrayDef = "${it.name.toLowerCase()}[]"
+ val arrayDef = "$it[]"
"@TypeConverter public static String" +
" arrayIntoString($arrayDef input) { return null;}" +
"@TypeConverter public static $arrayDef" +
- " stringIntoArray${it.name}(String input) { return null;}"
+ " stringIntoArray$it(String input) { return null;}"
}}
${ALL_PRIMITIVES.joinToString("\n") {
val arrayDef = "${it.box()}[]"
"@TypeConverter public static String" +
" arrayIntoString($arrayDef input) { return null;}" +
"@TypeConverter public static $arrayDef" +
- " stringIntoArray${it.name}Boxed(String input) { return null;}"
+ " stringIntoArray${it}Boxed(String input) { return null;}"
}}
}
""")
- private fun TypeKind.box(): String {
- return "java.lang." + when (this) {
- TypeKind.INT -> "Integer"
- TypeKind.CHAR -> "Character"
- else -> this.name.toLowerCase().capitalize()
- }
- }
-
- // these 2 box methods are ugly but makes tests nicer and they are private
- private fun TypeKind.typeMirror(invocation: TestInvocation): TypeMirror {
- return invocation.processingEnv.typeUtils.getPrimitiveType(this)
- }
-
- private fun TypeKind.affinity(): SQLTypeAffinity {
+ private fun TypeName.affinity(): SQLTypeAffinity {
return when (this) {
- TypeKind.FLOAT, TypeKind.DOUBLE -> SQLTypeAffinity.REAL
+ TypeName.FLOAT, TypeName.DOUBLE -> SQLTypeAffinity.REAL
else -> SQLTypeAffinity.INTEGER
}
}
- private fun TypeKind.box(invocation: TestInvocation): TypeMirror {
- return invocation.processingEnv.requireTypeMirror(box())
- }
+ private fun TypeName.box(invocation: TestInvocation) =
+ typeMirror(invocation).box(invocation.typeUtils)
+
+ private fun TypeName.typeMirror(invocation: TestInvocation) =
+ invocation.processingEnv.requireTypeMirror(this)
}
@Test
fun primitives() {
ALL_PRIMITIVES.forEach { primitive ->
- singleEntity("${primitive.name.toLowerCase()} x;") { field, invocation ->
+ singleEntity("$primitive x;") { field, invocation ->
assertThat(field, `is`(
Field(name = "x",
type = primitive.typeMirror(invocation),
@@ -148,7 +139,7 @@
""") { field, invocation ->
assertThat(field, `is`(
Field(name = "x",
- type = TypeKind.INT.typeMirror(invocation),
+ type = TypeName.INT.typeMirror(invocation),
element = field.element,
columnName = "foo",
affinity = SQLTypeAffinity.INTEGER)))
@@ -163,7 +154,7 @@
""") { field, invocation ->
assertThat(field, `is`(
Field(name = "x",
- type = TypeKind.INT.typeMirror(invocation),
+ type = TypeName.INT.typeMirror(invocation),
element = field.element,
columnName = "foo",
affinity = SQLTypeAffinity.INTEGER,
@@ -185,8 +176,7 @@
singleEntity("@TypeConverters(foo.bar.MyConverter.class)" +
"@ColumnInfo(typeAffinity = ColumnInfo.TEXT) byte[] arr;") { field, invocation ->
assertThat(field, `is`(Field(name = "arr",
- type = invocation.processingEnv.typeUtils.getArrayType(
- TypeKind.BYTE.typeMirror(invocation)),
+ type = invocation.processingEnv.getArrayType(TypeName.BYTE),
element = field.element,
affinity = SQLTypeAffinity.TEXT)))
assertThat((field.cursorValueReader as? ColumnTypeAdapter)?.typeAffinity,
@@ -201,10 +191,9 @@
"${primitive.toString().toLowerCase()}[] arr;") { field, invocation ->
assertThat(field, `is`(
Field(name = "arr",
- type = invocation.processingEnv.typeUtils.getArrayType(
- primitive.typeMirror(invocation)),
+ type = invocation.processingEnv.getArrayType(primitive),
element = field.element,
- affinity = if (primitive == TypeKind.BYTE) {
+ affinity = if (primitive == TypeName.BYTE) {
SQLTypeAffinity.BLOB
} else {
SQLTypeAffinity.TEXT
@@ -220,8 +209,8 @@
"${primitive.box()}[] arr;") { field, invocation ->
assertThat(field, `is`(
Field(name = "arr",
- type = invocation.processingEnv.typeUtils.getArrayType(
- primitive.box(invocation)),
+ type = invocation.processingEnv.getArrayType(
+ primitive.box()),
element = field.element,
affinity = SQLTypeAffinity.TEXT)))
}.compilesWithoutError()
@@ -239,7 +228,7 @@
}
""") { field, invocation ->
assertThat(field, `is`(Field(name = "item",
- type = TypeKind.INT.box(invocation),
+ type = TypeName.INT.box(invocation),
element = field.element,
affinity = SQLTypeAffinity.INTEGER)))
}.compilesWithoutError()
@@ -259,12 +248,12 @@
@Test
fun nameVariations() {
simpleRun {
- assertThat(Field(mock(Element::class.java), "x", TypeKind.INT.typeMirror(it),
+ assertThat(Field(mock(Element::class.java), "x", TypeName.INT.typeMirror(it),
SQLTypeAffinity.INTEGER).nameWithVariations, `is`(arrayListOf("x")))
- assertThat(Field(mock(Element::class.java), "x", TypeKind.BOOLEAN.typeMirror(it),
+ assertThat(Field(mock(Element::class.java), "x", TypeName.BOOLEAN.typeMirror(it),
SQLTypeAffinity.INTEGER).nameWithVariations, `is`(arrayListOf("x")))
assertThat(Field(mock(Element::class.java), "xAll",
- TypeKind.BOOLEAN.typeMirror(it), SQLTypeAffinity.INTEGER)
+ TypeName.BOOLEAN.typeMirror(it), SQLTypeAffinity.INTEGER)
.nameWithVariations, `is`(arrayListOf("xAll")))
}
}
@@ -273,13 +262,13 @@
fun nameVariations_is() {
val elm = mock(Element::class.java)
simpleRun {
- assertThat(Field(elm, "isX", TypeKind.BOOLEAN.typeMirror(it),
+ assertThat(Field(elm, "isX", TypeName.BOOLEAN.typeMirror(it),
SQLTypeAffinity.INTEGER).nameWithVariations, `is`(arrayListOf("isX", "x")))
- assertThat(Field(elm, "isX", TypeKind.INT.typeMirror(it),
+ assertThat(Field(elm, "isX", TypeName.INT.typeMirror(it),
SQLTypeAffinity.INTEGER).nameWithVariations, `is`(arrayListOf("isX")))
- assertThat(Field(elm, "is", TypeKind.BOOLEAN.typeMirror(it),
+ assertThat(Field(elm, "is", TypeName.BOOLEAN.typeMirror(it),
SQLTypeAffinity.INTEGER).nameWithVariations, `is`(arrayListOf("is")))
- assertThat(Field(elm, "isAllItems", TypeKind.BOOLEAN.typeMirror(it),
+ assertThat(Field(elm, "isAllItems", TypeName.BOOLEAN.typeMirror(it),
SQLTypeAffinity.INTEGER).nameWithVariations,
`is`(arrayListOf("isAllItems", "allItems")))
}
@@ -289,13 +278,13 @@
fun nameVariations_has() {
val elm = mock(Element::class.java)
simpleRun {
- assertThat(Field(elm, "hasX", TypeKind.BOOLEAN.typeMirror(it),
+ assertThat(Field(elm, "hasX", TypeName.BOOLEAN.typeMirror(it),
SQLTypeAffinity.INTEGER).nameWithVariations, `is`(arrayListOf("hasX", "x")))
- assertThat(Field(elm, "hasX", TypeKind.INT.typeMirror(it),
+ assertThat(Field(elm, "hasX", TypeName.INT.typeMirror(it),
SQLTypeAffinity.INTEGER).nameWithVariations, `is`(arrayListOf("hasX")))
- assertThat(Field(elm, "has", TypeKind.BOOLEAN.typeMirror(it),
+ assertThat(Field(elm, "has", TypeName.BOOLEAN.typeMirror(it),
SQLTypeAffinity.INTEGER).nameWithVariations, `is`(arrayListOf("has")))
- assertThat(Field(elm, "hasAllItems", TypeKind.BOOLEAN.typeMirror(it),
+ assertThat(Field(elm, "hasAllItems", TypeName.BOOLEAN.typeMirror(it),
SQLTypeAffinity.INTEGER).nameWithVariations,
`is`(arrayListOf("hasAllItems", "allItems")))
}
@@ -305,18 +294,18 @@
fun nameVariations_m() {
val elm = mock(Element::class.java)
simpleRun {
- assertThat(Field(elm, "mall", TypeKind.BOOLEAN.typeMirror(it),
+ assertThat(Field(elm, "mall", TypeName.BOOLEAN.typeMirror(it),
SQLTypeAffinity.INTEGER).nameWithVariations, `is`(arrayListOf("mall")))
- assertThat(Field(elm, "mallVars", TypeKind.BOOLEAN.typeMirror(it),
+ assertThat(Field(elm, "mallVars", TypeName.BOOLEAN.typeMirror(it),
SQLTypeAffinity.INTEGER).nameWithVariations, `is`(arrayListOf("mallVars")))
- assertThat(Field(elm, "mAll", TypeKind.BOOLEAN.typeMirror(it),
+ assertThat(Field(elm, "mAll", TypeName.BOOLEAN.typeMirror(it),
SQLTypeAffinity.INTEGER).nameWithVariations, `is`(arrayListOf("mAll", "all")))
- assertThat(Field(elm, "m", TypeKind.INT.typeMirror(it),
+ assertThat(Field(elm, "m", TypeName.INT.typeMirror(it),
SQLTypeAffinity.INTEGER).nameWithVariations, `is`(arrayListOf("m")))
- assertThat(Field(elm, "mallItems", TypeKind.BOOLEAN.typeMirror(it),
+ assertThat(Field(elm, "mallItems", TypeName.BOOLEAN.typeMirror(it),
SQLTypeAffinity.INTEGER).nameWithVariations,
`is`(arrayListOf("mallItems")))
- assertThat(Field(elm, "mAllItems", TypeKind.BOOLEAN.typeMirror(it),
+ assertThat(Field(elm, "mAllItems", TypeName.BOOLEAN.typeMirror(it),
SQLTypeAffinity.INTEGER).nameWithVariations,
`is`(arrayListOf("mAllItems", "allItems")))
}
@@ -326,11 +315,11 @@
fun nameVariations_underscore() {
val elm = mock(Element::class.java)
simpleRun {
- assertThat(Field(elm, "_all", TypeKind.BOOLEAN.typeMirror(it),
+ assertThat(Field(elm, "_all", TypeName.BOOLEAN.typeMirror(it),
SQLTypeAffinity.INTEGER).nameWithVariations, `is`(arrayListOf("_all", "all")))
- assertThat(Field(elm, "_", TypeKind.INT.typeMirror(it),
+ assertThat(Field(elm, "_", TypeName.INT.typeMirror(it),
SQLTypeAffinity.INTEGER).nameWithVariations, `is`(arrayListOf("_")))
- assertThat(Field(elm, "_allItems", TypeKind.BOOLEAN.typeMirror(it),
+ assertThat(Field(elm, "_allItems", TypeName.BOOLEAN.typeMirror(it),
SQLTypeAffinity.INTEGER).nameWithVariations,
`is`(arrayListOf("_allItems", "allItems")))
}
diff --git a/room/compiler/src/test/kotlin/androidx/room/processor/Fts3TableEntityProcessorTest.kt b/room/compiler/src/test/kotlin/androidx/room/processor/Fts3TableEntityProcessorTest.kt
index 95f574d5..cfd4511e 100644
--- a/room/compiler/src/test/kotlin/androidx/room/processor/Fts3TableEntityProcessorTest.kt
+++ b/room/compiler/src/test/kotlin/androidx/room/processor/Fts3TableEntityProcessorTest.kt
@@ -33,6 +33,7 @@
package androidx.room.processor
import androidx.room.FtsOptions
+import androidx.room.ext.requireTypeMirror
import androidx.room.parser.FtsVersion
import androidx.room.parser.SQLTypeAffinity
import androidx.room.vo.CallType
@@ -40,13 +41,13 @@
import androidx.room.vo.FieldGetter
import androidx.room.vo.FieldSetter
import androidx.room.vo.Fields
+import com.squareup.javapoet.TypeName
import org.hamcrest.CoreMatchers
import org.hamcrest.CoreMatchers.`is`
import org.hamcrest.MatcherAssert.assertThat
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
-import javax.lang.model.type.TypeKind
@RunWith(JUnit4::class)
class Fts3TableEntityProcessorTest : BaseFtsEntityParserTest() {
@@ -66,7 +67,7 @@
assertThat(entity.type.toString(), CoreMatchers.`is`("foo.bar.MyEntity"))
assertThat(entity.fields.size, CoreMatchers.`is`(1))
val field = entity.fields.first()
- val intType = invocation.processingEnv.typeUtils.getPrimitiveType(TypeKind.INT)
+ val intType = invocation.processingEnv.requireTypeMirror(TypeName.INT)
assertThat(field, CoreMatchers.`is`(Field(
element = field.element,
name = "rowId",
diff --git a/room/compiler/src/test/kotlin/androidx/room/processor/Fts4TableEntityProcessorTest.kt b/room/compiler/src/test/kotlin/androidx/room/processor/Fts4TableEntityProcessorTest.kt
index 8f65a5c..ed9f9db 100644
--- a/room/compiler/src/test/kotlin/androidx/room/processor/Fts4TableEntityProcessorTest.kt
+++ b/room/compiler/src/test/kotlin/androidx/room/processor/Fts4TableEntityProcessorTest.kt
@@ -19,6 +19,7 @@
import androidx.room.Fts4
import androidx.room.FtsOptions
import androidx.room.ext.asTypeElement
+import androidx.room.ext.requireTypeMirror
import androidx.room.parser.FtsVersion
import androidx.room.parser.SQLTypeAffinity
import androidx.room.vo.CallType
@@ -27,6 +28,7 @@
import androidx.room.vo.FieldSetter
import androidx.room.vo.Fields
import com.google.testing.compile.JavaFileObjects
+import com.squareup.javapoet.TypeName
import org.hamcrest.CoreMatchers
import org.hamcrest.CoreMatchers.`is`
import org.hamcrest.MatcherAssert.assertThat
@@ -34,7 +36,6 @@
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import simpleRun
-import javax.lang.model.type.TypeKind
@RunWith(JUnit4::class)
class Fts4TableEntityProcessorTest : BaseFtsEntityParserTest() {
@@ -54,7 +55,7 @@
assertThat(entity.type.toString(), CoreMatchers.`is`("foo.bar.MyEntity"))
assertThat(entity.fields.size, CoreMatchers.`is`(1))
val field = entity.fields.first()
- val intType = invocation.processingEnv.typeUtils.getPrimitiveType(TypeKind.INT)
+ val intType = invocation.processingEnv.requireTypeMirror(TypeName.INT)
assertThat(field, CoreMatchers.`is`(Field(
element = field.element,
name = "rowId",
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 711e36a..c5e251f 100644
--- a/room/compiler/src/test/kotlin/androidx/room/processor/QueryMethodProcessorTest.kt
+++ b/room/compiler/src/test/kotlin/androidx/room/processor/QueryMethodProcessorTest.kt
@@ -27,6 +27,7 @@
import androidx.room.ext.asExecutableElement
import androidx.room.ext.asTypeElement
import androidx.room.ext.getAllMethods
+import androidx.room.ext.getArrayType
import androidx.room.ext.hasAnnotation
import androidx.room.ext.requireTypeMirror
import androidx.room.ext.typeName
@@ -71,7 +72,6 @@
import org.junit.runners.Parameterized
import org.mockito.Mockito
import javax.lang.model.type.DeclaredType
-import javax.lang.model.type.TypeKind.INT
import javax.lang.model.type.TypeMirror
import javax.tools.JavaFileObject
@@ -132,7 +132,7 @@
assertThat(param.name, `is`("x"))
assertThat(param.sqlName, `is`("x"))
assertThat(param.type,
- `is`(invocation.processingEnv.typeUtils.getPrimitiveType(INT) as TypeMirror))
+ `is`(invocation.processingEnv.requireTypeMirror(TypeName.INT)))
}.compilesWithoutError()
}
@@ -149,9 +149,9 @@
val param = parsedQuery.parameters.first()
assertThat(param.name, `is`("ids"))
assertThat(param.sqlName, `is`("ids"))
- val types = invocation.processingEnv.typeUtils
+ val env = invocation.processingEnv
assertThat(param.type,
- `is`(types.getArrayType(types.getPrimitiveType(INT)) as TypeMirror))
+ `is`(env.getArrayType(TypeName.INT) as TypeMirror))
}.compilesWithoutError()
}
diff --git a/room/compiler/src/test/kotlin/androidx/room/processor/TableEntityProcessorTest.kt b/room/compiler/src/test/kotlin/androidx/room/processor/TableEntityProcessorTest.kt
index f9b4038..9611aba 100644
--- a/room/compiler/src/test/kotlin/androidx/room/processor/TableEntityProcessorTest.kt
+++ b/room/compiler/src/test/kotlin/androidx/room/processor/TableEntityProcessorTest.kt
@@ -17,6 +17,7 @@
package androidx.room.processor
import COMMON
+import androidx.room.ext.requireTypeMirror
import androidx.room.ext.typeName
import androidx.room.parser.SQLTypeAffinity
import androidx.room.processor.ProcessorErrors.RELATION_IN_ENTITY
@@ -38,8 +39,6 @@
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
-import java.lang.AssertionError
-import javax.lang.model.type.TypeKind.INT
@RunWith(JUnit4::class)
class TableEntityProcessorTest : BaseEntityParserTest() {
@@ -54,7 +53,7 @@
assertThat(entity.type.toString(), `is`("foo.bar.MyEntity"))
assertThat(entity.fields.size, `is`(1))
val field = entity.fields.first()
- val intType = invocation.processingEnv.typeUtils.getPrimitiveType(INT)
+ val intType = invocation.processingEnv.requireTypeMirror(TypeName.INT)
assertThat(field, `is`(Field(
element = field.element,
name = "id",
@@ -156,7 +155,7 @@
val cursorValueReader = idField.cursorValueReader
?: throw AssertionError("must have a cursor value reader")
assertThat(cursorValueReader.typeMirror().typeName(),
- `is`(invocation.typeUtils.getPrimitiveType(INT).typeName()))
+ `is`(invocation.processingEnv.requireTypeMirror(TypeName.INT).typeName()))
}.compilesWithoutError()
.withWarningContaining(
ProcessorErrors.mismatchedSetter(
@@ -180,7 +179,7 @@
val statementBinder = idField.statementBinder
?: throw AssertionError("must have a statement binder")
assertThat(statementBinder.typeMirror().typeName(),
- `is`(invocation.typeUtils.getPrimitiveType(INT).typeName()))
+ `is`(invocation.processingEnv.requireTypeMirror(TypeName.INT).typeName()))
}.compilesWithoutError()
}
diff --git a/room/compiler/src/test/kotlin/androidx/room/solver/BasicColumnTypeAdaptersTest.kt b/room/compiler/src/test/kotlin/androidx/room/solver/BasicColumnTypeAdaptersTest.kt
index 2053565..3bee5af 100644
--- a/room/compiler/src/test/kotlin/androidx/room/solver/BasicColumnTypeAdaptersTest.kt
+++ b/room/compiler/src/test/kotlin/androidx/room/solver/BasicColumnTypeAdaptersTest.kt
@@ -17,10 +17,10 @@
package androidx.room.solver
import androidx.room.ext.requireTypeMirror
-import androidx.room.ext.type
import androidx.room.ext.typeName
import androidx.room.processor.Context
import androidx.room.testing.TestInvocation
+import box
import com.squareup.javapoet.ClassName
import com.squareup.javapoet.FieldSpec
import com.squareup.javapoet.JavaFile
@@ -35,8 +35,6 @@
import simpleRun
import testCodeGenScope
import javax.annotation.processing.ProcessingEnvironment
-import javax.lang.model.type.PrimitiveType
-import javax.lang.model.type.TypeKind
import javax.lang.model.type.TypeMirror
@RunWith(Parameterized::class)
@@ -55,36 +53,52 @@
@JvmStatic
fun params(): List<Array<Any>> {
return listOf(
- arrayOf(Input(TypeKind.INT),
- "st.bindLong(6, inp);",
- "out = crs.getInt(9);"),
- arrayOf(Input(TypeKind.BYTE),
- "st.bindLong(6, inp);",
- "out = (byte) crs.getShort(9);"),
- arrayOf(Input(TypeKind.SHORT),
- "st.bindLong(6, inp);",
- "out = crs.getShort(9);"),
- arrayOf(Input(TypeKind.LONG),
- "st.bindLong(6, inp);",
- "out = crs.getLong(9);"),
- arrayOf(Input(TypeKind.CHAR),
- "st.bindLong(6, inp);",
- "out = (char) crs.getInt(9);"),
- arrayOf(Input(TypeKind.FLOAT),
- "st.bindDouble(6, inp);",
- "out = crs.getFloat(9);"),
- arrayOf(Input(TypeKind.DOUBLE),
- "st.bindDouble(6, inp);",
- "out = crs.getDouble(9);"),
- arrayOf(Input(TypeKind.DECLARED, "java.lang.String"),
- """
+ arrayOf(
+ Input(TypeName.INT),
+ "st.bindLong(6, inp);",
+ "out = crs.getInt(9);"
+ ),
+ arrayOf(
+ Input(TypeName.BYTE),
+ "st.bindLong(6, inp);",
+ "out = (byte) crs.getShort(9);"
+ ),
+ arrayOf(
+ Input(TypeName.SHORT),
+ "st.bindLong(6, inp);",
+ "out = crs.getShort(9);"
+ ),
+ arrayOf(
+ Input(TypeName.LONG),
+ "st.bindLong(6, inp);",
+ "out = crs.getLong(9);"
+ ),
+ arrayOf(
+ Input(TypeName.CHAR),
+ "st.bindLong(6, inp);",
+ "out = (char) crs.getInt(9);"
+ ),
+ arrayOf(
+ Input(TypeName.FLOAT),
+ "st.bindDouble(6, inp);",
+ "out = crs.getFloat(9);"
+ ),
+ arrayOf(
+ Input(TypeName.DOUBLE),
+ "st.bindDouble(6, inp);",
+ "out = crs.getDouble(9);"
+ ),
+ arrayOf(
+ Input(TypeName.get(String::class.java)),
+ """
if (inp == null) {
st.bindNull(6);
} else {
st.bindString(6, inp);
}
""".trimIndent(),
- "out = crs.getString(9);")
+ "out = crs.getString(9);"
+ )
)
}
}
@@ -93,7 +107,7 @@
fun bind() {
simpleRun { invocation ->
val adapter = TypeAdapterStore.create(Context(invocation.processingEnv))
- .findColumnTypeAdapter(input.getTypeMirror(invocation.processingEnv), null)!!
+ .findColumnTypeAdapter(input.getTypeMirror(invocation.processingEnv), null)!!
adapter.bindToStmt("st", "6", "inp", scope)
assertThat(scope.generate().toString().trim(), `is`(bindCode))
generateCode(invocation, false)
@@ -102,15 +116,17 @@
@Test
fun boxedBind() {
- if (!input.typeKind.isPrimitive) {
+ if (!input.typeName.isPrimitive) {
return // no-op for those
}
simpleRun { invocation ->
val adapter = TypeAdapterStore.create(Context(invocation.processingEnv))
- .findColumnTypeAdapter(
- input.getBoxedTypeMirror(invocation.processingEnv), null)!!
+ .findColumnTypeAdapter(
+ input.getBoxedTypeMirror(invocation.processingEnv), null
+ )!!
adapter.bindToStmt("st", "6", "inp", scope)
- assertThat(scope.generate().toString().trim(), `is`(
+ assertThat(
+ scope.generate().toString().trim(), `is`(
"""
if (inp == null) {
st.bindNull(6);
@@ -118,7 +134,8 @@
$bindCode
}
""".trimIndent()
- ))
+ )
+ )
generateCode(invocation, true)
}.compilesWithoutError()
}
@@ -127,16 +144,16 @@
val typeMirror = if (boxed) input.getBoxedTypeMirror(invocation.processingEnv)
else input.getTypeMirror(invocation.processingEnv)
val spec = TypeSpec.classBuilder("OutClass")
- .addField(FieldSpec.builder(SQLITE_STMT, "st").build())
- .addField(FieldSpec.builder(CURSOR, "crs").build())
- .addField(FieldSpec.builder(typeMirror.typeName(), "out").build())
- .addField(FieldSpec.builder(typeMirror.typeName(), "inp").build())
- .addMethod(
- MethodSpec.methodBuilder("foo")
- .addCode(scope.builder().build())
- .build()
- )
- .build()
+ .addField(FieldSpec.builder(SQLITE_STMT, "st").build())
+ .addField(FieldSpec.builder(CURSOR, "crs").build())
+ .addField(FieldSpec.builder(typeMirror.typeName(), "out").build())
+ .addField(FieldSpec.builder(typeMirror.typeName(), "inp").build())
+ .addMethod(
+ MethodSpec.methodBuilder("foo")
+ .addCode(scope.builder().build())
+ .build()
+ )
+ .build()
JavaFile.builder("foo.bar", spec).build().writeTo(invocation.processingEnv.filer)
}
@@ -144,7 +161,7 @@
fun read() {
simpleRun { invocation ->
val adapter = TypeAdapterStore.create(Context(invocation.processingEnv))
- .findColumnTypeAdapter(input.getTypeMirror(invocation.processingEnv), null)!!
+ .findColumnTypeAdapter(input.getTypeMirror(invocation.processingEnv), null)!!
adapter.readFromCursor("out", "crs", "9", scope)
assertThat(scope.generate().toString().trim(), `is`(cursorCode))
generateCode(invocation, false)
@@ -153,15 +170,17 @@
@Test
fun readBoxed() {
- if (!input.typeKind.isPrimitive) {
+ if (!input.typeName.isPrimitive) {
return // no-op for those
}
simpleRun { invocation ->
val adapter = TypeAdapterStore.create(Context(invocation.processingEnv))
- .findColumnTypeAdapter(
- input.getBoxedTypeMirror(invocation.processingEnv), null)!!
+ .findColumnTypeAdapter(
+ input.getBoxedTypeMirror(invocation.processingEnv), null
+ )!!
adapter.readFromCursor("out", "crs", "9", scope)
- assertThat(scope.generate().toString().trim(), `is`(
+ assertThat(
+ scope.generate().toString().trim(), `is`(
"""
if (crs.isNull(9)) {
out = null;
@@ -169,28 +188,21 @@
$cursorCode
}
""".trimIndent()
- ))
+ )
+ )
generateCode(invocation, true)
}.compilesWithoutError()
}
- data class Input(val typeKind: TypeKind, val qName: String? = null) {
+ data class Input(val typeName: TypeName) {
fun getTypeMirror(processingEnv: ProcessingEnvironment): TypeMirror {
- return if (typeKind.isPrimitive) {
- processingEnv.typeUtils.getPrimitiveType(typeKind)
- } else {
- processingEnv.requireTypeMirror(qName!!)
- }
+ return processingEnv.requireTypeMirror(typeName)
}
fun getBoxedTypeMirror(processingEnv: ProcessingEnvironment): TypeMirror {
- return if (typeKind.isPrimitive) {
+ return getTypeMirror(processingEnv).box(
processingEnv.typeUtils
- .boxedClass(getTypeMirror(processingEnv) as PrimitiveType)
- .type
- } else {
- getTypeMirror(processingEnv)
- }
+ )
}
}
}
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 643788e..c1309b5 100644
--- a/room/compiler/src/test/kotlin/androidx/room/solver/TypeAdapterStoreTest.kt
+++ b/room/compiler/src/test/kotlin/androidx/room/solver/TypeAdapterStoreTest.kt
@@ -66,7 +66,6 @@
import simpleRun
import testCodeGenScope
import javax.annotation.processing.ProcessingEnvironment
-import javax.lang.model.type.TypeKind
@Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN")
@RunWith(JUnit4::class)
@@ -79,7 +78,7 @@
fun testDirect() {
singleRun { invocation ->
val store = TypeAdapterStore.create(Context(invocation.processingEnv))
- val primitiveType = invocation.processingEnv.typeUtils.getPrimitiveType(TypeKind.INT)
+ val primitiveType = invocation.processingEnv.requireTypeMirror(TypeName.INT)
val adapter = store.findColumnTypeAdapter(primitiveType, null)
assertThat(adapter, notNullValue())
}.compilesWithoutError()
@@ -107,8 +106,7 @@
fun testVia1TypeAdapter() {
singleRun { invocation ->
val store = TypeAdapterStore.create(Context(invocation.processingEnv))
- val booleanType = invocation.processingEnv.typeUtils
- .getPrimitiveType(TypeKind.BOOLEAN)
+ val booleanType = invocation.processingEnv.requireTypeMirror(TypeName.BOOLEAN)
val adapter = store.findColumnTypeAdapter(booleanType, null)
assertThat(adapter, notNullValue())
assertThat(adapter, instanceOf(CompositeAdapter::class.java))
@@ -580,7 +578,7 @@
fun pointTypeConverters(env: ProcessingEnvironment): List<TypeConverter> {
val tPoint = env.requireTypeMirror("foo.bar.Point")
- val tBoolean = env.typeUtils.getPrimitiveType(TypeKind.BOOLEAN)
+ val tBoolean = env.requireTypeMirror(TypeName.BOOLEAN)
return listOf(
object : TypeConverter(tPoint, tBoolean) {
override fun convert(
diff --git a/room/compiler/src/test/kotlin/androidx/room/verifier/DatabaseVerifierTest.kt b/room/compiler/src/test/kotlin/androidx/room/verifier/DatabaseVerifierTest.kt
index 5a2fb8b..9324239 100644
--- a/room/compiler/src/test/kotlin/androidx/room/verifier/DatabaseVerifierTest.kt
+++ b/room/compiler/src/test/kotlin/androidx/room/verifier/DatabaseVerifierTest.kt
@@ -17,6 +17,7 @@
package androidx.room.verifier
import androidx.room.ext.requireTypeElement
+import androidx.room.ext.requireTypeMirror
import androidx.room.parser.Collate
import androidx.room.parser.SQLTypeAffinity
import androidx.room.parser.SqlParser
@@ -34,6 +35,7 @@
import androidx.room.vo.PrimaryKey
import collect
import columnNames
+import com.squareup.javapoet.TypeName
import org.hamcrest.CoreMatchers.`is`
import org.hamcrest.CoreMatchers.containsString
import org.hamcrest.CoreMatchers.hasItem
@@ -50,8 +52,6 @@
import javax.lang.model.element.ExecutableElement
import javax.lang.model.element.TypeElement
import javax.lang.model.type.DeclaredType
-import javax.lang.model.type.PrimitiveType
-import javax.lang.model.type.TypeKind
import javax.lang.model.type.TypeMirror
@RunWith(Parameterized::class)
@@ -224,7 +224,7 @@
"User",
field(
"id",
- primitive(invocation.context, TypeKind.INT),
+ primitive(invocation.context, TypeName.INT),
SQLTypeAffinity.INTEGER
),
field(
@@ -257,16 +257,16 @@
entity(
invocation,
"User",
- field("id", primitive(context, TypeKind.INT), SQLTypeAffinity.INTEGER),
+ field("id", primitive(context, TypeName.INT), SQLTypeAffinity.INTEGER),
field("name", context.COMMON_TYPES.STRING, SQLTypeAffinity.TEXT),
field("lastName", context.COMMON_TYPES.STRING, SQLTypeAffinity.TEXT),
- field("ratio", primitive(context, TypeKind.FLOAT), SQLTypeAffinity.REAL)
+ field("ratio", primitive(context, TypeName.FLOAT), SQLTypeAffinity.REAL)
)
),
listOf(
view(
"UserSummary", "SELECT id, name FROM User",
- field("id", primitive(context, TypeKind.INT), SQLTypeAffinity.INTEGER),
+ field("id", primitive(context, TypeName.INT), SQLTypeAffinity.INTEGER),
field("name", context.COMMON_TYPES.STRING, SQLTypeAffinity.TEXT)
)
)
@@ -347,8 +347,8 @@
f.setter = FieldSetter(name, type, CallType.FIELD)
}
- private fun primitive(context: Context, kind: TypeKind): PrimitiveType {
- return context.processingEnv.typeUtils.getPrimitiveType(kind)
+ private fun primitive(context: Context, typeName: TypeName): TypeMirror {
+ return context.processingEnv.requireTypeMirror(typeName)
}
private fun getPrimaryKeys(connection: Connection, tableName: String): List<String> {