Merge "Make Camera2RequestMetaData unwrap as CameraCaptureSession" into androidx-main
diff --git a/camera/camera-core/src/main/java/androidx/camera/core/processing/SurfaceProcessorNode.java b/camera/camera-core/src/main/java/androidx/camera/core/processing/SurfaceProcessorNode.java
index 347a8ca..efaa57f 100644
--- a/camera/camera-core/src/main/java/androidx/camera/core/processing/SurfaceProcessorNode.java
+++ b/camera/camera-core/src/main/java/androidx/camera/core/processing/SurfaceProcessorNode.java
@@ -142,6 +142,11 @@
private void sendSurfacesToProcessorWhenReady(@NonNull SettableSurface input,
@NonNull SettableSurface output) {
SurfaceRequest surfaceRequest = input.createSurfaceRequest(mCameraInternal);
+ setupRotationUpdates(
+ surfaceRequest,
+ output,
+ input.getMirroring(),
+ input.getRotationDegrees());
Futures.addCallback(output.createSurfaceOutputFuture(input.getSize(), input.getCropRect(),
input.getRotationDegrees(), input.getMirroring()),
new FutureCallback<SurfaceOutput>() {
@@ -150,7 +155,6 @@
Preconditions.checkNotNull(surfaceOutput);
mSurfaceProcessor.onOutputSurface(surfaceOutput);
mSurfaceProcessor.onInputSurface(surfaceRequest);
- setupSurfaceUpdatePipeline(input, surfaceRequest, output, surfaceOutput);
}
@Override
@@ -163,18 +167,35 @@
}, mainThreadExecutor());
}
- void setupSurfaceUpdatePipeline(@NonNull SettableSurface input,
- @NonNull SurfaceRequest inputSurfaceRequest, @NonNull SettableSurface output,
- @NonNull SurfaceOutput surfaceOutput) {
+ /**
+ * Propagates rotation updates from the input edge to the output edge.
+ *
+ * <p>Transformation info, such as rotation and crop rect, can be updated after the
+ * connection is established. When that happens, the node should update the output
+ * transformation via e.g. {@link SurfaceRequest#updateTransformationInfo} without recreating
+ * the pipeline.
+ *
+ * <p>Currently, we only propagates the rotation. When the
+ * input edge's rotation changes, we re-calculate the delta and notify the output edge.
+ *
+ * @param inputSurfaceRequest {@link SurfaceRequest} of the input edge.
+ * @param outputSurface {@link SettableSurface} of the output edge.
+ * @param mirrored whether the node mirrors the buffer.
+ * @param rotatedDegrees how much the node rotates the buffer.
+ */
+ void setupRotationUpdates(
+ @NonNull SurfaceRequest inputSurfaceRequest,
+ @NonNull SettableSurface outputSurface,
+ boolean mirrored,
+ int rotatedDegrees) {
inputSurfaceRequest.setTransformationInfoListener(mainThreadExecutor(), info -> {
- // Calculate rotation degrees
- // To obtain the required rotation degrees of output surface, the rotation degrees of
- // surfaceOutput has to be eliminated.
- int rotationDegrees = info.getRotationDegrees() - surfaceOutput.getRotationDegrees();
- if (input.getMirroring()) {
+ // To obtain the rotation degrees delta, the rotation performed by the node must be
+ // eliminated.
+ int rotationDegrees = info.getRotationDegrees() - rotatedDegrees;
+ if (mirrored) {
rotationDegrees = -rotationDegrees;
}
- output.setRotationDegrees(within360(rotationDegrees));
+ outputSurface.setRotationDegrees(within360(rotationDegrees));
});
}
diff --git a/room/room-compiler-processing/src/main/java/androidx/room/compiler/codegen/PoetExt.kt b/room/room-compiler-processing/src/main/java/androidx/room/compiler/codegen/PoetExt.kt
index 9e34117..584d4df 100644
--- a/room/room-compiler-processing/src/main/java/androidx/room/compiler/codegen/PoetExt.kt
+++ b/room/room-compiler-processing/src/main/java/androidx/room/compiler/codegen/PoetExt.kt
@@ -16,12 +16,6 @@
package androidx.room.compiler.codegen
-import androidx.room.compiler.processing.XNullability
-import com.squareup.kotlinpoet.javapoet.JClassName
-import com.squareup.kotlinpoet.javapoet.JTypeName
-import com.squareup.kotlinpoet.javapoet.toKClassName
-import com.squareup.kotlinpoet.javapoet.toKTypeName
-
typealias JCodeBlock = com.squareup.javapoet.CodeBlock
typealias JCodeBlockBuilder = com.squareup.javapoet.CodeBlock.Builder
typealias JAnnotationSpecBuilder = com.squareup.javapoet.AnnotationSpec.Builder
@@ -39,7 +33,3 @@
internal val N = "\$N"
internal val S = "\$S"
internal val W = "\$W"
-
-// TODO(b/247247366): Temporary migration API, delete me plz!
-fun JTypeName.toXTypeName() = XTypeName(this, this.toKTypeName(), XNullability.NONNULL)
-fun JClassName.toXClassName() = XClassName(this, this.toKClassName(), XNullability.NONNULL)
\ No newline at end of file
diff --git a/room/room-compiler-processing/src/main/java/androidx/room/compiler/codegen/XTypeName.kt b/room/room-compiler-processing/src/main/java/androidx/room/compiler/codegen/XTypeName.kt
index d1416b0..7e7dc7b 100644
--- a/room/room-compiler-processing/src/main/java/androidx/room/compiler/codegen/XTypeName.kt
+++ b/room/room-compiler-processing/src/main/java/androidx/room/compiler/codegen/XTypeName.kt
@@ -16,6 +16,8 @@
package androidx.room.compiler.codegen
+import com.squareup.kotlinpoet.asClassName as asKClassName
+import com.squareup.kotlinpoet.asTypeName as asKTypeName
import androidx.room.compiler.processing.XNullability
import com.squareup.kotlinpoet.ARRAY
import com.squareup.kotlinpoet.BOOLEAN_ARRAY
@@ -33,8 +35,6 @@
import com.squareup.kotlinpoet.MUTABLE_SET
import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy
import com.squareup.kotlinpoet.SHORT_ARRAY
-import com.squareup.kotlinpoet.asClassName
-import com.squareup.kotlinpoet.asTypeName
import com.squareup.kotlinpoet.javapoet.JClassName
import com.squareup.kotlinpoet.javapoet.JParameterizedTypeName
import com.squareup.kotlinpoet.javapoet.JTypeName
@@ -62,6 +62,9 @@
val isPrimitive: Boolean
get() = java.isPrimitive
+ val isBoxedPrimitive: Boolean
+ get() = java.isBoxedPrimitive
+
/**
* Returns the raw [XTypeName] if this is a parametrized type name, or itself if not.
*
@@ -82,11 +85,19 @@
// TODO(b/248633751): Handle primitive to boxed when becoming nullable?
return XTypeName(
java = java,
- kotlin = kotlin.copy(nullable = nullable),
+ kotlin = if (kotlin != UNAVAILABLE_KTYPE_NAME) {
+ kotlin.copy(nullable = nullable)
+ } else {
+ UNAVAILABLE_KTYPE_NAME
+ },
nullability = if (nullable) XNullability.NULLABLE else XNullability.NONNULL
)
}
+ fun equalsIgnoreNullability(other: XTypeName): Boolean {
+ return this.copy(nullable = false) == other.copy(nullable = false)
+ }
+
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is XTypeName) return false
@@ -113,6 +124,11 @@
append("]")
}
+ fun toString(codeLanguage: CodeLanguage) = when (codeLanguage) {
+ CodeLanguage.JAVA -> java.toString()
+ CodeLanguage.KOTLIN -> kotlin.toString()
+ }
+
companion object {
/**
* A convenience [XTypeName] that represents [Unit] in Kotlin and `void` in Java.
@@ -121,6 +137,15 @@
java = JTypeName.VOID,
kotlin = com.squareup.kotlinpoet.UNIT
)
+
+ /**
+ * A convenience [XTypeName] that represents [Any] in Kotlin and [Object] in Java.
+ */
+ val ANY_OBJECT = XTypeName(
+ java = JTypeName.OBJECT,
+ kotlin = com.squareup.kotlinpoet.ANY
+ )
+
val PRIMITIVE_BOOLEAN = Boolean::class.asPrimitiveTypeName()
val PRIMITIVE_BYTE = Byte::class.asPrimitiveTypeName()
val PRIMITIVE_SHORT = Short::class.asPrimitiveTypeName()
@@ -130,6 +155,15 @@
val PRIMITIVE_FLOAT = Float::class.asPrimitiveTypeName()
val PRIMITIVE_DOUBLE = Double::class.asPrimitiveTypeName()
+ val BOXED_BOOLEAN = Boolean::class.asClassName()
+ val BOXED_BYTE = Byte::class.asClassName()
+ val BOXED_SHORT = Short::class.asClassName()
+ val BOXED_INT = Int::class.asClassName()
+ val BOXED_LONG = Long::class.asClassName()
+ val BOXED_CHAR = Char::class.asClassName()
+ val BOXED_FLOAT = Float::class.asClassName()
+ val BOXED_DOUBLE = Double::class.asClassName()
+
val ANY_WILDCARD = XTypeName(
java = JWildcardTypeName.subtypeOf(Object::class.java),
kotlin = com.squareup.kotlinpoet.STAR
@@ -178,7 +212,14 @@
JArrayTypeName.of(componentTypeName.java) to
ARRAY.parameterizedBy(componentTypeName.kotlin)
}
- return XTypeName(java, kotlin)
+ return XTypeName(
+ java = java,
+ kotlin = if (componentTypeName.kotlin != UNAVAILABLE_KTYPE_NAME) {
+ kotlin
+ } else {
+ UNAVAILABLE_KTYPE_NAME
+ }
+ )
}
/**
@@ -191,7 +232,11 @@
fun getConsumerSuperName(bound: XTypeName): XTypeName {
return XTypeName(
java = JWildcardTypeName.supertypeOf(bound.java),
- kotlin = KWildcardTypeName.consumerOf(bound.kotlin)
+ kotlin = if (bound.kotlin != UNAVAILABLE_KTYPE_NAME) {
+ KWildcardTypeName.consumerOf(bound.kotlin)
+ } else {
+ UNAVAILABLE_KTYPE_NAME
+ }
)
}
@@ -205,7 +250,11 @@
fun getProducerExtendsName(bound: XTypeName): XTypeName {
return XTypeName(
java = JWildcardTypeName.subtypeOf(bound.java),
- kotlin = KWildcardTypeName.producerOf(bound.kotlin)
+ kotlin = if (bound.kotlin != UNAVAILABLE_KTYPE_NAME) {
+ KWildcardTypeName.producerOf(bound.kotlin)
+ } else {
+ UNAVAILABLE_KTYPE_NAME
+ }
)
}
}
@@ -241,14 +290,25 @@
): XTypeName {
return XTypeName(
java = JParameterizedTypeName.get(java, *typeArguments.map { it.java }.toTypedArray()),
- kotlin = kotlin.parameterizedBy(typeArguments.map { it.kotlin })
+ kotlin = if (
+ kotlin != UNAVAILABLE_KTYPE_NAME &&
+ typeArguments.none { it.kotlin == UNAVAILABLE_KTYPE_NAME }
+ ) {
+ kotlin.parameterizedBy(typeArguments.map { it.kotlin })
+ } else {
+ UNAVAILABLE_KTYPE_NAME
+ }
)
}
override fun copy(nullable: Boolean): XClassName {
return XClassName(
java = java,
- kotlin = kotlin.copy(nullable = nullable) as KClassName,
+ kotlin = if (kotlin != UNAVAILABLE_KTYPE_NAME) {
+ kotlin.copy(nullable = nullable) as KClassName
+ } else {
+ UNAVAILABLE_KTYPE_NAME
+ },
nullability = if (nullable) XNullability.NULLABLE else XNullability.NONNULL
)
}
@@ -294,7 +354,7 @@
} else {
JClassName.get(this.java)
}
- val kClassName = this.asClassName()
+ val kClassName = this.asKClassName()
return XClassName(
java = jClassName,
kotlin = kClassName,
@@ -323,7 +383,7 @@
fun KClass<*>.asMutableClassName(): XClassName {
val java = JClassName.get(this.java)
val kotlin = when (this) {
- Iterator::class -> MUTABLE_ITERABLE
+ Iterable::class -> MUTABLE_ITERABLE
Collection::class -> MUTABLE_COLLECTION
List::class -> MUTABLE_LIST
Set::class -> MUTABLE_SET
@@ -358,7 +418,7 @@
"$this does not represent a primitive."
}
val jTypeName = getPrimitiveJTypeName(this.java)
- val kTypeName = this.asTypeName()
+ val kTypeName = this.asKTypeName()
return XTypeName(jTypeName, kTypeName)
}
diff --git a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/DeclarationCollector.kt b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/DeclarationCollector.kt
index db24932..a3a4713 100644
--- a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/DeclarationCollector.kt
+++ b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/DeclarationCollector.kt
@@ -115,7 +115,7 @@
return false
}
// check package
- return packageName == closestMemberContainer.className.packageName()
+ return packageName == closestMemberContainer.asClassName().packageName
}
private fun XMethodElement.isStaticInterfaceMethod(): Boolean {
diff --git a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/XExecutableElement.kt b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/XExecutableElement.kt
index 9cc75c0..399c0bc7 100644
--- a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/XExecutableElement.kt
+++ b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/XExecutableElement.kt
@@ -31,7 +31,7 @@
* be an [XTypeElement].
* * When running with KSP, if this function is in source, the value will **NOT** be an
* [XTypeElement]. If you need the generated synthetic java class name, you can use
- * [XMemberContainer.className] property.
+ * [XMemberContainer.asClassName] property.
*/
override val enclosingElement: XMemberContainer
diff --git a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/XFieldElement.kt b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/XFieldElement.kt
index 0a7095d..27bd14d 100644
--- a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/XFieldElement.kt
+++ b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/XFieldElement.kt
@@ -32,7 +32,7 @@
* * When running with KSP, the value will **NOT** be an [XTypeElement]. It will
* be an [KspSyntheticFileMemberContainer] if this property is coming from the classpath or
* [KspFileMemberContainer] if this property is in source. If you need the generated
- * synthetic java class name, you can use [XMemberContainer.className] property.
+ * synthetic java class name, you can use [XMemberContainer.asClassName] property.
*/
override val enclosingElement: XMemberContainer
diff --git a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/XMemberContainer.kt b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/XMemberContainer.kt
index 1e51046..6d7cca4 100644
--- a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/XMemberContainer.kt
+++ b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/XMemberContainer.kt
@@ -28,21 +28,20 @@
interface XMemberContainer : XElement {
override val name: String
- get() = if (this is XTypeElement) this.name else className.simpleName()
+ get() = if (this is XTypeElement) this.name else asClassName().simpleNames.first()
/**
* The JVM ClassName for this container.
*
* For top level members of a Kotlin file, you can use this [ClassName] for code generation.
*/
- // TODO(b/247248619): Deprecate when more progress is made, otherwise -werror fails the build.
- // @Deprecated(
- // message = "Use asClassName().toJavaPoet() to be clear the name is for JavaPoet.",
- // replaceWith = ReplaceWith(
- // expression = "asClassName().toJavaPoet()",
- // imports = ["androidx.room.compiler.codegen.toJavaPoet"]
- // )
- // )
+ @Deprecated(
+ message = "Use asClassName().toJavaPoet() to be clear the name is for JavaPoet.",
+ replaceWith = ReplaceWith(
+ expression = "asClassName().toJavaPoet()",
+ imports = ["androidx.room.compiler.codegen.toJavaPoet"]
+ )
+ )
val className: ClassName
/**
diff --git a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/XProcessingEnv.kt b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/XProcessingEnv.kt
index 9d3f1bb..efaa56e 100644
--- a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/XProcessingEnv.kt
+++ b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/XProcessingEnv.kt
@@ -158,6 +158,20 @@
fun findType(klass: KClass<*>) = findType(klass.java.canonicalName!!)
+ fun requireTypeElement(typeName: XTypeName): XTypeElement {
+ if (typeName.isPrimitive) {
+ return requireTypeElement(typeName.java)
+ }
+ return when (backend) {
+ Backend.JAVAC -> requireTypeElement(typeName.java)
+ Backend.KSP -> {
+ val kClassName = typeName.kotlin as? KClassName
+ ?: error("cannot find required type element ${typeName.kotlin}")
+ requireTypeElement(kClassName.canonicalName)
+ }
+ }
+ }
+
fun requireTypeElement(typeName: TypeName) = requireTypeElement(typeName.toString())
fun requireTypeElement(klass: KClass<*>) = requireTypeElement(klass.java.canonicalName!!)
@@ -166,6 +180,8 @@
fun findTypeElement(klass: KClass<*>) = findTypeElement(klass.java.canonicalName!!)
+ fun getArrayType(typeName: XTypeName) = getArrayType(requireType(typeName))
+
fun getArrayType(typeName: TypeName) = getArrayType(requireType(typeName))
enum class Backend {
diff --git a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/XType.kt b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/XType.kt
index b79f94a..9256458 100644
--- a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/XType.kt
+++ b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/XType.kt
@@ -16,8 +16,9 @@
package androidx.room.compiler.processing
+import androidx.room.compiler.codegen.XClassName
import androidx.room.compiler.codegen.XTypeName
-import com.squareup.javapoet.ClassName
+import androidx.room.compiler.codegen.asClassName
import com.squareup.javapoet.TypeName
import kotlin.contracts.contract
import kotlin.reflect.KClass
@@ -121,11 +122,6 @@
fun boxed(): XType
/**
- * Returns `true` if this is a [List]
- */
- fun isList(): Boolean = isTypeOf(List::class)
-
- /**
* Returns `true` if this is the None type.
*/
fun isNone(): Boolean
@@ -162,6 +158,11 @@
* already [XNullability.NONNULL].
*/
fun makeNonNullable(): XType
+
+ /**
+ * Returns true if this type is a type variable.
+ */
+ fun isTypeVariable(): Boolean
}
/**
@@ -174,14 +175,6 @@
return this is XArrayType
}
-/**
- * Returns true if this is a [List] or [Set].
- */
-// TODO(b/248280754): Move to room-compiler, overloaded function name
-fun XType.isCollection(): Boolean {
- return isTypeOf(List::class) || isTypeOf(Set::class)
-}
-
private fun isAssignableWithoutVariance(from: XType, to: XType): Boolean {
val assignable = to.isAssignableFrom(from)
if (assignable) {
@@ -218,36 +211,40 @@
/**
* Returns `true` if this is a primitive or boxed it
*/
-fun XType.isInt(): Boolean = typeName == TypeName.INT || typeName == KnownTypeNames.BOXED_INT
+fun XType.isInt(): Boolean = asTypeName() == XTypeName.PRIMITIVE_INT ||
+ asTypeName().equalsIgnoreNullability(KnownTypeNames.BOXED_INT)
/**
* Returns `true` if this is a primitive or boxed long
*/
-fun XType.isLong(): Boolean = typeName == TypeName.LONG || typeName == KnownTypeNames.BOXED_LONG
+fun XType.isLong(): Boolean = asTypeName() == XTypeName.PRIMITIVE_LONG ||
+ asTypeName().equalsIgnoreNullability(KnownTypeNames.BOXED_LONG)
+
/**
* Returns `true` if this is `void`
*/
-fun XType.isVoid() = typeName == TypeName.VOID
+fun XType.isVoid() = asTypeName() == XTypeName.UNIT_VOID
/**
* Returns `true` if this is a [Void]
*/
-fun XType.isVoidObject(): Boolean = typeName == KnownTypeNames.BOXED_VOID
+fun XType.isVoidObject(): Boolean = asTypeName().equalsIgnoreNullability(KnownTypeNames.BOXED_VOID)
/**
* Returns `true` if this is the kotlin [Unit] type.
*/
-fun XType.isKotlinUnit(): Boolean = typeName == KnownTypeNames.KOTLIN_UNIT
+fun XType.isKotlinUnit(): Boolean = asTypeName().equalsIgnoreNullability(KnownTypeNames.KOTLIN_UNIT)
/**
* Returns `true` if this represents a `byte`.
*/
-fun XType.isByte(): Boolean = typeName == TypeName.BYTE || typeName == KnownTypeNames.BOXED_BYTE
+fun XType.isByte(): Boolean = asTypeName() == XTypeName.PRIMITIVE_BYTE ||
+ asTypeName().equalsIgnoreNullability(KnownTypeNames.BOXED_BYTE)
internal object KnownTypeNames {
- val BOXED_VOID = TypeName.VOID.box()
- val BOXED_INT = TypeName.INT.box()
- val BOXED_LONG = TypeName.LONG.box()
- val BOXED_BYTE = TypeName.BYTE.box()
- val KOTLIN_UNIT = ClassName.get("kotlin", "Unit")
+ val BOXED_VOID = Void::class.asClassName()
+ val BOXED_INT = Int::class.asClassName()
+ val BOXED_LONG = Long::class.asClassName()
+ val BOXED_BYTE = Byte::class.asClassName()
+ val KOTLIN_UNIT = XClassName.get("kotlin", "Unit")
}
diff --git a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/XTypeElement.kt b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/XTypeElement.kt
index 1faa32c9..0023e78 100644
--- a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/XTypeElement.kt
+++ b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/XTypeElement.kt
@@ -58,14 +58,13 @@
/**
* Javapoet [ClassName] of the type.
*/
- // TODO(b/247248619): Deprecate when more progress is made, otherwise -werror fails the build.
- // @Deprecated(
- // message = "Use asClassName().toJavaPoet() to be clear the name is for JavaPoet.",
- // replaceWith = ReplaceWith(
- // expression = "asClassName().toJavaPoet()",
- // imports = ["androidx.room.compiler.codegen.toJavaPoet"]
- // )
- // )
+ @Deprecated(
+ message = "Use asClassName().toJavaPoet() to be clear the name is for JavaPoet.",
+ replaceWith = ReplaceWith(
+ expression = "asClassName().toJavaPoet()",
+ imports = ["androidx.room.compiler.codegen.toJavaPoet"]
+ )
+ )
override val className: ClassName
/**
diff --git a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/XTypeParameterElement.kt b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/XTypeParameterElement.kt
index 75bfaf8..e6bc9ca 100644
--- a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/XTypeParameterElement.kt
+++ b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/XTypeParameterElement.kt
@@ -32,6 +32,7 @@
*/
val bounds: List<XType>
+ // TODO(b/259091615): Migrate to XTypeName
/** Returns the [TypeVariableName] for this type parameter) */
val typeVariableName: TypeVariableName
}
\ No newline at end of file
diff --git a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/javac/JavacType.kt b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/javac/JavacType.kt
index 7457b78..e5463e1 100644
--- a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/javac/JavacType.kt
+++ b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/javac/JavacType.kt
@@ -200,4 +200,6 @@
"TypeMirror#toXProcessing(XProcessingEnv)?"
)
}
+
+ override fun isTypeVariable() = typeMirror.kind == TypeKind.TYPEVAR
}
diff --git a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/javac/JavacTypeElement.kt b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/javac/JavacTypeElement.kt
index a2beb5a..1b50858 100644
--- a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/javac/JavacTypeElement.kt
+++ b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/javac/JavacTypeElement.kt
@@ -61,6 +61,13 @@
element.qualifiedName.toString()
}
+ @Deprecated(
+ "Use asClassName().toJavaPoet() to be clear the name is for JavaPoet.",
+ replaceWith = ReplaceWith(
+ "asClassName().toJavaPoet()",
+ "androidx.room.compiler.codegen.toJavaPoet"
+ )
+ )
override val className: ClassName by lazy {
xClassName.java
}
diff --git a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspFileMemberContainer.kt b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspFileMemberContainer.kt
index ab94b8c..370d338 100644
--- a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspFileMemberContainer.kt
+++ b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspFileMemberContainer.kt
@@ -44,6 +44,14 @@
get() = null
override val declaration: KSDeclaration?
get() = null
+
+ @Deprecated(
+ "Use asClassName().toJavaPoet() to be clear the name is for JavaPoet.",
+ replaceWith = ReplaceWith(
+ "asClassName().toJavaPoet()",
+ "androidx.room.compiler.codegen.toJavaPoet"
+ )
+ )
override val className: ClassName by lazy {
xClassName.java
}
diff --git a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspType.kt b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspType.kt
index 133b002..413bc62 100644
--- a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspType.kt
+++ b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspType.kt
@@ -95,7 +95,7 @@
}
override val superTypes: List<XType> by lazy {
- if (typeName == TypeName.OBJECT) {
+ if (xTypeName == XTypeName.ANY_OBJECT) {
// The object class doesn't have any supertypes.
return@lazy emptyList<XType>()
}
@@ -298,4 +298,6 @@
}
return copyWithNullability(XNullability.NONNULL)
}
+
+ override fun isTypeVariable() = false
}
diff --git a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspTypeArgumentType.kt b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspTypeArgumentType.kt
index 668554d..d4435f0 100644
--- a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspTypeArgumentType.kt
+++ b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspTypeArgumentType.kt
@@ -63,6 +63,8 @@
return _extendsBound
}
+ override fun isTypeVariable() = true
+
override fun copyWithNullability(nullability: XNullability): KspTypeArgumentType {
return KspTypeArgumentType(
env = env,
diff --git a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspTypeElement.kt b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspTypeElement.kt
index 7674249..81d8218 100644
--- a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspTypeElement.kt
+++ b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspTypeElement.kt
@@ -121,6 +121,13 @@
}
}
+ @Deprecated(
+ "Use asClassName().toJavaPoet() to be clear the name is for JavaPoet.",
+ replaceWith = ReplaceWith(
+ "asClassName().toJavaPoet()",
+ "androidx.room.compiler.codegen.toJavaPoet"
+ )
+ )
override val className: ClassName by lazy {
xClassName.java
}
diff --git a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/synthetic/KspSyntheticFileMemberContainer.kt b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/synthetic/KspSyntheticFileMemberContainer.kt
index 82addef..d584266 100644
--- a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/synthetic/KspSyntheticFileMemberContainer.kt
+++ b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/synthetic/KspSyntheticFileMemberContainer.kt
@@ -49,6 +49,13 @@
override val declaration: KSDeclaration?
get() = null
+ @Deprecated(
+ "Use asClassName().toJavaPoet() to be clear the name is for JavaPoet.",
+ replaceWith = ReplaceWith(
+ "asClassName().toJavaPoet()",
+ "androidx.room.compiler.codegen.toJavaPoet"
+ )
+ )
override val className: ClassName by lazy {
xClassName.java
}
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/codegen/XTypeNameTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/codegen/XTypeNameTest.kt
index f325855..3cfe27c 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/codegen/XTypeNameTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/codegen/XTypeNameTest.kt
@@ -16,6 +16,7 @@
package androidx.room.compiler.codegen
+import androidx.room.compiler.processing.XNullability
import com.google.common.truth.Truth.assertThat
import com.squareup.kotlinpoet.INT
import com.squareup.kotlinpoet.SHORT
@@ -131,4 +132,48 @@
assertThat(expectedRawClass.parametrizedBy(String::class.asClassName()).rawTypeName)
.isEqualTo(expectedRawClass)
}
+
+ @Test
+ fun equalsIgnoreNullability() {
+ assertThat(
+ XTypeName.BOXED_INT.copy(nullable = false).equalsIgnoreNullability(
+ XTypeName.BOXED_INT.copy(nullable = true)
+ )
+ ).isTrue()
+
+ assertThat(
+ XTypeName.BOXED_INT.copy(nullable = false).equalsIgnoreNullability(
+ XTypeName.BOXED_LONG.copy(nullable = true)
+ )
+ ).isFalse()
+ }
+
+ @Test
+ fun toString_codeLanguage() {
+ assertThat(XTypeName.ANY_OBJECT.toString(CodeLanguage.JAVA))
+ .isEqualTo("java.lang.Object")
+ assertThat(XTypeName.ANY_OBJECT.toString(CodeLanguage.KOTLIN))
+ .isEqualTo("kotlin.Any")
+ }
+
+ @Test
+ fun mutations_kotlinUnavailable() {
+ val typeName = XClassName(
+ java = JClassName.get("test", "Foo"),
+ kotlin = XTypeName.UNAVAILABLE_KTYPE_NAME,
+ nullability = XNullability.UNKNOWN
+ )
+ assertThat(typeName.copy(nullable = true).kotlin)
+ .isEqualTo(XTypeName.UNAVAILABLE_KTYPE_NAME)
+ assertThat(typeName.copy(nullable = false).kotlin)
+ .isEqualTo(XTypeName.UNAVAILABLE_KTYPE_NAME)
+ assertThat(typeName.parametrizedBy(XTypeName.BOXED_LONG).kotlin)
+ .isEqualTo(XTypeName.UNAVAILABLE_KTYPE_NAME)
+ assertThat(XTypeName.getArrayName(typeName).kotlin)
+ .isEqualTo(XTypeName.UNAVAILABLE_KTYPE_NAME)
+ assertThat(XTypeName.getConsumerSuperName(typeName).kotlin)
+ .isEqualTo(XTypeName.UNAVAILABLE_KTYPE_NAME)
+ assertThat(XTypeName.getProducerExtendsName(typeName).kotlin)
+ .isEqualTo(XTypeName.UNAVAILABLE_KTYPE_NAME)
+ }
}
\ No newline at end of file
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XProcessingEnvTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XProcessingEnvTest.kt
index eddaa86..0d60682 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XProcessingEnvTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XProcessingEnvTest.kt
@@ -144,12 +144,15 @@
runProcessorTest(
listOf(source)
) { invocation ->
- PRIMITIVE_TYPES.flatMap {
- listOf(it, it.box())
- }.forEach {
- val targetType = invocation.processingEnv.findType(it.toString())
- assertThat(targetType?.typeName).isEqualTo(it)
- assertThat(targetType?.boxed()?.typeName).isEqualTo(it.box())
+ PRIMITIVE_TYPES.zip(BOXED_PRIMITIVE_TYPES).forEach { (primitive, boxed) ->
+ val targetType = invocation.processingEnv.requireType(primitive)
+ assertThat(targetType.asTypeName()).isEqualTo(primitive)
+ assertThat(targetType.boxed().asTypeName()).isEqualTo(boxed)
+ }
+ BOXED_PRIMITIVE_TYPES.forEach { boxed ->
+ val targetType = invocation.processingEnv.requireType(boxed)
+ assertThat(targetType.asTypeName()).isEqualTo(boxed)
+ assertThat(targetType.boxed().asTypeName()).isEqualTo(boxed)
}
}
}
@@ -317,14 +320,25 @@
companion object {
val PRIMITIVE_TYPES = listOf(
- TypeName.BOOLEAN,
- TypeName.BYTE,
- TypeName.SHORT,
- TypeName.INT,
- TypeName.LONG,
- TypeName.CHAR,
- TypeName.FLOAT,
- TypeName.DOUBLE,
+ XTypeName.PRIMITIVE_BOOLEAN,
+ XTypeName.PRIMITIVE_BYTE,
+ XTypeName.PRIMITIVE_SHORT,
+ XTypeName.PRIMITIVE_INT,
+ XTypeName.PRIMITIVE_LONG,
+ XTypeName.PRIMITIVE_CHAR,
+ XTypeName.PRIMITIVE_FLOAT,
+ XTypeName.PRIMITIVE_DOUBLE,
+ )
+
+ val BOXED_PRIMITIVE_TYPES = listOf(
+ XTypeName.BOXED_BOOLEAN,
+ XTypeName.BOXED_BYTE,
+ XTypeName.BOXED_SHORT,
+ XTypeName.BOXED_INT,
+ XTypeName.BOXED_LONG,
+ XTypeName.BOXED_CHAR,
+ XTypeName.BOXED_FLOAT,
+ XTypeName.BOXED_DOUBLE,
)
}
}
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 54f581f..e6eeec0 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
@@ -28,6 +28,7 @@
import androidx.room.compiler.processing.util.getDeclaredMethodByJvmName
import androidx.room.compiler.processing.util.getField
import androidx.room.compiler.processing.util.getMethodByJvmName
+import androidx.room.compiler.processing.util.isCollection
import androidx.room.compiler.processing.util.javaElementUtils
import androidx.room.compiler.processing.util.kspResolver
import androidx.room.compiler.processing.util.runKspTest
@@ -1377,4 +1378,63 @@
""".trimIndent()
))) { it.checkType() }
}
+
+ @Test
+ fun isTypeVariable() {
+ val javaSubject = Source.java(
+ "test.JavaFoo",
+ """
+ package test;
+ class JavaFoo<T> {
+ T field;
+ T method(T param) {
+ return null;
+ }
+ }
+ """.trimIndent()
+ )
+ val javaImplSubject = Source.java(
+ "test.JavaFooImpl",
+ """
+ package test;
+ class JavaFooImpl extends JavaFoo<String> {
+ }
+ """.trimIndent()
+ )
+ val kotlinSubject = Source.kotlin(
+ "Foo.kt",
+ """
+ package test
+ open class KotlinFoo<T> {
+ val field: T = TODO();
+ fun method(param: T): T {
+ TODO()
+ }
+ }
+
+ class KotlinFooImpl : KotlinFoo<String>()
+ """.trimIndent()
+ )
+ runProcessorTest(
+ sources = listOf(javaSubject, javaImplSubject, kotlinSubject)
+ ) { invocation ->
+ listOf("test.JavaFoo", "test.KotlinFoo").forEach { fqn ->
+ val typeElement = invocation.processingEnv.requireTypeElement(fqn)
+ typeElement.getDeclaredField("field").let {
+ assertThat(it.type.isTypeVariable()).isTrue()
+ val asMemberOf =
+ it.asMemberOf(invocation.processingEnv.requireType(fqn + "Impl"))
+ assertThat(asMemberOf.isTypeVariable()).isFalse()
+ }
+ typeElement.getDeclaredMethodByJvmName("method").let {
+ assertThat(it.returnType.isTypeVariable()).isTrue()
+ assertThat(it.parameters.single().type.isTypeVariable()).isTrue()
+ val asMemberOf =
+ it.asMemberOf(invocation.processingEnv.requireType(fqn + "Impl"))
+ assertThat(asMemberOf.returnType.isTypeVariable()).isFalse()
+ assertThat(asMemberOf.parameterTypes.single().isTypeVariable()).isFalse()
+ }
+ }
+ }
+ }
}
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/ksp/KspTypeNamesGoldenTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/ksp/KspTypeNamesGoldenTest.kt
index f14cebf..a2131bd 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/ksp/KspTypeNamesGoldenTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/ksp/KspTypeNamesGoldenTest.kt
@@ -54,7 +54,7 @@
fun XExecutableElement.createNewUniqueKey(
owner: String
): String {
- val prefix = this.closestMemberContainer.className.canonicalName()
+ val prefix = this.closestMemberContainer.asClassName().canonicalName
val jvmName = if (this is XMethodElement) {
jvmName
} else {
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/ksp/synthetic/KspSyntheticFileMemberContainerTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/ksp/synthetic/KspSyntheticFileMemberContainerTest.kt
index 7ff027c..2b5bb77 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/ksp/synthetic/KspSyntheticFileMemberContainerTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/ksp/synthetic/KspSyntheticFileMemberContainerTest.kt
@@ -56,10 +56,10 @@
val className = elements.map {
val owner = invocation.kspResolver.getOwnerJvmClassName(it as KSPropertyDeclaration)
assertWithMessage(it.toString()).that(owner).isNotNull()
- KspSyntheticFileMemberContainer(owner!!).className
+ KspSyntheticFileMemberContainer(owner!!).asClassName()
}.first()
- assertThat(className.packageName()).isEmpty()
- assertThat(className.simpleNames()).containsExactly("AppKt")
+ assertThat(className.packageName).isEmpty()
+ assertThat(className.simpleNames).containsExactly("AppKt")
}
}
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/util/TestExtensions.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/util/TestExtensions.kt
index 2f897ca..23e4c3a 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/util/TestExtensions.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/util/TestExtensions.kt
@@ -17,6 +17,7 @@
package androidx.room.compiler.processing.util
import androidx.room.compiler.processing.XExecutableElement
+import androidx.room.compiler.processing.XType
import androidx.room.compiler.processing.XTypeElement
fun XTypeElement.getAllFieldNames() = getAllFieldsIncludingPrivateSupers().map {
@@ -42,3 +43,7 @@
fun XExecutableElement.getParameter(name: String) = parameters.firstOrNull {
it.name == name
} ?: throw AssertionError("cannot find parameter with name $name")
+
+fun XType.isCollection(): Boolean {
+ return isTypeOf(List::class) || isTypeOf(Set::class)
+}
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/ext/xpoet_ext.kt b/room/room-compiler/src/main/kotlin/androidx/room/ext/xpoet_ext.kt
index 17d262b..c0abedc 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/ext/xpoet_ext.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/ext/xpoet_ext.kt
@@ -51,8 +51,7 @@
object SupportDbTypeNames {
val DB = XClassName.get("$SQLITE_PACKAGE.db", "SupportSQLiteDatabase")
- val SQLITE_STMT: XClassName =
- XClassName.get("$SQLITE_PACKAGE.db", "SupportSQLiteStatement")
+ val SQLITE_STMT = XClassName.get("$SQLITE_PACKAGE.db", "SupportSQLiteStatement")
val SQLITE_OPEN_HELPER = XClassName.get("$SQLITE_PACKAGE.db", "SupportSQLiteOpenHelper")
val SQLITE_OPEN_HELPER_CALLBACK =
XClassName.get("$SQLITE_PACKAGE.db", "SupportSQLiteOpenHelper", "Callback")
@@ -62,24 +61,17 @@
}
object RoomTypeNames {
- val STRING_UTIL: XClassName = XClassName.get("$ROOM_PACKAGE.util", "StringUtil")
- val ROOM_DB: XClassName = XClassName.get(ROOM_PACKAGE, "RoomDatabase")
+ val STRING_UTIL = XClassName.get("$ROOM_PACKAGE.util", "StringUtil")
+ val ROOM_DB = XClassName.get(ROOM_PACKAGE, "RoomDatabase")
val ROOM_DB_KT = XClassName.get(ROOM_PACKAGE, "RoomDatabaseKt")
val ROOM_DB_CALLBACK = XClassName.get(ROOM_PACKAGE, "RoomDatabase", "Callback")
val ROOM_DB_CONFIG = XClassName.get(ROOM_PACKAGE, "DatabaseConfiguration")
- val INSERTION_ADAPTER: XClassName =
- XClassName.get(ROOM_PACKAGE, "EntityInsertionAdapter")
- val UPSERTION_ADAPTER: XClassName =
- XClassName.get(ROOM_PACKAGE, "EntityUpsertionAdapter")
- val DELETE_OR_UPDATE_ADAPTER: XClassName =
- XClassName.get(ROOM_PACKAGE, "EntityDeletionOrUpdateAdapter")
- val SHARED_SQLITE_STMT: XClassName =
- XClassName.get(ROOM_PACKAGE, "SharedSQLiteStatement")
+ val INSERTION_ADAPTER = XClassName.get(ROOM_PACKAGE, "EntityInsertionAdapter")
+ val UPSERTION_ADAPTER = XClassName.get(ROOM_PACKAGE, "EntityUpsertionAdapter")
+ val DELETE_OR_UPDATE_ADAPTER = XClassName.get(ROOM_PACKAGE, "EntityDeletionOrUpdateAdapter")
+ val SHARED_SQLITE_STMT = XClassName.get(ROOM_PACKAGE, "SharedSQLiteStatement")
val INVALIDATION_TRACKER = XClassName.get(ROOM_PACKAGE, "InvalidationTracker")
- val INVALIDATION_OBSERVER: ClassName =
- ClassName.get("$ROOM_PACKAGE.InvalidationTracker", "Observer")
- val ROOM_SQL_QUERY: XClassName =
- XClassName.get(ROOM_PACKAGE, "RoomSQLiteQuery")
+ val ROOM_SQL_QUERY = XClassName.get(ROOM_PACKAGE, "RoomSQLiteQuery")
val OPEN_HELPER = XClassName.get(ROOM_PACKAGE, "RoomOpenHelper")
val OPEN_HELPER_DELEGATE = XClassName.get(ROOM_PACKAGE, "RoomOpenHelper", "Delegate")
val OPEN_HELPER_VALIDATION_RESULT =
@@ -93,14 +85,11 @@
val VIEW_INFO = XClassName.get("$ROOM_PACKAGE.util", "ViewInfo")
val LIMIT_OFFSET_DATA_SOURCE: ClassName =
ClassName.get("$ROOM_PACKAGE.paging", "LimitOffsetDataSource")
- val DB_UTIL: XClassName =
- XClassName.get("$ROOM_PACKAGE.util", "DBUtil")
- val CURSOR_UTIL: XClassName =
- XClassName.get("$ROOM_PACKAGE.util", "CursorUtil")
+ val DB_UTIL = XClassName.get("$ROOM_PACKAGE.util", "DBUtil")
+ val CURSOR_UTIL = XClassName.get("$ROOM_PACKAGE.util", "CursorUtil")
val MIGRATION = XClassName.get("$ROOM_PACKAGE.migration", "Migration")
val AUTO_MIGRATION_SPEC = XClassName.get("$ROOM_PACKAGE.migration", "AutoMigrationSpec")
- val UUID_UTIL: XClassName =
- XClassName.get("$ROOM_PACKAGE.util", "UUIDUtil")
+ val UUID_UTIL = XClassName.get("$ROOM_PACKAGE.util", "UUIDUtil")
val AMBIGUOUS_COLUMN_RESOLVER = XClassName.get(ROOM_PACKAGE, "AmbiguousColumnResolver")
val RELATION_UTIL = XClassName.get("androidx.room.util", "RelationUtil")
}
@@ -131,9 +120,9 @@
}
object AndroidTypeNames {
- val CURSOR: XClassName = XClassName.get("android.database", "Cursor")
+ val CURSOR = XClassName.get("android.database", "Cursor")
val BUILD = XClassName.get("android.os", "Build")
- val CANCELLATION_SIGNAL: XClassName = XClassName.get("android.os", "CancellationSignal")
+ val CANCELLATION_SIGNAL = XClassName.get("android.os", "CancellationSignal")
}
object CollectionTypeNames {
@@ -143,6 +132,8 @@
}
object CommonTypeNames {
+ val VOID = Void::class.asClassName()
+ val COLLECTION = Collection::class.asClassName()
val LIST = List::class.asClassName()
val MUTABLE_LIST = List::class.asMutableClassName()
val ARRAY_LIST = XClassName.get("java.util", "ArrayList")
@@ -153,9 +144,8 @@
val MUTABLE_SET = Set::class.asMutableClassName()
val HASH_SET = XClassName.get("java.util", "HashSet")
val STRING = String::class.asClassName()
- val INTEGER = ClassName.get("java.lang", "Integer")
val OPTIONAL = ClassName.get("java.util", "Optional")
- val UUID = ClassName.get("java.util", "UUID")
+ val UUID = XClassName.get("java.util", "UUID")
val BYTE_BUFFER = XClassName.get("java.nio", "ByteBuffer")
val JAVA_CLASS = XClassName.get("java.lang", "Class")
}
@@ -241,9 +231,9 @@
}
object KotlinTypeNames {
- val UNIT = ClassName.get("kotlin", "Unit")
+ val ANY = Any::class.asClassName()
+ val UNIT = XClassName.get("kotlin", "Unit")
val CONTINUATION = XClassName.get("kotlin.coroutines", "Continuation")
- val COROUTINE_SCOPE = ClassName.get("kotlinx.coroutines", "CoroutineScope")
val CHANNEL = ClassName.get("kotlinx.coroutines.channels", "Channel")
val RECEIVE_CHANNEL = ClassName.get("kotlinx.coroutines.channels", "ReceiveChannel")
val SEND_CHANNEL = ClassName.get("kotlinx.coroutines.channels", "SendChannel")
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/ext/xtype_ext.kt b/room/room-compiler/src/main/kotlin/androidx/room/ext/xtype_ext.kt
index 1bb79c5..0d8e62e 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/ext/xtype_ext.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/ext/xtype_ext.kt
@@ -16,7 +16,7 @@
package androidx.room.ext
-import androidx.room.compiler.codegen.toJavaPoet
+import androidx.room.compiler.codegen.XTypeName
import androidx.room.compiler.processing.XType
import androidx.room.compiler.processing.isArray
import androidx.room.compiler.processing.isByte
@@ -24,9 +24,6 @@
import androidx.room.compiler.processing.isKotlinUnit
import androidx.room.compiler.processing.isVoid
import androidx.room.compiler.processing.isVoidObject
-import androidx.room.ext.CommonTypeNames.BYTE_BUFFER
-import com.squareup.javapoet.ClassName
-import com.squareup.javapoet.TypeName
/**
* Returns `true` if this type is not the `void` type.
@@ -61,12 +58,12 @@
/**
* Returns `true` if this is a `ByteBuffer` type.
*/
-fun XType.isByteBuffer(): Boolean = asTypeName() == BYTE_BUFFER
+fun XType.isByteBuffer() = asTypeName().equalsIgnoreNullability(CommonTypeNames.BYTE_BUFFER)
/**
* Returns `true` if this represents a `UUID` type.
*/
-fun XType.isUUID(): Boolean = typeName == CommonTypeNames.UUID
+fun XType.isUUID() = asTypeName().equalsIgnoreNullability(CommonTypeNames.UUID)
/**
* Checks if the class of the provided type has the equals() and hashCode() methods declared.
@@ -81,7 +78,7 @@
if (this.isSupportedMapTypeArg()) return true
val typeElement = this.typeElement ?: return false
- if (typeElement.className == ClassName.OBJECT) {
+ if (typeElement.asClassName().equalsIgnoreNullability(XTypeName.ANY_OBJECT)) {
return false
}
@@ -90,13 +87,13 @@
}
val hasEquals = typeElement.getDeclaredMethods().any {
it.jvmName == "equals" &&
- it.returnType.typeName == TypeName.BOOLEAN &&
+ it.returnType.asTypeName() == XTypeName.PRIMITIVE_BOOLEAN &&
it.parameters.count() == 1 &&
- it.parameters[0].type.typeName == TypeName.OBJECT
+ it.parameters[0].type.asTypeName().equalsIgnoreNullability(XTypeName.ANY_OBJECT)
}
val hasHashCode = typeElement.getDeclaredMethods().any {
it.jvmName == "hashCode" &&
- it.returnType.typeName == TypeName.INT &&
+ it.returnType.asTypeName() == XTypeName.PRIMITIVE_INT &&
it.parameters.count() == 0
}
@@ -110,12 +107,24 @@
* Map or Multimap return type.
*/
fun XType.isSupportedMapTypeArg(): Boolean {
- if (this.typeName.isPrimitive) return true
- if (this.typeName.isBoxedPrimitive) return true
- if (this.typeName == CommonTypeNames.STRING.toJavaPoet()) return true
+ if (this.asTypeName().isPrimitive) return true
+ if (this.asTypeName().isBoxedPrimitive) return true
+ if (this.asTypeName().equalsIgnoreNullability(CommonTypeNames.STRING)) return true
if (this.isTypeOf(ByteArray::class)) return true
if (this.isArray() && this.isByte()) return true
val typeElement = this.typeElement ?: return false
if (typeElement.isEnum()) return true
return false
}
+
+/**
+ * Returns `true` if this is a [List]
+ */
+fun XType.isList(): Boolean = isTypeOf(List::class)
+
+/**
+ * Returns true if this is a [List] or [Set].
+ */
+fun XType.isCollection(): Boolean {
+ return isTypeOf(List::class) || isTypeOf(Set::class)
+}
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/parser/SqlParser.kt b/room/room-compiler/src/main/kotlin/androidx/room/parser/SqlParser.kt
index f8266b0..8af2da7 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/parser/SqlParser.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/parser/SqlParser.kt
@@ -17,13 +17,11 @@
package androidx.room.parser
import androidx.room.ColumnInfo
-import androidx.room.compiler.codegen.toJavaPoet
+import androidx.room.compiler.codegen.XTypeName
import androidx.room.compiler.processing.XProcessingEnv
import androidx.room.compiler.processing.XType
import androidx.room.ext.CommonTypeNames
import androidx.room.parser.expansion.isCoreSelect
-import com.squareup.javapoet.ArrayTypeName
-import com.squareup.javapoet.TypeName
import java.util.Locale
import org.antlr.v4.runtime.tree.ParseTree
import org.antlr.v4.runtime.tree.TerminalNode
@@ -269,13 +267,20 @@
fun getTypeMirrors(env: XProcessingEnv): List<XType>? {
return when (this) {
- TEXT -> withBoxedAndNullableTypes(env, CommonTypeNames.STRING.toJavaPoet())
- INTEGER -> withBoxedAndNullableTypes(
- env, TypeName.INT, TypeName.BYTE, TypeName.CHAR,
- TypeName.LONG, TypeName.SHORT
+ TEXT -> withBoxedAndNullableTypes(env, CommonTypeNames.STRING)
+ INTEGER -> withBoxedAndNullableTypes(env,
+ XTypeName.PRIMITIVE_INT, XTypeName.PRIMITIVE_BYTE, XTypeName.PRIMITIVE_CHAR,
+ XTypeName.PRIMITIVE_LONG, XTypeName.PRIMITIVE_SHORT
)
- REAL -> withBoxedAndNullableTypes(env, TypeName.DOUBLE, TypeName.FLOAT)
- BLOB -> withBoxedAndNullableTypes(env, ArrayTypeName.of(TypeName.BYTE))
+
+ REAL -> withBoxedAndNullableTypes(env,
+ XTypeName.PRIMITIVE_DOUBLE, XTypeName.PRIMITIVE_FLOAT
+ )
+
+ BLOB -> withBoxedAndNullableTypes(env,
+ XTypeName.getArrayName(XTypeName.PRIMITIVE_BYTE)
+ )
+
else -> null
}
}
@@ -289,7 +294,7 @@
*/
private fun withBoxedAndNullableTypes(
env: XProcessingEnv,
- vararg typeNames: TypeName
+ vararg typeNames: XTypeName
): List<XType> {
return typeNames.flatMap { typeName ->
sequence {
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/preconditions/Checks.kt b/room/room-compiler/src/main/kotlin/androidx/room/preconditions/Checks.kt
index 3d0466c..f91c0b4 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/preconditions/Checks.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/preconditions/Checks.kt
@@ -17,10 +17,8 @@
package androidx.room.preconditions
import androidx.room.compiler.processing.XElement
+import androidx.room.compiler.processing.XType
import androidx.room.log.RLog
-import com.squareup.javapoet.ParameterizedTypeName
-import com.squareup.javapoet.TypeName
-import com.squareup.javapoet.TypeVariableName
import kotlin.contracts.contract
import kotlin.reflect.KClass
@@ -62,16 +60,15 @@
}
fun notUnbound(
- typeName: TypeName,
+ type: XType,
element: XElement,
errorMsg: String,
vararg args: Any
): Boolean {
// TODO support bounds cases like <T extends Foo> T bar()
- val failed = check(typeName !is TypeVariableName, element, errorMsg, args)
- if (typeName is ParameterizedTypeName) {
- val nestedFailure = typeName.typeArguments
- .any { notUnbound(it, element, errorMsg, args) }
+ val failed = check(!type.isTypeVariable(), element, errorMsg, args)
+ if (type.typeArguments.isNotEmpty()) {
+ val nestedFailure = type.typeArguments.any { notUnbound(it, element, errorMsg, args) }
return !(failed || nestedFailure)
}
return !failed
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/processor/AutoMigrationProcessor.kt b/room/room-compiler/src/main/kotlin/androidx/room/processor/AutoMigrationProcessor.kt
index 543335a..071aab0 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/processor/AutoMigrationProcessor.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/processor/AutoMigrationProcessor.kt
@@ -79,7 +79,7 @@
if (!implementsMigrationSpec) {
context.logger.e(
typeElement,
- autoMigrationElementMustImplementSpec(typeElement.className.simpleName())
+ autoMigrationElementMustImplementSpec(typeElement.asClassName().canonicalName)
)
return null
}
@@ -98,7 +98,7 @@
return null
}
- val specClassName = specElement?.className?.simpleName()
+ val specClassName = specElement?.asClassName()?.simpleNames?.first()
val deleteColumnEntries = specElement?.let { element ->
element.getAnnotations(DeleteColumn::class).map {
AutoMigration.DeletedColumn(
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/processor/Context.kt b/room/room-compiler/src/main/kotlin/androidx/room/processor/Context.kt
index a3bc71c..fcca5f5 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/processor/Context.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/processor/Context.kt
@@ -18,10 +18,10 @@
import androidx.room.RewriteQueriesToDropUnusedColumns
import androidx.room.compiler.codegen.CodeLanguage
-import androidx.room.compiler.codegen.asClassName
import androidx.room.compiler.processing.XElement
import androidx.room.compiler.processing.XProcessingEnv
import androidx.room.compiler.processing.XType
+import androidx.room.ext.CommonTypeNames
import androidx.room.log.RLog
import androidx.room.parser.expansion.ProjectionExpander
import androidx.room.parser.optimization.RemoveUnusedColumnQueryRewriter
@@ -131,19 +131,19 @@
class CommonTypes(val processingEnv: XProcessingEnv) {
val VOID: XType by lazy {
- processingEnv.requireType("java.lang.Void")
+ processingEnv.requireType(CommonTypeNames.VOID)
}
val STRING: XType by lazy {
- processingEnv.requireType(String::class.asClassName())
+ processingEnv.requireType(CommonTypeNames.STRING)
}
val READONLY_COLLECTION: XType by lazy {
- processingEnv.requireType(Collection::class.asClassName())
+ processingEnv.requireType(CommonTypeNames.COLLECTION)
}
val LIST: XType by lazy {
- processingEnv.requireType(List::class.asClassName())
+ processingEnv.requireType(CommonTypeNames.LIST)
}
val SET: XType by lazy {
- processingEnv.requireType(Set::class.asClassName())
+ processingEnv.requireType(CommonTypeNames.SET)
}
}
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/processor/CustomConverterProcessor.kt b/room/room-compiler/src/main/kotlin/androidx/room/processor/CustomConverterProcessor.kt
index ad2acae..6ee5a37 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/processor/CustomConverterProcessor.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/processor/CustomConverterProcessor.kt
@@ -59,7 +59,9 @@
if (typeElement == null) {
context.logger.e(
element,
- ProcessorErrors.typeConverterMustBeDeclared(it.typeName)
+ ProcessorErrors.typeConverterMustBeDeclared(
+ it.asTypeName().toString(context.codeLanguage)
+ )
)
emptyList()
} else {
@@ -84,7 +86,7 @@
private fun reportDuplicates(context: Context, converters: List<CustomTypeConverter>) {
converters
- .groupBy { it.from.typeName to it.to.typeName }
+ .groupBy { it.from.asTypeName() to it.to.asTypeName() }
.filterValues { it.size > 1 }
.values.forEach { possiblyDuplicateConverters ->
possiblyDuplicateConverters.forEach { converter ->
@@ -157,9 +159,8 @@
context.logger.e(methodElement, TYPE_CONVERTER_BAD_RETURN_TYPE)
return null
}
- val returnTypeName = returnType.typeName
context.checker.notUnbound(
- returnTypeName, methodElement,
+ returnType, methodElement,
TYPE_CONVERTER_UNBOUND_GENERIC
)
val params = methodElement.parameters
@@ -170,7 +171,7 @@
val param = params.map {
it.asMemberOf(container.type)
}.first()
- context.checker.notUnbound(param.typeName, params[0], TYPE_CONVERTER_UNBOUND_GENERIC)
+ context.checker.notUnbound(param, params[0], TYPE_CONVERTER_UNBOUND_GENERIC)
return CustomTypeConverter(
enclosingClass = container,
isEnclosingClassKotlinObject = isContainerKotlinObject,
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/processor/DaoProcessor.kt b/room/room-compiler/src/main/kotlin/androidx/room/processor/DaoProcessor.kt
index a0f36c1..fb8cb9e 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/processor/DaoProcessor.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/processor/DaoProcessor.kt
@@ -223,9 +223,8 @@
null
}
- val type = declaredType.typeName
context.checker.notUnbound(
- type, element,
+ declaredType, element,
ProcessorErrors.CANNOT_USE_UNBOUND_GENERICS_IN_DAO_CLASSES
)
@@ -256,7 +255,7 @@
context.logger.e(
element,
ProcessorErrors.daoMustHaveMatchingConstructor(
- element.qualifiedName, dbType.typeName.toString()
+ element.qualifiedName, dbType.asTypeName().toString(context.codeLanguage)
)
)
}
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/processor/DatabaseProcessor.kt b/room/room-compiler/src/main/kotlin/androidx/room/processor/DatabaseProcessor.kt
index 2c15c2a..039ce5a 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/processor/DatabaseProcessor.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/processor/DatabaseProcessor.kt
@@ -18,12 +18,12 @@
import androidx.room.AutoMigration
import androidx.room.SkipQueryVerification
-import androidx.room.compiler.codegen.toJavaPoet
+import androidx.room.compiler.codegen.XTypeName
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.ext.RoomTypeNames.ROOM_DB
+import androidx.room.ext.RoomTypeNames
import androidx.room.migration.bundle.DatabaseBundle
import androidx.room.migration.bundle.SchemaBundle
import androidx.room.processor.ProcessorErrors.AUTO_MIGRATION_FOUND_BUT_EXPORT_SCHEMA_OFF
@@ -42,7 +42,6 @@
import androidx.room.vo.Warning
import androidx.room.vo.columnNames
import androidx.room.vo.findFieldByColumnName
-import com.squareup.javapoet.TypeName
import java.io.File
import java.io.FileInputStream
import java.nio.file.Path
@@ -52,9 +51,7 @@
val context = baseContext.fork(element)
val roomDatabaseType: XType by lazy {
- context.processingEnv.requireType(
- ROOM_DB.toJavaPoet().packageName() + "." + ROOM_DB.toJavaPoet().simpleName()
- )
+ context.processingEnv.requireType(RoomTypeNames.ROOM_DB)
}
fun process(): Database {
@@ -94,7 +91,7 @@
it.isAbstract()
}.filterNot {
// remove methods that belong to room
- it.enclosingElement.className == ROOM_DB.toJavaPoet()
+ it.enclosingElement.asClassName() == RoomTypeNames.ROOM_DB
}.mapNotNull { executable ->
// TODO when we add support for non Dao return types (e.g. database), this code needs
// to change
@@ -168,7 +165,7 @@
return autoMigrationList.mapNotNull {
val databaseSchemaFolderPath = Path.of(
context.schemaOutFolderPath!!,
- element.className.canonicalName()
+ element.asClassName().canonicalName
)
val autoMigration = it.value
val validatedFromSchemaFile = getValidatedSchemaFile(
@@ -319,13 +316,13 @@
.filter { it.value.size > 1 } // get the ones with duplicate names
.forEach {
// do not report duplicates from the same entity
- if (it.value.distinctBy { it.second.typeName.toJavaPoet() }.size > 1) {
+ if (it.value.distinctBy { it.second.typeName }.size > 1) {
context.logger.e(
element,
ProcessorErrors.duplicateIndexInDatabase(
it.key,
it.value.map {
- "${it.second.typeName.toJavaPoet()} > ${it.first}"
+ "${it.second.typeName.toString(context.codeLanguage)} > ${it.first}"
}
)
)
@@ -338,11 +335,11 @@
daoMethods: List<DaoMethod>,
entities: List<Entity>
) {
- val entityTypeNames = entities.map { it.typeName.toJavaPoet() }.toSet()
+ val entityTypeNames = entities.map { it.typeName }.toSet()
daoMethods.groupBy { it.dao.typeName }
.forEach {
if (it.value.size > 1) {
- val error = ProcessorErrors.duplicateDao(it.key.toJavaPoet(),
+ val error = ProcessorErrors.duplicateDao(it.key.toString(context.codeLanguage),
it.value.map { it.element.jvmName }
)
it.value.forEach { daoMethod ->
@@ -358,7 +355,7 @@
val check = fun(
element: XElement,
dao: Dao,
- typeName: TypeName?
+ typeName: XTypeName?
) {
typeName?.let {
if (!entityTypeNames.contains(typeName)) {
@@ -366,8 +363,8 @@
element,
ProcessorErrors.shortcutEntityIsNotInDatabase(
database = dbElement.qualifiedName,
- dao = dao.typeName.toJavaPoet().toString(),
- entity = typeName.toString()
+ dao = dao.typeName.toString(context.codeLanguage),
+ entity = typeName.toString(context.codeLanguage)
)
)
}
@@ -376,12 +373,12 @@
daoMethods.forEach { daoMethod ->
daoMethod.dao.deleteOrUpdateShortcutMethods.forEach { method ->
method.entities.forEach {
- check(method.element, daoMethod.dao, it.value.entityTypeName.toJavaPoet())
+ check(method.element, daoMethod.dao, it.value.entityTypeName)
}
}
daoMethod.dao.insertOrUpsertShortcutMethods.forEach { method ->
method.entities.forEach {
- check(method.element, daoMethod.dao, it.value.entityTypeName.toJavaPoet())
+ check(method.element, daoMethod.dao, it.value.entityTypeName)
}
}
}
@@ -395,14 +392,14 @@
val entitiesInfo = entities.map {
Triple(
it.tableName.lowercase(Locale.US),
- it.typeName.toJavaPoet().toString(),
+ it.typeName.toString(context.codeLanguage),
it.element
)
}
val viewsInfo = views.map {
Triple(
it.viewName.lowercase(Locale.US),
- it.typeName.toJavaPoet().toString(),
+ it.typeName.toString(context.codeLanguage),
it.element
)
}
@@ -456,7 +453,7 @@
context.logger.e(
element,
ProcessorErrors.invalidEntityTypeInDatabaseAnnotation(
- it.typeName
+ it.asTypeName().toString(context.codeLanguage)
)
)
null
@@ -476,7 +473,7 @@
context.logger.e(
element,
ProcessorErrors.invalidViewTypeInDatabaseAnnotation(
- it.typeName
+ it.asTypeName().toString(context.codeLanguage)
)
)
null
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/processor/FieldProcessor.kt b/room/room-compiler/src/main/kotlin/androidx/room/processor/FieldProcessor.kt
index 3325e6f..1645d65 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/processor/FieldProcessor.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/processor/FieldProcessor.kt
@@ -36,7 +36,6 @@
val context = baseContext.fork(element)
fun process(): Field {
val member = element.asMemberOf(containing)
- val type = member.typeName
val columnInfo = element.getAnnotation(ColumnInfo::class)?.value
val name = element.name
val rawCName = if (columnInfo != null && columnInfo.name != ColumnInfo.INHERIT_FIELD_NAME) {
@@ -56,7 +55,7 @@
ProcessorErrors.COLUMN_NAME_CANNOT_BE_EMPTY
)
context.checker.notUnbound(
- type, element,
+ member, element,
ProcessorErrors.CANNOT_USE_UNBOUND_GENERICS_IN_ENTITY_FIELDS
)
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/processor/FtsTableEntityProcessor.kt b/room/room-compiler/src/main/kotlin/androidx/room/processor/FtsTableEntityProcessor.kt
index 6d9fc0c..787cacf 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/processor/FtsTableEntityProcessor.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/processor/FtsTableEntityProcessor.kt
@@ -176,7 +176,7 @@
context.logger.e(
contentEntityElement,
ProcessorErrors.externalContentNotAnEntity(
- contentEntityElement.className.canonicalName()
+ contentEntityElement.asClassName().canonicalName
)
)
return null
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/processor/InsertionMethodProcessor.kt b/room/room-compiler/src/main/kotlin/androidx/room/processor/InsertionMethodProcessor.kt
index f75be97..592abec 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/processor/InsertionMethodProcessor.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/processor/InsertionMethodProcessor.kt
@@ -20,7 +20,6 @@
import androidx.room.Insert
import androidx.room.OnConflictStrategy
-import androidx.room.compiler.codegen.toJavaPoet
import androidx.room.compiler.processing.XMethodElement
import androidx.room.compiler.processing.XType
import androidx.room.vo.InsertionMethod
@@ -47,9 +46,8 @@
)
val returnType = delegate.extractReturnType()
- val returnTypeName = returnType.typeName
context.checker.notUnbound(
- returnTypeName, executableElement,
+ returnType, executableElement,
ProcessorErrors.CANNOT_USE_UNBOUND_GENERICS_IN_INSERTION_METHODS
)
@@ -64,7 +62,7 @@
entity.primaryKey.autoGenerateId || !missingPrimaryKeys,
executableElement,
ProcessorErrors.missingPrimaryKeysInPartialEntityForInsert(
- partialEntityName = pojo.typeName.toJavaPoet().toString(),
+ partialEntityName = pojo.typeName.toString(context.codeLanguage),
primaryKeyNames = entity.primaryKey.fields.columnNames
)
)
@@ -79,7 +77,7 @@
missingRequiredFields.isEmpty(),
executableElement,
ProcessorErrors.missingRequiredColumnsInPartialEntity(
- partialEntityName = pojo.typeName.toJavaPoet().toString(),
+ partialEntityName = pojo.typeName.toString(context.codeLanguage),
missingColumnNames = missingRequiredFields.map { it.columnName }
)
)
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/processor/PojoProcessor.kt b/room/room-compiler/src/main/kotlin/androidx/room/processor/PojoProcessor.kt
index 6252b56..0f67cea 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/processor/PojoProcessor.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/processor/PojoProcessor.kt
@@ -22,14 +22,13 @@
import androidx.room.Junction
import androidx.room.PrimaryKey
import androidx.room.Relation
-import androidx.room.compiler.codegen.toJavaPoet
import androidx.room.compiler.processing.XExecutableElement
import androidx.room.compiler.processing.XFieldElement
import androidx.room.compiler.processing.XType
import androidx.room.compiler.processing.XTypeElement
import androidx.room.compiler.processing.XVariableElement
-import androidx.room.compiler.processing.isCollection
import androidx.room.compiler.processing.isVoid
+import androidx.room.ext.isCollection
import androidx.room.ext.isNotVoid
import androidx.room.processor.ProcessorErrors.CANNOT_FIND_GETTER_FOR_FIELD
import androidx.room.processor.ProcessorErrors.CANNOT_FIND_SETTER_FOR_FIELD
@@ -512,7 +511,7 @@
context.logger.e(
relationElement,
ProcessorErrors.relationCannotFindEntityField(
- entityName = entity.typeName.toJavaPoet().toString(),
+ entityName = entity.typeName.toString(context.codeLanguage),
columnName = annotation.value.entityColumn,
availableColumns = entity.columnNames
)
@@ -558,7 +557,7 @@
context.logger.w(
Warning.MISSING_INDEX_ON_JUNCTION, field.element,
ProcessorErrors.junctionColumnWithoutIndex(
- entityName = entityOrView.typeName.toJavaPoet().toString(),
+ entityName = entityOrView.typeName.toString(context.codeLanguage),
columnName = columnName
)
)
@@ -578,7 +577,7 @@
context.logger.e(
junctionElement,
ProcessorErrors.relationCannotFindJunctionParentField(
- entityName = entityOrView.typeName.toJavaPoet().toString(),
+ entityName = entityOrView.typeName.toString(context.codeLanguage),
columnName = junctionParentColumn,
availableColumns = entityOrView.columnNames
)
@@ -597,7 +596,7 @@
context.logger.e(
junctionElement,
ProcessorErrors.relationCannotFindJunctionEntityField(
- entityName = entityOrView.typeName.toJavaPoet().toString(),
+ entityName = entityOrView.typeName.toString(context.codeLanguage),
columnName = junctionEntityColumn,
availableColumns = entityOrView.columnNames
)
@@ -654,7 +653,7 @@
context.logger.e(
relationElement,
ProcessorErrors.relationBadProject(
- entity.typeName.toJavaPoet().toString(),
+ entity.typeName.toString(context.codeLanguage),
missingColumns, entity.columnNames
)
)
@@ -677,7 +676,7 @@
entityField: Field,
typeArgElement: XTypeElement
): List<String> {
- return if (inferEntity || typeArg.typeName == entity.typeName.toJavaPoet()) {
+ return if (inferEntity || typeArg.asTypeName() == entity.typeName) {
entity.columnNames
} else {
val columnAdapter = context.typeAdapterStore.findCursorValueReader(typeArg, null)
@@ -780,9 +779,9 @@
element = field.element,
msg = ProcessorErrors.mismatchedGetter(
fieldName = field.name,
- ownerType = element.type.typeName,
- getterType = field.getter.type.typeName,
- fieldType = field.typeName.toJavaPoet()
+ ownerType = element.type.asTypeName().toString(context.codeLanguage),
+ getterType = field.getter.type.asTypeName().toString(context.codeLanguage),
+ fieldType = field.typeName.toString(context.codeLanguage)
)
)
field.statementBinder = context.typeAdapterStore.findStatementValueBinder(
@@ -864,9 +863,9 @@
element = field.element,
msg = ProcessorErrors.mismatchedSetter(
fieldName = field.name,
- ownerType = element.type.typeName,
- setterType = field.setter.type.typeName,
- fieldType = field.typeName.toJavaPoet()
+ ownerType = element.type.asTypeName().toString(context.codeLanguage),
+ setterType = field.setter.type.asTypeName().toString(context.codeLanguage),
+ fieldType = field.typeName.toString(context.codeLanguage)
)
)
field.cursorValueReader = context.typeAdapterStore.findCursorValueReader(
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 9cc2640..ca1602c 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
@@ -23,7 +23,6 @@
import androidx.room.RewriteQueriesToDropUnusedColumns
import androidx.room.Update
import androidx.room.Upsert
-import androidx.room.compiler.codegen.toJavaPoet
import androidx.room.ext.KotlinTypeNames
import androidx.room.ext.RoomTypeNames.ROOM_DB
import androidx.room.ext.SupportDbTypeNames
@@ -31,7 +30,6 @@
import androidx.room.parser.SQLTypeAffinity
import androidx.room.vo.CustomTypeConverter
import androidx.room.vo.Field
-import com.squareup.javapoet.TypeName
object ProcessorErrors {
private fun String.trim(): String {
@@ -138,7 +136,7 @@
val QUERY_PARAMETERS_CANNOT_START_WITH_UNDERSCORE = "Query/Insert method parameters cannot " +
"start with underscore (_)."
- fun cannotFindQueryResultAdapter(returnTypeName: TypeName) = "Not sure how to convert a " +
+ fun cannotFindQueryResultAdapter(returnTypeName: String) = "Not sure how to convert a " +
"Cursor to this method's return type ($returnTypeName)."
fun classMustImplementEqualsAndHashCode(keyType: String) = "The key" +
@@ -161,14 +159,14 @@
val MAP_INFO_MUST_HAVE_AT_LEAST_ONE_COLUMN_PROVIDED = "To use the @MapInfo annotation, you " +
"must provide either the key column name, value column name, or both."
- fun keyMayNeedMapInfo(keyArg: TypeName): String {
+ fun keyMayNeedMapInfo(keyArg: String): String {
return """
Looks like you may need to use @MapInfo to clarify the 'keyColumn' needed for
the return type of a method. Type argument that needs @MapInfo: $keyArg
""".trim()
}
- fun valueMayNeedMapInfo(valueArg: TypeName): String {
+ fun valueMayNeedMapInfo(valueArg: String): String {
return """
Looks like you may need to use @MapInfo to clarify the 'valueColumn' needed for
the return type of a method. Type argument that needs @MapInfo: $valueArg
@@ -226,7 +224,7 @@
"annotated with @Entity or a collection/array of it."
val DB_MUST_EXTEND_ROOM_DB = "Classes annotated with @Database should extend " +
- ROOM_DB.toJavaPoet()
+ ROOM_DB.canonicalName
val OBSERVABLE_QUERY_NOTHING_TO_OBSERVE = "Observable query return type (LiveData, Flowable" +
", DataSource, DataSourceFactory etc) can only be used with SELECT queries that" +
@@ -267,7 +265,7 @@
return MISSING_PARAMETER_FOR_BIND.format(bindVarName.joinToString(", "))
}
- fun valueCollectionMustBeListOrSet(mapValueTypeName: TypeName): String {
+ fun valueCollectionMustBeListOrSet(mapValueTypeName: String): String {
return "Multimap 'value' collection type must be a List or Set. Found $mapValueTypeName."
}
@@ -288,7 +286,7 @@
val DAO_METHOD_CONFLICTS_WITH_OTHERS = "Dao method has conflicts."
- fun duplicateDao(dao: TypeName, methodNames: List<String>): String {
+ fun duplicateDao(dao: String, methodNames: List<String>): String {
return """
All of these functions [${methodNames.joinToString(", ")}] return the same DAO
class [$dao].
@@ -300,7 +298,7 @@
}
fun pojoMissingNonNull(
- pojoTypeName: TypeName,
+ pojoTypeName: String,
missingPojoFields: List<String>,
allQueryColumns: List<String>
): String {
@@ -313,10 +311,10 @@
}
fun cursorPojoMismatch(
- pojoTypeNames: List<TypeName>,
+ pojoTypeNames: List<String>,
unusedColumns: List<String>,
allColumns: List<String>,
- pojoUnusedFields: Map<TypeName, List<Field>>,
+ pojoUnusedFields: Map<String, List<Field>>,
): String {
val unusedColumnsWarning = if (unusedColumns.isNotEmpty()) {
val pojoNames = if (pojoTypeNames.size > 1) {
@@ -368,7 +366,7 @@
" ${converters.joinToString(", ") { it.toString() }}"
}
- fun typeConverterMustBeDeclared(typeName: TypeName): String {
+ fun typeConverterMustBeDeclared(typeName: String): String {
return "Invalid type converter type: $typeName. Type converters must be a class."
}
@@ -713,7 +711,7 @@
val RAW_QUERY_BAD_RETURN_TYPE = "RawQuery methods must return a non-void type."
- fun rawQueryBadEntity(typeName: TypeName): String {
+ fun rawQueryBadEntity(typeName: String): String {
return """
observedEntities field in RawQuery must either reference a class that is annotated
with @Entity or it should reference a POJO that either contains @Embedded fields that
@@ -822,7 +820,7 @@
"perform the query."
fun cannotFindPreparedQueryResultAdapter(
- returnType: TypeName,
+ returnType: String,
type: QueryType
) = StringBuilder().apply {
append("Not sure how to handle query method's return type ($returnType). ")
@@ -856,9 +854,9 @@
fun mismatchedGetter(
fieldName: String,
- ownerType: TypeName,
- getterType: TypeName,
- fieldType: TypeName
+ ownerType: String,
+ getterType: String,
+ fieldType: String
) = """
$ownerType's $fieldName field has type $fieldType but its getter returns $getterType.
This mismatch might cause unexpected $fieldName values in the database when $ownerType
@@ -867,9 +865,9 @@
fun mismatchedSetter(
fieldName: String,
- ownerType: TypeName,
- setterType: TypeName,
- fieldType: TypeName
+ ownerType: String,
+ setterType: String,
+ fieldType: String
) = """
$ownerType's $fieldName field has type $fieldType but its setter accepts $setterType.
This mismatch might cause unexpected $fieldName values when $ownerType is read from the
@@ -879,11 +877,11 @@
val DATABASE_INVALID_DAO_METHOD_RETURN_TYPE = "Abstract database methods must return a @Dao " +
"annotated class or interface."
- fun invalidEntityTypeInDatabaseAnnotation(typeName: TypeName): String {
+ fun invalidEntityTypeInDatabaseAnnotation(typeName: String): String {
return "Invalid Entity type: $typeName. An entity in the database must be a class."
}
- fun invalidViewTypeInDatabaseAnnotation(typeName: TypeName): String {
+ fun invalidViewTypeInDatabaseAnnotation(typeName: String): String {
return "Invalid View type: $typeName. Views in a database must be a class or an " +
"interface."
}
@@ -899,7 +897,7 @@
"or an interface."
fun shortcutMethodArgumentMustBeAClass(
- typeName: TypeName
+ typeName: String
): String {
return "Invalid query argument: $typeName. It must be a class or an interface."
}
@@ -1100,7 +1098,7 @@
fun ambiguousColumn(
columnName: String,
location: AmbiguousColumnLocation,
- typeName: TypeName?
+ typeName: String?
): String {
val (locationDesc, recommendation) = when (location) {
AmbiguousColumnLocation.MAP_INFO -> {
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/processor/QueryMethodProcessor.kt b/room/room-compiler/src/main/kotlin/androidx/room/processor/QueryMethodProcessor.kt
index e78d084..d9333f1 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/processor/QueryMethodProcessor.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/processor/QueryMethodProcessor.kt
@@ -19,7 +19,6 @@
import androidx.room.Query
import androidx.room.SkipQueryVerification
import androidx.room.Transaction
-import androidx.room.compiler.codegen.toJavaPoet
import androidx.room.compiler.processing.XAnnotationBox
import androidx.room.compiler.processing.XMethodElement
import androidx.room.compiler.processing.XType
@@ -134,9 +133,8 @@
ParsedQuery.MISSING
}
- val returnTypeName = returnType.typeName
context.checker.notUnbound(
- returnTypeName, executableElement,
+ returnType, executableElement,
ProcessorErrors.CANNOT_USE_UNBOUND_GENERICS_IN_QUERY_METHODS
)
@@ -194,7 +192,10 @@
context.checker.check(
resultBinder.adapter != null,
executableElement,
- ProcessorErrors.cannotFindPreparedQueryResultAdapter(returnType.typeName, query.type)
+ ProcessorErrors.cannotFindPreparedQueryResultAdapter(
+ returnType.asTypeName().toString(context.codeLanguage),
+ query.type
+ )
)
val parameters = delegate.extractQueryParams(query)
@@ -220,7 +221,9 @@
context.checker.check(
resultBinder.adapter != null,
executableElement,
- ProcessorErrors.cannotFindQueryResultAdapter(returnType.typeName)
+ ProcessorErrors.cannotFindQueryResultAdapter(
+ returnType.asTypeName().toString(context.codeLanguage)
+ )
)
val inTransaction = executableElement.hasAnnotation(Transaction::class)
@@ -251,10 +254,12 @@
val pojoMappings = mappings.filterIsInstance<PojoRowAdapter.PojoMapping>()
val pojoUnusedFields = pojoMappings
.filter { it.unusedFields.isNotEmpty() }
- .associate { it.pojo.typeName.toJavaPoet() to it.unusedFields }
+ .associate { it.pojo.typeName.toString(context.codeLanguage) to it.unusedFields }
if (unusedColumns.isNotEmpty() || pojoUnusedFields.isNotEmpty()) {
val warningMsg = ProcessorErrors.cursorPojoMismatch(
- pojoTypeNames = pojoMappings.map { it.pojo.typeName.toJavaPoet() },
+ pojoTypeNames = pojoMappings.map {
+ it.pojo.typeName.toString(context.codeLanguage)
+ },
unusedColumns = unusedColumns,
allColumns = columnNames,
pojoUnusedFields = pojoUnusedFields,
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/processor/RawQueryMethodProcessor.kt b/room/room-compiler/src/main/kotlin/androidx/room/processor/RawQueryMethodProcessor.kt
index ec08a3d..14eba31 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/processor/RawQueryMethodProcessor.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/processor/RawQueryMethodProcessor.kt
@@ -45,9 +45,8 @@
ProcessorErrors.MISSING_RAWQUERY_ANNOTATION
)
- val returnTypeName = returnType.typeName
context.checker.notUnbound(
- returnTypeName, executableElement,
+ returnType, executableElement,
ProcessorErrors.CANNOT_USE_UNBOUND_GENERICS_IN_QUERY_METHODS
)
@@ -125,7 +124,9 @@
if (tableNames.isEmpty()) {
context.logger.e(
executableElement,
- ProcessorErrors.rawQueryBadEntity(it.type.typeName)
+ ProcessorErrors.rawQueryBadEntity(
+ it.type.asTypeName().toString(context.codeLanguage)
+ )
)
}
tableNames
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/processor/ShortcutMethodProcessor.kt b/room/room-compiler/src/main/kotlin/androidx/room/processor/ShortcutMethodProcessor.kt
index 8d558de..631b130 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/processor/ShortcutMethodProcessor.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/processor/ShortcutMethodProcessor.kt
@@ -15,7 +15,6 @@
*/
package androidx.room.processor
-import androidx.room.compiler.codegen.toJavaPoet
import androidx.room.compiler.processing.XAnnotationBox
import androidx.room.compiler.processing.XMethodElement
import androidx.room.compiler.processing.XType
@@ -122,7 +121,7 @@
context.logger.e(
targetEntity.element,
ProcessorErrors.shortcutMethodArgumentMustBeAClass(
- typeName = param.pojoType.typeName
+ typeName = param.pojoType.asTypeName().toString(context.codeLanguage)
)
)
null
@@ -139,7 +138,7 @@
context.logger.e(
it.element,
ProcessorErrors.cannotFindAsEntityField(
- targetEntity.typeName.toJavaPoet().toString()
+ targetEntity.typeName.toString(context.codeLanguage)
)
)
@@ -157,7 +156,7 @@
context.logger.e(
executableElement,
ProcessorErrors.noColumnsInPartialEntity(
- partialEntityName = pojo.typeName.toJavaPoet().toString()
+ partialEntityName = pojo.typeName.toString(context.codeLanguage)
)
)
}
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/processor/TableEntityProcessor.kt b/room/room-compiler/src/main/kotlin/androidx/room/processor/TableEntityProcessor.kt
index 1edbcda..1cf568e6 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/processor/TableEntityProcessor.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/processor/TableEntityProcessor.kt
@@ -16,7 +16,6 @@
package androidx.room.processor
-import androidx.room.compiler.codegen.toJavaPoet
import androidx.room.compiler.processing.XType
import androidx.room.compiler.processing.XTypeElement
import androidx.room.ext.isNotNone
@@ -111,7 +110,7 @@
Warning.INDEX_FROM_PARENT_FIELD_IS_DROPPED,
ProcessorErrors.droppedSuperClassFieldIndex(
it.columnName, element.qualifiedName,
- it.element.enclosingElement.className.toString()
+ it.element.enclosingElement.asClassName().toString(context.codeLanguage)
)
)
null
@@ -515,7 +514,7 @@
Warning.INDEX_FROM_EMBEDDED_ENTITY_IS_DROPPED,
embedded.field.element,
ProcessorErrors.droppedEmbeddedIndex(
- entityName = embedded.pojo.typeName.toJavaPoet().toString(),
+ entityName = embedded.pojo.typeName.toString(context.codeLanguage),
fieldPath = embedded.field.getPath(),
grandParent = element.qualifiedName
)
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/processor/UpdateMethodProcessor.kt b/room/room-compiler/src/main/kotlin/androidx/room/processor/UpdateMethodProcessor.kt
index 3b442a4..166c5eee2 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/processor/UpdateMethodProcessor.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/processor/UpdateMethodProcessor.kt
@@ -18,7 +18,6 @@
import androidx.room.OnConflictStrategy
import androidx.room.Update
-import androidx.room.compiler.codegen.toJavaPoet
import androidx.room.compiler.processing.XMethodElement
import androidx.room.compiler.processing.XType
import androidx.room.vo.UpdateMethod
@@ -52,7 +51,7 @@
context.checker.check(
missingPrimaryKeys.isEmpty(), executableElement,
ProcessorErrors.missingPrimaryKeysInPartialEntityForUpdate(
- partialEntityName = pojo.typeName.toJavaPoet().toString(),
+ partialEntityName = pojo.typeName.toString(context.codeLanguage),
primaryKeyNames = missingPrimaryKeys.map { it.columnName }
)
)
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/processor/UpsertionMethodProcessor.kt b/room/room-compiler/src/main/kotlin/androidx/room/processor/UpsertionMethodProcessor.kt
index 4098bb4..4b4a363 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/processor/UpsertionMethodProcessor.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/processor/UpsertionMethodProcessor.kt
@@ -17,7 +17,6 @@
package androidx.room.processor
import androidx.room.Upsert
-import androidx.room.compiler.codegen.toJavaPoet
import androidx.room.compiler.processing.XMethodElement
import androidx.room.compiler.processing.XType
import androidx.room.vo.UpsertionMethod
@@ -39,9 +38,8 @@
)
val returnType = delegate.extractReturnType()
- val returnTypeName = returnType.typeName
context.checker.notUnbound(
- returnTypeName, executableElement,
+ returnType, executableElement,
ProcessorErrors.CANNOT_USE_UNBOUND_GENERICS_IN_UPSERTION_METHODS
)
@@ -56,7 +54,7 @@
entity.primaryKey.autoGenerateId || !missingPrimaryKeys,
executableElement,
ProcessorErrors.missingPrimaryKeysInPartialEntityForUpsert(
- partialEntityName = pojo.typeName.toJavaPoet().toString(),
+ partialEntityName = pojo.typeName.toString(context.codeLanguage),
primaryKeyNames = entity.primaryKey.fields.columnNames
)
)
@@ -71,7 +69,7 @@
missingRequiredFields.isEmpty(),
executableElement,
ProcessorErrors.missingRequiredColumnsInPartialEntity(
- partialEntityName = pojo.typeName.toJavaPoet().toString(),
+ partialEntityName = pojo.typeName.toString(context.codeLanguage),
missingColumnNames = missingRequiredFields.map { it.columnName }
)
)
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/solver/NullAwareTypeConverterStore.kt b/room/room-compiler/src/main/kotlin/androidx/room/solver/NullAwareTypeConverterStore.kt
index 453ffd0..0aac808 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/solver/NullAwareTypeConverterStore.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/solver/NullAwareTypeConverterStore.kt
@@ -52,9 +52,7 @@
*/
private val knownColumnTypes: List<XType>
) : TypeConverterStore {
- private val knownColumnTypeNames = knownColumnTypes.map {
- it.typeName
- }
+ private val knownColumnTypeNames = knownColumnTypes.map { it.asTypeName() }
override val typeConverters = if (context.processingEnv.backend == Backend.KSP) {
val processedConverters = typeConverters.toMutableList()
// create copies for converters that receive non-null values
@@ -159,7 +157,7 @@
private fun isColumnType(type: XType): Boolean {
// compare using type names to handle both null and non-null.
- return knownColumnTypeNames.contains(type.typeName)
+ return knownColumnTypeNames.contains(type.asTypeName())
}
private fun findConverterIntoStatementInternal(
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/solver/TypeAdapterStore.kt b/room/room-compiler/src/main/kotlin/androidx/room/solver/TypeAdapterStore.kt
index ff8e11b..94556b8 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/solver/TypeAdapterStore.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/solver/TypeAdapterStore.kt
@@ -17,7 +17,6 @@
package androidx.room.solver
import androidx.annotation.VisibleForTesting
-import androidx.room.compiler.codegen.toJavaPoet
import androidx.room.compiler.processing.XType
import androidx.room.compiler.processing.isArray
import androidx.room.compiler.processing.isEnum
@@ -40,8 +39,8 @@
import androidx.room.processor.EntityProcessor
import androidx.room.processor.FieldProcessor
import androidx.room.processor.PojoProcessor
+import androidx.room.processor.ProcessorErrors
import androidx.room.processor.ProcessorErrors.DO_NOT_USE_GENERIC_IMMUTABLE_MULTIMAP
-import androidx.room.processor.ProcessorErrors.valueCollectionMustBeListOrSet
import androidx.room.solver.binderprovider.CoroutineFlowResultBinderProvider
import androidx.room.solver.binderprovider.CursorQueryResultBinderProvider
import androidx.room.solver.binderprovider.DataSourceFactoryQueryResultBinderProvider
@@ -584,12 +583,12 @@
) ?: return null
validateMapTypeArgs(
+ context = context,
keyTypeArg = keyTypeArg,
valueTypeArg = valueTypeArg,
keyReader = findCursorValueReader(keyTypeArg, null),
valueReader = findCursorValueReader(valueTypeArg, null),
- mapInfo = mapInfo,
- logger = context.logger
+ mapInfo = mapInfo
)
return GuavaImmutableMultimapQueryResultAdapter(
context = context,
@@ -601,9 +600,9 @@
immutableClassName = immutableClassName
)
} else if (typeMirror.isTypeOf(java.util.Map::class) ||
- typeMirror.rawType.typeName == ARRAY_MAP.toJavaPoet() ||
- typeMirror.rawType.typeName == LONG_SPARSE_ARRAY.toJavaPoet() ||
- typeMirror.rawType.typeName == INT_SPARSE_ARRAY.toJavaPoet()
+ typeMirror.rawType.asTypeName().equalsIgnoreNullability(ARRAY_MAP) ||
+ typeMirror.rawType.asTypeName().equalsIgnoreNullability(LONG_SPARSE_ARRAY) ||
+ typeMirror.rawType.asTypeName().equalsIgnoreNullability(INT_SPARSE_ARRAY)
) {
val mapType = when (typeMirror.rawType.asTypeName()) {
LONG_SPARSE_ARRAY -> MultimapQueryResultAdapter.MapType.LONG_SPARSE
@@ -650,7 +649,9 @@
MultimapQueryResultAdapter.CollectionValueType.SET
else -> {
context.logger.e(
- valueCollectionMustBeListOrSet(mapValueTypeArg.typeName)
+ ProcessorErrors.valueCollectionMustBeListOrSet(
+ mapValueTypeArg.asTypeName().toString(context.codeLanguage)
+ )
)
return null
}
@@ -671,12 +672,12 @@
) ?: return null
validateMapTypeArgs(
+ context = context,
keyTypeArg = keyTypeArg,
valueTypeArg = valueTypeArg,
keyReader = findCursorValueReader(keyTypeArg, null),
valueReader = findCursorValueReader(valueTypeArg, null),
- mapInfo = mapInfo,
- logger = context.logger
+ mapInfo = mapInfo
)
return MapQueryResultAdapter(
context = context,
@@ -701,12 +702,12 @@
) ?: return null
validateMapTypeArgs(
+ context = context,
keyTypeArg = keyTypeArg,
valueTypeArg = mapValueTypeArg,
keyReader = findCursorValueReader(keyTypeArg, null),
valueReader = findCursorValueReader(mapValueTypeArg, null),
- mapInfo = mapInfo,
- logger = context.logger
+ mapInfo = mapInfo
)
return MapQueryResultAdapter(
context = context,
@@ -737,7 +738,7 @@
}
val typeElement = typeMirror.typeElement
- if (typeElement != null && !typeMirror.typeName.isPrimitive) {
+ if (typeElement != null && !typeMirror.asTypeName().isPrimitive) {
if (typeMirror.typeArguments.isNotEmpty()) {
// TODO one day support this
return null
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/solver/binderprovider/CursorQueryResultBinderProvider.kt b/room/room-compiler/src/main/kotlin/androidx/room/solver/binderprovider/CursorQueryResultBinderProvider.kt
index 009c521..cf1fdb7 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/solver/binderprovider/CursorQueryResultBinderProvider.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/solver/binderprovider/CursorQueryResultBinderProvider.kt
@@ -16,9 +16,8 @@
package androidx.room.solver.binderprovider
-import androidx.room.compiler.codegen.toJavaPoet
import androidx.room.compiler.processing.XType
-import androidx.room.ext.AndroidTypeNames.CURSOR
+import androidx.room.ext.AndroidTypeNames
import androidx.room.parser.ParsedQuery
import androidx.room.processor.Context
import androidx.room.solver.QueryResultBinderProvider
@@ -36,5 +35,5 @@
}
override fun matches(declared: XType): Boolean =
- declared.typeArguments.isEmpty() && declared.typeName == CURSOR.toJavaPoet()
+ declared.typeArguments.isEmpty() && declared.asTypeName() == AndroidTypeNames.CURSOR
}
\ No newline at end of file
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/solver/binderprovider/MultiTypedPagingSourceQueryResultBinderProvider.kt b/room/room-compiler/src/main/kotlin/androidx/room/solver/binderprovider/MultiTypedPagingSourceQueryResultBinderProvider.kt
index eb300a8..f6e88f4 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/solver/binderprovider/MultiTypedPagingSourceQueryResultBinderProvider.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/solver/binderprovider/MultiTypedPagingSourceQueryResultBinderProvider.kt
@@ -16,6 +16,7 @@
package androidx.room.solver.binderprovider
+import androidx.room.compiler.codegen.XTypeName
import androidx.room.compiler.processing.XRawType
import androidx.room.compiler.processing.XType
import androidx.room.parser.ParsedQuery
@@ -78,7 +79,7 @@
return false
}
- if (declared.typeArguments.first().typeName != TypeName.INT.box()) {
+ if (declared.typeArguments.first().asTypeName() != XTypeName.BOXED_INT) {
context.logger.e(ProcessorErrors.PAGING_SPECIFY_PAGING_SOURCE_TYPE)
}
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/solver/prepared/result/PreparedQueryResultAdapter.kt b/room/room-compiler/src/main/kotlin/androidx/room/solver/prepared/result/PreparedQueryResultAdapter.kt
index f9cfbc5..7d6a09d 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/solver/prepared/result/PreparedQueryResultAdapter.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/solver/prepared/result/PreparedQueryResultAdapter.kt
@@ -19,13 +19,13 @@
import androidx.room.compiler.codegen.CodeLanguage
import androidx.room.compiler.codegen.XCodeBlock.Builder.Companion.addLocalVal
import androidx.room.compiler.codegen.XPropertySpec
-import androidx.room.compiler.codegen.asClassName
import androidx.room.compiler.processing.XType
import androidx.room.compiler.processing.isInt
import androidx.room.compiler.processing.isKotlinUnit
import androidx.room.compiler.processing.isLong
import androidx.room.compiler.processing.isVoid
import androidx.room.compiler.processing.isVoidObject
+import androidx.room.ext.KotlinTypeNames
import androidx.room.parser.QueryType
import androidx.room.solver.CodeGenScope
import androidx.room.solver.prepared.binder.PreparedQueryResultBinder
@@ -81,7 +81,7 @@
if (returnType.isVoidObject()) {
addStatement("return null")
} else if (returnType.isKotlinUnit() && language == CodeLanguage.JAVA) {
- addStatement("return %T.INSTANCE", Unit::class.asClassName())
+ addStatement("return %T.INSTANCE", KotlinTypeNames.UNIT)
}
} else {
val resultVar = scope.getTmpVar("_result")
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/solver/query/result/MultimapQueryResultAdapter.kt b/room/room-compiler/src/main/kotlin/androidx/room/solver/query/result/MultimapQueryResultAdapter.kt
index 41f6df3..810202e 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/solver/query/result/MultimapQueryResultAdapter.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/solver/query/result/MultimapQueryResultAdapter.kt
@@ -19,12 +19,10 @@
import androidx.room.compiler.codegen.CodeLanguage
import androidx.room.compiler.codegen.XClassName
import androidx.room.compiler.codegen.XCodeBlock
-import androidx.room.compiler.codegen.toJavaPoet
import androidx.room.compiler.processing.XType
import androidx.room.ext.CollectionTypeNames
import androidx.room.ext.CommonTypeNames
import androidx.room.ext.implementsEqualsAndHashcode
-import androidx.room.log.RLog
import androidx.room.parser.ParsedQuery
import androidx.room.processor.Context
import androidx.room.processor.ProcessorErrors
@@ -79,14 +77,18 @@
is SingleNamedColumnRowAdapter.SingleNamedColumnRowMapping ->
MAP_INFO to null
is PojoRowAdapter.PojoMapping ->
- POJO to it.pojo.typeName.toJavaPoet()
+ POJO to it.pojo.typeName
is EntityRowAdapter.EntityMapping ->
- ENTITY to it.entity.typeName.toJavaPoet()
+ ENTITY to it.entity.typeName
else -> error("Unknown mapping type: $it")
}
context.logger.w(
Warning.AMBIGUOUS_COLUMN_IN_RESULT,
- ProcessorErrors.ambiguousColumn(ambiguousColumnName, location, objectTypeName)
+ ProcessorErrors.ambiguousColumn(
+ columnName = ambiguousColumnName,
+ location = location,
+ typeName = objectTypeName?.toString(context.codeLanguage)
+ )
)
}
}
@@ -115,37 +117,37 @@
* of a Dao method.
*/
fun validateMapTypeArgs(
+ context: Context,
keyTypeArg: XType,
valueTypeArg: XType,
keyReader: CursorValueReader?,
valueReader: CursorValueReader?,
mapInfo: MapInfo?,
- logger: RLog
) {
if (!keyTypeArg.implementsEqualsAndHashcode()) {
- logger.w(
+ context.logger.w(
Warning.DOES_NOT_IMPLEMENT_EQUALS_HASHCODE,
ProcessorErrors.classMustImplementEqualsAndHashCode(
- keyTypeArg.typeName.toString()
+ keyTypeArg.asTypeName().toString(context.codeLanguage)
)
)
}
val hasKeyColumnName = mapInfo?.keyColumnName?.isNotEmpty() ?: false
if (!hasKeyColumnName && keyReader != null) {
- logger.e(
+ context.logger.e(
ProcessorErrors.keyMayNeedMapInfo(
- keyTypeArg.typeName
+ keyTypeArg.asTypeName().toString(context.codeLanguage)
)
)
}
val hasValueColumnName = mapInfo?.valueColumnName?.isNotEmpty() ?: false
if (!hasValueColumnName && valueReader != null) {
- logger.e(
+ context.logger.e(
ProcessorErrors.valueMayNeedMapInfo(
- valueTypeArg.typeName
+ valueTypeArg.asTypeName().toString(context.codeLanguage)
)
)
}
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/solver/query/result/PojoRowAdapter.kt b/room/room-compiler/src/main/kotlin/androidx/room/solver/query/result/PojoRowAdapter.kt
index d2b4ba1..570c1f9 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/solver/query/result/PojoRowAdapter.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/solver/query/result/PojoRowAdapter.kt
@@ -16,7 +16,6 @@
package androidx.room.solver.query.result
-import androidx.room.compiler.codegen.toJavaPoet
import androidx.room.compiler.processing.XType
import androidx.room.parser.ParsedQuery
import androidx.room.processor.Context
@@ -69,14 +68,18 @@
if (nonNulls.isNotEmpty()) {
context.logger.e(
ProcessorErrors.pojoMissingNonNull(
- pojoTypeName = pojo.typeName.toJavaPoet(),
+ pojoTypeName = pojo.typeName.toString(context.codeLanguage),
missingPojoFields = nonNulls.map { it.name },
allQueryColumns = info.columns.map { it.name }
)
)
}
if (matchedFields.isEmpty()) {
- context.logger.e(ProcessorErrors.cannotFindQueryResultAdapter(out.typeName))
+ context.logger.e(
+ ProcessorErrors.cannotFindQueryResultAdapter(
+ out.asTypeName().toString(context.codeLanguage)
+ )
+ )
}
} else {
matchedFields = remainingFields.map { it }
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/solver/shortcut/result/InsertOrUpsertMethodAdapter.kt b/room/room-compiler/src/main/kotlin/androidx/room/solver/shortcut/result/InsertOrUpsertMethodAdapter.kt
index 56d437e..682c533 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/solver/shortcut/result/InsertOrUpsertMethodAdapter.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/solver/shortcut/result/InsertOrUpsertMethodAdapter.kt
@@ -20,18 +20,19 @@
import androidx.room.compiler.codegen.XCodeBlock
import androidx.room.compiler.codegen.XPropertySpec
import androidx.room.compiler.codegen.XTypeName
-import androidx.room.compiler.codegen.asClassName
import androidx.room.compiler.processing.XType
import androidx.room.compiler.processing.isArray
import androidx.room.compiler.processing.isKotlinUnit
import androidx.room.compiler.processing.isLong
import androidx.room.compiler.processing.isVoid
import androidx.room.compiler.processing.isVoidObject
+import androidx.room.ext.CommonTypeNames
+import androidx.room.ext.KotlinTypeNames
+import androidx.room.ext.isList
import androidx.room.processor.Context
import androidx.room.processor.ProcessorErrors
import androidx.room.solver.CodeGenScope
import androidx.room.vo.ShortcutQueryParameter
-import com.squareup.javapoet.TypeName
class InsertOrUpsertMethodAdapter private constructor(private val methodType: MethodType) {
companion object {
@@ -142,7 +143,7 @@
} else if (returnType.isArray()) {
val param = returnType.componentType
if (param.isLong()) {
- if (param.typeName == TypeName.LONG) {
+ if (param.asTypeName() == XTypeName.PRIMITIVE_LONG) {
ReturnType.ID_ARRAY
} else {
ReturnType.ID_ARRAY_BOX
@@ -215,7 +216,7 @@
} else if (methodReturnType == ReturnType.VOID_OBJECT) {
addStatement("return null")
} else if (methodReturnType == ReturnType.UNIT && language == CodeLanguage.JAVA) {
- addStatement("return %T.INSTANCE", Unit::class.asClassName())
+ addStatement("return %T.INSTANCE", KotlinTypeNames.UNIT)
}
}
nextControlFlow("finally").apply {
@@ -244,7 +245,7 @@
val returnTypeName: XTypeName
) {
VOID("", XTypeName.UNIT_VOID), // return void
- VOID_OBJECT("", Void::class.asClassName()), // return Void
+ VOID_OBJECT("", CommonTypeNames.VOID), // return Void
UNIT("", XTypeName.UNIT_VOID), // return kotlin.Unit.INSTANCE
SINGLE_ID("AndReturnId", XTypeName.PRIMITIVE_LONG), // return long
ID_ARRAY(
@@ -253,11 +254,11 @@
), // return long[]
ID_ARRAY_BOX(
"AndReturnIdsArrayBox",
- XTypeName.getArrayName(Long::class.asClassName())
+ XTypeName.getArrayName(XTypeName.BOXED_LONG)
), // return Long[]
ID_LIST(
"AndReturnIdsList",
- List::class.asClassName().parametrizedBy(Long::class.asClassName())
+ CommonTypeNames.LIST.parametrizedBy(XTypeName.BOXED_LONG)
), // return List<Long>
}
}
\ No newline at end of file
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/solver/transaction/binder/CoroutineTransactionMethodBinder.kt b/room/room-compiler/src/main/kotlin/androidx/room/solver/transaction/binder/CoroutineTransactionMethodBinder.kt
index 828d0db..46c348e 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/solver/transaction/binder/CoroutineTransactionMethodBinder.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/solver/transaction/binder/CoroutineTransactionMethodBinder.kt
@@ -22,7 +22,6 @@
import androidx.room.compiler.codegen.XFunSpec.Builder.Companion.addStatement
import androidx.room.compiler.codegen.XPropertySpec
import androidx.room.compiler.codegen.XTypeName
-import androidx.room.compiler.codegen.asClassName
import androidx.room.compiler.processing.XType
import androidx.room.ext.Function1TypeSpec
import androidx.room.ext.KotlinTypeNames
@@ -87,7 +86,7 @@
XTypeName.getConsumerSuperName(returnType.asTypeName())
),
parameterName = innerContinuationParamName,
- returnTypeName = Any::class.asClassName()
+ returnTypeName = KotlinTypeNames.ANY
) {
addStatement("%L", adapterScope.generate())
}
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/solver/transaction/binder/InstantTransactionMethodBinder.kt b/room/room-compiler/src/main/kotlin/androidx/room/solver/transaction/binder/InstantTransactionMethodBinder.kt
index 6510c5b..4a8cae4 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/solver/transaction/binder/InstantTransactionMethodBinder.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/solver/transaction/binder/InstantTransactionMethodBinder.kt
@@ -19,9 +19,9 @@
import androidx.room.compiler.codegen.CodeLanguage
import androidx.room.compiler.codegen.XClassName
import androidx.room.compiler.codegen.XPropertySpec
-import androidx.room.compiler.codegen.asClassName
import androidx.room.compiler.processing.XType
import androidx.room.compiler.processing.isKotlinUnit
+import androidx.room.ext.KotlinTypeNames
import androidx.room.ext.isNotKotlinUnit
import androidx.room.ext.isNotVoid
import androidx.room.solver.CodeGenScope
@@ -71,7 +71,7 @@
if (resultVar != null) {
addStatement("return %N", resultVar)
} else if (returnType.isKotlinUnit() && language == CodeLanguage.JAVA) {
- addStatement("return %T.INSTANCE", Unit::class.asClassName())
+ addStatement("return %T.INSTANCE", KotlinTypeNames.UNIT)
}
}
nextControlFlow("finally").apply {
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/solver/types/BoxedBooleanToBoxedIntConverter.kt b/room/room-compiler/src/main/kotlin/androidx/room/solver/types/BoxedBooleanToBoxedIntConverter.kt
index 92acbc1..4d2d68f0 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/solver/types/BoxedBooleanToBoxedIntConverter.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/solver/types/BoxedBooleanToBoxedIntConverter.kt
@@ -18,7 +18,7 @@
import androidx.room.compiler.codegen.CodeLanguage
import androidx.room.compiler.codegen.XCodeBlock
-import androidx.room.compiler.codegen.asClassName
+import androidx.room.compiler.codegen.XTypeName
import androidx.room.compiler.processing.XProcessingEnv
import androidx.room.solver.CodeGenScope
@@ -28,10 +28,10 @@
object BoxedBooleanToBoxedIntConverter {
fun create(processingEnvironment: XProcessingEnv): List<TypeConverter> {
val tBoolean = processingEnvironment.requireType(
- Boolean::class.asClassName()
+ XTypeName.BOXED_BOOLEAN
).makeNullable()
val tInt = processingEnvironment.requireType(
- Int::class.asClassName()
+ XTypeName.BOXED_INT
).makeNullable()
return listOf(
object : SingleStatementTypeConverter(tBoolean, tInt) {
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/solver/types/EnumColumnTypeAdapter.kt b/room/room-compiler/src/main/kotlin/androidx/room/solver/types/EnumColumnTypeAdapter.kt
index ac06bb2..9905c5e 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/solver/types/EnumColumnTypeAdapter.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/solver/types/EnumColumnTypeAdapter.kt
@@ -23,6 +23,7 @@
import androidx.room.compiler.processing.XEnumTypeElement
import androidx.room.compiler.processing.XNullability
import androidx.room.compiler.processing.XType
+import androidx.room.ext.CommonTypeNames
import androidx.room.parser.SQLTypeAffinity.TEXT
import androidx.room.solver.CodeGenScope
import androidx.room.writer.TypeWriter
@@ -139,7 +140,7 @@
}
}.build()
builder.apply {
- returns(String::class.asClassName().copy(nullable = false))
+ returns(CommonTypeNames.STRING.copy(nullable = false))
addParameter(
out.asTypeName().copy(nullable = false),
paramName
@@ -207,7 +208,7 @@
builder.apply {
returns(out.asTypeName().copy(nullable = false))
addParameter(
- String::class.asClassName().copy(nullable = false),
+ CommonTypeNames.STRING.copy(nullable = false),
paramName
)
addCode(body)
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/solver/types/NullAwareTypeConverters.kt b/room/room-compiler/src/main/kotlin/androidx/room/solver/types/NullAwareTypeConverters.kt
index 3b30e79..815fe8d 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/solver/types/NullAwareTypeConverters.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/solver/types/NullAwareTypeConverters.kt
@@ -92,7 +92,8 @@
}
private fun XCodeBlock.Builder.addIllegalStateException() {
- val message = "Expected non-null ${from.typeName}, but it was null."
+ val typeName = from.asTypeName().copy(nullable = false).toString(language)
+ val message = "Expected non-null $typeName, but it was null."
when (language) {
CodeLanguage.JAVA -> {
addStatement(
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/solver/types/StringColumnTypeAdapter.kt b/room/room-compiler/src/main/kotlin/androidx/room/solver/types/StringColumnTypeAdapter.kt
index d8bb5d3..c68a9a9 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/solver/types/StringColumnTypeAdapter.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/solver/types/StringColumnTypeAdapter.kt
@@ -16,7 +16,6 @@
package androidx.room.solver.types
-import androidx.room.compiler.codegen.toJavaPoet
import androidx.room.compiler.processing.XNullability
import androidx.room.compiler.processing.XProcessingEnv
import androidx.room.compiler.processing.XType
@@ -69,7 +68,7 @@
companion object {
fun create(env: XProcessingEnv): List<StringColumnTypeAdapter> {
- val stringType = env.requireType(CommonTypeNames.STRING.toJavaPoet())
+ val stringType = env.requireType(CommonTypeNames.STRING)
return if (env.backend == XProcessingEnv.Backend.KSP) {
listOf(
StringColumnTypeAdapter(stringType.makeNonNullable()),
@@ -77,7 +76,7 @@
)
} else {
listOf(
- StringColumnTypeAdapter(stringType)
+ StringColumnTypeAdapter(stringType.makeNullable())
)
}
}
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/solver/types/UpCastTypeConverter.kt b/room/room-compiler/src/main/kotlin/androidx/room/solver/types/UpCastTypeConverter.kt
index 2465b26..e478031 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/solver/types/UpCastTypeConverter.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/solver/types/UpCastTypeConverter.kt
@@ -40,7 +40,7 @@
// normally, we don't need to generate any code here but if the upcast is converting from
// a primitive to boxed; we need to. Otherwise, output value won't become an object and
// that might break the rest of the code generation (e.g. checking nullable on primitive)
- return if (to.typeName.isBoxedPrimitive && from.typeName.isPrimitive) {
+ return if (to.asTypeName().isBoxedPrimitive && from.asTypeName().isPrimitive) {
super.doConvert(inputVarName, scope)
} else {
inputVarName
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/vo/Field.kt b/room/room-compiler/src/main/kotlin/androidx/room/vo/Field.kt
index bf23f75..7921989 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/vo/Field.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/vo/Field.kt
@@ -17,7 +17,6 @@
package androidx.room.vo
import androidx.room.compiler.codegen.XTypeName
-import androidx.room.compiler.codegen.asClassName
import androidx.room.compiler.processing.XFieldElement
import androidx.room.compiler.processing.XNullability
import androidx.room.compiler.processing.XType
@@ -103,7 +102,7 @@
if (
typeName == XTypeName.PRIMITIVE_BOOLEAN ||
- typeName == Boolean::class.asClassName()
+ typeName == XTypeName.BOXED_BOOLEAN
) {
if (name.length > 2 && name.startsWith("is") && name[2].isUpperCase()) {
result.add(name.substring(2).decapitalize(Locale.US))
@@ -120,7 +119,7 @@
nameWithVariations.map { "get${it.capitalize(Locale.US)}" } +
if (
typeName == XTypeName.PRIMITIVE_BOOLEAN ||
- typeName == Boolean::class.asClassName()
+ typeName == XTypeName.BOXED_BOOLEAN
) {
nameWithVariations.flatMap {
listOf("is${it.capitalize(Locale.US)}", "has${it.capitalize(Locale.US)}")
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/vo/RawQueryMethod.kt b/room/room-compiler/src/main/kotlin/androidx/room/vo/RawQueryMethod.kt
index 3aafee5..171aec5 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/vo/RawQueryMethod.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/vo/RawQueryMethod.kt
@@ -17,10 +17,10 @@
package androidx.room.vo
import androidx.room.compiler.codegen.XTypeName
-import androidx.room.compiler.codegen.asClassName
import androidx.room.compiler.processing.XMethodElement
import androidx.room.compiler.processing.XType
import androidx.room.compiler.processing.isKotlinUnit
+import androidx.room.ext.CommonTypeNames
import androidx.room.ext.SupportDbTypeNames
import androidx.room.ext.isNotVoid
import androidx.room.solver.query.result.QueryResultBinder
@@ -46,7 +46,7 @@
val paramName: String,
val typeName: XTypeName
) {
- fun isString() = String::class.asClassName() == typeName
+ fun isString() = CommonTypeNames.STRING == typeName
fun isSupportQuery() = SupportDbTypeNames.QUERY == typeName
}
}
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/vo/RelationCollector.kt b/room/room-compiler/src/main/kotlin/androidx/room/vo/RelationCollector.kt
index 219cb0d..dce1f83 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/vo/RelationCollector.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/vo/RelationCollector.kt
@@ -21,7 +21,6 @@
import androidx.room.compiler.codegen.XCodeBlock
import androidx.room.compiler.codegen.XCodeBlock.Builder.Companion.addLocalVal
import androidx.room.compiler.codegen.XTypeName
-import androidx.room.compiler.codegen.asClassName
import androidx.room.compiler.processing.XNullability
import androidx.room.ext.CollectionTypeNames
import androidx.room.ext.CommonTypeNames
@@ -31,8 +30,8 @@
import androidx.room.parser.SQLTypeAffinity
import androidx.room.parser.SqlParser
import androidx.room.processor.Context
+import androidx.room.processor.ProcessorErrors
import androidx.room.processor.ProcessorErrors.ISSUE_TRACKER_LINK
-import androidx.room.processor.ProcessorErrors.cannotFindQueryResultAdapter
import androidx.room.processor.ProcessorErrors.relationAffinityMismatch
import androidx.room.processor.ProcessorErrors.relationJunctionChildAffinityMismatch
import androidx.room.processor.ProcessorErrors.relationJunctionParentAffinityMismatch
@@ -44,7 +43,6 @@
import androidx.room.verifier.DatabaseVerificationErrors
import androidx.room.writer.QueryWriter
import androidx.room.writer.RelationCollectorFunctionWriter
-import java.nio.ByteBuffer
import java.util.Locale
/**
@@ -413,7 +411,9 @@
if (rowAdapter == null) {
context.logger.e(
relation.field.element,
- cannotFindQueryResultAdapter(relation.pojoType.typeName)
+ ProcessorErrors.cannotFindQueryResultAdapter(
+ relation.pojoType.asTypeName().toString(context.codeLanguage)
+ )
)
null
} else {
@@ -544,14 +544,14 @@
if (canUseLongSparseArray) {
XTypeName.PRIMITIVE_LONG
} else {
- Long::class.asClassName()
+ XTypeName.BOXED_LONG
}
- SQLTypeAffinity.REAL -> Double::class.asClassName()
- SQLTypeAffinity.TEXT -> String::class.asClassName()
- SQLTypeAffinity.BLOB -> ByteBuffer::class.asClassName()
+ SQLTypeAffinity.REAL -> XTypeName.BOXED_DOUBLE
+ SQLTypeAffinity.TEXT -> CommonTypeNames.STRING
+ SQLTypeAffinity.BLOB -> CommonTypeNames.BYTE_BUFFER
else -> {
// no affinity default to String
- String::class.asClassName()
+ CommonTypeNames.STRING
}
}
}
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/writer/DaoWriter.kt b/room/room-compiler/src/main/kotlin/androidx/room/writer/DaoWriter.kt
index ea0d93b..17a4ce7 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/writer/DaoWriter.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/writer/DaoWriter.kt
@@ -31,6 +31,7 @@
import androidx.room.compiler.processing.XElement
import androidx.room.compiler.processing.XMethodElement
import androidx.room.compiler.processing.XType
+import androidx.room.ext.CommonTypeNames
import androidx.room.ext.RoomMemberNames
import androidx.room.ext.RoomTypeNames
import androidx.room.ext.RoomTypeNames.DELETE_OR_UPDATE_ADAPTER
@@ -227,8 +228,8 @@
},
).apply {
returns(
- List::class.asClassName().parametrizedBy(
- Class::class.asClassName().parametrizedBy(XTypeName.ANY_WILDCARD)
+ CommonTypeNames.LIST.parametrizedBy(
+ CommonTypeNames.JAVA_CLASS.parametrizedBy(XTypeName.ANY_WILDCARD)
)
)
addCode(body)
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/writer/DatabaseWriter.kt b/room/room-compiler/src/main/kotlin/androidx/room/writer/DatabaseWriter.kt
index f1d09cf..37941e3 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/writer/DatabaseWriter.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/writer/DatabaseWriter.kt
@@ -26,7 +26,6 @@
import androidx.room.compiler.codegen.XTypeName
import androidx.room.compiler.codegen.XTypeSpec
import androidx.room.compiler.codegen.XTypeSpec.Builder.Companion.addOriginatingElement
-import androidx.room.compiler.codegen.asClassName
import androidx.room.ext.AndroidTypeNames
import androidx.room.ext.CommonTypeNames
import androidx.room.ext.KotlinTypeNames
@@ -67,7 +66,7 @@
private fun createCreateTypeConvertersMap(): XFunSpec {
val scope = CodeGenScope(this)
val classOfAnyTypeName = CommonTypeNames.JAVA_CLASS.parametrizedBy(
- XTypeName.getProducerExtendsName(Any::class.asClassName())
+ XTypeName.getProducerExtendsName(KotlinTypeNames.ANY)
)
val typeConvertersTypeName = CommonTypeNames.HASH_MAP.parametrizedBy(
classOfAnyTypeName,
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/writer/EntityCursorConverterWriter.kt b/room/room-compiler/src/main/kotlin/androidx/room/writer/EntityCursorConverterWriter.kt
index 399a208..c1f0457 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/writer/EntityCursorConverterWriter.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/writer/EntityCursorConverterWriter.kt
@@ -16,10 +16,10 @@
package androidx.room.writer
+import androidx.room.compiler.codegen.CodeLanguage
import androidx.room.compiler.codegen.XCodeBlock
import androidx.room.compiler.codegen.XFunSpec
import androidx.room.compiler.codegen.XTypeName
-import androidx.room.compiler.codegen.toJavaPoet
import androidx.room.ext.AndroidTypeNames.CURSOR
import androidx.room.ext.RoomMemberNames
import androidx.room.ext.capitalize
@@ -30,7 +30,7 @@
import java.util.Locale
class EntityCursorConverterWriter(val entity: Entity) : TypeWriter.SharedFunctionSpec(
- "entityCursorConverter_${entity.typeName.toJavaPoet().toString().stripNonJava()}"
+ "entityCursorConverter_${entity.typeName.toString(CodeLanguage.JAVA).stripNonJava()}"
) {
override fun getUniqueKey(): String {
return "generic_entity_converter_of_${entity.element.qualifiedName}"
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/writer/EntityDeletionAdapterWriter.kt b/room/room-compiler/src/main/kotlin/androidx/room/writer/EntityDeletionAdapterWriter.kt
index aeb8f5b2..d1d1379 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/writer/EntityDeletionAdapterWriter.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/writer/EntityDeletionAdapterWriter.kt
@@ -21,7 +21,7 @@
import androidx.room.compiler.codegen.XFunSpec.Builder.Companion.addStatement
import androidx.room.compiler.codegen.XTypeName
import androidx.room.compiler.codegen.XTypeSpec
-import androidx.room.compiler.codegen.asClassName
+import androidx.room.ext.CommonTypeNames
import androidx.room.ext.RoomTypeNames
import androidx.room.ext.SupportDbTypeNames
import androidx.room.solver.CodeGenScope
@@ -63,7 +63,7 @@
visibility = VisibilityModifier.PUBLIC,
isOverride = true
).apply {
- returns(String::class.asClassName())
+ returns(CommonTypeNames.STRING)
val query = "DELETE FROM `$tableName` WHERE " +
fields.columnNames.joinToString(" AND ") { "`$it` = ?" }
addStatement("return %S", query)
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/writer/EntityInsertionAdapterWriter.kt b/room/room-compiler/src/main/kotlin/androidx/room/writer/EntityInsertionAdapterWriter.kt
index adaf080..5e2b01f 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/writer/EntityInsertionAdapterWriter.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/writer/EntityInsertionAdapterWriter.kt
@@ -22,8 +22,8 @@
import androidx.room.compiler.codegen.XPropertySpec
import androidx.room.compiler.codegen.XTypeName
import androidx.room.compiler.codegen.XTypeSpec
-import androidx.room.compiler.codegen.asClassName
import androidx.room.compiler.processing.XNullability
+import androidx.room.ext.CommonTypeNames
import androidx.room.ext.RoomTypeNames
import androidx.room.ext.SupportDbTypeNames
import androidx.room.solver.CodeGenScope
@@ -78,7 +78,7 @@
visibility = VisibilityModifier.PUBLIC,
isOverride = true
).apply {
- returns(String::class.asClassName())
+ returns(CommonTypeNames.STRING)
val query = buildString {
if (onConflict.isNotEmpty()) {
append("INSERT OR $onConflict INTO `$tableName`")
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/writer/EntityUpdateAdapterWriter.kt b/room/room-compiler/src/main/kotlin/androidx/room/writer/EntityUpdateAdapterWriter.kt
index fc17282..c7f487c 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/writer/EntityUpdateAdapterWriter.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/writer/EntityUpdateAdapterWriter.kt
@@ -20,7 +20,7 @@
import androidx.room.compiler.codegen.XFunSpec
import androidx.room.compiler.codegen.XFunSpec.Builder.Companion.addStatement
import androidx.room.compiler.codegen.XTypeSpec
-import androidx.room.compiler.codegen.asClassName
+import androidx.room.ext.CommonTypeNames
import androidx.room.ext.RoomTypeNames
import androidx.room.ext.SupportDbTypeNames
import androidx.room.solver.CodeGenScope
@@ -56,7 +56,7 @@
visibility = VisibilityModifier.PUBLIC,
isOverride = true
).apply {
- returns(String::class.asClassName())
+ returns(CommonTypeNames.STRING)
val pojoCols = pojo.columnNames.joinToString(",") {
"`$it` = ?"
}
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/writer/PreparedStatementWriter.kt b/room/room-compiler/src/main/kotlin/androidx/room/writer/PreparedStatementWriter.kt
index 4fde443..1e742cf 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/writer/PreparedStatementWriter.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/writer/PreparedStatementWriter.kt
@@ -20,7 +20,7 @@
import androidx.room.compiler.codegen.XFunSpec.Builder.Companion.addStatement
import androidx.room.compiler.codegen.XPropertySpec
import androidx.room.compiler.codegen.XTypeSpec
-import androidx.room.compiler.codegen.asClassName
+import androidx.room.ext.CommonTypeNames
import androidx.room.ext.RoomTypeNames
import androidx.room.solver.CodeGenScope
@@ -39,7 +39,7 @@
visibility = VisibilityModifier.PUBLIC,
isOverride = true
).apply {
- returns(String::class.asClassName())
+ returns(CommonTypeNames.STRING)
val queryName = scope.getTmpVar("_query")
val queryGenScope = scope.fork()
queryWriter.prepareQuery(queryName, queryGenScope)
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/writer/QueryWriter.kt b/room/room-compiler/src/main/kotlin/androidx/room/writer/QueryWriter.kt
index ec8031f..c170531 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/writer/QueryWriter.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/writer/QueryWriter.kt
@@ -21,6 +21,7 @@
import androidx.room.compiler.codegen.XMemberName.Companion.packageMember
import androidx.room.compiler.codegen.XTypeName
import androidx.room.compiler.codegen.asClassName
+import androidx.room.ext.CommonTypeNames
import androidx.room.ext.RoomMemberNames
import androidx.room.ext.RoomTypeNames
import androidx.room.parser.ParsedQuery
@@ -112,7 +113,7 @@
}
addLocalVal(
outSqlQueryName,
- String::class.asClassName(),
+ CommonTypeNames.STRING,
"%L.toString()",
stringBuilderVar
)
@@ -140,7 +141,7 @@
} else {
addLocalVal(
outSqlQueryName,
- String::class.asClassName(),
+ CommonTypeNames.STRING,
"%S",
query.queryWithReplacedBindParams
)
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/writer/RelationCollectorFunctionWriter.kt b/room/room-compiler/src/main/kotlin/androidx/room/writer/RelationCollectorFunctionWriter.kt
index b76318d..1ecfd81 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/writer/RelationCollectorFunctionWriter.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/writer/RelationCollectorFunctionWriter.kt
@@ -23,13 +23,12 @@
import androidx.room.compiler.codegen.XFunSpec.Builder.Companion.addStatement
import androidx.room.compiler.codegen.XMemberName.Companion.packageMember
import androidx.room.compiler.codegen.XTypeName
-import androidx.room.compiler.codegen.asClassName
-import androidx.room.compiler.codegen.toJavaPoet
import androidx.room.ext.AndroidTypeNames
import androidx.room.ext.CollectionTypeNames
import androidx.room.ext.CollectionsSizeExprCode
import androidx.room.ext.CommonTypeNames
import androidx.room.ext.Function1TypeSpec
+import androidx.room.ext.KotlinTypeNames
import androidx.room.ext.MapKeySetExprCode
import androidx.room.ext.RoomMemberNames
import androidx.room.ext.RoomTypeNames
@@ -45,7 +44,7 @@
private val collector: RelationCollector
) : TypeWriter.SharedFunctionSpec(
"fetchRelationship${collector.relation.entity.tableName.stripNonJava()}" +
- "As${collector.relation.pojoTypeName.toJavaPoet().toString().stripNonJava()}"
+ "As${collector.relation.pojoTypeName.toString(CodeLanguage.JAVA).stripNonJava()}"
) {
companion object {
const val PARAM_MAP_VARIABLE = "_map"
@@ -61,7 +60,7 @@
val relation = collector.relation
return "RelationCollectorMethodWriter" +
"-${collector.mapTypeName}" +
- "-${relation.entity.typeName.toJavaPoet()}" +
+ "-${relation.entity.typeName.toString(CodeLanguage.JAVA)}" +
"-${relation.entityField.columnName}" +
"-${relation.pojoTypeName}" +
"-${relation.createLoadAllSql()}"
@@ -238,7 +237,7 @@
)
indent()
addStatement("%L", getRecursiveCall(paramName))
- addStatement("return %T.INSTANCE", Unit::class.asClassName())
+ addStatement("return %T.INSTANCE", KotlinTypeNames.UNIT)
unindent()
addStatement("})")
} else {
@@ -246,10 +245,10 @@
language = language,
parameterTypeName = collector.mapTypeName,
parameterName = paramName,
- returnTypeName = Unit::class.asClassName(),
+ returnTypeName = KotlinTypeNames.UNIT,
) {
addStatement("%L", getRecursiveCall(paramName))
- addStatement("return %T.INSTANCE", Unit::class.asClassName())
+ addStatement("return %T.INSTANCE", KotlinTypeNames.UNIT)
}
addStatement(
"%M(%L, %L, %L)",
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/writer/TypeWriter.kt b/room/room-compiler/src/main/kotlin/androidx/room/writer/TypeWriter.kt
index f49c5c2..9583754 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/writer/TypeWriter.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/writer/TypeWriter.kt
@@ -29,8 +29,9 @@
import androidx.room.ext.S
import androidx.room.solver.CodeGenScope
import com.squareup.kotlinpoet.javapoet.JAnnotationSpec
+import com.squareup.kotlinpoet.javapoet.JClassName
import com.squareup.kotlinpoet.javapoet.KAnnotationSpec
-import com.squareup.kotlinpoet.javapoet.toKClassName
+import com.squareup.kotlinpoet.javapoet.KClassName
import kotlin.reflect.KClass
/**
@@ -101,18 +102,19 @@
processingEnv: XProcessingEnv
) {
processingEnv.findGeneratedAnnotation()?.let {
+ val annotationName = it.asClassName().canonicalName
val memberValue = RoomProcessor::class.java.canonicalName
adapterTypeSpecBuilder.apply(
javaTypeBuilder = {
addAnnotation(
- JAnnotationSpec.builder(it.className)
+ JAnnotationSpec.builder(JClassName.bestGuess(annotationName))
.addMember("value", "$S", memberValue)
.build()
)
},
kotlinTypeBuilder = {
addAnnotation(
- KAnnotationSpec.builder(it.className.toKClassName())
+ KAnnotationSpec.builder(KClassName.bestGuess(annotationName))
.addMember("value = [%S]", memberValue)
.build()
)
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/ext/ElementExtTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/ext/ElementExtTest.kt
index afac914..78e96b6 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/ext/ElementExtTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/ext/ElementExtTest.kt
@@ -16,14 +16,14 @@
package androidx.room.ext
+import androidx.room.compiler.codegen.XClassName
+import androidx.room.compiler.codegen.XTypeName
import androidx.room.compiler.processing.XMethodElement
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.XTestInvocation
import androidx.room.compiler.processing.util.compileFiles
import androidx.room.compiler.processing.util.runProcessorTest
import com.google.common.truth.Truth.assertThat
-import com.squareup.javapoet.ClassName
-import com.squareup.javapoet.TypeName
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
@@ -210,34 +210,9 @@
.first {
it.jvmName == "method"
}
- assertThat(field.type.typeName).isEqualTo(TypeName.INT)
- assertThat(method.returnType.typeName).isEqualTo(TypeName.INT)
- assertThat(element.type.typeName).isEqualTo(ClassName.get("foo.bar", "Baz"))
- }
- }
-
- @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
- )
- runTest { invocation ->
- val processingEnv = invocation.processingEnv
- primitiveTypeNames.forEach { primitiveTypeName ->
- val typeMirror = processingEnv.requireType(primitiveTypeName)
- assertThat(typeMirror.typeName).isEqualTo(primitiveTypeName)
- assertThat(
- typeMirror.boxed().typeName
- ).isEqualTo(primitiveTypeName.box())
- }
+ assertThat(field.type.asTypeName()).isEqualTo(XTypeName.PRIMITIVE_INT)
+ assertThat(method.returnType.asTypeName()).isEqualTo(XTypeName.PRIMITIVE_INT)
+ assertThat(element.type.asTypeName()).isEqualTo(XClassName.get("foo.bar", "Baz"))
}
}
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/parser/SQLTypeAffinityTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/parser/SQLTypeAffinityTest.kt
index fff0299..e9ad56d 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/parser/SQLTypeAffinityTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/parser/SQLTypeAffinityTest.kt
@@ -16,6 +16,7 @@
package androidx.room.parser
+import androidx.room.compiler.codegen.CodeLanguage
import androidx.room.compiler.processing.XNullability
import androidx.room.compiler.processing.XType
import androidx.room.compiler.processing.util.runProcessorTest
@@ -45,7 +46,7 @@
}
fun XType.toSignature(): String {
- return "${typeName}${nullability.toSignature()}"
+ return "${asTypeName().toString(CodeLanguage.JAVA)}${nullability.toSignature()}"
}
val result = SQLTypeAffinity.values().associate {
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/AutoMigrationProcessorTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/AutoMigrationProcessorTest.kt
index e328370..5197e66 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/AutoMigrationProcessorTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/AutoMigrationProcessorTest.kt
@@ -131,7 +131,7 @@
).process()
invocation.assertCompilationResult {
hasErrorContaining(
- ProcessorErrors.autoMigrationElementMustImplementSpec("MyAutoMigration")
+ ProcessorErrors.autoMigrationElementMustImplementSpec("foo.bar.MyAutoMigration")
)
}
}
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/CustomConverterProcessorTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/CustomConverterProcessorTest.kt
index 5ef999b..aa449e9 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/CustomConverterProcessorTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/CustomConverterProcessorTest.kt
@@ -338,7 +338,7 @@
// instead of not running the code path in ksp tests
hasErrorContaining(TYPE_CONVERTER_EMPTY_CLASS)
} else {
- hasErrorContaining(ProcessorErrors.typeConverterMustBeDeclared(TypeName.INT))
+ hasErrorContaining(ProcessorErrors.typeConverterMustBeDeclared("int"))
}
}
}
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/DaoProcessorTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/DaoProcessorTest.kt
index 52f0496..78f4cec 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/DaoProcessorTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/DaoProcessorTest.kt
@@ -29,7 +29,6 @@
import androidx.room.vo.ReadQueryMethod
import androidx.room.vo.Warning
import com.google.common.truth.Truth
-import com.squareup.javapoet.TypeName
import createVerifierFromEntitiesAndViews
import java.io.File
import org.hamcrest.CoreMatchers.`is`
@@ -438,7 +437,7 @@
assertThat(method.element.jvmName, `is`("getAllIds"))
invocation.assertCompilationResult {
hasErrorContaining(
- ProcessorErrors.cannotFindQueryResultAdapter(TypeName.VOID)
+ ProcessorErrors.cannotFindQueryResultAdapter("void")
)
}
}
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/DatabaseProcessorTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/DatabaseProcessorTest.kt
index f6f9d51..07063d5 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/DatabaseProcessorTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/DatabaseProcessorTest.kt
@@ -18,6 +18,7 @@
import COMMON
import androidx.room.DatabaseProcessingStep
+import androidx.room.compiler.codegen.CodeLanguage
import androidx.room.compiler.processing.XType
import androidx.room.compiler.processing.XTypeElement
import androidx.room.compiler.processing.util.CompilationResultSubject
@@ -39,12 +40,14 @@
import androidx.room.vo.Warning
import com.google.auto.service.processor.AutoServiceProcessor
import com.google.common.truth.Truth.assertThat
-import com.squareup.javapoet.ClassName
-import com.squareup.javapoet.TypeName
-import org.hamcrest.CoreMatchers.`is`
+import java.io.File
+import java.io.FileOutputStream
+import java.net.URL
+import java.net.URLClassLoader
import org.hamcrest.CoreMatchers.equalTo
import org.hamcrest.CoreMatchers.hasItems
import org.hamcrest.CoreMatchers.instanceOf
+import org.hamcrest.CoreMatchers.`is`
import org.hamcrest.CoreMatchers.not
import org.hamcrest.CoreMatchers.notNullValue
import org.hamcrest.CoreMatchers.sameInstance
@@ -55,10 +58,6 @@
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.mockito.Mockito.mock
-import java.io.File
-import java.io.FileOutputStream
-import java.net.URL
-import java.net.URLClassLoader
@RunWith(JUnit4::class)
class DatabaseProcessorTest {
@@ -253,7 +252,7 @@
assertThat(db.entities.size, `is`(2))
assertThat(db.daoMethods.map { it.element.jvmName }, `is`(listOf("userDao", "bookDao")))
assertThat(
- db.entities.map { it.type.typeName.toString() },
+ db.entities.map { it.type.asTypeName().toString(CodeLanguage.JAVA) },
`is`(listOf("foo.bar.User", "foo.bar.Book"))
)
}
@@ -512,7 +511,7 @@
)
hasErrorContaining(
ProcessorErrors.duplicateDao(
- ClassName.get("foo.bar", "UserDao"), listOf("userDao", "userDao2")
+ "foo.bar.UserDao", listOf("userDao", "userDao2")
)
)
}
@@ -594,7 +593,8 @@
"""
package foo.bar;
import androidx.room.*;
- @Entity(foreignKeys = @ForeignKey(entity = ${COMMON.USER_TYPE_NAME}.class,
+ @Entity(foreignKeys = @ForeignKey(
+ entity = ${COMMON.USER_TYPE_NAME.canonicalName}.class,
parentColumns = "lastName",
childColumns = "name"))
public class Entity1 {
@@ -630,7 +630,8 @@
"""
package foo.bar;
import androidx.room.*;
- @Entity(foreignKeys = @ForeignKey(entity = ${COMMON.USER_TYPE_NAME}.class,
+ @Entity(foreignKeys = @ForeignKey(
+ entity = ${COMMON.USER_TYPE_NAME.canonicalName}.class,
parentColumns = "lastName",
childColumns = "name"))
public class Entity1 {
@@ -651,7 +652,7 @@
invocation.assertCompilationResult {
hasErrorContaining(
ProcessorErrors.foreignKeyMissingIndexInParent(
- parentEntity = COMMON.USER_TYPE_NAME.toString(),
+ parentEntity = COMMON.USER_TYPE_NAME.canonicalName,
parentColumns = listOf("lastName"),
childEntity = "foo.bar.Entity1",
childColumns = listOf("name")
@@ -1247,14 +1248,10 @@
} else {
invocation.assertCompilationResult {
hasErrorContaining(
- ProcessorErrors.invalidEntityTypeInDatabaseAnnotation(
- TypeName.LONG
- )
+ ProcessorErrors.invalidEntityTypeInDatabaseAnnotation("long")
)
hasErrorContaining(
- ProcessorErrors.invalidViewTypeInDatabaseAnnotation(
- TypeName.INT
- )
+ ProcessorErrors.invalidViewTypeInDatabaseAnnotation("int")
)
}
}
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/DeleteOrUpdateShortcutMethodProcessorTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/DeleteOrUpdateShortcutMethodProcessorTest.kt
index 6c0353f..089cd3f 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/DeleteOrUpdateShortcutMethodProcessorTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/DeleteOrUpdateShortcutMethodProcessorTest.kt
@@ -18,16 +18,17 @@
import COMMON
import androidx.room.Dao
+import androidx.room.compiler.codegen.CodeLanguage
import androidx.room.compiler.codegen.XClassName
import androidx.room.compiler.codegen.XTypeName
-import androidx.room.compiler.codegen.toJavaPoet
+import androidx.room.compiler.codegen.asMutableClassName
import androidx.room.compiler.processing.XMethodElement
import androidx.room.compiler.processing.XType
import androidx.room.compiler.processing.XTypeElement
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.XTestInvocation
import androidx.room.compiler.processing.util.runProcessorTest
-import androidx.room.ext.CommonTypeNames.STRING
+import androidx.room.ext.CommonTypeNames
import androidx.room.ext.GuavaUtilConcurrentTypeNames
import androidx.room.ext.KotlinTypeNames
import androidx.room.ext.LifecyclesTypeNames
@@ -36,10 +37,6 @@
import androidx.room.ext.RxJava3TypeNames
import androidx.room.testing.context
import androidx.room.vo.DeleteOrUpdateShortcutMethod
-import com.squareup.javapoet.ArrayTypeName
-import com.squareup.javapoet.ClassName
-import com.squareup.javapoet.ParameterizedTypeName
-import com.squareup.javapoet.TypeName
import kotlin.reflect.KClass
import org.hamcrest.CoreMatchers.`is`
import org.hamcrest.MatcherAssert.assertThat
@@ -75,7 +72,7 @@
"""
const val DAO_SUFFIX = "}"
- val USER_TYPE_NAME: TypeName = COMMON.USER_TYPE_NAME
+ val USER_TYPE_NAME: XTypeName = COMMON.USER_TYPE_NAME
val USERNAME_TYPE_NAME: XTypeName = XClassName.get("foo.bar", "Username")
val BOOK_TYPE_NAME: XTypeName = XClassName.get("foo.bar", "Book")
}
@@ -109,12 +106,12 @@
assertThat(shortcut.element.jvmName, `is`("foo"))
assertThat(shortcut.parameters.size, `is`(1))
val param = shortcut.parameters.first()
- assertThat(param.type.typeName, `is`(USER_TYPE_NAME))
- assertThat(param.pojoType?.typeName, `is`(USER_TYPE_NAME))
+ assertThat(param.type.asTypeName(), `is`(USER_TYPE_NAME))
+ assertThat(param.pojoType?.asTypeName(), `is`(USER_TYPE_NAME))
assertThat(shortcut.entities.size, `is`(1))
assertThat(shortcut.entities["user"]?.isPartialEntity, `is`(false))
assertThat(
- shortcut.entities["user"]?.pojo?.typeName?.toJavaPoet(),
+ shortcut.entities["user"]?.pojo?.typeName,
`is`(USER_TYPE_NAME)
)
}
@@ -151,16 +148,16 @@
assertThat(shortcut.parameters.size, `is`(2))
shortcut.parameters.forEach {
- assertThat(it.type.typeName, `is`(USER_TYPE_NAME))
- assertThat(it.pojoType?.typeName, `is`(USER_TYPE_NAME))
+ assertThat(it.type.asTypeName(), `is`(USER_TYPE_NAME))
+ assertThat(it.pojoType?.asTypeName(), `is`(USER_TYPE_NAME))
}
assertThat(shortcut.entities.size, `is`(2))
assertThat(
- shortcut.entities["u1"]?.pojo?.typeName?.toJavaPoet(),
+ shortcut.entities["u1"]?.pojo?.typeName,
`is`(USER_TYPE_NAME)
)
assertThat(
- shortcut.entities["u1"]?.pojo?.typeName?.toJavaPoet(),
+ shortcut.entities["u1"]?.pojo?.typeName,
`is`(USER_TYPE_NAME)
)
assertThat(
@@ -193,17 +190,15 @@
assertThat(shortcut.parameters.size, `is`(1))
val param = shortcut.parameters.first()
assertThat(
- param.type.typeName,
+ param.type.asTypeName(),
`is`(
- ParameterizedTypeName.get(
- ClassName.get("java.util", "List"), USER_TYPE_NAME
- ) as TypeName
+ CommonTypeNames.MUTABLE_LIST.parametrizedBy(USER_TYPE_NAME)
)
)
- assertThat(param.pojoType?.typeName, `is`(USER_TYPE_NAME))
+ assertThat(param.pojoType?.asTypeName(), `is`(USER_TYPE_NAME))
assertThat(shortcut.entities.size, `is`(1))
assertThat(
- shortcut.entities["users"]?.pojo?.typeName?.toJavaPoet(),
+ shortcut.entities["users"]?.pojo?.typeName,
`is`(USER_TYPE_NAME)
)
}
@@ -222,14 +217,14 @@
assertThat(shortcut.parameters.size, `is`(1))
val param = shortcut.parameters.first()
assertThat(
- param.type.typeName,
+ param.type.asTypeName(),
`is`(
- ArrayTypeName.of(COMMON.USER_TYPE_NAME) as TypeName
+ XTypeName.getArrayName(COMMON.USER_TYPE_NAME)
)
)
assertThat(shortcut.entities.size, `is`(1))
assertThat(
- shortcut.entities["users"]?.pojo?.typeName?.toJavaPoet(),
+ shortcut.entities["users"]?.pojo?.typeName,
`is`(USER_TYPE_NAME)
)
}
@@ -247,17 +242,14 @@
assertThat(shortcut.parameters.size, `is`(1))
val param = shortcut.parameters.first()
assertThat(
- param.type.typeName,
+ param.type.asTypeName(),
`is`(
- ParameterizedTypeName.get(
- ClassName.get("java.util", "Set"),
- COMMON.USER_TYPE_NAME
- ) as TypeName
+ CommonTypeNames.MUTABLE_SET.parametrizedBy(COMMON.USER_TYPE_NAME)
)
)
assertThat(shortcut.entities.size, `is`(1))
assertThat(
- shortcut.entities["users"]?.pojo?.typeName?.toJavaPoet(),
+ shortcut.entities["users"]?.pojo?.typeName,
`is`(USER_TYPE_NAME)
)
}
@@ -275,17 +267,14 @@
assertThat(shortcut.parameters.size, `is`(1))
val param = shortcut.parameters.first()
assertThat(
- param.type.typeName,
+ param.type.asTypeName(),
`is`(
- ParameterizedTypeName.get(
- ClassName.get("java.lang", "Iterable"),
- COMMON.USER_TYPE_NAME
- ) as TypeName
+ Iterable::class.asMutableClassName().parametrizedBy(COMMON.USER_TYPE_NAME)
)
)
assertThat(shortcut.entities.size, `is`(1))
assertThat(
- shortcut.entities["users"]?.pojo?.typeName?.toJavaPoet(),
+ shortcut.entities["users"]?.pojo?.typeName,
`is`(USER_TYPE_NAME)
)
}
@@ -304,17 +293,16 @@
assertThat(shortcut.parameters.size, `is`(1))
val param = shortcut.parameters.first()
assertThat(
- param.type.typeName,
+ param.type.asTypeName(),
`is`(
- ParameterizedTypeName.get(
- ClassName.get("foo.bar", "MyClass.MyList"),
- STRING.toJavaPoet(), COMMON.USER_TYPE_NAME
- ) as TypeName
+ XClassName.get("foo.bar", "MyClass.MyList").parametrizedBy(
+ CommonTypeNames.STRING, COMMON.USER_TYPE_NAME
+ )
)
)
assertThat(shortcut.entities.size, `is`(1))
assertThat(
- shortcut.entities["users"]?.pojo?.typeName?.toJavaPoet(),
+ shortcut.entities["users"]?.pojo?.typeName,
`is`(USER_TYPE_NAME)
)
}
@@ -342,17 +330,17 @@
) { shortcut, _ ->
assertThat(shortcut.parameters.size, `is`(2))
assertThat(
- shortcut.parameters[0].type.typeName.toString(),
+ shortcut.parameters[0].type.asTypeName().toString(CodeLanguage.JAVA),
`is`("foo.bar.User")
)
assertThat(
- shortcut.parameters[1].type.typeName.toString(),
+ shortcut.parameters[1].type.asTypeName().toString(CodeLanguage.JAVA),
`is`("foo.bar.Book")
)
assertThat(shortcut.parameters.map { it.name }, `is`(listOf("u1", "b1")))
assertThat(shortcut.entities.size, `is`(2))
assertThat(
- shortcut.entities["u1"]?.pojo?.typeName?.toJavaPoet(),
+ shortcut.entities["u1"]?.pojo?.typeName,
`is`(USER_TYPE_NAME)
)
assertThat(
@@ -453,7 +441,7 @@
assertThat(param.pojoType?.asTypeName(), `is`(USERNAME_TYPE_NAME))
assertThat(shortcut.entities.size, `is`(1))
assertThat(shortcut.entities["username"]?.isPartialEntity, `is`(true))
- assertThat(shortcut.entities["username"]?.entityTypeName?.toJavaPoet(),
+ assertThat(shortcut.entities["username"]?.entityTypeName,
`is`(USER_TYPE_NAME))
assertThat(
shortcut.entities["username"]?.pojo?.typeName,
@@ -620,9 +608,7 @@
) { _, invocation ->
invocation.assertCompilationResult {
hasErrorContaining(
- ProcessorErrors.shortcutMethodArgumentMustBeAClass(
- TypeName.LONG
- )
+ ProcessorErrors.shortcutMethodArgumentMustBeAClass("long")
)
}
}
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/EntityNameMatchingVariationsTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/EntityNameMatchingVariationsTest.kt
index 1c3792d..093dcc2 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/EntityNameMatchingVariationsTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/EntityNameMatchingVariationsTest.kt
@@ -16,6 +16,7 @@
package androidx.room.processor
+import androidx.room.compiler.codegen.CodeLanguage
import androidx.room.parser.SQLTypeAffinity
import androidx.room.vo.CallType
import androidx.room.vo.Field
@@ -60,7 +61,8 @@
public void $setterName(int id) { this.$fieldName = id; }
"""
) { entity, invocation ->
- assertThat(entity.type.typeName.toString()).isEqualTo("foo.bar.MyEntity")
+ assertThat(entity.type.asTypeName().toString(CodeLanguage.JAVA))
+ .isEqualTo("foo.bar.MyEntity")
assertThat(entity.fields.size).isEqualTo(1)
val field = entity.fields.first()
val intType = invocation.processingEnv.requireType(TypeName.INT)
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/FieldProcessorTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/FieldProcessorTest.kt
index a4a393c..733cacd 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/FieldProcessorTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/FieldProcessorTest.kt
@@ -17,6 +17,8 @@
package androidx.room.processor
import androidx.room.Entity
+import androidx.room.compiler.codegen.CodeLanguage
+import androidx.room.compiler.codegen.XTypeName
import androidx.room.compiler.processing.XFieldElement
import androidx.room.compiler.processing.XTypeElement
import androidx.room.compiler.processing.util.Source
@@ -27,19 +29,15 @@
import androidx.room.solver.types.ColumnTypeAdapter
import androidx.room.testing.context
import androidx.room.vo.Field
-import com.squareup.javapoet.ArrayTypeName
-import com.squareup.javapoet.TypeName
-import org.hamcrest.CoreMatchers.`is`
import org.hamcrest.CoreMatchers.equalTo
+import org.hamcrest.CoreMatchers.`is`
import org.hamcrest.CoreMatchers.nullValue
import org.hamcrest.MatcherAssert.assertThat
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.mockito.Mockito.mock
-import java.util.Locale
-@Suppress("HasPlatformType")
@RunWith(JUnit4::class)
class FieldProcessorTest {
companion object {
@@ -53,60 +51,77 @@
"""
const val ENTITY_SUFFIX = "}"
val ALL_PRIMITIVES = arrayListOf(
- TypeName.INT,
- TypeName.BYTE,
- TypeName.SHORT,
- TypeName.LONG,
- TypeName.CHAR,
- TypeName.FLOAT,
- TypeName.DOUBLE
+ XTypeName.PRIMITIVE_INT,
+ XTypeName.PRIMITIVE_BYTE,
+ XTypeName.PRIMITIVE_SHORT,
+ XTypeName.PRIMITIVE_LONG,
+ XTypeName.PRIMITIVE_CHAR,
+ XTypeName.PRIMITIVE_FLOAT,
+ XTypeName.PRIMITIVE_DOUBLE
+ )
+ val ALL_BOXED_PRIMITIVES = arrayListOf(
+ XTypeName.BOXED_INT,
+ XTypeName.BOXED_BYTE,
+ XTypeName.BOXED_SHORT,
+ XTypeName.BOXED_LONG,
+ XTypeName.BOXED_CHAR,
+ XTypeName.BOXED_FLOAT,
+ XTypeName.BOXED_DOUBLE
)
val ARRAY_CONVERTER = Source.java(
"foo.bar.MyConverter",
"""
- package foo.bar;
- import androidx.room.*;
- public class MyConverter {
- ${
- ALL_PRIMITIVES.joinToString("\n") {
- val arrayDef = "$it[]"
- "@TypeConverter public static String" +
- " arrayIntoString($arrayDef input) { return null;}" +
- "@TypeConverter public static $arrayDef" +
- " stringIntoArray$it(String input) { return null;}"
+ |package foo.bar;
+ |import androidx.room.*;
+ |public class MyConverter {
+ |${
+ ALL_PRIMITIVES.joinToString("|\n") {
+ val arrayName = it.toString(CodeLanguage.JAVA)
+ val arrayDef = "$arrayName[]"
+ """
+ | @TypeConverter
+ | public static String arrayIntoString($arrayDef input) { return null; }
+ | @TypeConverter
+ | public static $arrayDef stringIntoArray$arrayName(String input) { return null; }
+ """
+ }
}
+ |${
+ ALL_BOXED_PRIMITIVES.joinToString("|\n") {
+ val arrayName = it.simpleNames.single()
+ val arrayDef = "$arrayName[]"
+ """
+ | @TypeConverter
+ | public static String arrayIntoString($arrayDef input) { return null; }
+ | @TypeConverter
+ | public static $arrayDef stringIntoArray$arrayName(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}Boxed(String input) { return null;}"
- }
- }
- }
- """
+ |}
+ """.trimMargin()
)
- private fun TypeName.affinity(): SQLTypeAffinity {
+ private fun XTypeName.affinity(): SQLTypeAffinity {
return when (this) {
- TypeName.FLOAT, TypeName.DOUBLE -> SQLTypeAffinity.REAL
+ XTypeName.PRIMITIVE_FLOAT, XTypeName.BOXED_FLOAT,
+ XTypeName.PRIMITIVE_DOUBLE, XTypeName.BOXED_DOUBLE -> SQLTypeAffinity.REAL
else -> SQLTypeAffinity.INTEGER
}
}
- private fun TypeName.box(invocation: XTestInvocation) =
+ private fun XTypeName.box(invocation: XTestInvocation) =
typeMirror(invocation).boxed()
- private fun TypeName.typeMirror(invocation: XTestInvocation) =
+ private fun XTypeName.typeMirror(invocation: XTestInvocation) =
invocation.processingEnv.requireType(this)
}
@Test
fun primitives() {
ALL_PRIMITIVES.forEach { primitive ->
- singleEntity("$primitive x;") { field, invocation ->
+ val fieldName = primitive.toString(CodeLanguage.JAVA)
+ singleEntity("$fieldName x;") { field, invocation ->
assertThat(
field,
`is`(
@@ -124,16 +139,17 @@
@Test
fun boxed() {
- ALL_PRIMITIVES.forEach { primitive ->
- singleEntity("@Nullable ${primitive.box()} y;") { field, invocation ->
+ ALL_BOXED_PRIMITIVES.forEach { boxedPrimitive ->
+ val fieldName = boxedPrimitive.simpleNames.single()
+ singleEntity("@Nullable $fieldName y;") { field, invocation ->
assertThat(
field,
`is`(
Field(
name = "y",
- type = primitive.box(invocation).makeNullable(),
+ type = boxedPrimitive.typeMirror(invocation).makeNullable(),
element = field.element,
- affinity = primitive.affinity()
+ affinity = boxedPrimitive.affinity()
)
)
)
@@ -155,7 +171,7 @@
`is`(
Field(
name = "x",
- type = TypeName.INT.typeMirror(invocation),
+ type = XTypeName.PRIMITIVE_INT.typeMirror(invocation),
element = field.element,
columnName = "foo",
affinity = SQLTypeAffinity.INTEGER
@@ -178,7 +194,7 @@
`is`(
Field(
name = "x",
- type = TypeName.INT.typeMirror(invocation),
+ type = XTypeName.PRIMITIVE_INT.typeMirror(invocation),
element = field.element,
columnName = "foo",
affinity = SQLTypeAffinity.INTEGER,
@@ -216,7 +232,7 @@
`is`(
Field(
name = "arr",
- type = invocation.processingEnv.getArrayType(TypeName.BYTE)
+ type = invocation.processingEnv.getArrayType(XTypeName.PRIMITIVE_BYTE)
.makeNonNullable(),
element = field.element,
affinity = SQLTypeAffinity.TEXT
@@ -235,7 +251,7 @@
ALL_PRIMITIVES.forEach { primitive ->
singleEntity(
"@TypeConverters(foo.bar.MyConverter.class) @NonNull " +
- "${primitive.toString().lowercase(Locale.US)}[] arr;"
+ "${primitive.toString(CodeLanguage.JAVA)}[] arr;"
) { field, invocation ->
assertThat(
field,
@@ -245,7 +261,7 @@
type = invocation.processingEnv.getArrayType(primitive)
.makeNonNullable(),
element = field.element,
- affinity = if (primitive == TypeName.BYTE) {
+ affinity = if (primitive == XTypeName.PRIMITIVE_BYTE) {
SQLTypeAffinity.BLOB
} else {
SQLTypeAffinity.TEXT
@@ -259,16 +275,14 @@
@Test
fun boxedArray() {
- ALL_PRIMITIVES.forEach { primitive ->
+ ALL_BOXED_PRIMITIVES.forEach { boxedPrimitive ->
singleEntity(
"@TypeConverters(foo.bar.MyConverter.class) " +
- "${primitive.box()}[] arr;"
+ "${boxedPrimitive.toString(CodeLanguage.JAVA)}[] arr;"
) { field, invocation ->
val expected = Field(
name = "arr",
- type = invocation.processingEnv.getArrayType(
- primitive.box()
- ),
+ type = invocation.processingEnv.getArrayType(boxedPrimitive),
element = field.element,
affinity = SQLTypeAffinity.TEXT,
nonNull = false // no annotation
@@ -287,8 +301,8 @@
)
)
assertThat(
- field.type.typeName,
- `is`(ArrayTypeName.of(primitive.box()))
+ field.type.asTypeName(),
+ `is`(XTypeName.getArrayName(boxedPrimitive))
)
}
}
@@ -312,7 +326,7 @@
`is`(
Field(
name = "item",
- type = TypeName.INT.box(invocation).makeNonNullable(),
+ type = XTypeName.PRIMITIVE_INT.box(invocation).makeNonNullable(),
element = field.element,
affinity = SQLTypeAffinity.INTEGER
)
@@ -350,14 +364,14 @@
val fieldElement = mock(XFieldElement::class.java)
assertThat(
Field(
- fieldElement, "x", TypeName.INT.typeMirror(it),
+ fieldElement, "x", XTypeName.PRIMITIVE_INT.typeMirror(it),
SQLTypeAffinity.INTEGER
).nameWithVariations,
`is`(arrayListOf("x"))
)
assertThat(
Field(
- fieldElement, "x", TypeName.BOOLEAN.typeMirror(it),
+ fieldElement, "x", XTypeName.PRIMITIVE_BOOLEAN.typeMirror(it),
SQLTypeAffinity.INTEGER
).nameWithVariations,
`is`(arrayListOf("x"))
@@ -365,7 +379,7 @@
assertThat(
Field(
fieldElement, "xAll",
- TypeName.BOOLEAN.typeMirror(it), SQLTypeAffinity.INTEGER
+ XTypeName.PRIMITIVE_BOOLEAN.typeMirror(it), SQLTypeAffinity.INTEGER
)
.nameWithVariations,
`is`(arrayListOf("xAll"))
@@ -379,28 +393,28 @@
runProcessorTest {
assertThat(
Field(
- elm, "isX", TypeName.BOOLEAN.typeMirror(it),
+ elm, "isX", XTypeName.PRIMITIVE_BOOLEAN.typeMirror(it),
SQLTypeAffinity.INTEGER
).nameWithVariations,
`is`(arrayListOf("isX", "x"))
)
assertThat(
Field(
- elm, "isX", TypeName.INT.typeMirror(it),
+ elm, "isX", XTypeName.PRIMITIVE_INT.typeMirror(it),
SQLTypeAffinity.INTEGER
).nameWithVariations,
`is`(arrayListOf("isX"))
)
assertThat(
Field(
- elm, "is", TypeName.BOOLEAN.typeMirror(it),
+ elm, "is", XTypeName.PRIMITIVE_BOOLEAN.typeMirror(it),
SQLTypeAffinity.INTEGER
).nameWithVariations,
`is`(arrayListOf("is"))
)
assertThat(
Field(
- elm, "isAllItems", TypeName.BOOLEAN.typeMirror(it),
+ elm, "isAllItems", XTypeName.PRIMITIVE_BOOLEAN.typeMirror(it),
SQLTypeAffinity.INTEGER
).nameWithVariations,
`is`(arrayListOf("isAllItems", "allItems"))
@@ -414,28 +428,28 @@
runProcessorTest {
assertThat(
Field(
- elm, "hasX", TypeName.BOOLEAN.typeMirror(it),
+ elm, "hasX", XTypeName.PRIMITIVE_BOOLEAN.typeMirror(it),
SQLTypeAffinity.INTEGER
).nameWithVariations,
`is`(arrayListOf("hasX", "x"))
)
assertThat(
Field(
- elm, "hasX", TypeName.INT.typeMirror(it),
+ elm, "hasX", XTypeName.PRIMITIVE_INT.typeMirror(it),
SQLTypeAffinity.INTEGER
).nameWithVariations,
`is`(arrayListOf("hasX"))
)
assertThat(
Field(
- elm, "has", TypeName.BOOLEAN.typeMirror(it),
+ elm, "has", XTypeName.PRIMITIVE_BOOLEAN.typeMirror(it),
SQLTypeAffinity.INTEGER
).nameWithVariations,
`is`(arrayListOf("has"))
)
assertThat(
Field(
- elm, "hasAllItems", TypeName.BOOLEAN.typeMirror(it),
+ elm, "hasAllItems", XTypeName.PRIMITIVE_BOOLEAN.typeMirror(it),
SQLTypeAffinity.INTEGER
).nameWithVariations,
`is`(arrayListOf("hasAllItems", "allItems"))
@@ -449,42 +463,42 @@
runProcessorTest {
assertThat(
Field(
- elm, "mall", TypeName.BOOLEAN.typeMirror(it),
+ elm, "mall", XTypeName.PRIMITIVE_BOOLEAN.typeMirror(it),
SQLTypeAffinity.INTEGER
).nameWithVariations,
`is`(arrayListOf("mall"))
)
assertThat(
Field(
- elm, "mallVars", TypeName.BOOLEAN.typeMirror(it),
+ elm, "mallVars", XTypeName.PRIMITIVE_BOOLEAN.typeMirror(it),
SQLTypeAffinity.INTEGER
).nameWithVariations,
`is`(arrayListOf("mallVars"))
)
assertThat(
Field(
- elm, "mAll", TypeName.BOOLEAN.typeMirror(it),
+ elm, "mAll", XTypeName.PRIMITIVE_BOOLEAN.typeMirror(it),
SQLTypeAffinity.INTEGER
).nameWithVariations,
`is`(arrayListOf("mAll", "all"))
)
assertThat(
Field(
- elm, "m", TypeName.INT.typeMirror(it),
+ elm, "m", XTypeName.PRIMITIVE_INT.typeMirror(it),
SQLTypeAffinity.INTEGER
).nameWithVariations,
`is`(arrayListOf("m"))
)
assertThat(
Field(
- elm, "mallItems", TypeName.BOOLEAN.typeMirror(it),
+ elm, "mallItems", XTypeName.PRIMITIVE_BOOLEAN.typeMirror(it),
SQLTypeAffinity.INTEGER
).nameWithVariations,
`is`(arrayListOf("mallItems"))
)
assertThat(
Field(
- elm, "mAllItems", TypeName.BOOLEAN.typeMirror(it),
+ elm, "mAllItems", XTypeName.PRIMITIVE_BOOLEAN.typeMirror(it),
SQLTypeAffinity.INTEGER
).nameWithVariations,
`is`(arrayListOf("mAllItems", "allItems"))
@@ -498,21 +512,21 @@
runProcessorTest {
assertThat(
Field(
- elm, "_all", TypeName.BOOLEAN.typeMirror(it),
+ elm, "_all", XTypeName.PRIMITIVE_BOOLEAN.typeMirror(it),
SQLTypeAffinity.INTEGER
).nameWithVariations,
`is`(arrayListOf("_all", "all"))
)
assertThat(
Field(
- elm, "_", TypeName.INT.typeMirror(it),
+ elm, "_", XTypeName.PRIMITIVE_INT.typeMirror(it),
SQLTypeAffinity.INTEGER
).nameWithVariations,
`is`(arrayListOf("_"))
)
assertThat(
Field(
- elm, "_allItems", TypeName.BOOLEAN.typeMirror(it),
+ elm, "_allItems", XTypeName.PRIMITIVE_BOOLEAN.typeMirror(it),
SQLTypeAffinity.INTEGER
).nameWithVariations,
`is`(arrayListOf("_allItems", "allItems"))
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/Fts3TableEntityProcessorTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/Fts3TableEntityProcessorTest.kt
index bf4a2d5..5fe3711 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/Fts3TableEntityProcessorTest.kt
+++ b/room/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.compiler.codegen.CodeLanguage
import androidx.room.parser.FtsVersion
import androidx.room.parser.SQLTypeAffinity
import androidx.room.vo.CallType
@@ -63,7 +64,8 @@
public void setRowId(int id) { this.rowId = rowId; }
"""
) { entity, invocation ->
- assertThat(entity.type.typeName.toString(), `is`("foo.bar.MyEntity"))
+ assertThat(entity.type.asTypeName().toString(CodeLanguage.JAVA),
+ `is`("foo.bar.MyEntity"))
assertThat(entity.fields.size, `is`(1))
val field = entity.fields.first()
val intType = invocation.processingEnv.requireType(TypeName.INT)
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/Fts4TableEntityProcessorTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/Fts4TableEntityProcessorTest.kt
index 3434fdf..9b1f407 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/Fts4TableEntityProcessorTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/Fts4TableEntityProcessorTest.kt
@@ -17,6 +17,7 @@
package androidx.room.processor
import androidx.room.FtsOptions
+import androidx.room.compiler.codegen.CodeLanguage
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.runProcessorTest
import androidx.room.parser.FtsVersion
@@ -50,7 +51,8 @@
public void setRowId(int id) { this.rowId = rowId; }
"""
) { entity, invocation ->
- assertThat(entity.type.typeName.toString(), `is`("foo.bar.MyEntity"))
+ assertThat(entity.type.asTypeName().toString(CodeLanguage.JAVA),
+ `is`("foo.bar.MyEntity"))
assertThat(entity.fields.size, `is`(1))
val field = entity.fields.first()
val intType = invocation.processingEnv.requireType(TypeName.INT)
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/InsertOrUpsertShortcutMethodProcessorTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/InsertOrUpsertShortcutMethodProcessorTest.kt
index 4458240..a238f1f 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/InsertOrUpsertShortcutMethodProcessorTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/InsertOrUpsertShortcutMethodProcessorTest.kt
@@ -18,8 +18,11 @@
import COMMON
import androidx.room.Dao
+import androidx.room.compiler.codegen.CodeLanguage
import androidx.room.compiler.codegen.XClassName
import androidx.room.compiler.codegen.XTypeName
+import androidx.room.compiler.codegen.asClassName
+import androidx.room.compiler.codegen.asMutableClassName
import androidx.room.compiler.codegen.toJavaPoet
import androidx.room.compiler.processing.XMethodElement
import androidx.room.compiler.processing.XType
@@ -38,10 +41,6 @@
import androidx.room.testing.context
import androidx.room.vo.InsertOrUpsertShortcutMethod
import com.google.common.truth.Truth.assertThat
-import com.squareup.javapoet.ArrayTypeName
-import com.squareup.javapoet.ClassName
-import com.squareup.javapoet.ParameterizedTypeName
-import com.squareup.javapoet.TypeName
import kotlin.reflect.KClass
import org.junit.Test
@@ -74,7 +73,7 @@
abstract class MyClass {
"""
const val DAO_SUFFIX = "}"
- val USER_TYPE_NAME: TypeName = COMMON.USER_TYPE_NAME
+ val USER_TYPE_NAME: XTypeName = COMMON.USER_TYPE_NAME
val USERNAME_TYPE_NAME: XTypeName = XClassName.get("foo.bar", "Username")
val BOOK_TYPE_NAME: XTypeName = XClassName.get("foo.bar", "Book")
}
@@ -89,7 +88,7 @@
) { insertionUpsertion, invocation ->
assertThat(insertionUpsertion.element.jvmName).isEqualTo("foo")
assertThat(insertionUpsertion.parameters.size).isEqualTo(0)
- assertThat(insertionUpsertion.returnType.typeName).isEqualTo(TypeName.VOID)
+ assertThat(insertionUpsertion.returnType.asTypeName()).isEqualTo(XTypeName.UNIT_VOID)
assertThat(insertionUpsertion.entities.size).isEqualTo(0)
invocation.assertCompilationResult {
hasErrorContaining(noParamsError())
@@ -131,20 +130,20 @@
assertThat(insertionUpsertion.parameters.size).isEqualTo(1)
val param = insertionUpsertion.parameters.first()
- assertThat(param.type.typeName)
+ assertThat(param.type.asTypeName())
.isEqualTo(USER_TYPE_NAME)
- assertThat(param.pojoType?.typeName)
+ assertThat(param.pojoType?.asTypeName())
.isEqualTo(USER_TYPE_NAME)
assertThat(insertionUpsertion.entities["user"]?.isPartialEntity)
.isEqualTo(false)
- assertThat(insertionUpsertion.entities["user"]?.pojo?.typeName?.toJavaPoet())
- .isEqualTo(ClassName.get("foo.bar", "User") as TypeName)
+ assertThat(insertionUpsertion.entities["user"]?.pojo?.typeName)
+ .isEqualTo(XClassName.get("foo.bar", "User"))
- assertThat(insertionUpsertion.returnType.typeName)
- .isEqualTo(TypeName.LONG)
+ assertThat(insertionUpsertion.returnType.asTypeName())
+ .isEqualTo(XTypeName.PRIMITIVE_LONG)
}
}
@Test
@@ -159,23 +158,23 @@
assertThat(insertionUpsertion.parameters.size).isEqualTo(2)
insertionUpsertion.parameters.forEach {
- assertThat(it.type.typeName).isEqualTo(USER_TYPE_NAME)
- assertThat(it.pojoType?.typeName).isEqualTo(USER_TYPE_NAME)
+ assertThat(it.type.asTypeName()).isEqualTo(USER_TYPE_NAME)
+ assertThat(it.pojoType?.asTypeName()).isEqualTo(USER_TYPE_NAME)
}
assertThat(insertionUpsertion.entities.size)
.isEqualTo(2)
- assertThat(insertionUpsertion.entities["u1"]?.pojo?.typeName?.toJavaPoet())
+ assertThat(insertionUpsertion.entities["u1"]?.pojo?.typeName)
.isEqualTo(USER_TYPE_NAME)
- assertThat(insertionUpsertion.entities["u2"]?.pojo?.typeName?.toJavaPoet())
+ assertThat(insertionUpsertion.entities["u2"]?.pojo?.typeName)
.isEqualTo(USER_TYPE_NAME)
assertThat(insertionUpsertion.parameters.map { it.name })
.isEqualTo(listOf("u1", "u2"))
- assertThat(insertionUpsertion.returnType.typeName)
- .isEqualTo(TypeName.VOID)
+ assertThat(insertionUpsertion.returnType.asTypeName())
+ .isEqualTo(XTypeName.UNIT_VOID)
}
}
@@ -190,28 +189,22 @@
assertThat(insertionUpsertion.element.jvmName).isEqualTo("insertUsers")
assertThat(insertionUpsertion.parameters.size).isEqualTo(1)
val param = insertionUpsertion.parameters.first()
- assertThat(param.type.typeName)
+ assertThat(param.type.asTypeName())
.isEqualTo(
- ParameterizedTypeName.get(
- ClassName.get("java.util", "List"),
- USER_TYPE_NAME
- ) as TypeName
+ CommonTypeNames.MUTABLE_LIST.parametrizedBy(USER_TYPE_NAME)
)
- assertThat(param.pojoType?.typeName)
+ assertThat(param.pojoType?.asTypeName())
.isEqualTo(USER_TYPE_NAME)
assertThat(insertionUpsertion.entities.size).isEqualTo(1)
- assertThat(insertionUpsertion.entities["users"]?.pojo?.typeName?.toJavaPoet())
+ assertThat(insertionUpsertion.entities["users"]?.pojo?.typeName)
.isEqualTo(USER_TYPE_NAME)
- assertThat(insertionUpsertion.returnType.typeName)
+ assertThat(insertionUpsertion.returnType.asTypeName())
.isEqualTo(
- ParameterizedTypeName.get(
- ClassName.get("java.util", "List"),
- ClassName.get("java.lang", "Long")
- ) as TypeName
+ CommonTypeNames.MUTABLE_LIST.parametrizedBy(XTypeName.BOXED_LONG)
)
}
}
@@ -227,16 +220,16 @@
assertThat(insertionUpsertion.element.jvmName).isEqualTo("insertUsers")
assertThat(insertionUpsertion.parameters.size).isEqualTo(1)
val param = insertionUpsertion.parameters.first()
- assertThat(param.type.typeName)
- .isEqualTo(ArrayTypeName.of(COMMON.USER_TYPE_NAME) as TypeName)
+ assertThat(param.type.asTypeName())
+ .isEqualTo(XTypeName.getArrayName(COMMON.USER_TYPE_NAME))
assertThat(insertionUpsertion.entities.size).isEqualTo(1)
- assertThat(insertionUpsertion.entities["users"]?.pojo?.typeName?.toJavaPoet())
+ assertThat(insertionUpsertion.entities["users"]?.pojo?.typeName)
.isEqualTo(USER_TYPE_NAME)
- assertThat(insertionUpsertion.returnType.typeName)
- .isEqualTo(TypeName.VOID)
+ assertThat(insertionUpsertion.returnType.asTypeName())
+ .isEqualTo(XTypeName.UNIT_VOID)
}
}
@@ -251,20 +244,17 @@
assertThat(insertionUpsertion.element.jvmName).isEqualTo("insertUsers")
assertThat(insertionUpsertion.parameters.size).isEqualTo(1)
val param = insertionUpsertion.parameters.first()
- assertThat(param.type.typeName)
+ assertThat(param.type.asTypeName())
.isEqualTo(
- ParameterizedTypeName.get(
- ClassName.get("java.util", "Set"),
- COMMON.USER_TYPE_NAME
- ) as TypeName
+ CommonTypeNames.MUTABLE_SET.parametrizedBy(COMMON.USER_TYPE_NAME)
)
assertThat(insertionUpsertion.entities.size).isEqualTo(1)
- assertThat(insertionUpsertion.entities["users"]?.pojo?.typeName?.toJavaPoet())
+ assertThat(insertionUpsertion.entities["users"]?.pojo?.typeName)
.isEqualTo(USER_TYPE_NAME)
- assertThat(insertionUpsertion.returnType.typeName).isEqualTo(TypeName.VOID)
+ assertThat(insertionUpsertion.returnType.asTypeName()).isEqualTo(XTypeName.UNIT_VOID)
}
}
@@ -279,20 +269,17 @@
assertThat(insertionUpsertion.element.jvmName).isEqualTo("insertUsers")
assertThat(insertionUpsertion.parameters.size).isEqualTo(1)
val param = insertionUpsertion.parameters.first()
- assertThat(param.type.typeName)
+ assertThat(param.type.asTypeName())
.isEqualTo(
- ParameterizedTypeName.get(
- ClassName.get("java.util", "Queue"),
- USER_TYPE_NAME
- ) as TypeName
+ java.util.Queue::class.asClassName().parametrizedBy(USER_TYPE_NAME)
)
assertThat(insertionUpsertion.entities.size).isEqualTo(1)
- assertThat(insertionUpsertion.entities["users"]?.pojo?.typeName?.toJavaPoet())
+ assertThat(insertionUpsertion.entities["users"]?.pojo?.typeName)
.isEqualTo(USER_TYPE_NAME)
- assertThat(insertionUpsertion.returnType.typeName).isEqualTo(TypeName.VOID)
+ assertThat(insertionUpsertion.returnType.asTypeName()).isEqualTo(XTypeName.UNIT_VOID)
}
}
@@ -307,20 +294,17 @@
assertThat(insertionUpsertion.element.jvmName).isEqualTo("insert")
assertThat(insertionUpsertion.parameters.size).isEqualTo(1)
val param = insertionUpsertion.parameters.first()
- assertThat(param.type.typeName)
+ assertThat(param.type.asTypeName())
.isEqualTo(
- ParameterizedTypeName.get(
- ClassName.get("java.lang", "Iterable"),
- USER_TYPE_NAME
- ) as TypeName
+ Iterable::class.asMutableClassName().parametrizedBy(USER_TYPE_NAME)
)
assertThat(insertionUpsertion.entities.size).isEqualTo(1)
- assertThat(insertionUpsertion.entities["users"]?.pojo?.typeName?.toJavaPoet())
+ assertThat(insertionUpsertion.entities["users"]?.pojo?.typeName)
.isEqualTo(USER_TYPE_NAME)
- assertThat(insertionUpsertion.returnType.typeName).isEqualTo(TypeName.VOID)
+ assertThat(insertionUpsertion.returnType.asTypeName()).isEqualTo(XTypeName.UNIT_VOID)
}
}
@@ -336,20 +320,19 @@
assertThat(insertionUpsertion.element.jvmName).isEqualTo("insert")
assertThat(insertionUpsertion.parameters.size).isEqualTo(1)
val param = insertionUpsertion.parameters.first()
- assertThat(param.type.typeName)
+ assertThat(param.type.asTypeName())
.isEqualTo(
- ParameterizedTypeName.get(
- ClassName.get("foo.bar", "MyClass.MyList"),
- CommonTypeNames.STRING.toJavaPoet(), USER_TYPE_NAME
- ) as TypeName
+ XClassName.get("foo.bar", "MyClass.MyList").parametrizedBy(
+ CommonTypeNames.STRING, USER_TYPE_NAME
+ )
)
assertThat(insertionUpsertion.entities.size).isEqualTo(1)
- assertThat(insertionUpsertion.entities["users"]?.pojo?.typeName?.toJavaPoet())
+ assertThat(insertionUpsertion.entities["users"]?.pojo?.typeName)
.isEqualTo(USER_TYPE_NAME)
- assertThat(insertionUpsertion.returnType.typeName).isEqualTo(TypeName.VOID)
+ assertThat(insertionUpsertion.returnType.asTypeName()).isEqualTo(XTypeName.UNIT_VOID)
}
}
@@ -362,19 +345,21 @@
"""
) { insertionUpsertion, _ ->
assertThat(insertionUpsertion.parameters.size).isEqualTo(2)
- assertThat(insertionUpsertion.parameters[0].type.typeName.toString())
- .isEqualTo("foo.bar.User")
+ assertThat(
+ insertionUpsertion.parameters[0].type.asTypeName().toString(CodeLanguage.JAVA)
+ ).isEqualTo("foo.bar.User")
- assertThat(insertionUpsertion.parameters[1].type.typeName.toString())
- .isEqualTo("foo.bar.Book")
+ assertThat(
+ insertionUpsertion.parameters[1].type.asTypeName().toString(CodeLanguage.JAVA)
+ ).isEqualTo("foo.bar.Book")
assertThat(insertionUpsertion.parameters.map { it.name }).isEqualTo(listOf("u1", "b1"))
- assertThat(insertionUpsertion.returnType.typeName).isEqualTo(TypeName.VOID)
+ assertThat(insertionUpsertion.returnType.asTypeName()).isEqualTo(XTypeName.UNIT_VOID)
assertThat(insertionUpsertion.entities.size).isEqualTo(2)
- assertThat(insertionUpsertion.entities["u1"]?.pojo?.typeName?.toJavaPoet())
+ assertThat(insertionUpsertion.entities["u1"]?.pojo?.typeName)
.isEqualTo(USER_TYPE_NAME)
assertThat(insertionUpsertion.entities["b1"]?.pojo?.typeName)
@@ -593,7 +578,7 @@
assertThat(insertionUpsertion.entities["username"]?.isPartialEntity)
.isEqualTo(true)
- assertThat(insertionUpsertion.entities["username"]?.entityTypeName?.toJavaPoet())
+ assertThat(insertionUpsertion.entities["username"]?.entityTypeName)
.isEqualTo(USER_TYPE_NAME)
assertThat(insertionUpsertion.entities["username"]?.pojo?.typeName)
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/PojoProcessorTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/PojoProcessorTest.kt
index 2785605..639ba0d 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/PojoProcessorTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/PojoProcessorTest.kt
@@ -687,7 +687,7 @@
assertThat(pojo.relations.size, `is`(1))
val rel = pojo.relations.first()
assertThat(rel.projection, `is`(listOf("uid")))
- assertThat(rel.entity.typeName.toJavaPoet(), `is`(COMMON.USER_TYPE_NAME as TypeName))
+ assertThat(rel.entity.typeName, `is`(COMMON.USER_TYPE_NAME))
}
}
@@ -705,7 +705,7 @@
assertThat(pojo.relations.size, `is`(1))
val rel = pojo.relations.first()
assertThat(rel.projection, `is`(listOf("name")))
- assertThat(rel.entity.typeName.toJavaPoet(), `is`(COMMON.USER_TYPE_NAME as TypeName))
+ assertThat(rel.entity.typeName, `is`(COMMON.USER_TYPE_NAME))
}
}
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/QueryMethodProcessorTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/QueryMethodProcessorTest.kt
index 78038eb..4cd4627 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/QueryMethodProcessorTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/QueryMethodProcessorTest.kt
@@ -19,12 +19,16 @@
import COMMON
import androidx.room.Dao
import androidx.room.Query
+import androidx.room.compiler.codegen.XClassName
+import androidx.room.compiler.codegen.XTypeName
+import androidx.room.compiler.codegen.asClassName
import androidx.room.compiler.codegen.toJavaPoet
import androidx.room.compiler.processing.XType
import androidx.room.compiler.processing.XTypeElement
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.XTestInvocation
import androidx.room.compiler.processing.util.runProcessorTest
+import androidx.room.ext.CommonTypeNames
import androidx.room.ext.CommonTypeNames.LIST
import androidx.room.ext.GuavaUtilConcurrentTypeNames
import androidx.room.ext.KotlinTypeNames
@@ -54,7 +58,6 @@
import androidx.room.vo.Warning
import androidx.room.vo.WriteQueryMethod
import com.google.common.truth.Truth.assertThat
-import com.squareup.javapoet.ArrayTypeName
import com.squareup.javapoet.ClassName
import com.squareup.javapoet.ParameterizedTypeName
import com.squareup.javapoet.TypeName
@@ -102,7 +105,7 @@
abstract class MyClass {
"""
const val DAO_SUFFIX = "}"
- val POJO: ClassName = ClassName.get("foo.bar", "MyClass.Pojo")
+ val POJO = XClassName.get("foo.bar", "MyClass.Pojo")
@Parameterized.Parameters(name = "enableDbVerification={0}")
@JvmStatic
fun getParams() = arrayOf(true, false)
@@ -130,8 +133,8 @@
assertThat(parsedQuery.element.jvmName, `is`("foo"))
assertThat(parsedQuery.parameters.size, `is`(0))
assertThat(
- parsedQuery.returnType.typeName,
- `is`(ArrayTypeName.of(TypeName.INT) as TypeName)
+ parsedQuery.returnType.asTypeName(),
+ `is`(XTypeName.getArrayName(XTypeName.PRIMITIVE_INT))
)
}
}
@@ -145,7 +148,7 @@
"""
) { parsedQuery, invocation ->
assertThat(parsedQuery.element.jvmName, `is`("foo"))
- assertThat(parsedQuery.returnType.typeName, `is`(TypeName.LONG))
+ assertThat(parsedQuery.returnType.asTypeName(), `is`(XTypeName.PRIMITIVE_LONG))
assertThat(parsedQuery.parameters.size, `is`(1))
val param = parsedQuery.parameters.first()
assertThat(param.name, `is`("x"))
@@ -166,14 +169,14 @@
"""
) { parsedQuery, _ ->
assertThat(parsedQuery.element.jvmName, `is`("foo"))
- assertThat(parsedQuery.returnType.typeName, `is`(TypeName.LONG))
+ assertThat(parsedQuery.returnType.asTypeName(), `is`(XTypeName.PRIMITIVE_LONG))
assertThat(parsedQuery.parameters.size, `is`(1))
val param = parsedQuery.parameters.first()
assertThat(param.name, `is`("ids"))
assertThat(param.sqlName, `is`("ids"))
assertThat(
- param.type.typeName,
- `is`(ArrayTypeName.of(TypeName.INT))
+ param.type.asTypeName(),
+ `is`(XTypeName.getArrayName(XTypeName.PRIMITIVE_INT))
)
}
}
@@ -333,7 +336,7 @@
singleQueryMethod<ReadQueryMethod>(
"""
@Query("select * from User")
- abstract public <T> ${LIST.toJavaPoet()}<T> foo(int x);
+ abstract public <T> ${LIST.canonicalName}<T> foo(int x);
"""
) { parsedQuery, invocation ->
val expected: TypeName = ParameterizedTypeName.get(
@@ -431,8 +434,8 @@
"""
) { parsedQuery, _ ->
assertThat(
- parsedQuery.returnType.typeName,
- `is`(ClassName.get(Integer::class.java) as TypeName)
+ parsedQuery.returnType.asTypeName(),
+ `is`(XTypeName.BOXED_INT)
)
}
}
@@ -451,9 +454,9 @@
"""
) { parsedQuery, _ ->
assertThat(
- parsedQuery.parameters.first().type.typeName,
+ parsedQuery.parameters.first().type.asTypeName(),
`is`(
- TypeName.INT.box()
+ XTypeName.BOXED_INT
)
)
}
@@ -470,7 +473,7 @@
invocation.assertCompilationResult {
hasErrorContaining(
ProcessorErrors
- .cannotFindPreparedQueryResultAdapter(TypeName.FLOAT, QueryType.DELETE)
+ .cannotFindPreparedQueryResultAdapter("float", QueryType.DELETE)
)
}
}
@@ -486,7 +489,7 @@
) { parsedQuery, _ ->
assertThat(parsedQuery.element.jvmName, `is`("foo"))
assertThat(parsedQuery.parameters.size, `is`(1))
- assertThat(parsedQuery.returnType.typeName, `is`(TypeName.INT))
+ assertThat(parsedQuery.returnType.asTypeName(), `is`(XTypeName.PRIMITIVE_INT))
}
}
@@ -500,7 +503,7 @@
) { parsedQuery, _ ->
assertThat(parsedQuery.element.jvmName, `is`("foo"))
assertThat(parsedQuery.parameters.size, `is`(1))
- assertThat(parsedQuery.returnType.typeName, `is`(TypeName.VOID))
+ assertThat(parsedQuery.returnType.asTypeName(), `is`(XTypeName.UNIT_VOID))
}
}
@@ -511,13 +514,13 @@
@Query("update user set name = :name")
abstract public void updateAllNames(String name);
"""
- ) { parsedQuery, invocation ->
+ ) { parsedQuery, _ ->
assertThat(parsedQuery.element.jvmName, `is`("updateAllNames"))
assertThat(parsedQuery.parameters.size, `is`(1))
- assertThat(parsedQuery.returnType.typeName, `is`(TypeName.VOID))
+ assertThat(parsedQuery.returnType.asTypeName(), `is`(XTypeName.UNIT_VOID))
assertThat(
- parsedQuery.parameters.first().type.typeName,
- `is`(invocation.context.COMMON_TYPES.STRING.typeName)
+ parsedQuery.parameters.first().type.asTypeName(),
+ `is`(CommonTypeNames.STRING)
)
}
}
@@ -529,13 +532,13 @@
@Query("insert into user (name) values (:name)")
abstract public void insertUsername(String name);
"""
- ) { parsedQuery, invocation ->
+ ) { parsedQuery, _ ->
assertThat(parsedQuery.element.jvmName, `is`("insertUsername"))
assertThat(parsedQuery.parameters.size, `is`(1))
- assertThat(parsedQuery.returnType.typeName, `is`(TypeName.VOID))
+ assertThat(parsedQuery.returnType.asTypeName(), `is`(XTypeName.UNIT_VOID))
assertThat(
- parsedQuery.parameters.first().type.typeName,
- `is`(invocation.context.COMMON_TYPES.STRING.typeName)
+ parsedQuery.parameters.first().type.asTypeName(),
+ `is`(CommonTypeNames.STRING)
)
}
}
@@ -547,13 +550,13 @@
@Query("insert into user (name) values (:name)")
abstract public long insertUsername(String name);
"""
- ) { parsedQuery, invocation ->
+ ) { parsedQuery, _ ->
assertThat(parsedQuery.element.jvmName, `is`("insertUsername"))
assertThat(parsedQuery.parameters.size, `is`(1))
- assertThat(parsedQuery.returnType.typeName, `is`(TypeName.LONG))
+ assertThat(parsedQuery.returnType.asTypeName(), `is`(XTypeName.PRIMITIVE_LONG))
assertThat(
- parsedQuery.parameters.first().type.typeName,
- `is`(invocation.context.COMMON_TYPES.STRING.typeName)
+ parsedQuery.parameters.first().type.asTypeName(),
+ `is`(CommonTypeNames.STRING)
)
}
}
@@ -566,11 +569,11 @@
abstract public int insert(String name);
"""
) { parsedQuery, invocation ->
- assertThat(parsedQuery.returnType.typeName, `is`(TypeName.INT))
+ assertThat(parsedQuery.returnType.asTypeName(), `is`(XTypeName.PRIMITIVE_INT))
invocation.assertCompilationResult {
hasErrorContaining(
ProcessorErrors
- .cannotFindPreparedQueryResultAdapter(TypeName.INT, QueryType.INSERT)
+ .cannotFindPreparedQueryResultAdapter("int", QueryType.INSERT)
)
}
}
@@ -611,10 +614,7 @@
invocation.assertCompilationResult {
hasErrorContaining(
ProcessorErrors.cannotFindPreparedQueryResultAdapter(
- ParameterizedTypeName.get(
- LifecyclesTypeNames.LIVE_DATA,
- TypeName.INT.box()
- ),
+ "androidx.lifecycle.LiveData<java.lang.Integer>",
QueryType.DELETE
)
)
@@ -633,10 +633,7 @@
invocation.assertCompilationResult {
hasErrorContaining(
ProcessorErrors.cannotFindPreparedQueryResultAdapter(
- ParameterizedTypeName.get(
- LifecyclesTypeNames.LIVE_DATA,
- TypeName.INT.box()
- ),
+ "androidx.lifecycle.LiveData<java.lang.Integer>",
QueryType.UPDATE
)
)
@@ -796,8 +793,8 @@
assertThat(parsedQuery.element.jvmName, `is`("foo"))
assertThat(parsedQuery.parameters.size, `is`(0))
assertThat(
- parsedQuery.returnType.typeName,
- `is`(ArrayTypeName.of(TypeName.INT) as TypeName)
+ parsedQuery.returnType.asTypeName(),
+ `is`(XTypeName.getArrayName(XTypeName.PRIMITIVE_INT))
)
}
}
@@ -814,8 +811,8 @@
assertThat(parsedQuery.element.jvmName, `is`("getPojo"))
assertThat(parsedQuery.parameters.size, `is`(0))
assertThat(
- parsedQuery.returnType.typeName,
- `is`(COMMON.NOT_AN_ENTITY_TYPE_NAME as TypeName)
+ parsedQuery.returnType.asTypeName(),
+ `is`(COMMON.NOT_AN_ENTITY_TYPE_NAME)
)
val adapter = parsedQuery.queryResultBinder.adapter
assertThat(checkNotNull(adapter))
@@ -873,12 +870,9 @@
val pojoRowAdapter = listAdapter.rowAdapters.single() as PojoRowAdapter
assertThat(pojoRowAdapter.relationCollectors.size, `is`(1))
assertThat(
- pojoRowAdapter.relationCollectors[0].relationTypeName.toJavaPoet(),
+ pojoRowAdapter.relationCollectors[0].relationTypeName,
`is`(
- ParameterizedTypeName.get(
- ClassName.get(ArrayList::class.java),
- COMMON.USER_TYPE_NAME
- ) as TypeName
+ CommonTypeNames.ARRAY_LIST.parametrizedBy(COMMON.USER_TYPE_NAME)
)
)
invocation.assertCompilationResult {
@@ -1098,15 +1092,15 @@
invocation.assertCompilationResult {
hasErrorContaining(
cannotFindQueryResultAdapter(
- ClassName.get("foo.bar", "MyClass", "Pojo")
+ XClassName.get("foo.bar", "MyClass", "Pojo").canonicalName
)
)
hasWarningContaining(
ProcessorErrors.cursorPojoMismatch(
- pojoTypeNames = listOf(POJO),
+ pojoTypeNames = listOf(POJO.canonicalName),
unusedColumns = listOf("name", "lastName"),
pojoUnusedFields = mapOf(
- POJO to listOf(
+ POJO.canonicalName to listOf(
createField("nameX"),
createField("lastNameX")
)
@@ -1133,7 +1127,7 @@
hasErrorContaining("no such column: age")
hasErrorContaining(
cannotFindQueryResultAdapter(
- ClassName.get("foo.bar", "MyClass", "Pojo")
+ XClassName.get("foo.bar", "MyClass", "Pojo").canonicalName
)
)
hasErrorCount(2)
@@ -1156,7 +1150,7 @@
invocation.assertCompilationResult {
hasWarningContaining(
ProcessorErrors.cursorPojoMismatch(
- pojoTypeNames = listOf(POJO),
+ pojoTypeNames = listOf(POJO.canonicalName),
unusedColumns = listOf("uid"),
pojoUnusedFields = emptyMap(),
allColumns = listOf("uid", "name", "lastName"),
@@ -1185,10 +1179,10 @@
invocation.assertCompilationResult {
hasWarningContaining(
ProcessorErrors.cursorPojoMismatch(
- pojoTypeNames = listOf(POJO),
+ pojoTypeNames = listOf(POJO.canonicalName),
unusedColumns = emptyList(),
allColumns = listOf("lastName"),
- pojoUnusedFields = mapOf(POJO to listOf(createField("name"))),
+ pojoUnusedFields = mapOf(POJO.canonicalName to listOf(createField("name"))),
)
)
}
@@ -1215,15 +1209,15 @@
invocation.assertCompilationResult {
hasWarningContaining(
ProcessorErrors.cursorPojoMismatch(
- pojoTypeNames = listOf(POJO),
+ pojoTypeNames = listOf(POJO.canonicalName),
unusedColumns = emptyList(),
- pojoUnusedFields = mapOf(POJO to listOf(createField("name"))),
+ pojoUnusedFields = mapOf(POJO.canonicalName to listOf(createField("name"))),
allColumns = listOf("lastName"),
)
)
hasErrorContaining(
ProcessorErrors.pojoMissingNonNull(
- pojoTypeName = POJO,
+ pojoTypeName = POJO.canonicalName,
missingPojoFields = listOf("name"),
allQueryColumns = listOf("lastName")
)
@@ -1251,10 +1245,12 @@
invocation.assertCompilationResult {
hasWarningContaining(
ProcessorErrors.cursorPojoMismatch(
- pojoTypeNames = listOf(POJO),
+ pojoTypeNames = listOf(POJO.canonicalName),
unusedColumns = listOf("uid"),
allColumns = listOf("uid", "name"),
- pojoUnusedFields = mapOf(POJO to listOf(createField("lastName")))
+ pojoUnusedFields = mapOf(
+ POJO.canonicalName to listOf(createField("lastName"))
+ )
)
)
}
@@ -1558,9 +1554,7 @@
) { _, invocation ->
invocation.assertCompilationResult {
hasErrorContaining(
- valueMayNeedMapInfo(
- ClassName.get("java.lang", "String")
- )
+ valueMayNeedMapInfo(String::class.asClassName().canonicalName)
)
}
}
@@ -1577,9 +1571,7 @@
) { _, invocation ->
invocation.assertCompilationResult {
hasErrorContaining(
- valueMayNeedMapInfo(
- ClassName.get("java.lang", "String")
- )
+ valueMayNeedMapInfo(String::class.asClassName().canonicalName)
)
}
}
@@ -1595,9 +1587,7 @@
) { _, invocation ->
invocation.assertCompilationResult {
hasErrorContaining(
- valueMayNeedMapInfo(
- ClassName.get("java.lang", "String")
- )
+ valueMayNeedMapInfo(String::class.asClassName().canonicalName)
)
}
}
@@ -1613,9 +1603,7 @@
) { _, invocation ->
invocation.assertCompilationResult {
hasErrorContaining(
- valueMayNeedMapInfo(
- ClassName.get("java.lang", "String")
- )
+ valueMayNeedMapInfo(String::class.asClassName().canonicalName)
)
}
}
@@ -1631,9 +1619,7 @@
) { _, invocation ->
invocation.assertCompilationResult {
hasErrorContaining(
- valueMayNeedMapInfo(
- ClassName.get("java.lang", "Long")
- )
+ valueMayNeedMapInfo(XTypeName.BOXED_LONG.canonicalName)
)
}
}
@@ -1649,9 +1635,7 @@
) { _, invocation ->
invocation.assertCompilationResult {
hasErrorContaining(
- valueMayNeedMapInfo(
- ClassName.get("java.lang", "Long")
- )
+ valueMayNeedMapInfo(XTypeName.BOXED_LONG.canonicalName)
)
}
}
@@ -1667,9 +1651,7 @@
) { _, invocation ->
invocation.assertCompilationResult {
hasErrorContaining(
- valueMayNeedMapInfo(
- ClassName.get("java.lang", "Long")
- )
+ valueMayNeedMapInfo(XTypeName.BOXED_LONG.canonicalName)
)
}
}
@@ -1686,9 +1668,7 @@
) { _, invocation ->
invocation.assertCompilationResult {
hasErrorContaining(
- keyMayNeedMapInfo(
- ClassName.get("java.util", "Date")
- )
+ keyMayNeedMapInfo("java.util.Date")
)
}
}
@@ -1705,9 +1685,7 @@
) { _, invocation ->
invocation.assertCompilationResult {
hasErrorContaining(
- valueMayNeedMapInfo(
- ClassName.get("java.util", "Date")
- )
+ valueMayNeedMapInfo("java.util.Date")
)
}
}
@@ -1809,7 +1787,7 @@
ProcessorErrors.ambiguousColumn(
"uid",
ProcessorErrors.AmbiguousColumnLocation.POJO,
- ClassName.get("foo.bar", "Id")
+ "foo.bar.Id"
)
)
}
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/RawQueryMethodProcessorTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/RawQueryMethodProcessorTest.kt
index 7942588..325996b 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/RawQueryMethodProcessorTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/RawQueryMethodProcessorTest.kt
@@ -19,6 +19,9 @@
import COMMON
import androidx.room.Dao
import androidx.room.RawQuery
+import androidx.room.compiler.codegen.XClassName
+import androidx.room.compiler.codegen.XTypeName
+import androidx.room.compiler.codegen.asClassName
import androidx.room.compiler.processing.XTypeElement
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.XTestInvocation
@@ -35,9 +38,6 @@
import androidx.room.testing.context
import androidx.room.vo.RawQueryMethod
import androidx.sqlite.db.SupportSQLiteQuery
-import com.squareup.javapoet.ArrayTypeName
-import com.squareup.javapoet.ClassName
-import com.squareup.javapoet.TypeName
import org.hamcrest.CoreMatchers.`is`
import org.hamcrest.MatcherAssert.assertThat
import org.junit.Test
@@ -62,8 +62,8 @@
)
)
assertThat(
- query.returnType.typeName,
- `is`(ArrayTypeName.of(TypeName.INT) as TypeName)
+ query.returnType.asTypeName(),
+ `is`(XTypeName.getArrayName(XTypeName.PRIMITIVE_INT))
)
}
}
@@ -179,7 +179,7 @@
@Test
fun pojo() {
- val pojo: TypeName = ClassName.get("foo.bar.MyClass", "MyPojo")
+ val pojo = XClassName.get("foo.bar.MyClass", "MyPojo")
singleQueryMethod(
"""
public class MyPojo {
@@ -201,7 +201,7 @@
)
)
)
- assertThat(query.returnType.typeName, `is`(pojo))
+ assertThat(query.returnType.asTypeName(), `is`(pojo))
assertThat(query.observedTableNames, `is`(emptySet()))
}
}
@@ -329,13 +329,13 @@
fun observed_notAnEntity() {
singleQueryMethod(
"""
- @RawQuery(observedEntities = {${COMMON.NOT_AN_ENTITY_TYPE_NAME}.class})
+ @RawQuery(observedEntities = {${COMMON.NOT_AN_ENTITY_TYPE_NAME.canonicalName}.class})
abstract public int[] foo(SupportSQLiteQuery query);
"""
) { _, invocation ->
invocation.assertCompilationResult {
hasErrorContaining(
- ProcessorErrors.rawQueryBadEntity(COMMON.NOT_AN_ENTITY_TYPE_NAME)
+ ProcessorErrors.rawQueryBadEntity(COMMON.NOT_AN_ENTITY_TYPE_NAME.canonicalName)
)
}
}
@@ -424,7 +424,7 @@
invocation.assertCompilationResult {
hasErrorContaining(
ProcessorErrors.valueMayNeedMapInfo(
- ClassName.get("java.lang", "String")
+ String::class.asClassName().canonicalName
)
)
}
@@ -442,7 +442,7 @@
invocation.assertCompilationResult {
hasErrorContaining(
ProcessorErrors.valueMayNeedMapInfo(
- ClassName.get("java.lang", "String")
+ String::class.asClassName().canonicalName
)
)
}
@@ -460,7 +460,7 @@
invocation.assertCompilationResult {
hasErrorContaining(
ProcessorErrors.valueMayNeedMapInfo(
- ClassName.get("java.lang", "String")
+ String::class.asClassName().canonicalName
)
)
}
@@ -477,9 +477,7 @@
) { _, invocation ->
invocation.assertCompilationResult {
hasErrorContaining(
- ProcessorErrors.valueMayNeedMapInfo(
- ClassName.get("java.lang", "Long")
- )
+ ProcessorErrors.valueMayNeedMapInfo(XTypeName.BOXED_LONG.canonicalName)
)
}
}
@@ -495,9 +493,7 @@
) { _, invocation ->
invocation.assertCompilationResult {
hasErrorContaining(
- ProcessorErrors.valueMayNeedMapInfo(
- ClassName.get("java.lang", "Long")
- )
+ ProcessorErrors.valueMayNeedMapInfo(XTypeName.BOXED_LONG.canonicalName)
)
}
}
@@ -513,9 +509,7 @@
) { _, invocation ->
invocation.assertCompilationResult {
hasErrorContaining(
- ProcessorErrors.valueMayNeedMapInfo(
- ClassName.get("java.lang", "Long")
- )
+ ProcessorErrors.valueMayNeedMapInfo(XTypeName.BOXED_LONG.canonicalName)
)
}
}
@@ -532,9 +526,7 @@
) { _, invocation ->
invocation.assertCompilationResult {
hasErrorContaining(
- ProcessorErrors.keyMayNeedMapInfo(
- ClassName.get("java.util", "Date")
- )
+ ProcessorErrors.keyMayNeedMapInfo("java.util.Date")
)
}
}
@@ -551,9 +543,7 @@
) { _, invocation ->
invocation.assertCompilationResult {
hasErrorContaining(
- ProcessorErrors.valueMayNeedMapInfo(
- ClassName.get("java.util", "Date")
- )
+ ProcessorErrors.valueMayNeedMapInfo("java.util.Date")
)
}
}
@@ -571,7 +561,7 @@
invocation.assertCompilationResult {
hasErrorContaining(
ProcessorErrors.valueMayNeedMapInfo(
- ClassName.get("java.lang", "String")
+ String::class.asClassName().canonicalName
)
)
}
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/TableEntityProcessorTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/TableEntityProcessorTest.kt
index 7a4b1ae..37534d1 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/TableEntityProcessorTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/TableEntityProcessorTest.kt
@@ -17,6 +17,8 @@
package androidx.room.processor
import COMMON
+import androidx.room.compiler.codegen.CodeLanguage
+import androidx.room.compiler.codegen.XTypeName
import androidx.room.compiler.codegen.toJavaPoet
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.compileFiles
@@ -33,7 +35,6 @@
import androidx.room.vo.Pojo
import androidx.room.vo.columnNames
import com.google.common.truth.Truth.assertThat
-import com.squareup.javapoet.ClassName
import com.squareup.javapoet.TypeName
import org.hamcrest.CoreMatchers.hasItems
import org.hamcrest.CoreMatchers.`is`
@@ -56,7 +57,10 @@
public void setId(int id) { this.id = id; }
"""
) { entity, invocation ->
- assertThat(entity.type.typeName.toString(), `is`("foo.bar.MyEntity"))
+ assertThat(
+ entity.type.asTypeName().toString(CodeLanguage.JAVA),
+ `is`("foo.bar.MyEntity")
+ )
assertThat(entity.fields.size, `is`(1))
val field = entity.fields.first()
val intType = invocation.processingEnv.requireType(TypeName.INT)
@@ -281,16 +285,16 @@
val cursorValueReader = idField.cursorValueReader
?: throw AssertionError("must have a cursor value reader")
assertThat(
- cursorValueReader.typeMirror().typeName,
- `is`(invocation.processingEnv.requireType(TypeName.INT).typeName)
+ cursorValueReader.typeMirror().asTypeName(),
+ `is`(invocation.processingEnv.requireType(XTypeName.PRIMITIVE_INT).asTypeName())
)
invocation.assertCompilationResult {
hasWarningContaining(
ProcessorErrors.mismatchedSetter(
fieldName = "id",
- ownerType = ClassName.bestGuess("foo.bar.MyEntity"),
- setterType = TypeName.INT,
- fieldType = TypeName.INT.box()
+ ownerType = "foo.bar.MyEntity",
+ setterType = "int",
+ fieldType = XTypeName.BOXED_INT.canonicalName
)
)
}
@@ -311,8 +315,8 @@
val statementBinder = idField.statementBinder
?: throw AssertionError("must have a statement binder")
assertThat(
- statementBinder.typeMirror().typeName,
- `is`(invocation.processingEnv.requireType(TypeName.INT).typeName)
+ statementBinder.typeMirror().asTypeName(),
+ `is`(invocation.processingEnv.requireType(XTypeName.PRIMITIVE_INT).asTypeName())
)
}
}
@@ -2045,7 +2049,7 @@
fun foreignKey_invalidAction() {
val annotation = mapOf(
"foreignKeys" to """{@ForeignKey(
- entity = ${COMMON.USER_TYPE_NAME}.class,
+ entity = ${COMMON.USER_TYPE_NAME.canonicalName}.class,
parentColumns = "lastName",
childColumns = "name",
onDelete = 101
@@ -2105,7 +2109,7 @@
fun foreignKey_notAnEntity() {
val annotation = mapOf(
"foreignKeys" to """{@ForeignKey(
- entity = ${COMMON.NOT_AN_ENTITY_TYPE_NAME}.class,
+ entity = ${COMMON.NOT_AN_ENTITY_TYPE_NAME.canonicalName}.class,
parentColumns = "lastName",
childColumns = "name"
)}
@@ -2122,7 +2126,7 @@
invocation.assertCompilationResult {
hasErrorContaining(
ProcessorErrors.foreignKeyNotAnEntity(
- COMMON.NOT_AN_ENTITY_TYPE_NAME.toString()
+ COMMON.NOT_AN_ENTITY_TYPE_NAME.canonicalName
)
)
}
@@ -2133,7 +2137,7 @@
fun foreignKey_invalidChildColumn() {
val annotation = mapOf(
"foreignKeys" to """{@ForeignKey(
- entity = ${COMMON.USER_TYPE_NAME}.class,
+ entity = ${COMMON.USER_TYPE_NAME.canonicalName}.class,
parentColumns = "lastName",
childColumns = "namex"
)}
@@ -2161,7 +2165,7 @@
fun foreignKey_columnCountMismatch() {
val annotation = mapOf(
"foreignKeys" to """{@ForeignKey(
- entity = ${COMMON.USER_TYPE_NAME}.class,
+ entity = ${COMMON.USER_TYPE_NAME.canonicalName}.class,
parentColumns = "lastName",
childColumns = {"name", "id"}
)}
@@ -2189,7 +2193,7 @@
fun foreignKey_emptyChildColumns() {
val annotation = mapOf(
"foreignKeys" to """{@ForeignKey(
- entity = ${COMMON.USER_TYPE_NAME}.class,
+ entity = ${COMMON.USER_TYPE_NAME.canonicalName}.class,
parentColumns = "lastName",
childColumns = {}
)}
@@ -2213,7 +2217,7 @@
fun foreignKey_emptyParentColumns() {
val annotation = mapOf(
"foreignKeys" to """{@ForeignKey(
- entity = ${COMMON.USER_TYPE_NAME}.class,
+ entity = ${COMMON.USER_TYPE_NAME.canonicalName}.class,
parentColumns = {},
childColumns = {"name"}
)}
@@ -2237,7 +2241,7 @@
fun foreignKey_simple() {
val annotation = mapOf(
"foreignKeys" to """{@ForeignKey(
- entity = ${COMMON.USER_TYPE_NAME}.class,
+ entity = ${COMMON.USER_TYPE_NAME.canonicalName}.class,
parentColumns = "lastName",
childColumns = "name",
onDelete = ForeignKey.SET_NULL,
@@ -2269,7 +2273,7 @@
fun foreignKey_dontDuplicationChildIndex_SingleColumn() {
val annotation = mapOf(
"foreignKeys" to """{@ForeignKey(
- entity = ${COMMON.USER_TYPE_NAME}.class,
+ entity = ${COMMON.USER_TYPE_NAME.canonicalName}.class,
parentColumns = "lastName",
childColumns = "name",
onDelete = ForeignKey.SET_NULL,
@@ -2297,7 +2301,7 @@
fun foreignKey_dontDuplicationChildIndex_MultipleColumns() {
val annotation = mapOf(
"foreignKeys" to """{@ForeignKey(
- entity = ${COMMON.USER_TYPE_NAME}.class,
+ entity = ${COMMON.USER_TYPE_NAME.canonicalName}.class,
parentColumns = {"lastName", "name"},
childColumns = {"lName", "name"},
onDelete = ForeignKey.SET_NULL,
@@ -2327,7 +2331,7 @@
fun foreignKey_dontDuplicationChildIndex_WhenCovered() {
val annotation = mapOf(
"foreignKeys" to """{@ForeignKey(
- entity = ${COMMON.USER_TYPE_NAME}.class,
+ entity = ${COMMON.USER_TYPE_NAME.canonicalName}.class,
parentColumns = {"lastName"},
childColumns = {"name"},
onDelete = ForeignKey.SET_NULL,
@@ -2357,7 +2361,7 @@
fun foreignKey_warnMissingChildIndex() {
val annotation = mapOf(
"foreignKeys" to """{@ForeignKey(
- entity = ${COMMON.USER_TYPE_NAME}.class,
+ entity = ${COMMON.USER_TYPE_NAME.canonicalName}.class,
parentColumns = "lastName",
childColumns = "name",
onDelete = ForeignKey.SET_NULL,
@@ -2385,7 +2389,7 @@
fun foreignKey_warnMissingChildrenIndex() {
val annotation = mapOf(
"foreignKeys" to """{@ForeignKey(
- entity = ${COMMON.USER_TYPE_NAME}.class,
+ entity = ${COMMON.USER_TYPE_NAME.canonicalName}.class,
parentColumns = {"lastName", "name"},
childColumns = {"lName", "name"}
)}
@@ -2418,7 +2422,7 @@
fun foreignKey_dontIndexIfAlreadyPrimaryKey() {
val annotation = mapOf(
"foreignKeys" to """{@ForeignKey(
- entity = ${COMMON.USER_TYPE_NAME}.class,
+ entity = ${COMMON.USER_TYPE_NAME.canonicalName}.class,
parentColumns = "lastName",
childColumns = "id",
onDelete = ForeignKey.SET_NULL,
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/autovalue/AutoValuePojoProcessorDelegateTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/autovalue/AutoValuePojoProcessorDelegateTest.kt
index cb7c91a..145140c 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/autovalue/AutoValuePojoProcessorDelegateTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/autovalue/AutoValuePojoProcessorDelegateTest.kt
@@ -16,6 +16,7 @@
package androidx.room.processor.autovalue
+import androidx.room.compiler.codegen.XClassName
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.XTestInvocation
import androidx.room.compiler.processing.util.compileFiles
@@ -26,21 +27,20 @@
import androidx.room.testing.context
import androidx.room.vo.Pojo
import com.google.auto.value.processor.AutoValueProcessor
-import com.squareup.javapoet.ClassName
+import java.io.File
import org.hamcrest.CoreMatchers.`is`
import org.hamcrest.CoreMatchers.notNullValue
import org.hamcrest.MatcherAssert.assertThat
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
-import java.io.File
@RunWith(JUnit4::class)
class AutoValuePojoProcessorDelegateTest {
companion object {
- val MY_POJO: ClassName = ClassName.get("foo.bar", "MyPojo")
- val AUTOVALUE_MY_POJO: ClassName = ClassName.get("foo.bar", "AutoValue_MyPojo")
+ val MY_POJO = XClassName.get("foo.bar", "MyPojo")
+ val AUTOVALUE_MY_POJO = XClassName.get("foo.bar", "AutoValue_MyPojo")
val HEADER = """
package foo.bar;
@@ -80,7 +80,7 @@
long getId() { return this.id; }
"""
) { pojo, invocation ->
- assertThat(pojo.type.typeName, `is`(MY_POJO))
+ assertThat(pojo.type.asTypeName(), `is`(MY_POJO))
assertThat(pojo.fields.size, `is`(1))
assertThat(pojo.constructor?.element, `is`(notNullValue()))
invocation.assertCompilationResult {
@@ -94,7 +94,7 @@
val libraryClasspath = compileFiles(
sources = listOf(
Source.java(
- MY_POJO.toString(),
+ MY_POJO.canonicalName,
"""
$HEADER
@AutoValue.CopyAnnotations
@@ -275,8 +275,8 @@
classpathFiles: List<File> = emptyList(),
handler: (Pojo, XTestInvocation) -> Unit
) {
- val pojoSource = Source.java(MY_POJO.toString(), pojoCode)
- val autoValuePojoSource = Source.java(AUTOVALUE_MY_POJO.toString(), autoValuePojoCode)
+ val pojoSource = Source.java(MY_POJO.canonicalName, pojoCode)
+ val autoValuePojoSource = Source.java(AUTOVALUE_MY_POJO.canonicalName, autoValuePojoCode)
val all: List<Source> = sources.toList() + pojoSource + autoValuePojoSource
runProcessorTest(
sources = all,
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/solver/Signatures.kt b/room/room-compiler/src/test/kotlin/androidx/room/solver/Signatures.kt
index 4b6fbf2..3bb81ea 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/solver/Signatures.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/solver/Signatures.kt
@@ -16,6 +16,7 @@
package androidx.room.solver
+import androidx.room.compiler.codegen.CodeLanguage
import androidx.room.compiler.processing.XNullability
import androidx.room.compiler.processing.XType
import androidx.room.solver.types.CompositeTypeConverter
@@ -33,7 +34,8 @@
}
fun XType.toSignature() =
- "$typeName${nullability.toSignature()}".substringAfterLast(".")
+ (asTypeName().toString(CodeLanguage.JAVA) + nullability.toSignature())
+ .substringAfterLast(".")
fun TypeConverter.toSignature(): String {
return when (this) {
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 6809ade..285de55 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
@@ -21,6 +21,7 @@
import androidx.paging.PagingSource
import androidx.room.Dao
import androidx.room.compiler.codegen.XCodeBlock
+import androidx.room.compiler.codegen.XTypeName
import androidx.room.compiler.codegen.toJavaPoet
import androidx.room.compiler.processing.XProcessingEnv
import androidx.room.compiler.processing.XRawType
@@ -185,12 +186,12 @@
assertThat(adapter, instanceOf(CompositeAdapter::class.java))
val composite = adapter as CompositeAdapter
assertThat(
- composite.intoStatementConverter?.from?.typeName,
- `is`(TypeName.BOOLEAN.box())
+ composite.intoStatementConverter?.from?.asTypeName(),
+ `is`(XTypeName.BOXED_BOOLEAN.copy(nullable = true))
)
assertThat(
- composite.columnTypeAdapter.out.typeName,
- `is`(TypeName.INT.box())
+ composite.columnTypeAdapter.out.asTypeName(),
+ `is`(XTypeName.BOXED_INT.copy(nullable = true))
)
}
}
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/solver/TypeConverterStoreTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/solver/TypeConverterStoreTest.kt
index a6c6499..150a7a3 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/solver/TypeConverterStoreTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/solver/TypeConverterStoreTest.kt
@@ -16,6 +16,7 @@
package androidx.room.solver
+import androidx.room.compiler.codegen.CodeLanguage
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.runProcessorTest
import androidx.room.processor.CustomConverterProcessor
@@ -136,7 +137,8 @@
private fun TypeConverter.toSignature(): String {
return when (this) {
is CompositeTypeConverter -> "${conv1.toSignature()} : ${conv2.toSignature()}"
- else -> "${from.typeName} -> ${to.typeName}"
+ else -> from.asTypeName().toString(CodeLanguage.JAVA) + " -> " +
+ to.asTypeName().toString(CodeLanguage.JAVA)
}
}
}
\ No newline at end of file
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/testing/test_util.kt b/room/room-compiler/src/test/kotlin/androidx/room/testing/test_util.kt
index 45d6eab..7aa7720 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/testing/test_util.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/testing/test_util.kt
@@ -46,7 +46,6 @@
import androidx.room.testing.context
import androidx.room.verifier.DatabaseVerifier
import androidx.room.writer.TypeWriter
-import com.squareup.javapoet.ClassName
import java.io.File
import org.mockito.Mockito.doReturn
import org.mockito.Mockito.mock
@@ -79,7 +78,7 @@
loadJavaCode("common/input/UserSummary.java", "foo.bar.UserSummary")
}
val USER_TYPE_NAME by lazy {
- ClassName.get("foo.bar", "User")
+ XClassName.get("foo.bar", "User")
}
val BOOK by lazy {
loadJavaCode("common/input/Book.java", "foo.bar.Book")
@@ -102,7 +101,7 @@
}
val NOT_AN_ENTITY_TYPE_NAME by lazy {
- ClassName.get("foo.bar", "NotAnEntity")
+ XClassName.get("foo.bar", "NotAnEntity")
}
val MULTI_PKEY_ENTITY by lazy {