Merge changes I79864ffd,I86422b7b,I7fd61193 into androidx-main
* changes:
Add XMethodElement#name to reflect source name
Add name property to XMethodElement
Rename XMethodElement.name to jvmName
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 7dd33ea2..227a69a 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
@@ -69,14 +69,14 @@
// Finally, visit all methods declared in this type.
if (type == xTypeElement) {
type.getDeclaredMethods().forEach {
- methodsByName.getOrPut(it.name) { linkedSetOf() }.add(it)
+ methodsByName.getOrPut(it.jvmName) { linkedSetOf() }.add(it)
}
} else {
type.getDeclaredMethods()
.filter { it.isAccessibleFrom(type.packageName) }
.filterNot { it.isStaticInterfaceMethod() }
.map { it.copyTo(xTypeElement) }
- .forEach { methodsByName.getOrPut(it.name) { linkedSetOf() }.add(it) }
+ .forEach { methodsByName.getOrPut(it.jvmName) { linkedSetOf() }.add(it) }
}
}
collectAllMethodsByName(xTypeElement)
diff --git a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/JavaPoetExt.kt b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/JavaPoetExt.kt
index 71d289a..a5ae507 100644
--- a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/JavaPoetExt.kt
+++ b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/JavaPoetExt.kt
@@ -109,7 +109,7 @@
executableElement: XMethodElement,
resolvedType: XMethodType = executableElement.executableType
): MethodSpec.Builder {
- return MethodSpec.methodBuilder(executableElement.name).apply {
+ return MethodSpec.methodBuilder(executableElement.jvmName).apply {
addTypeVariables(
resolvedType.typeVariableNames
)
diff --git a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/XMethodElement.kt b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/XMethodElement.kt
index 5596483..c85e818 100644
--- a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/XMethodElement.kt
+++ b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/XMethodElement.kt
@@ -24,11 +24,26 @@
*/
interface XMethodElement : XExecutableElement {
/**
- * The name of the method.
+ * The name of the method in source.
+ *
+ * For Kotlin sources, this might be different from [jvmName] if:
+ * * Function is annotated with @JvmName
+ * * Function has a value class as a parameter or return type
+ * * Function is internal
+ *
+ * @see jvmName
*/
val name: String
/**
+ * The name of the method in JVM.
+ * Use this properly when you need to generate code accessing this method.
+ *
+ * @see name
+ */
+ val jvmName: String
+
+ /**
* The return type for the method. Note that it might be [XType.isNone] if it does not return or
* [XType.isError] if the return type cannot be resolved.
*/
@@ -43,7 +58,7 @@
get() = buildString {
append(enclosingElement.fallbackLocationText)
append(".")
- append(name)
+ append(jvmName)
append("(")
// don't report last parameter if it is a suspend function
append(
diff --git a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/javac/JavacMethodElement.kt b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/javac/JavacMethodElement.kt
index f1961d3..66093c0 100644
--- a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/javac/JavacMethodElement.kt
+++ b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/javac/JavacMethodElement.kt
@@ -45,7 +45,11 @@
}
}
- override val name: String
+ override val name: String by lazy {
+ kotlinMetadata?.name ?: jvmName
+ }
+
+ override val jvmName: String
get() = element.simpleName.toString()
override val enclosingElement: XTypeElement by lazy {
@@ -146,7 +150,7 @@
}
}
return kotlinDefaultImplClass?.getDeclaredMethods()?.any {
- it.name == this.name && paramsMatch(parameters, it.parameters)
+ it.jvmName == this.jvmName && paramsMatch(parameters, it.parameters)
} ?: false
}
diff --git a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/javac/kotlin/KotlinClassMetadataUtils.kt b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/javac/kotlin/KotlinClassMetadataUtils.kt
index ca4d05a..d597e66 100644
--- a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/javac/kotlin/KotlinClassMetadataUtils.kt
+++ b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/javac/kotlin/KotlinClassMetadataUtils.kt
@@ -479,7 +479,7 @@
* JVM name for internal properties.
* See: https://kotlinlang.org/docs/java-to-kotlin-interop.html#properties
*/
-private fun computeGetterName(
+internal fun computeGetterName(
propName: String
): String {
return if (propName.startsWith("is")) {
@@ -499,7 +499,7 @@
* JVM name for internal properties.
* See: https://kotlinlang.org/docs/java-to-kotlin-interop.html#properties
*/
-private fun computeSetterName(propName: String): String {
+internal fun computeSetterName(propName: String): String {
return if (propName.startsWith("is")) {
"set${propName.substring(2)}"
} else {
diff --git a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspClassFileUtility.kt b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspClassFileUtility.kt
index 2bfe05e..68edf1e 100644
--- a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspClassFileUtility.kt
+++ b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspClassFileUtility.kt
@@ -112,14 +112,14 @@
): List<KspMethodElement> {
// no reason to try to load .class if we don't have any fields to sort
if (methods.isEmpty()) return methods
- val comparator = getNamesComparator(owner, Type.METHOD, KspMethodElement::name)
+ val comparator = getNamesComparator(owner, Type.METHOD, KspMethodElement::jvmName)
return if (comparator == null) {
methods
} else {
methods.forEach {
// make sure each name gets registered so that if we didn't find it in .class for
// whatever reason, we keep the order given from KSP.
- comparator.register(it.name)
+ comparator.register(it.jvmName)
}
methods.sortedWith(comparator)
}
diff --git a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspMethodElement.kt b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspMethodElement.kt
index 472a2d7..dfa6955 100644
--- a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspMethodElement.kt
+++ b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspMethodElement.kt
@@ -40,8 +40,11 @@
),
XMethodElement {
+ override val name: String
+ get() = declaration.simpleName.asString()
+
@OptIn(KspExperimental::class)
- override val name: String by lazy {
+ override val jvmName: String by lazy {
val jvmName = runCatching {
// see https://github.com/google/ksp/issues/716
env.resolver.getJvmName(declaration)
diff --git a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/ResolverExt.kt b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/ResolverExt.kt
index c63e831..35daded 100644
--- a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/ResolverExt.kt
+++ b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/ResolverExt.kt
@@ -58,7 +58,7 @@
return false
}
// do a quick check on name before doing the more expensive operations
- if (overriderElement.name != overrideeElement.name) {
+ if (overriderElement.jvmName != overrideeElement.jvmName) {
return false
}
val ksOverrider = overriderElement.getDeclarationForOverride()
diff --git a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/synthetic/KspSyntheticPropertyMethodElement.kt b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/synthetic/KspSyntheticPropertyMethodElement.kt
index e04225d..6f11ebc 100644
--- a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/synthetic/KspSyntheticPropertyMethodElement.kt
+++ b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/synthetic/KspSyntheticPropertyMethodElement.kt
@@ -25,6 +25,8 @@
import androidx.room.compiler.processing.XMethodType
import androidx.room.compiler.processing.XType
import androidx.room.compiler.processing.XTypeElement
+import androidx.room.compiler.processing.javac.kotlin.computeGetterName
+import androidx.room.compiler.processing.javac.kotlin.computeSetterName
import androidx.room.compiler.processing.ksp.KspAnnotated
import androidx.room.compiler.processing.ksp.KspAnnotated.UseSiteFilter.Companion.NO_USE_SITE_OR_GETTER
import androidx.room.compiler.processing.ksp.KspAnnotated.UseSiteFilter.Companion.NO_USE_SITE_OR_SETTER
@@ -63,7 +65,7 @@
) {
@OptIn(KspExperimental::class)
- override val name: String by lazy {
+ override val jvmName: String by lazy {
env.resolver.getJvmName(accessor) ?: error("Cannot find the name for accessor $accessor")
}
@@ -152,6 +154,9 @@
filter = NO_USE_SITE_OR_GETTER
) {
+ override val name: String by lazy {
+ computeGetterName(field.declaration.simpleName.asString())
+ }
override val returnType: XType by lazy {
field.type
}
@@ -179,6 +184,9 @@
filter = NO_USE_SITE_OR_SETTER
) {
+ override val name by lazy {
+ computeSetterName(field.declaration.simpleName.asString())
+ }
override val returnType: XType by lazy {
env.voidType
}
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/FallbackLocationInformationTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/FallbackLocationInformationTest.kt
index fa4306c..0995eb1 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/FallbackLocationInformationTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/FallbackLocationInformationTest.kt
@@ -19,7 +19,7 @@
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.compileFiles
import androidx.room.compiler.processing.util.getField
-import androidx.room.compiler.processing.util.getMethod
+import androidx.room.compiler.processing.util.getMethodByJvmName
import androidx.room.compiler.processing.util.runProcessorTest
import com.google.common.truth.Truth.assertThat
import org.junit.Test
@@ -70,7 +70,7 @@
).isEqualTo(
"prop in foo.bar.KotlinSubject"
)
- kotlinSubject.getMethod("method1").let { method ->
+ kotlinSubject.getMethodByJvmName("method1").let { method ->
assertThat(
method.fallbackLocationText
).isEqualTo(
@@ -82,7 +82,7 @@
"arg1 in foo.bar.KotlinSubject.method1(int)"
)
}
- kotlinSubject.getMethod("suspendFun").let { suspendFun ->
+ kotlinSubject.getMethodByJvmName("suspendFun").let { suspendFun ->
assertThat(
suspendFun.fallbackLocationText
).isEqualTo(
@@ -96,11 +96,11 @@
}
assertThat(
- kotlinSubject.getMethod("getProp").fallbackLocationText
+ kotlinSubject.getMethodByJvmName("getProp").fallbackLocationText
).isEqualTo(
"foo.bar.KotlinSubject.getProp()"
)
- kotlinSubject.getMethod("setProp").let { propSetter ->
+ kotlinSubject.getMethodByJvmName("setProp").let { propSetter ->
assertThat(
propSetter.fallbackLocationText
).isEqualTo(
@@ -113,7 +113,7 @@
)
}
- kotlinSubject.getMethod("setPropWithAccessors").let { propSetter ->
+ kotlinSubject.getMethodByJvmName("setPropWithAccessors").let { propSetter ->
// javac does not know that this is synthetic setter
assertThat(
propSetter.fallbackLocationText
@@ -170,7 +170,7 @@
).isEqualTo(
"field1 in foo.bar.JavaSubject"
)
- javaSubject.getMethod("method1").let { method ->
+ javaSubject.getMethodByJvmName("method1").let { method ->
assertThat(
method.fallbackLocationText
).isEqualTo(
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/InternalModifierTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/InternalModifierTest.kt
index f5098cd..3a0bff2b 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/InternalModifierTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/InternalModifierTest.kt
@@ -65,7 +65,7 @@
fun XFieldElement.toSignature() = "$name : ${type.toSignature()}"
fun XMethodElement.toSignature() = buildString {
- append(name)
+ append(jvmName)
append("(")
parameters.forEach {
append(it.type.toSignature())
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/KotlinMetadataTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/KotlinMetadataTest.kt
index 9f62b03..fbcc78d 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/KotlinMetadataTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/KotlinMetadataTest.kt
@@ -18,7 +18,7 @@
import androidx.room.compiler.processing.testcode.KotlinTestClass
import androidx.room.compiler.processing.util.Source
-import androidx.room.compiler.processing.util.getMethod
+import androidx.room.compiler.processing.util.getMethodByJvmName
import androidx.room.compiler.processing.util.getParameter
import androidx.room.compiler.processing.util.runProcessorTest
import androidx.room.compiler.processing.util.typeName
@@ -38,7 +38,7 @@
sources = listOf(source)
) {
val element = it.processingEnv.requireTypeElement(KotlinTestClass::class)
- element.getMethod("mySuspendMethod").apply {
+ element.getMethodByJvmName("mySuspendMethod").apply {
assertThat(parameters).hasSize(2)
assertThat(getParameter("param1").type.typeName)
.isEqualTo(String::class.typeName())
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/KspClassFileUtilityTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/KspClassFileUtilityTest.kt
index d21fd36..21395f6 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/KspClassFileUtilityTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/KspClassFileUtilityTest.kt
@@ -108,7 +108,7 @@
sources = listOf(libSource)
) { invocation ->
val element = invocation.processingEnv.requireTypeElement("KotlinClass")
- assertThat(element.getDeclaredMethods().map { it.name })
+ assertThat(element.getDeclaredMethods().map { it.jvmName })
.containsExactly("b", "a", "c", "isB", "isA", "isC")
.inOrder()
}
@@ -133,7 +133,7 @@
sources = listOf(libSource),
) { invocation ->
val element = invocation.processingEnv.requireTypeElement("JavaClass")
- assertThat(element.getDeclaredMethods().map { it.name })
+ assertThat(element.getDeclaredMethods().map { it.jvmName })
.containsExactly("b", "a", "c", "isB", "isA", "isC")
.inOrder()
}
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/MethodSpecHelperTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/MethodSpecHelperTest.kt
index 5e2919a..c789359 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/MethodSpecHelperTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/MethodSpecHelperTest.kt
@@ -506,7 +506,7 @@
.requireTypeElement("java.lang.Object")
.getAllNonPrivateInstanceMethods()
.map {
- it.name
+ it.jvmName
}
val target = processingEnv.requireTypeElement("foo.bar.Baz")
val methods = if (ignoreInheritedMethods) {
@@ -517,7 +517,7 @@
val selectedMethods = methods.filter {
it.isOverrideableIgnoringContainer()
}.filterNot {
- it.name in objectMethodNames
+ it.jvmName in objectMethodNames
}
return target to selectedMethods
}
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/TypeAliasTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/TypeAliasTest.kt
index a24ad96..46e2c5b6 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/TypeAliasTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/TypeAliasTest.kt
@@ -21,7 +21,7 @@
import androidx.room.compiler.processing.util.className
import androidx.room.compiler.processing.util.compileFiles
import androidx.room.compiler.processing.util.getField
-import androidx.room.compiler.processing.util.getMethod
+import androidx.room.compiler.processing.util.getMethodByJvmName
import androidx.room.compiler.processing.util.runProcessorTest
import com.google.common.truth.Truth.assertThat
import com.squareup.javapoet.ParameterizedTypeName
@@ -72,7 +72,7 @@
)
)
}
- elm.getMethod("suspendFun").parameters.last().type.let {
+ elm.getMethodByJvmName("suspendFun").parameters.last().type.let {
assertThat(it.typeName).isEqualTo(
ParameterizedTypeName.get(
CONTINUATION_CLASS_NAME,
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XAnnotationBoxTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XAnnotationBoxTest.kt
index 237cf7b..c86cdc4 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XAnnotationBoxTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XAnnotationBoxTest.kt
@@ -30,7 +30,7 @@
import androidx.room.compiler.processing.util.XTestInvocation
import androidx.room.compiler.processing.util.compileFiles
import androidx.room.compiler.processing.util.getField
-import androidx.room.compiler.processing.util.getMethod
+import androidx.room.compiler.processing.util.getMethodByJvmName
import androidx.room.compiler.processing.util.getParameter
import androidx.room.compiler.processing.util.runProcessorTest
import androidx.room.compiler.processing.util.runProcessorTestWithoutKsp
@@ -334,31 +334,31 @@
val subject = invocation.processingEnv.requireTypeElement("Subject")
subject.getField("prop1").assertHasSuppressWithValue("onProp1")
- subject.getMethod("getProp1").assertDoesNotHaveAnnotation()
- subject.getMethod("setProp1").assertDoesNotHaveAnnotation()
- subject.getMethod("setProp1").parameters.first().assertDoesNotHaveAnnotation()
+ subject.getMethodByJvmName("getProp1").assertDoesNotHaveAnnotation()
+ subject.getMethodByJvmName("setProp1").assertDoesNotHaveAnnotation()
+ subject.getMethodByJvmName("setProp1").parameters.first().assertDoesNotHaveAnnotation()
subject.getField("prop2").assertHasSuppressWithValue("onField2")
- subject.getMethod("getProp2").assertHasSuppressWithValue("onGetter2")
- subject.getMethod("setProp2").assertHasSuppressWithValue("onSetter2")
- subject.getMethod("setProp2").parameters.first().assertHasSuppressWithValue(
+ subject.getMethodByJvmName("getProp2").assertHasSuppressWithValue("onGetter2")
+ subject.getMethodByJvmName("setProp2").assertHasSuppressWithValue("onSetter2")
+ subject.getMethodByJvmName("setProp2").parameters.first().assertHasSuppressWithValue(
"onSetterParam2"
)
- subject.getMethod("getProp3").assertHasSuppressWithValue("onGetter3")
- subject.getMethod("setProp3").assertHasSuppressWithValue("onSetter3")
- subject.getMethod("setProp3").parameters.first().assertHasSuppressWithValue(
+ subject.getMethodByJvmName("getProp3").assertHasSuppressWithValue("onGetter3")
+ subject.getMethodByJvmName("setProp3").assertHasSuppressWithValue("onSetter3")
+ subject.getMethodByJvmName("setProp3").parameters.first().assertHasSuppressWithValue(
"onSetterParam3"
)
assertThat(
- subject.getMethod("getProp3").getOtherAnnotationValue()
+ subject.getMethodByJvmName("getProp3").getOtherAnnotationValue()
).isEqualTo("_onGetter3")
assertThat(
- subject.getMethod("setProp3").getOtherAnnotationValue()
+ subject.getMethodByJvmName("setProp3").getOtherAnnotationValue()
).isEqualTo("_onSetter3")
val otherAnnotationValue =
- subject.getMethod("setProp3").parameters.first().getOtherAnnotationValue()
+ subject.getMethodByJvmName("setProp3").parameters.first().getOtherAnnotationValue()
assertThat(
otherAnnotationValue
).isEqualTo("_onSetterParam3")
@@ -384,11 +384,11 @@
)
runTest(sources = listOf(src)) { invocation ->
val subject = invocation.processingEnv.requireTypeElement("Subject")
- subject.getMethod("noAnnotations").let { method ->
+ subject.getMethodByJvmName("noAnnotations").let { method ->
method.assertDoesNotHaveAnnotation()
method.getParameter("x").assertDoesNotHaveAnnotation()
}
- subject.getMethod("methodAnnotation").let { method ->
+ subject.getMethodByJvmName("methodAnnotation").let { method ->
method.assertHasSuppressWithValue("onMethod")
method.getParameter("annotated").assertHasSuppressWithValue("onParam")
method.getParameter("notAnnotated").assertDoesNotHaveAnnotation()
@@ -418,8 +418,8 @@
assertThat(subject.getConstructors()).hasSize(1)
val constructor = subject.getConstructors().single()
constructor.getParameter("x").assertHasSuppressWithValue("onConstructorParam")
- subject.getMethod("getX").assertHasSuppressWithValue("onGetter")
- subject.getMethod("setX").assertHasSuppressWithValue("onSetter")
+ subject.getMethodByJvmName("getX").assertHasSuppressWithValue("onGetter")
+ subject.getMethodByJvmName("setX").assertHasSuppressWithValue("onSetter")
subject.getField("x").assertHasSuppressWithValue("onField")
}
}
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XAnnotationTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XAnnotationTest.kt
index 5503384..7d01fefa 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XAnnotationTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XAnnotationTest.kt
@@ -30,7 +30,7 @@
import androidx.room.compiler.processing.util.XTestInvocation
import androidx.room.compiler.processing.util.compileFiles
import androidx.room.compiler.processing.util.getField
-import androidx.room.compiler.processing.util.getMethod
+import androidx.room.compiler.processing.util.getMethodByJvmName
import androidx.room.compiler.processing.util.getParameter
import androidx.room.compiler.processing.util.runProcessorTest
import androidx.room.compiler.processing.util.runProcessorTestWithoutKsp
@@ -464,31 +464,31 @@
val subject = invocation.processingEnv.requireTypeElement("Subject")
subject.getField("prop1").assertHasSuppressWithValue("onProp1")
- subject.getMethod("getProp1").assertDoesNotHaveAnnotation()
- subject.getMethod("setProp1").assertDoesNotHaveAnnotation()
- subject.getMethod("setProp1").parameters.first().assertDoesNotHaveAnnotation()
+ subject.getMethodByJvmName("getProp1").assertDoesNotHaveAnnotation()
+ subject.getMethodByJvmName("setProp1").assertDoesNotHaveAnnotation()
+ subject.getMethodByJvmName("setProp1").parameters.first().assertDoesNotHaveAnnotation()
subject.getField("prop2").assertHasSuppressWithValue("onField2")
- subject.getMethod("getProp2").assertHasSuppressWithValue("onGetter2")
- subject.getMethod("setProp2").assertHasSuppressWithValue("onSetter2")
- subject.getMethod("setProp2").parameters.first().assertHasSuppressWithValue(
+ subject.getMethodByJvmName("getProp2").assertHasSuppressWithValue("onGetter2")
+ subject.getMethodByJvmName("setProp2").assertHasSuppressWithValue("onSetter2")
+ subject.getMethodByJvmName("setProp2").parameters.first().assertHasSuppressWithValue(
"onSetterParam2"
)
- subject.getMethod("getProp3").assertHasSuppressWithValue("onGetter3")
- subject.getMethod("setProp3").assertHasSuppressWithValue("onSetter3")
- subject.getMethod("setProp3").parameters.first().assertHasSuppressWithValue(
+ subject.getMethodByJvmName("getProp3").assertHasSuppressWithValue("onGetter3")
+ subject.getMethodByJvmName("setProp3").assertHasSuppressWithValue("onSetter3")
+ subject.getMethodByJvmName("setProp3").parameters.first().assertHasSuppressWithValue(
"onSetterParam3"
)
assertThat(
- subject.getMethod("getProp3").getOtherAnnotationValue()
+ subject.getMethodByJvmName("getProp3").getOtherAnnotationValue()
).isEqualTo("_onGetter3")
assertThat(
- subject.getMethod("setProp3").getOtherAnnotationValue()
+ subject.getMethodByJvmName("setProp3").getOtherAnnotationValue()
).isEqualTo("_onSetter3")
val otherAnnotationValue =
- subject.getMethod("setProp3").parameters.first().getOtherAnnotationValue()
+ subject.getMethodByJvmName("setProp3").parameters.first().getOtherAnnotationValue()
assertThat(
otherAnnotationValue
).isEqualTo("_onSetterParam3")
@@ -514,11 +514,11 @@
)
runTest(sources = listOf(src)) { invocation ->
val subject = invocation.processingEnv.requireTypeElement("Subject")
- subject.getMethod("noAnnotations").let { method ->
+ subject.getMethodByJvmName("noAnnotations").let { method ->
method.assertDoesNotHaveAnnotation()
method.getParameter("x").assertDoesNotHaveAnnotation()
}
- subject.getMethod("methodAnnotation").let { method ->
+ subject.getMethodByJvmName("methodAnnotation").let { method ->
method.assertHasSuppressWithValue("onMethod")
method.getParameter("annotated").assertHasSuppressWithValue("onParam")
method.getParameter("notAnnotated").assertDoesNotHaveAnnotation()
@@ -548,8 +548,8 @@
assertThat(subject.getConstructors()).hasSize(1)
val constructor = subject.getConstructors().single()
constructor.getParameter("x").assertHasSuppressWithValue("onConstructorParam")
- subject.getMethod("getX").assertHasSuppressWithValue("onGetter")
- subject.getMethod("setX").assertHasSuppressWithValue("onSetter")
+ subject.getMethodByJvmName("getX").assertHasSuppressWithValue("onGetter")
+ subject.getMethodByJvmName("setX").assertHasSuppressWithValue("onSetter")
subject.getField("x").assertHasSuppressWithValue("onField")
}
}
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XElementTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XElementTest.kt
index 56651da..2508281 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XElementTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XElementTest.kt
@@ -20,7 +20,7 @@
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.className
import androidx.room.compiler.processing.util.getField
-import androidx.room.compiler.processing.util.getMethod
+import androidx.room.compiler.processing.util.getMethodByJvmName
import androidx.room.compiler.processing.util.getParameter
import androidx.room.compiler.processing.util.runProcessorTestWithoutKsp
import androidx.room.compiler.processing.util.runProcessorTest
@@ -112,30 +112,34 @@
element.getField("transientField").assertModifiers("transient")
element.getField("staticField").assertModifiers("static")
- element.getMethod("privateMethod").assertModifiers("private")
- element.getMethod("packagePrivateMethod").assertModifiers()
- element.getMethod("publicMethod").assertModifiers("public")
- element.getMethod("protectedMethod").assertModifiers("protected")
- element.getMethod("finalMethod").assertModifiers("final")
- element.getMethod("abstractMethod").assertModifiers("abstract")
- element.getMethod("staticMethod").assertModifiers("static")
+ element.getMethodByJvmName("privateMethod").assertModifiers("private")
+ element.getMethodByJvmName("packagePrivateMethod").assertModifiers()
+ element.getMethodByJvmName("publicMethod").assertModifiers("public")
+ element.getMethodByJvmName("protectedMethod").assertModifiers("protected")
+ element.getMethodByJvmName("finalMethod").assertModifiers("final")
+ element.getMethodByJvmName("abstractMethod").assertModifiers("abstract")
+ element.getMethodByJvmName("staticMethod").assertModifiers("static")
assertThat(
- element.getMethod("privateMethod").isOverrideableIgnoringContainer()
+ element.getMethodByJvmName("privateMethod").isOverrideableIgnoringContainer()
).isFalse()
assertThat(
- element.getMethod("packagePrivateMethod").isOverrideableIgnoringContainer()
- ).isTrue()
- assertThat(element.getMethod("publicMethod").isOverrideableIgnoringContainer()).isTrue()
- assertThat(
- element.getMethod("protectedMethod").isOverrideableIgnoringContainer()
- ).isTrue()
- assertThat(element.getMethod("finalMethod").isOverrideableIgnoringContainer()).isFalse()
- assertThat(
- element.getMethod("abstractMethod").isOverrideableIgnoringContainer()
+ element.getMethodByJvmName("packagePrivateMethod").isOverrideableIgnoringContainer()
).isTrue()
assertThat(
- element.getMethod("staticMethod").isOverrideableIgnoringContainer()
+ element.getMethodByJvmName("publicMethod").isOverrideableIgnoringContainer()
+ ).isTrue()
+ assertThat(
+ element.getMethodByJvmName("protectedMethod").isOverrideableIgnoringContainer()
+ ).isTrue()
+ assertThat(
+ element.getMethodByJvmName("finalMethod").isOverrideableIgnoringContainer()
+ ).isFalse()
+ assertThat(
+ element.getMethodByJvmName("abstractMethod").isOverrideableIgnoringContainer()
+ ).isTrue()
+ assertThat(
+ element.getMethodByJvmName("staticMethod").isOverrideableIgnoringContainer()
).isFalse()
}
}
@@ -174,23 +178,23 @@
listOf(genericBase, boundedChild)
) {
fun validateElement(element: XTypeElement, tTypeName: TypeName, rTypeName: TypeName) {
- element.getMethod("returnT").let { method ->
+ element.getMethodByJvmName("returnT").let { method ->
assertThat(method.parameters).isEmpty()
assertThat(method.returnType.typeName).isEqualTo(tTypeName)
}
- element.getMethod("receiveT").let { method ->
+ element.getMethodByJvmName("receiveT").let { method ->
method.getParameter("param1").let { param ->
assertThat(param.type.typeName).isEqualTo(tTypeName)
}
assertThat(method.returnType.typeName).isEqualTo(TypeName.INT)
}
- element.getMethod("receiveR").let { method ->
+ element.getMethodByJvmName("receiveR").let { method ->
method.getParameter("param1").let { param ->
assertThat(param.type.typeName).isEqualTo(rTypeName)
}
assertThat(method.returnType.typeName).isEqualTo(TypeName.INT)
}
- element.getMethod("returnR").let { method ->
+ element.getMethodByJvmName("returnR").let { method ->
assertThat(method.parameters).isEmpty()
assertThat(method.returnType.typeName).isEqualTo(rTypeName)
}
@@ -235,7 +239,7 @@
val element = it.processingEnv.requireTypeElement("foo.bar.Baz")
assertThat(element.hasAnnotation(RunWith::class)).isTrue()
assertThat(element.hasAnnotation(Test::class)).isFalse()
- element.getMethod("testMethod").let { method ->
+ element.getMethodByJvmName("testMethod").let { method ->
assertThat(method.hasAnnotation(Test::class)).isTrue()
assertThat(method.hasAnnotation(Override::class)).isFalse()
assertThat(
@@ -306,7 +310,7 @@
assertThat(element.hasAllAnnotations(listOf(RunWith::class.className(),
Test::class.className()))).isFalse()
- element.getMethod("testMethod").let { method ->
+ element.getMethodByJvmName("testMethod").let { method ->
assertThat(method.hasAllAnnotations(*arrayOf<KClass<Annotation>>())).isTrue()
assertThat(method.hasAllAnnotations(Test::class)).isTrue()
assertThat(method.hasAllAnnotations(Test::class, OtherAnnotation::class)).isTrue()
@@ -392,7 +396,7 @@
assertThat(element.hasAnyAnnotation(listOf(RunWith::class.className(),
Test::class.className()))).isTrue()
- element.getMethod("testMethod").let { method ->
+ element.getMethodByJvmName("testMethod").let { method ->
assertThat(method.hasAnyAnnotation(*arrayOf<KClass<Annotation>>())).isFalse()
assertThat(method.hasAnyAnnotation(Test::class)).isTrue()
assertThat(method.hasAnyAnnotation(Test::class, OtherAnnotation::class)).isTrue()
@@ -488,7 +492,7 @@
assertThat(field.isVariableElement()).isTrue()
assertThat(field.isMethod()).isFalse()
}
- element.getMethod("method").let { method ->
+ element.getMethodByJvmName("method").let { method ->
assertThat(method.isTypeElement()).isFalse()
assertThat(method.isAbstract()).isFalse()
assertThat(method.isVariableElement()).isFalse()
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XExecutableElementTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XExecutableElementTest.kt
index a30674a..6c599c4 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XExecutableElementTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XExecutableElementTest.kt
@@ -21,8 +21,8 @@
import androidx.room.compiler.processing.util.UNIT_CLASS_NAME
import androidx.room.compiler.processing.util.className
import androidx.room.compiler.processing.util.compileFiles
-import androidx.room.compiler.processing.util.getDeclaredMethod
-import androidx.room.compiler.processing.util.getMethod
+import androidx.room.compiler.processing.util.getDeclaredMethodByJvmName
+import androidx.room.compiler.processing.util.getMethodByJvmName
import androidx.room.compiler.processing.util.getParameter
import androidx.room.compiler.processing.util.runProcessorTest
import androidx.room.compiler.processing.util.typeName
@@ -60,7 +60,7 @@
)
) {
val element = it.processingEnv.requireTypeElement("foo.bar.Baz")
- element.getDeclaredMethod("foo").let { method ->
+ element.getDeclaredMethodByJvmName("foo").let { method ->
assertThat(method.isJavaDefault()).isFalse()
assertThat(method.isVarArgs()).isFalse()
assertThat(method.isOverrideableIgnoringContainer()).isFalse()
@@ -70,7 +70,7 @@
assertThat(returnType.isVoid() || returnType.isKotlinUnit()).isTrue()
assertThat(returnType.defaultValue()).isEqualTo("null")
}
- element.getDeclaredMethod("bar").let { method ->
+ element.getDeclaredMethodByJvmName("bar").let { method ->
assertThat(method.isOverrideableIgnoringContainer()).isTrue()
assertThat(method.parameters).hasSize(1)
method.getParameter("param1").let { param ->
@@ -104,7 +104,7 @@
sources = listOf(subject)
) {
val element = it.processingEnv.requireTypeElement("foo.bar.Baz")
- assertThat(element.getMethod("method").isVarArgs()).isTrue()
+ assertThat(element.getMethodByJvmName("method").isVarArgs()).isTrue()
}
}
@@ -123,8 +123,8 @@
sources = listOf(subject)
) {
val element = it.processingEnv.requireTypeElement("Subject")
- assertThat(element.getMethod("method").isVarArgs()).isTrue()
- assertThat(element.getMethod("suspendMethod").isVarArgs()).isFalse()
+ assertThat(element.getMethodByJvmName("method").isVarArgs()).isTrue()
+ assertThat(element.getMethodByJvmName("suspendMethod").isVarArgs()).isFalse()
}
}
@@ -174,34 +174,34 @@
) { invocation ->
listOf("Base", "Sub").forEach { className ->
val element = invocation.processingEnv.requireTypeElement("foo.bar.$className")
- element.getMethod("noDefault").let { method ->
+ element.getMethodByJvmName("noDefault").let { method ->
assertThat(method.hasKotlinDefaultImpl()).isFalse()
}
- element.getMethod("withDefault").let { method ->
+ element.getMethodByJvmName("withDefault").let { method ->
assertThat(method.hasKotlinDefaultImpl()).isTrue()
}
element.getAllMethods().first {
- it.name == "nameMatch" && it.parameters.isEmpty()
+ it.jvmName == "nameMatch" && it.parameters.isEmpty()
}.let { nameMatchWithoutDefault ->
assertThat(nameMatchWithoutDefault.hasKotlinDefaultImpl()).isFalse()
}
element.getAllMethods().first {
- it.name == "nameMatch" && it.parameters.size == 1
+ it.jvmName == "nameMatch" && it.parameters.size == 1
}.let { nameMatchWithoutDefault ->
assertThat(nameMatchWithoutDefault.hasKotlinDefaultImpl()).isTrue()
}
- element.getMethod("withDefaultWithParams").let { method ->
+ element.getMethodByJvmName("withDefaultWithParams").let { method ->
assertThat(method.hasKotlinDefaultImpl()).isTrue()
}
- element.getMethod("withDefaultWithTypeArgs").let { method ->
+ element.getMethodByJvmName("withDefaultWithTypeArgs").let { method ->
assertThat(method.hasKotlinDefaultImpl()).isTrue()
}
// private functions in interfaces don't appear in kapt stubs
if (invocation.isKsp && className == "Base") {
- element.getMethod("privateWithDefault").let { method ->
+ element.getMethodByJvmName("privateWithDefault").let { method ->
assertThat(method.hasKotlinDefaultImpl()).isFalse()
}
}
@@ -269,34 +269,34 @@
) { invocation ->
listOf("Base", "Sub").forEach { className ->
val element = invocation.processingEnv.requireTypeElement("foo.bar.$className")
- element.getMethod("noDefault").let { method ->
+ element.getMethodByJvmName("noDefault").let { method ->
assertThat(method.hasKotlinDefaultImpl()).isFalse()
}
- element.getMethod("withDefault_noArg").let { method ->
+ element.getMethodByJvmName("withDefault_noArg").let { method ->
assertThat(method.hasKotlinDefaultImpl()).isTrue()
}
element.getAllMethods().first {
- it.name == "nameMatch" && it.parameters.isEmpty()
+ it.jvmName == "nameMatch" && it.parameters.isEmpty()
}.let { nameMatchWithoutDefault ->
assertThat(nameMatchWithoutDefault.hasKotlinDefaultImpl()).isFalse()
}
element.getAllMethods().first {
- it.name == "nameMatch" && it.parameters.size == 1
+ it.jvmName == "nameMatch" && it.parameters.size == 1
}.let { nameMatchWithoutDefault ->
assertThat(nameMatchWithoutDefault.hasKotlinDefaultImpl()).isTrue()
}
- element.getMethod("withDefaultWithParams").let { method ->
+ element.getMethodByJvmName("withDefaultWithParams").let { method ->
assertThat(method.hasKotlinDefaultImpl()).isTrue()
}
- element.getMethod("withDefaultWithTypeArgs").let { method ->
+ element.getMethodByJvmName("withDefaultWithTypeArgs").let { method ->
assertThat(method.hasKotlinDefaultImpl()).isTrue()
}
// private functions in interfaces don't appear in kapt stubs
if (invocation.isKsp && className == "Base") {
- element.getMethod("privateWithDefault").let { method ->
+ element.getMethodByJvmName("privateWithDefault").let { method ->
assertThat(method.hasKotlinDefaultImpl()).isFalse()
}
}
@@ -304,13 +304,13 @@
listOf("Base2", "Sub2").forEach { className ->
val element = invocation.processingEnv.requireTypeElement("foo.bar.$className")
- element.getMethod("withDefaultWithInProjectionType").let { method ->
+ element.getMethodByJvmName("withDefaultWithInProjectionType").let { method ->
assertThat(method.hasKotlinDefaultImpl()).isTrue()
}
- element.getMethod("withDefaultWithOutProjectionType").let { method ->
+ element.getMethodByJvmName("withDefaultWithOutProjectionType").let { method ->
assertThat(method.hasKotlinDefaultImpl()).isTrue()
}
- element.getMethod("withDefaultWithSubtypeArg").let { method ->
+ element.getMethodByJvmName("withDefaultWithSubtypeArg").let { method ->
assertThat(method.hasKotlinDefaultImpl()).isTrue()
}
}
@@ -333,7 +333,7 @@
sources = listOf(src)
) { invocation ->
val subject = invocation.processingEnv.requireTypeElement("Subject")
- subject.getMethod("noArg").let { method ->
+ subject.getMethodByJvmName("noArg").let { method ->
assertThat(method.parameters).hasSize(1)
assertThat(method.isSuspendFunction()).isTrue()
assertThat(method.returnType.typeName).isEqualTo(TypeName.OBJECT)
@@ -348,7 +348,7 @@
assertThat(cont.nullability).isEqualTo(XNullability.NONNULL)
}
}
- subject.getMethod("intReturn").let { method ->
+ subject.getMethodByJvmName("intReturn").let { method ->
assertThat(method.parameters).hasSize(1)
method.parameters.last().let { cont ->
assertThat(cont.type.typeName).isEqualTo(
@@ -370,7 +370,7 @@
)
}
}
- subject.getMethod("twoParams").let { method ->
+ subject.getMethodByJvmName("twoParams").let { method ->
assertThat(method.parameters).hasSize(3)
assertThat(method.parameters[0].type.typeName).isEqualTo(
String::class.typeName()
@@ -423,7 +423,7 @@
runProcessorTest(sources = listOf(src)) { invocation ->
val klass = invocation.processingEnv.requireTypeElement("MyDataClass")
val methodNames = klass.getAllMethods().map {
- it.name
+ it.jvmName
}.toList()
assertThat(methodNames).containsNoneIn(
listOf(
@@ -432,14 +432,14 @@
)
listOf("getX", "getProp1", "getProp2", "getProp3", "getProp5", "getProp6",
"getProp8\$main").forEach {
- klass.getMethod(it).let { method ->
+ klass.getMethodByJvmName(it).let { method ->
assertThat(method.returnType.typeName).isEqualTo(String::class.typeName())
assertThat(method.parameters).isEmpty()
assertThat(method.returnType.nullability).isEqualTo(XNullability.NONNULL)
}
}
listOf("setY", "setProp2", "setProp8\$main").forEach {
- klass.getMethod(it).let { method ->
+ klass.getMethodByJvmName(it).let { method ->
assertThat(method.returnType.typeName).isEqualTo(TypeName.VOID)
assertThat(method.parameters.first().type.typeName).isEqualTo(
String::class.typeName()
@@ -451,14 +451,14 @@
}
}
listOf("getProp5", "getProp7").forEach {
- klass.getMethod(it).let { method ->
+ klass.getMethodByJvmName(it).let { method ->
assertThat(method.isProtected()).isTrue()
assertThat(method.isPublic()).isFalse()
assertThat(method.isPrivate()).isFalse()
}
}
listOf("setProp5", "setProp6").forEach {
- klass.getMethod(it).let { method ->
+ klass.getMethodByJvmName(it).let { method ->
assertThat(method.isProtected()).isTrue()
assertThat(method.isPublic()).isFalse()
assertThat(method.isPrivate()).isFalse()
@@ -483,7 +483,7 @@
val base = invocation.processingEnv.requireTypeElement("Base")
val subject = invocation.processingEnv.requireType("Subject")
val nullableSubject = invocation.processingEnv.requireType("NullableSubject")
- val method = base.getMethod("foo")
+ val method = base.getMethodByJvmName("foo")
method.getParameter("t").let { param ->
param.asMemberOf(subject).let {
assertThat(it.typeName).isEqualTo(String::class.typeName())
@@ -551,8 +551,8 @@
base: XTypeElement,
baseMethodName: String = ownerMethodName
): Boolean {
- val overrider = owner.getMethod(ownerMethodName)
- val overridden = base.getMethod(baseMethodName)
+ val overrider = owner.getMethodByJvmName(ownerMethodName)
+ val overridden = base.getMethodByJvmName(baseMethodName)
return overrider.overrides(
overridden, owner
)
@@ -652,14 +652,14 @@
) { invocation ->
listOf("JavaInterface", "KotlinInterface").forEach { qName ->
invocation.processingEnv.requireTypeElement(qName).let {
- assertThat(it.getMethod("interfaceMethod").isAbstract()).isTrue()
+ assertThat(it.getMethodByJvmName("interfaceMethod").isAbstract()).isTrue()
}
}
listOf("JavaAbstractClass", "KotlinAbstractClass").forEach { qName ->
invocation.processingEnv.requireTypeElement(qName).let {
- assertThat(it.getMethod("abstractMethod").isAbstract()).isTrue()
- assertThat(it.getMethod("nonAbstractMethod").isAbstract()).isFalse()
+ assertThat(it.getMethodByJvmName("abstractMethod").isAbstract()).isTrue()
+ assertThat(it.getMethodByJvmName("nonAbstractMethod").isAbstract()).isFalse()
}
}
}
@@ -696,13 +696,13 @@
) { invocation ->
val elm = invocation.processingEnv.requireTypeElement("JavaImpl")
assertThat(
- elm.getMethod("getX").returnType.typeName
+ elm.getMethodByJvmName("getX").returnType.typeName
).isEqualTo(TypeName.INT)
assertThat(
- elm.getMethod("getY").returnType.typeName
+ elm.getMethodByJvmName("getY").returnType.typeName
).isEqualTo(TypeName.INT)
assertThat(
- elm.getMethod("setY").parameters.first().type.typeName
+ elm.getMethodByJvmName("setY").parameters.first().type.typeName
).isEqualTo(TypeName.INT)
}
}
@@ -738,13 +738,13 @@
) { invocation ->
val elm = invocation.processingEnv.requireTypeElement("JavaImpl")
assertThat(
- elm.getMethod("getX").returnType.typeName
+ elm.getMethodByJvmName("getX").returnType.typeName
).isEqualTo(TypeName.INT.box())
assertThat(
- elm.getMethod("getY").returnType.typeName
+ elm.getMethodByJvmName("getY").returnType.typeName
).isEqualTo(TypeName.INT.box())
assertThat(
- elm.getMethod("setY").parameters.first().type.typeName
+ elm.getMethodByJvmName("setY").parameters.first().type.typeName
).isEqualTo(TypeName.INT.box())
}
}
@@ -790,37 +790,37 @@
listOf("app", "lib").map {
invocation.processingEnv.requireTypeElement("$it.Subject")
}.forEach { subject ->
- subject.getMethod("method1").let { method ->
+ subject.getMethodByJvmName("method1").let { method ->
assertWithMessage(method.fallbackLocationText)
.that(method.defaults()).containsExactly(true, false).inOrder()
}
- subject.getMethod("method2").let { method ->
+ subject.getMethodByJvmName("method2").let { method ->
assertWithMessage(method.fallbackLocationText)
.that(method.defaults()).containsExactly(false, true).inOrder()
}
- subject.getMethod("varargMethod1").let { method ->
+ subject.getMethodByJvmName("varargMethod1").let { method ->
assertWithMessage(method.fallbackLocationText)
.that(method.defaults()).containsExactly(true, false).inOrder()
}
- subject.getMethod("varargMethod2").let { method ->
+ subject.getMethodByJvmName("varargMethod2").let { method ->
assertWithMessage(method.fallbackLocationText)
.that(method.defaults()).containsExactly(false, true).inOrder()
}
- subject.getMethod("suspendMethod").let { method ->
+ subject.getMethodByJvmName("suspendMethod").let { method ->
assertWithMessage(method.fallbackLocationText)
.that(method.defaults()).containsExactly(false)
}
- subject.getMethod("setProp").let { method ->
+ subject.getMethodByJvmName("setProp").let { method ->
assertWithMessage(method.fallbackLocationText)
.that(method.defaults()).containsExactly(false)
}
val jvmOverloadedMethodCount = subject.getDeclaredMethods().count {
- it.name == "jvmOverloadsMethod"
+ it.jvmName == "jvmOverloadsMethod"
}
if (invocation.isKsp) {
assertWithMessage(subject.fallbackLocationText)
.that(jvmOverloadedMethodCount).isEqualTo(1)
- subject.getMethod("jvmOverloadsMethod").let { method ->
+ subject.getMethodByJvmName("jvmOverloadsMethod").let { method ->
assertWithMessage(method.fallbackLocationText)
.that(method.defaults())
.containsExactly(false, true, true).inOrder()
@@ -829,7 +829,7 @@
assertWithMessage(subject.fallbackLocationText)
.that(jvmOverloadedMethodCount).isEqualTo(3)
val actuals = subject.getDeclaredMethods().filter {
- it.name == "jvmOverloadsMethod"
+ it.jvmName == "jvmOverloadsMethod"
}.associateBy(
keySelector = { it.parameters.size },
valueTransform = { it.defaults() }
@@ -907,7 +907,7 @@
return (subject.getConstructors() + subject.getDeclaredMethods()).mapNotNull {
val throwTypes = it.thrownTypes
val name = if (it is XMethodElement) {
- it.name
+ it.jvmName
} else {
"<init>"
}
@@ -996,16 +996,16 @@
)
runProcessorTest(sources = listOf(source)) { invocation ->
val objectMethodNames = invocation.processingEnv.requireTypeElement(TypeName.OBJECT)
- .getAllNonPrivateInstanceMethods().map { it.name }.toSet()
+ .getAllNonPrivateInstanceMethods().map { it.jvmName }.toSet()
fun XTypeElement.methodsSignature(): String {
return getAllNonPrivateInstanceMethods()
- .filterNot { it.name in objectMethodNames }
+ .filterNot { it.jvmName in objectMethodNames }
.sortedBy {
- it.name
+ it.jvmName
}.joinToString("\n") { methodElement ->
buildString {
- append(methodElement.name)
+ append(methodElement.jvmName)
append("(")
val paramTypes = if (asMemberOf) {
methodElement.asMemberOf(this@methodsSignature.type).parameterTypes
@@ -1072,4 +1072,83 @@
)
}
}
+
+ @Test
+ fun name() {
+ fun buildSources(pkg: String) = listOf(
+ Source.kotlin(
+ "KotlinSource.kt",
+ """
+ package $pkg;
+ @JvmInline
+ value class ValueClass(val value: String)
+ internal class InternalClass(val value: String)
+ class KotlinSubject {
+ var property: String = ""
+ internal var internalProperty: String = ""
+ var valueClassProperty: ValueClass = ValueClass("")
+ internal var internalClassProperty = InternalClass("")
+ fun normalFun() { TODO() }
+ @JvmName("jvmNameForFun")
+ fun jvmNameFun() { TODO() }
+ internal fun internalFun() { TODO() }
+ fun valueReceivingFun(param: ValueClass) { TODO() }
+ fun valueReturningFun(): ValueClass { TODO() }
+ internal fun internalValueReceivingFun(param: ValueClass) { TODO() }
+ internal fun internalValueReturningFun(): ValueClass { TODO() }
+ }
+ """.trimIndent()
+ )
+ )
+
+ val sources = buildSources("app")
+ val classpath = compileFiles(buildSources("lib"))
+ runProcessorTest(
+ sources = sources,
+ classpath = classpath
+ ) { invocation ->
+ // we use this to remove the hash added by the compiler for function names that don't
+ // have valid JVM names
+ // regex: match 7 characters after -
+ val removeHashRegex = """(?<=-)(.{7})""".toRegex()
+
+ fun XTypeElement.collectNameJvmNamePairs() = getDeclaredMethods().map {
+ it.name to removeHashRegex.replace(it.jvmName, "HASH")
+ }
+ listOf("app", "lib").forEach { pkg ->
+ val kotlinSubject = invocation.processingEnv
+ .requireTypeElement("$pkg.KotlinSubject")
+ val validJvmProperties = listOf(
+ "getInternalClassProperty" to "getInternalClassProperty\$main",
+ "getInternalProperty" to "getInternalProperty\$main",
+ "getProperty" to "getProperty",
+ "internalFun" to "internalFun\$main",
+ "jvmNameFun" to "jvmNameForFun",
+ "normalFun" to "normalFun",
+ "setInternalClassProperty" to "setInternalClassProperty\$main",
+ "setInternalProperty" to "setInternalProperty\$main",
+ "setProperty" to "setProperty",
+ )
+ // these won't show up in KAPT stubs as they don't have valid jvm names
+ val nonJvmProperties = listOf(
+ "getValueClassProperty" to "getValueClassProperty-HASH",
+ "internalValueReceivingFun" to "internalValueReceivingFun-HASH\$main",
+ "internalValueReturningFun" to "internalValueReturningFun-HASH\$main",
+ "setValueClassProperty" to "setValueClassProperty-HASH",
+ "valueReceivingFun" to "valueReceivingFun-HASH",
+ "valueReturningFun" to "valueReturningFun-HASH",
+ )
+ val expected = if (invocation.isKsp || pkg == "lib") {
+ validJvmProperties + nonJvmProperties
+ } else {
+ validJvmProperties
+ }
+ assertWithMessage("declarations in $pkg")
+ .that(kotlinSubject.collectNameJvmNamePairs())
+ .containsExactlyElementsIn(
+ expected
+ )
+ }
+ }
+ }
}
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XExecutableTypeTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XExecutableTypeTest.kt
index c683ad3..93eff55 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XExecutableTypeTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XExecutableTypeTest.kt
@@ -19,7 +19,7 @@
import androidx.room.compiler.processing.util.CONTINUATION_CLASS_NAME
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.UNIT_CLASS_NAME
-import androidx.room.compiler.processing.util.getMethod
+import androidx.room.compiler.processing.util.getMethodByJvmName
import androidx.room.compiler.processing.util.runProcessorTest
import androidx.room.compiler.processing.util.typeName
import com.google.common.truth.Truth.assertThat
@@ -101,8 +101,8 @@
) {
assertThat(subjects).isNotEmpty()
subjects.forEach {
- callback(myInterface.getMethod(methodName).asMemberOf(it.type))
- callback(it.getMethod(methodName).executableType)
+ callback(myInterface.getMethodByJvmName(methodName).asMemberOf(it.type))
+ callback(it.getMethodByJvmName(methodName).executableType)
}
}
@@ -168,8 +168,8 @@
) {
assertThat(subjects).isNotEmpty()
subjects.forEach {
- callback(myInterface.getMethod(methodName).asMemberOf(it.type))
- callback(it.getMethod(methodName).executableType)
+ callback(myInterface.getMethodByJvmName(methodName).asMemberOf(it.type))
+ callback(it.getMethodByJvmName(methodName).executableType)
}
}
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XNullabilityTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XNullabilityTest.kt
index 957ee88..9a28341 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XNullabilityTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XNullabilityTest.kt
@@ -21,7 +21,7 @@
import androidx.room.compiler.processing.XNullability.UNKNOWN
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.getField
-import androidx.room.compiler.processing.util.getMethod
+import androidx.room.compiler.processing.util.getMethodByJvmName
import androidx.room.compiler.processing.util.getParameter
import androidx.room.compiler.processing.util.runProcessorTestWithoutKsp
import androidx.room.compiler.processing.util.runProcessorTest
@@ -85,12 +85,12 @@
element.getField("nullableAnnotated").let { field ->
assertThat(field.type.nullability).isEqualTo(NULLABLE)
}
- element.getMethod("returnsNonNull").let { method ->
+ element.getMethodByJvmName("returnsNonNull").let { method ->
assertThat(method.returnType.nullability).isEqualTo(NONNULL)
assertThat(method.executableType.returnType.nullability)
.isEqualTo(NONNULL)
}
- element.getMethod("parameters").let { method ->
+ element.getMethodByJvmName("parameters").let { method ->
assertThat(method.returnType.nullability).isEqualTo(UNKNOWN)
method.getParameter("primitiveParam").let { param ->
assertThat(param.type.nullability).isEqualTo(NONNULL)
@@ -106,7 +106,7 @@
}
}
// also assert parameter types from executable type
- element.getMethod("parameters").executableType.let { method ->
+ element.getMethodByJvmName("parameters").executableType.let { method ->
assertThat(method.returnType.nullability).isEqualTo(UNKNOWN)
// int primitiveParam,
method.parameterTypes[0].let { paramType ->
@@ -179,11 +179,11 @@
val declared = field.type
assertThat(declared.typeArguments.first().nullability).isEqualTo(NULLABLE)
}
- element.getMethod("nullableReturn").let { method ->
+ element.getMethodByJvmName("nullableReturn").let { method ->
assertThat(method.returnType.nullability).isEqualTo(NULLABLE)
assertThat(method.executableType.returnType.nullability).isEqualTo(NULLABLE)
}
- element.getMethod("suspendNullableReturn").let { method ->
+ element.getMethodByJvmName("suspendNullableReturn").let { method ->
// kotlin adds @Nullable annotation for suspend methods' javac signature
assertThat(method.returnType.nullability).isEqualTo(NULLABLE)
val executableType = method.executableType
@@ -192,7 +192,7 @@
assertThat(executableType.getSuspendFunctionReturnType().nullability)
.isEqualTo(NULLABLE)
}
- element.getMethod("genericWithNullableTypeArgReturn").let { method ->
+ element.getMethodByJvmName("genericWithNullableTypeArgReturn").let { method ->
listOf(method.returnType, method.executableType.returnType).forEach { type ->
assertThat(type.nullability).isEqualTo(NONNULL)
assertThat(type.typeArguments[0].nullability)
@@ -201,7 +201,7 @@
.isEqualTo(NULLABLE)
}
}
- element.getMethod("suspendGenericWithNullableTypeArgReturn").let { method ->
+ element.getMethodByJvmName("suspendGenericWithNullableTypeArgReturn").let { method ->
val executableType = method.executableType
check(executableType.isSuspendFunction())
executableType.getSuspendFunctionReturnType().let { type ->
@@ -217,11 +217,11 @@
assertThat(type.typeArguments).isEmpty()
}
}
- element.getMethod("nonNullReturn").let { method ->
+ element.getMethodByJvmName("nonNullReturn").let { method ->
assertThat(method.returnType.nullability).isEqualTo(NONNULL)
assertThat(method.executableType.returnType.nullability).isEqualTo(NONNULL)
}
- element.getMethod("suspendNonNullReturn").let { method ->
+ element.getMethodByJvmName("suspendNonNullReturn").let { method ->
// suspend methods return nullable in java declarations
assertThat(method.returnType.nullability).isEqualTo(NULLABLE)
val executableType = method.executableType
@@ -230,7 +230,7 @@
assertThat(executableType.getSuspendFunctionReturnType().nullability)
.isEqualTo(NONNULL)
}
- element.getMethod("methodParams").let { method ->
+ element.getMethodByJvmName("methodParams").let { method ->
assertThat(method.getParameter("nonNull").type.nullability)
.isEqualTo(NONNULL)
assertThat(method.getParameter("nullable").type.nullability)
@@ -366,7 +366,7 @@
)
runProcessorTest(sources = listOf(src)) { invocation ->
val voidType = invocation.processingEnv.requireTypeElement("Foo")
- .getMethod("subject").returnType
+ .getMethodByJvmName("subject").returnType
assertThat(voidType.typeName).isEqualTo(TypeName.VOID)
voidType.makeNullable().let {
assertThat(it.nullability).isEqualTo(NULLABLE)
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XProcessingStepTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XProcessingStepTest.kt
index 73d1fcd..e203311 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XProcessingStepTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XProcessingStepTest.kt
@@ -1132,8 +1132,8 @@
val methods = elements.filterIsInstance<XMethodElement>()
val params = elements.filterIsInstance<XExecutableParameterElement>()
assertThat(methods).hasSize(2)
- assertThat(methods.firstOrNull { it.name == "mainMethod" }).isNotNull()
- assertThat(methods.firstOrNull { it.name == "innerMethod" }).isNotNull()
+ assertThat(methods.firstOrNull { it.jvmName == "mainMethod" }).isNotNull()
+ assertThat(methods.firstOrNull { it.jvmName == "innerMethod" }).isNotNull()
assertThat(params).hasSize(1)
assertThat(params.firstOrNull { it.name == "param" }).isNotNull()
}
@@ -1223,8 +1223,8 @@
val methods = elements.filterIsInstance<XMethodElement>()
val params = elements.filterIsInstance<XExecutableParameterElement>()
assertThat(methods).hasSize(2)
- assertThat(methods.firstOrNull { it.name == "mainMethod" }).isNotNull()
- assertThat(methods.firstOrNull { it.name == "innerMethod" }).isNotNull()
+ assertThat(methods.firstOrNull { it.jvmName == "mainMethod" }).isNotNull()
+ assertThat(methods.firstOrNull { it.jvmName == "innerMethod" }).isNotNull()
assertThat(params).hasSize(1)
assertThat(params.firstOrNull { it.name == "param" }).isNotNull()
}
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XRoundEnvTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XRoundEnvTest.kt
index 7463ffa..f017783 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XRoundEnvTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XRoundEnvTest.kt
@@ -18,9 +18,9 @@
import androidx.room.compiler.processing.testcode.OtherAnnotation
import androidx.room.compiler.processing.util.Source
-import androidx.room.compiler.processing.util.getDeclaredMethod
+import androidx.room.compiler.processing.util.getDeclaredMethodByJvmName
import androidx.room.compiler.processing.util.getField
-import androidx.room.compiler.processing.util.getMethod
+import androidx.room.compiler.processing.util.getMethodByJvmName
import androidx.room.compiler.processing.util.runKspTest
import androidx.room.compiler.processing.util.runProcessorTest
import com.google.common.truth.Truth.assertThat
@@ -63,13 +63,13 @@
containsExactlyElementsIn(annotatedElementsByName)
hasSize(3)
contains(targetElement)
- contains(targetElement.getMethod("myFunction"))
+ contains(targetElement.getMethodByJvmName("myFunction"))
if (testInvocation.isKsp) {
contains(targetElement.getField("myProperty"))
} else {
// Javac sees a property annotation on the synthetic function
- contains(targetElement.getDeclaredMethod("getMyProperty\$annotations"))
+ contains(targetElement.getDeclaredMethodByJvmName("getMyProperty\$annotations"))
}
}
}
@@ -104,8 +104,8 @@
).apply {
hasSize(3)
- contains(targetElement.getDeclaredMethod("getMyProperty1"))
- contains(targetElement.getDeclaredMethod("setMyProperty2"))
+ contains(targetElement.getDeclaredMethodByJvmName("getMyProperty1"))
+ contains(targetElement.getDeclaredMethodByJvmName("setMyProperty2"))
contains(targetElement.getField("myProperty3"))
}
}
@@ -146,7 +146,7 @@
)
assertThat(annotatedElements).hasSize(1)
val subject = annotatedElements.filterIsInstance<XMethodElement>().first()
- assertThat(subject.name).isEqualTo("myFun")
+ assertThat(subject.jvmName).isEqualTo("myFun")
assertThat(subject.enclosingElement.className).isEqualTo(
ClassName.get("", "BazKt")
)
@@ -178,7 +178,7 @@
assertThat(annotatedElements).hasSize(3)
val byName = annotatedElements.associateBy {
when (it) {
- is XMethodElement -> it.name
+ is XMethodElement -> it.jvmName
is XFieldElement -> it.name
else -> error("unexpected type $it")
}
@@ -299,11 +299,11 @@
)
val setterParam = annotatedParams.first { it.name == "p0" || it.name == "arg0" }
assertThat(setterParam.enclosingMethodElement).isEqualTo(
- typeElement.getDeclaredMethod("setProperty")
+ typeElement.getDeclaredMethodByJvmName("setProperty")
)
val methodParam = annotatedParams.first { it.name == "methodParam" }
assertThat(methodParam.enclosingMethodElement).isEqualTo(
- typeElement.getDeclaredMethod("method")
+ typeElement.getDeclaredMethodByJvmName("method")
)
}
}
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XTypeElementTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XTypeElementTest.kt
index 34e6c53..dfe7eeb 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XTypeElementTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XTypeElementTest.kt
@@ -21,7 +21,7 @@
import androidx.room.compiler.processing.util.compileFiles
import androidx.room.compiler.processing.util.getAllFieldNames
import androidx.room.compiler.processing.util.getField
-import androidx.room.compiler.processing.util.getMethod
+import androidx.room.compiler.processing.util.getMethodByJvmName
import androidx.room.compiler.processing.util.runProcessorTest
import com.google.common.truth.Truth.assertThat
import com.google.common.truth.Truth.assertWithMessage
@@ -342,7 +342,7 @@
assertThat(subClass.getDeclaredFields().map { it.name })
.containsExactly("subClassProp")
- val baseMethod = baseClass.getMethod("baseMethod")
+ val baseMethod = baseClass.getMethodByJvmName("baseMethod")
baseMethod.asMemberOf(subClass.type).let { methodType ->
val genericArg = methodType.parameterTypes.first()
assertThat(genericArg.typeName).isEqualTo(TypeName.INT.box())
@@ -438,7 +438,7 @@
assertWithMessage(subject.qualifiedName)
.that(allFields.toList())
.containsExactlyElementsIn(expectedFields)
- val methodNames = subject.getDeclaredMethods().map { it.name }
+ val methodNames = subject.getDeclaredMethods().map { it.jvmName }
assertWithMessage(subject.qualifiedName)
.that(methodNames)
.containsAtLeast("getNoBackingVal", "getNoBackingVar", "setNoBackingVar")
@@ -508,7 +508,7 @@
"x", "y"
)
assertWithMessage(subject.fallbackLocationText)
- .that(subject.getDeclaredMethods().map { it.name })
+ .that(subject.getDeclaredMethods().map { it.jvmName })
.containsExactly(
"getX", "setX", "getY", "setY"
)
@@ -529,10 +529,10 @@
runProcessorTest(sources = listOf(src)) { invocation ->
val element = invocation.processingEnv.requireTypeElement("MyInterface")
assertThat(element.getAllFieldsIncludingPrivateSupers().toList()).isEmpty()
- element.getMethod("getX").let {
+ element.getMethodByJvmName("getX").let {
assertThat(it.isAbstract()).isTrue()
}
- element.getMethod("setX").let {
+ element.getMethodByJvmName("setX").let {
assertThat(it.isAbstract()).isTrue()
}
}
@@ -559,22 +559,22 @@
"nonAbstractVar", "jvmVar"
)
assertThat(
- element.getDeclaredMethods().map { it.name }
+ element.getDeclaredMethods().map { it.jvmName }
).containsExactly(
"getAbstractVar", "setAbstractVar",
"getNonAbstractVar", "setNonAbstractVar"
)
- element.getMethod("getAbstractVar").let {
+ element.getMethodByJvmName("getAbstractVar").let {
assertThat(it.isAbstract()).isTrue()
}
- element.getMethod("setAbstractVar").let {
+ element.getMethodByJvmName("setAbstractVar").let {
assertThat(it.isAbstract()).isTrue()
}
- element.getMethod("getNonAbstractVar").let {
+ element.getMethodByJvmName("getNonAbstractVar").let {
assertThat(it.isAbstract()).isFalse()
}
- element.getMethod("setNonAbstractVar").let {
+ element.getMethodByJvmName("setNonAbstractVar").let {
assertThat(it.isAbstract()).isFalse()
}
}
@@ -642,7 +642,7 @@
assertWithMessage(subject.qualifiedName)
.that(
subject.getDeclaredMethods().map {
- it.name
+ it.jvmName
}
).containsExactly(
"getMutable", "setMutable", "getImmutable"
@@ -684,16 +684,16 @@
runProcessorTest(sources = listOf(src)) { invocation ->
val base = invocation.processingEnv.requireTypeElement("Base")
val objectMethodNames = invocation.objectMethodNames()
- assertThat(base.getDeclaredMethods().names()).containsExactly(
+ assertThat(base.getDeclaredMethods().jvmNames()).containsExactly(
"baseFun", "suspendFun", "privateBaseFun", "staticBaseFun"
)
val sub = invocation.processingEnv.requireTypeElement("SubClass")
- assertThat(sub.getDeclaredMethods().names()).containsExactly(
+ assertThat(sub.getDeclaredMethods().jvmNames()).containsExactly(
"baseFun", "subFun", "privateSubFun", "staticFun"
)
assertThat(
- sub.getAllNonPrivateInstanceMethods().names() - objectMethodNames
+ sub.getAllNonPrivateInstanceMethods().jvmNames() - objectMethodNames
).containsExactly(
"baseFun", "suspendFun", "subFun"
)
@@ -732,7 +732,7 @@
) { invocation ->
listOf("lib", "app").forEach { pkg ->
val objectMethodNames = invocation.processingEnv.requireTypeElement(Any::class)
- .getAllMethods().names()
+ .getAllMethods().jvmNames()
fun XMethodElement.signature(
owner: XType
@@ -741,11 +741,11 @@
val params = methodType.parameterTypes.joinToString(",") {
it.typeName.toString()
}
- return "$name($params):${returnType.typeName}"
+ return "$jvmName($params):${returnType.typeName}"
}
fun XTypeElement.allMethodSignatures(): List<String> = getAllMethods().filterNot {
- it.name in objectMethodNames
+ it.jvmName in objectMethodNames
}.map { it.signature(this.type) }.toList()
invocation.processingEnv.requireTypeElement("$pkg.Subject1").let { subject ->
assertWithMessage(subject.qualifiedName).that(
@@ -799,7 +799,7 @@
runProcessorTest(sources = listOf(src)) { invocation ->
val objectMethodNames = invocation.processingEnv.requireTypeElement(Any::class)
- .getAllMethods().names()
+ .getAllMethods().jvmNames()
fun XMethodElement.signature(
owner: XType
): String {
@@ -807,11 +807,11 @@
val params = methodType.parameterTypes.joinToString(",") {
it.typeName.toString()
}
- return "$name($params):${returnType.typeName}"
+ return "$jvmName($params):${returnType.typeName}"
}
fun XTypeElement.allMethodSignatures(): List<String> = getAllMethods().filterNot {
- it.name in objectMethodNames
+ it.jvmName in objectMethodNames
}.map { it.signature(this.type) }.toList()
invocation.processingEnv.requireTypeElement(
@@ -878,7 +878,7 @@
val objectMethodNames = invocation.objectMethodNames()
val klass = invocation.processingEnv.requireTypeElement("SubClass")
assertThat(
- klass.getAllMethods().names() - objectMethodNames
+ klass.getAllMethods().jvmNames() - objectMethodNames
).containsExactly(
"baseMethod", "overriddenMethod", "baseCompanionMethod",
"interfaceMethod", "subMethod", "privateSubMethod", "subCompanionMethod"
@@ -904,27 +904,27 @@
runProcessorTest(sources = listOf(src)) { invocation ->
val objectMethodNames = invocation.objectMethodNames()
invocation.processingEnv.requireTypeElement("JustGetter").let { base ->
- assertThat(base.getDeclaredMethods().names()).containsExactly(
+ assertThat(base.getDeclaredMethods().jvmNames()).containsExactly(
"getX"
)
- assertThat(base.getAllMethods().names() - objectMethodNames).containsExactly(
+ assertThat(base.getAllMethods().jvmNames() - objectMethodNames).containsExactly(
"getX"
)
assertThat(
- base.getAllNonPrivateInstanceMethods().names() - objectMethodNames
+ base.getAllNonPrivateInstanceMethods().jvmNames() - objectMethodNames
).containsExactly(
"getX"
)
}
invocation.processingEnv.requireTypeElement("GetterSetter").let { sub ->
- assertThat(sub.getDeclaredMethods().names()).containsExactly(
+ assertThat(sub.getDeclaredMethods().jvmNames()).containsExactly(
"getY", "setY"
)
- assertThat(sub.getAllMethods().names() - objectMethodNames).containsExactly(
+ assertThat(sub.getAllMethods().jvmNames() - objectMethodNames).containsExactly(
"getX", "getY", "setY"
)
assertThat(
- sub.getAllNonPrivateInstanceMethods().names() - objectMethodNames
+ sub.getAllNonPrivateInstanceMethods().jvmNames() - objectMethodNames
).containsExactly(
"getX", "getY", "setY"
)
@@ -962,7 +962,7 @@
runProcessorTest(sources = listOf(src)) { invocation ->
val objectMethodNames = invocation.processingEnv.requireTypeElement(
Any::class
- ).getAllMethods().names()
+ ).getAllMethods().jvmNames()
val subject = invocation.processingEnv.requireTypeElement("CompanionSubject")
assertThat(subject.getAllFieldNames() - "Companion").containsExactly(
"mutableStatic", "immutableStatic", "companionProp",
@@ -974,22 +974,22 @@
"companionMethodWithJvmStatic"
)
assertThat(
- subject.getDeclaredMethods().names()
+ subject.getDeclaredMethods().jvmNames()
).containsExactlyElementsIn(
expectedMethodNames
)
assertThat(
- subject.getAllMethods().names() - objectMethodNames
+ subject.getAllMethods().jvmNames() - objectMethodNames
).containsExactlyElementsIn(
expectedMethodNames
)
assertThat(
- subject.getAllNonPrivateInstanceMethods().names() - objectMethodNames
+ subject.getAllNonPrivateInstanceMethods().jvmNames() - objectMethodNames
).isEmpty()
val subClass = invocation.processingEnv.requireTypeElement("SubClass")
assertThat(subClass.getDeclaredMethods()).isEmpty()
assertThat(
- subClass.getAllMethods().names() - objectMethodNames
+ subClass.getAllMethods().jvmNames() - objectMethodNames
).containsExactlyElementsIn(
expectedMethodNames
)
@@ -999,7 +999,7 @@
assertWithMessage(it.name).that(it.isStatic()).isTrue()
}
subject.getDeclaredMethods().forEach {
- assertWithMessage(it.name).that(it.isStatic()).isTrue()
+ assertWithMessage(it.jvmName).that(it.isStatic()).isTrue()
}
// make sure asMemberOf works fine for statics
@@ -1015,7 +1015,7 @@
try {
it.asMemberOf(subClassType)
} catch (th: Throwable) {
- throw AssertionError("Couldn't run asMemberOf for ${it.name}")
+ throw AssertionError("Couldn't run asMemberOf for ${it.jvmName}")
}
}
}
@@ -1036,24 +1036,24 @@
)
runProcessorTest(sources = listOf(src)) { invocation ->
invocation.processingEnv.requireTypeElement("JustGetter").let { base ->
- assertThat(base.getDeclaredMethods().names()).containsExactly(
+ assertThat(base.getDeclaredMethods().jvmNames()).containsExactly(
"getX"
)
- assertThat(base.getAllMethods().names()).containsExactly(
+ assertThat(base.getAllMethods().jvmNames()).containsExactly(
"getX"
)
- assertThat(base.getAllNonPrivateInstanceMethods().names()).containsExactly(
+ assertThat(base.getAllNonPrivateInstanceMethods().jvmNames()).containsExactly(
"getX"
)
}
invocation.processingEnv.requireTypeElement("GetterSetter").let { sub ->
- assertThat(sub.getDeclaredMethods().names()).containsExactly(
+ assertThat(sub.getDeclaredMethods().jvmNames()).containsExactly(
"getY", "setY"
)
- assertThat(sub.getAllMethods().names()).containsExactly(
+ assertThat(sub.getAllMethods().jvmNames()).containsExactly(
"getX", "getY", "setY"
)
- assertThat(sub.getAllNonPrivateInstanceMethods().names()).containsExactly(
+ assertThat(sub.getAllNonPrivateInstanceMethods().jvmNames()).containsExactly(
"getX", "getY", "setY"
)
}
@@ -1141,8 +1141,8 @@
)
runProcessorTest(sources = listOf(src)) { invocation ->
val subject = invocation.processingEnv.requireTypeElement("MyInterface")
- assertThat(subject.getMethod("notJvmDefault").isJavaDefault()).isFalse()
- assertThat(subject.getMethod("jvmDefault").isJavaDefault()).isTrue()
+ assertThat(subject.getMethodByJvmName("notJvmDefault").isJavaDefault()).isFalse()
+ assertThat(subject.getMethodByJvmName("jvmDefault").isJavaDefault()).isTrue()
}
}
@@ -1266,7 +1266,7 @@
.that(typeElement.isEnum())
.isTrue()
assertWithMessage("$qName does not report enum constants in methods")
- .that(typeElement.getDeclaredMethods().map { it.name })
+ .that(typeElement.getDeclaredMethods().map { it.jvmName })
.run {
contains("enumMethod")
containsNoneOf("VAL1", "VAL2")
@@ -1356,13 +1356,13 @@
private fun XTestInvocation.objectMethodNames() = processingEnv
.requireTypeElement("java.lang.Object")
.getAllMethods()
- .names()
+ .jvmNames()
- private fun Sequence<XMethodElement>.names() = map {
- it.name
+ private fun Sequence<XMethodElement>.jvmNames() = map {
+ it.jvmName
}.toList()
- private fun List<XMethodElement>.names() = map {
- it.name
+ private fun List<XMethodElement>.jvmNames() = map {
+ it.jvmName
}.toList()
}
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 79a50b7..741f59d 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
@@ -19,9 +19,9 @@
import androidx.room.compiler.processing.ksp.ERROR_TYPE_NAME
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.className
-import androidx.room.compiler.processing.util.getDeclaredMethod
+import androidx.room.compiler.processing.util.getDeclaredMethodByJvmName
import androidx.room.compiler.processing.util.getField
-import androidx.room.compiler.processing.util.getMethod
+import androidx.room.compiler.processing.util.getMethodByJvmName
import androidx.room.compiler.processing.util.javaElementUtils
import androidx.room.compiler.processing.util.kspResolver
import androidx.room.compiler.processing.util.runKspTest
@@ -83,7 +83,7 @@
)
}
- type.typeElement!!.getMethod("wildcardParam").let { method ->
+ type.typeElement!!.getMethodByJvmName("wildcardParam").let { method ->
val wildcardParam = method.parameters.first()
val extendsBoundOrSelf = wildcardParam.type.extendsBoundOrSelf()
assertThat(extendsBoundOrSelf.rawType)
@@ -124,7 +124,7 @@
assertThat(field.type.isError()).isTrue()
assertThat(field.type.typeName).isEqualTo(errorTypeName)
}
- element.getDeclaredMethod("badMethod").let { method ->
+ element.getDeclaredMethodByJvmName("badMethod").let { method ->
assertThat(method.returnType.isError()).isTrue()
assertThat(method.returnType.typeName).isEqualTo(errorTypeName)
}
@@ -349,7 +349,7 @@
)
runProcessorTest(sources = listOf(kotlinSubject)) { invocation ->
invocation.processingEnv.requireTypeElement("KotlinSubject").let {
- val continuationParam = it.getMethod("unitSuspend").parameters.last()
+ val continuationParam = it.getMethodByJvmName("unitSuspend").parameters.last()
val typeArg = continuationParam.type.typeArguments.first()
assertThat(
typeArg.extendsBound()?.isKotlinUnit()
@@ -383,18 +383,18 @@
)
runProcessorTest(sources = listOf(javaBase, kotlinSubject)) { invocation ->
invocation.processingEnv.requireTypeElement("KotlinSubject").let {
- it.getMethod("voidMethod").returnType.let {
+ it.getMethodByJvmName("voidMethod").returnType.let {
assertThat(it.isVoidObject()).isFalse()
assertThat(it.isVoid()).isTrue()
assertThat(it.isKotlinUnit()).isFalse()
}
- val method = it.getMethod("getVoid")
+ val method = it.getMethodByJvmName("getVoid")
method.returnType.let {
assertThat(it.isVoidObject()).isTrue()
assertThat(it.isVoid()).isFalse()
assertThat(it.isKotlinUnit()).isFalse()
}
- it.getMethod("anotherVoid").returnType.let {
+ it.getMethodByJvmName("anotherVoid").returnType.let {
assertThat(it.isVoidObject()).isTrue()
assertThat(it.isVoid()).isFalse()
assertThat(it.isKotlinUnit()).isFalse()
@@ -614,7 +614,7 @@
)
runProcessorTest(listOf(libSource)) { invocation ->
val actual = invocation.processingEnv.requireTypeElement("MyClass")
- .getDeclaredMethod("setLists").parameters.associate {
+ .getDeclaredMethodByJvmName("setLists").parameters.associate {
it.name to it.type.typeName.toString()
}
assertThat(actual["starList"]).isEqualTo("java.util.List<?>")
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/compat/XConvertersTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/compat/XConvertersTest.kt
index babf19b..c0722cb 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/compat/XConvertersTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/compat/XConvertersTest.kt
@@ -24,7 +24,7 @@
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.XTestInvocation
import androidx.room.compiler.processing.util.getDeclaredField
-import androidx.room.compiler.processing.util.getDeclaredMethod
+import androidx.room.compiler.processing.util.getDeclaredMethodByJvmName
import androidx.room.compiler.processing.util.runKaptTest
import com.google.auto.common.MoreElements
import com.google.auto.common.MoreTypes
@@ -203,12 +203,12 @@
invocation.getJavacTypeElement("KotlinClass").enclosedElements
).first { it.simpleName.toString() == "foo" }
assertThat(kotlinFoo.toXProcessing(invocation.processingEnv))
- .isEqualTo(kotlinClass.getDeclaredMethod("foo"))
+ .isEqualTo(kotlinClass.getDeclaredMethodByJvmName("foo"))
val javaFoo = ElementFilter.methodsIn(
invocation.getJavacTypeElement("JavaClass").enclosedElements
).first { it.simpleName.toString() == "foo" }
assertThat(javaFoo.toXProcessing(invocation.processingEnv))
- .isEqualTo(javaClass.getDeclaredMethod("foo"))
+ .isEqualTo(javaClass.getDeclaredMethodByJvmName("foo"))
}
}
@@ -257,14 +257,14 @@
val javaClass = invocation.processingEnv.requireTypeElement("JavaClass")
assertThat(
- kotlinClass.getDeclaredMethod("foo").parameters.map { it.toJavac() }
+ kotlinClass.getDeclaredMethodByJvmName("foo").parameters.map { it.toJavac() }
).containsExactlyElementsIn(
ElementFilter.methodsIn(
invocation.getJavacTypeElement("KotlinClass").enclosedElements
).first { it.simpleName.toString() == "foo" }.parameters
)
assertThat(
- javaClass.getDeclaredMethod("foo").parameters.map { it.toJavac() }
+ javaClass.getDeclaredMethodByJvmName("foo").parameters.map { it.toJavac() }
).containsExactlyElementsIn(
ElementFilter.methodsIn(
invocation.getJavacTypeElement("JavaClass").enclosedElements
@@ -275,12 +275,12 @@
invocation.getJavacTypeElement("KotlinClass").enclosedElements
).first { it.simpleName.toString() == "foo" }.parameters.first()
assertThat(kotlinParam.toXProcessing(invocation.processingEnv))
- .isEqualTo(kotlinClass.getDeclaredMethod("foo").parameters.first())
+ .isEqualTo(kotlinClass.getDeclaredMethodByJvmName("foo").parameters.first())
val javaParam = ElementFilter.methodsIn(
invocation.getJavacTypeElement("JavaClass").enclosedElements
).first { it.simpleName.toString() == "foo" }.parameters.first()
assertThat(javaParam.toXProcessing(invocation.processingEnv))
- .isEqualTo(javaClass.getDeclaredMethod("foo").parameters.first())
+ .isEqualTo(javaClass.getDeclaredMethodByJvmName("foo").parameters.first())
}
}
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/ksp/KSAsMemberOfTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/ksp/KSAsMemberOfTest.kt
index 0262667..f2c68e0 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/ksp/KSAsMemberOfTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/ksp/KSAsMemberOfTest.kt
@@ -20,7 +20,7 @@
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.className
import androidx.room.compiler.processing.util.getField
-import androidx.room.compiler.processing.util.getMethod
+import androidx.room.compiler.processing.util.getMethodByJvmName
import androidx.room.compiler.processing.util.runKspTest
import com.google.common.truth.Truth.assertThat
import com.squareup.javapoet.ClassName
@@ -196,7 +196,7 @@
runKspTest(sources = listOf(kotlinSrc, javaSrc)) { invocation ->
listOf("KotlinClass", "JavaClass").forEach {
val typeElement = invocation.processingEnv.requireTypeElement(it)
- typeElement.getMethod("staticFun").let { staticFun ->
+ typeElement.getMethodByJvmName("staticFun").let { staticFun ->
val asMember = staticFun.asMemberOf(typeElement.type)
assertThat(asMember.returnType.typeName).isEqualTo(TypeName.VOID)
assertThat(
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 dabf34b..a090664 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
@@ -49,18 +49,18 @@
) {
// collect all methods in the Object class to exclude them from matching
val objectMethodNames = invocation.processingEnv.requireTypeElement(Any::class)
- .getAllMethods().map { it.name }.toSet()
+ .getAllMethods().map { it.jvmName }.toSet()
fun XExecutableElement.createNewUniqueKey(
owner: String
): String {
val prefix = this.enclosingElement.className.canonicalName()
- val name = if (this is XMethodElement) {
- name
+ val jvmName = if (this is XMethodElement) {
+ jvmName
} else {
"<init>"
}
- val key = "$owner.$prefix.$name"
+ val key = "$owner.$prefix.$jvmName"
check(!output.containsKey(key)) {
"test expects unique method names. $key is here: ${output[key]}"
}
@@ -78,16 +78,17 @@
// KAPT might duplicate overridden methods. ignore them for test purposes
// see b/205911014
val declaredMethodNames = klass.getDeclaredMethods().map {
- it.name
+ it.jvmName
}.toSet()
val methods = klass.getDeclaredMethods() + klass.getAllMethods().filterNot {
- it.name in declaredMethodNames
+ it.jvmName in declaredMethodNames
}
methods
.filterNot {
// remote these synthetics generated by kapt for property annotations
- it.name.contains("\$annotations") || objectMethodNames.contains(it.name)
+ it.jvmName.contains("\$annotations") ||
+ objectMethodNames.contains(it.jvmName)
}
.forEach { method ->
val testKey = method.createNewUniqueKey(klass.qualifiedName)
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/ksp/KspTypeTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/ksp/KspTypeTest.kt
index 69caa37..bbfba03 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/ksp/KspTypeTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/ksp/KspTypeTest.kt
@@ -26,7 +26,7 @@
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.className
import androidx.room.compiler.processing.util.getField
-import androidx.room.compiler.processing.util.getMethod
+import androidx.room.compiler.processing.util.getMethodByJvmName
import androidx.room.compiler.processing.util.runKspTest
import androidx.room.compiler.processing.util.runProcessorTest
import androidx.room.compiler.processing.util.typeName
@@ -273,7 +273,7 @@
)
runProcessorTest(sources = listOf(src)) { invocation ->
val voidMethod = invocation.processingEnv.requireTypeElement("foo.bar.Baz")
- .getMethod("voidMethod")
+ .getMethodByJvmName("voidMethod")
val returnType = voidMethod.returnType
assertThat(
returnType.typeName
@@ -517,7 +517,7 @@
) { invocation ->
val typeElement = invocation.processingEnv.requireTypeElement("foo.bar.Baz")
- val method = typeElement.getMethod("wildcardMethod")
+ val method = typeElement.getMethodByJvmName("wildcardMethod")
val asMember = method.asMemberOf(typeElement.type)
fun assertParamType(paramType: XType) {
val arg1 = paramType.typeArguments.single()
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 89ff8e0..2f897ca 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
@@ -31,13 +31,13 @@
it.name == name
}
-fun XTypeElement.getDeclaredMethod(name: String) = getDeclaredMethods().firstOrNull {
- it.name == name
-} ?: throw AssertionError("cannot find method with name $name")
+fun XTypeElement.getDeclaredMethodByJvmName(jvmName: String) = getDeclaredMethods().firstOrNull {
+ it.jvmName == jvmName
+} ?: throw AssertionError("cannot find method with name $jvmName")
-fun XTypeElement.getMethod(name: String) = getAllMethods().firstOrNull {
- it.name == name
-} ?: throw AssertionError("cannot find method with name $name")
+fun XTypeElement.getMethodByJvmName(jvmName: String) = getAllMethods().firstOrNull {
+ it.jvmName == jvmName
+} ?: throw AssertionError("cannot find method with jvmName $jvmName")
fun XExecutableElement.getParameter(name: String) = parameters.firstOrNull {
it.name == name
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 38825dd..4f5bc7a 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
@@ -79,13 +79,13 @@
}
val hasEquals = typeElement.getDeclaredMethods().any {
- it.name == "equals" &&
+ it.jvmName == "equals" &&
it.returnType.typeName == TypeName.BOOLEAN &&
it.parameters.count() == 1 &&
it.parameters[0].type.typeName == TypeName.OBJECT
}
val hasHashCode = typeElement.getDeclaredMethods().any {
- it.name == "hashCode" &&
+ it.jvmName == "hashCode" &&
it.returnType.typeName == TypeName.INT &&
it.parameters.count() == 0
}
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 018ffde..c944130 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
@@ -246,7 +246,7 @@
annotatedMethods: List<XMethodElement>
) = unannotatedMethods.mapNotNull { unannotated ->
annotatedMethods.firstOrNull {
- if (it.name != unannotated.name) {
+ if (it.jvmName != unannotated.jvmName) {
return@firstOrNull false
}
if (!it.returnType.boxed().isSameType(unannotated.returnType.boxed())) {
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 082d4c2..8ad1fd4 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
@@ -107,7 +107,7 @@
} else {
val dao = DaoProcessor(context, daoElement, declaredType, dbVerifier)
.process()
- DaoMethod(executable, executable.name, dao)
+ DaoMethod(executable, dao)
}
}.toList()
@@ -331,7 +331,9 @@
daoMethods.groupBy { it.dao.typeName }
.forEach {
if (it.value.size > 1) {
- val error = ProcessorErrors.duplicateDao(it.key, it.value.map { it.name })
+ val error = ProcessorErrors.duplicateDao(it.key,
+ it.value.map { it.element.jvmName }
+ )
it.value.forEach { daoMethod ->
context.logger.e(
daoMethod.element,
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/processor/DeletionMethodProcessor.kt b/room/room-compiler/src/main/kotlin/androidx/room/processor/DeletionMethodProcessor.kt
index 4baac98..2bb3d9f 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/processor/DeletionMethodProcessor.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/processor/DeletionMethodProcessor.kt
@@ -50,7 +50,6 @@
return DeletionMethod(
element = delegate.executableElement,
- name = delegate.executableElement.name,
entities = entities,
parameters = params,
methodBinder = methodBinder
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 2291f87..4b81209 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
@@ -95,7 +95,6 @@
return InsertionMethod(
element = executableElement,
- name = executableElement.name,
returnType = returnType,
entities = entities,
parameters = params,
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/processor/MethodProcessorDelegate.kt b/room/room-compiler/src/main/kotlin/androidx/room/processor/MethodProcessorDelegate.kt
index e7443fb..2301cf4e 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/processor/MethodProcessorDelegate.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/processor/MethodProcessorDelegate.kt
@@ -162,7 +162,7 @@
override fun findTransactionMethodBinder(callType: TransactionMethod.CallType) =
InstantTransactionMethodBinder(
- TransactionMethodAdapter(executableElement.name, callType)
+ TransactionMethodAdapter(executableElement.jvmName, callType)
)
}
@@ -256,7 +256,7 @@
override fun findTransactionMethodBinder(callType: TransactionMethod.CallType) =
CoroutineTransactionMethodBinder(
- adapter = TransactionMethodAdapter(executableElement.name, callType),
+ adapter = TransactionMethodAdapter(executableElement.jvmName, callType),
continuationParamName = continuationParam.name
)
}
\ No newline at end of file
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/processor/PojoMethodProcessor.kt b/room/room-compiler/src/main/kotlin/androidx/room/processor/PojoMethodProcessor.kt
index eb5bc6e..cec9a9d 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/processor/PojoMethodProcessor.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/processor/PojoMethodProcessor.kt
@@ -32,8 +32,7 @@
val asMember = element.asMemberOf(owner)
return PojoMethod(
element = element,
- resolvedType = asMember,
- name = element.name
+ resolvedType = asMember
)
}
}
\ No newline at end of file
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 2fe5d17..5943caa 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
@@ -739,14 +739,14 @@
},
assignFromField = {
field.getter = FieldGetter(
- name = field.name,
+ jvmName = field.name,
type = field.type,
callType = CallType.FIELD
)
},
assignFromMethod = { match ->
field.getter = FieldGetter(
- name = match.name,
+ jvmName = match.element.jvmName,
type = match.resolvedType.returnType,
callType = CallType.METHOD
)
@@ -799,7 +799,7 @@
) {
if (constructor != null && constructor.hasField(field)) {
field.setter = FieldSetter(
- name = field.name,
+ jvmName = field.name,
type = field.type,
callType = CallType.CONSTRUCTOR
)
@@ -814,7 +814,7 @@
},
assignFromField = {
field.setter = FieldSetter(
- name = field.name,
+ jvmName = field.name,
type = field.type,
callType = CallType.FIELD
)
@@ -822,7 +822,7 @@
assignFromMethod = { match ->
val paramType = match.resolvedType.parameterTypes.first()
field.setter = FieldSetter(
- name = match.name,
+ jvmName = match.element.jvmName,
type = paramType,
callType = CallType.METHOD
)
@@ -883,8 +883,8 @@
// b/69164099
field.type.isAssignableFromWithoutVariance(getType(it)) &&
(
- field.nameWithVariations.contains(it.name) ||
- nameVariations.contains(it.name)
+ field.nameWithVariations.contains(it.element.jvmName) ||
+ nameVariations.contains(it.element.jvmName)
)
}
.groupBy {
@@ -917,7 +917,7 @@
return null
}
if (candidates.size > 1) {
- reportAmbiguity(candidates.map { it.name })
+ reportAmbiguity(candidates.map { it.element.jvmName })
}
return candidates.first()
}
@@ -927,7 +927,7 @@
fun onPreProcess(element: XTypeElement)
/**
- * Constructors are XExecutableElement rather than XConstrcutorElement to account for
+ * Constructors are XExecutableElement rather than XConstructorElement to account for
* factory methods.
*/
fun findConstructors(element: XTypeElement): List<XExecutableElement>
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 49c17c2..ab71220 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
@@ -191,7 +191,6 @@
return WriteQueryMethod(
element = executableElement,
query = query,
- name = executableElement.name,
returnType = returnType,
parameters = parameters,
preparedQueryResultBinder = resultBinder
@@ -280,7 +279,6 @@
return ReadQueryMethod(
element = executableElement,
query = query,
- name = executableElement.name,
returnType = returnType,
parameters = parameters,
inTransaction = inTransaction,
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 42fe78b..d2bfc80 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
@@ -71,7 +71,7 @@
val inTransaction = executableElement.hasAnnotation(Transaction::class)
val rawQueryMethod = RawQueryMethod(
element = executableElement,
- name = executableElement.name,
+ name = executableElement.jvmName,
observedTableNames = observedTableNames,
returnType = returnType,
runtimeQueryParam = runtimeQueryParam,
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/processor/ShortcutParameterProcessor.kt b/room/room-compiler/src/main/kotlin/androidx/room/processor/ShortcutParameterProcessor.kt
index 994ddfe..d706e03 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/processor/ShortcutParameterProcessor.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/processor/ShortcutParameterProcessor.kt
@@ -65,7 +65,7 @@
fun extractPojoTypeFromIterator(iterableType: XType): XType {
iterableType.typeElement!!.getAllNonPrivateInstanceMethods().forEach {
- if (it.name == "iterator") {
+ if (it.jvmName == "iterator") {
return it.asMemberOf(iterableType)
.returnType
.typeArguments
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 eba9d79..9156f3b 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
@@ -70,7 +70,6 @@
return UpdateMethod(
element = delegate.executableElement,
- name = delegate.executableElement.name,
entities = entities,
onConflictStrategy = onConflict,
methodBinder = methodBinder,
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/vo/Constructor.kt b/room/room-compiler/src/main/kotlin/androidx/room/vo/Constructor.kt
index 9545f48..566d845 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/vo/Constructor.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/vo/Constructor.kt
@@ -54,7 +54,7 @@
builder.addStatement(
"$L = $T.$L($L)", outVar,
element.enclosingElement.className,
- element.name, args
+ element.jvmName, args
)
}
else -> throw IllegalStateException("Invalid constructor kind ${element.kindName()}")
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/vo/CustomTypeConverter.kt b/room/room-compiler/src/main/kotlin/androidx/room/vo/CustomTypeConverter.kt
index dcbcc90..eaab06c 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/vo/CustomTypeConverter.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/vo/CustomTypeConverter.kt
@@ -34,6 +34,6 @@
val typeName: TypeName by lazy { enclosingClass.typeName }
val fromTypeName: TypeName by lazy { from.typeName }
val toTypeName: TypeName by lazy { to.typeName }
- val methodName by lazy { method.name }
+ val methodName by lazy { method.jvmName }
val isStatic by lazy { method.isStatic() }
}
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/vo/DaoMethod.kt b/room/room-compiler/src/main/kotlin/androidx/room/vo/DaoMethod.kt
index 15119f6..d89e0fd 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/vo/DaoMethod.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/vo/DaoMethod.kt
@@ -21,4 +21,4 @@
/**
* References a method that returns a dao in a Database
*/
-data class DaoMethod(val element: XMethodElement, val name: String, val dao: Dao)
+data class DaoMethod(val element: XMethodElement, val dao: Dao)
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/vo/DeletionMethod.kt b/room/room-compiler/src/main/kotlin/androidx/room/vo/DeletionMethod.kt
index 2217833..0d4dbe9 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/vo/DeletionMethod.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/vo/DeletionMethod.kt
@@ -20,8 +20,7 @@
class DeletionMethod(
element: XMethodElement,
- name: String,
entities: Map<String, ShortcutEntity>,
parameters: List<ShortcutQueryParameter>,
methodBinder: DeleteOrUpdateMethodBinder?
-) : ShortcutMethod(element, name, entities, parameters, methodBinder)
+) : ShortcutMethod(element, entities, parameters, methodBinder)
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/vo/FieldGetter.kt b/room/room-compiler/src/main/kotlin/androidx/room/vo/FieldGetter.kt
index 3257361..ae3ce9c 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/vo/FieldGetter.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/vo/FieldGetter.kt
@@ -21,7 +21,7 @@
import androidx.room.compiler.processing.XType
import com.squareup.javapoet.CodeBlock
-data class FieldGetter(val name: String, val type: XType, val callType: CallType) {
+data class FieldGetter(val jvmName: String, val type: XType, val callType: CallType) {
fun writeGet(ownerVar: String, outVar: String, builder: CodeBlock.Builder) {
val stmt = when (callType) {
CallType.FIELD -> "final $T $L = $L.$L"
@@ -29,7 +29,7 @@
CallType.CONSTRUCTOR -> null
}
stmt?.let {
- builder.addStatement(stmt, type.typeName, outVar, ownerVar, name)
+ builder.addStatement(stmt, type.typeName, outVar, ownerVar, jvmName)
}
}
}
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/vo/FieldSetter.kt b/room/room-compiler/src/main/kotlin/androidx/room/vo/FieldSetter.kt
index afe74d6..01a3ba3 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/vo/FieldSetter.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/vo/FieldSetter.kt
@@ -20,7 +20,7 @@
import androidx.room.compiler.processing.XType
import com.squareup.javapoet.CodeBlock
-data class FieldSetter(val name: String, val type: XType, val callType: CallType) {
+data class FieldSetter(val jvmName: String, val type: XType, val callType: CallType) {
fun writeSet(ownerVar: String, inVar: String, builder: CodeBlock.Builder) {
val stmt = when (callType) {
CallType.FIELD -> "$L.$L = $L"
@@ -28,7 +28,7 @@
CallType.CONSTRUCTOR -> null
}
stmt?.let {
- builder.addStatement(stmt, ownerVar, name, inVar)
+ builder.addStatement(stmt, ownerVar, jvmName, inVar)
}
}
}
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/vo/InsertionMethod.kt b/room/room-compiler/src/main/kotlin/androidx/room/vo/InsertionMethod.kt
index 3eb1fd3..2260329 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/vo/InsertionMethod.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/vo/InsertionMethod.kt
@@ -23,7 +23,6 @@
data class InsertionMethod(
val element: XMethodElement,
- val name: String,
@OnConflictStrategy val onConflict: Int,
val entities: Map<String, ShortcutEntity>,
val returnType: XType,
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/vo/PojoMethod.kt b/room/room-compiler/src/main/kotlin/androidx/room/vo/PojoMethod.kt
index 1361d75..6fcf320 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/vo/PojoMethod.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/vo/PojoMethod.kt
@@ -25,5 +25,4 @@
class PojoMethod(
val element: XMethodElement,
val resolvedType: XMethodType,
- val name: String
)
\ No newline at end of file
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/vo/QueryMethod.kt b/room/room-compiler/src/main/kotlin/androidx/room/vo/QueryMethod.kt
index 222a715..2a87a34 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/vo/QueryMethod.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/vo/QueryMethod.kt
@@ -29,7 +29,6 @@
sealed class QueryMethod(
val element: XMethodElement,
val query: ParsedQuery,
- val name: String,
val returnType: XType,
val parameters: List<QueryParameter>
) {
@@ -58,12 +57,11 @@
class ReadQueryMethod(
element: XMethodElement,
query: ParsedQuery,
- name: String,
returnType: XType,
parameters: List<QueryParameter>,
val inTransaction: Boolean,
val queryResultBinder: QueryResultBinder
-) : QueryMethod(element, query, name, returnType, parameters)
+) : QueryMethod(element, query, returnType, parameters)
/**
* A query method who's query is a INSERT, UPDATE or DELETE statement.
@@ -71,8 +69,7 @@
class WriteQueryMethod(
element: XMethodElement,
query: ParsedQuery,
- name: String,
returnType: XType,
parameters: List<QueryParameter>,
val preparedQueryResultBinder: PreparedQueryResultBinder
-) : QueryMethod(element, query, name, returnType, parameters)
\ No newline at end of file
+) : QueryMethod(element, query, returnType, parameters)
\ No newline at end of file
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/vo/ShortcutMethod.kt b/room/room-compiler/src/main/kotlin/androidx/room/vo/ShortcutMethod.kt
index 6467743..dc4c618 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/vo/ShortcutMethod.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/vo/ShortcutMethod.kt
@@ -24,7 +24,6 @@
*/
abstract class ShortcutMethod(
val element: XMethodElement,
- val name: String,
val entities: Map<String, ShortcutEntity>,
val parameters: List<ShortcutQueryParameter>,
val methodBinder: DeleteOrUpdateMethodBinder?
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/vo/UpdateMethod.kt b/room/room-compiler/src/main/kotlin/androidx/room/vo/UpdateMethod.kt
index 125abb1..28be8f7 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/vo/UpdateMethod.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/vo/UpdateMethod.kt
@@ -22,9 +22,8 @@
class UpdateMethod(
element: XMethodElement,
- name: String,
entities: Map<String, ShortcutEntity>,
parameters: List<ShortcutQueryParameter>,
methodBinder: DeleteOrUpdateMethodBinder?,
@OnConflictStrategy val onConflictStrategy: Int
-) : ShortcutMethod(element, name, entities, parameters, methodBinder)
+) : ShortcutMethod(element, entities, parameters, methodBinder)
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 5b296d9..b51def8 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
@@ -511,7 +511,7 @@
KotlinDefaultMethodDelegateBinder.executeAndReturn(
daoName = dao.typeName,
daoImplName = dao.implTypeName,
- methodName = method.element.name,
+ methodName = method.element.jvmName,
returnType = method.element.returnType,
parameterNames = method.element.parameters.map { it.name },
scope = scope
@@ -532,9 +532,9 @@
}
}
if (method.element.returnType.isVoid()) {
- addStatement("$L($L)", method.element.name, CodeBlock.join(args, ",$W"))
+ addStatement("$L($L)", method.element.jvmName, CodeBlock.join(args, ",$W"))
} else {
- addStatement("return $L($L)", method.element.name, CodeBlock.join(args, ",$W"))
+ addStatement("return $L($L)", method.element.jvmName, CodeBlock.join(args, ",$W"))
}
}.build()
}
@@ -604,7 +604,8 @@
}
class PreparedStatementField(val method: QueryMethod) : SharedFieldSpec(
- "preparedStmtOf${method.name.capitalize(Locale.US)}", RoomTypeNames.SHARED_SQLITE_STMT
+ "preparedStmtOf${method.element.jvmName.capitalize(Locale.US)}",
+ RoomTypeNames.SHARED_SQLITE_STMT
) {
override fun prepare(writer: ClassWriter, builder: FieldSpec.Builder) {
builder.addModifiers(PRIVATE, FINAL)
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/writer/FieldReadWriteWriter.kt b/room/room-compiler/src/main/kotlin/androidx/room/writer/FieldReadWriteWriter.kt
index 31009d9..51719ba 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/writer/FieldReadWriteWriter.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/writer/FieldReadWriteWriter.kt
@@ -319,7 +319,7 @@
val varName = if (field.getter.callType == CallType.FIELD) {
"$ownerVar.${field.name}"
} else {
- "$ownerVar.${field.getter.name}()"
+ "$ownerVar.${field.getter.jvmName}()"
}
binder.bindToStmt(stmtParamVar, indexVar, varName, scope)
}
@@ -338,7 +338,7 @@
when (field.setter.callType) {
CallType.FIELD -> {
reader.readFromCursor(
- "$ownerVar.${field.setter.name}", cursorVar,
+ "$ownerVar.${field.setter.jvmName}", cursorVar,
indexVar, scope
)
}
@@ -348,7 +348,7 @@
)
addStatement("final $T $L", field.setter.type.typeName, tmpField)
reader.readFromCursor(tmpField, cursorVar, indexVar, scope)
- addStatement("$L.$L($L)", ownerVar, field.setter.name, tmpField)
+ addStatement("$L.$L($L)", ownerVar, field.setter.jvmName, tmpField)
}
CallType.CONSTRUCTOR -> {
// no-op
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 4136fcc..afac914 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
@@ -208,7 +208,7 @@
}
val method = element.getDeclaredMethods()
.first {
- it.name == "method"
+ it.jvmName == "method"
}
assertThat(field.type.typeName).isEqualTo(TypeName.INT)
assertThat(method.returnType.typeName).isEqualTo(TypeName.INT)
@@ -261,13 +261,13 @@
private fun XTestInvocation.objectMethodNames(): List<String> {
return processingEnv.requireTypeElement("java.lang.Object")
.getAllMethods().map {
- it.name
+ it.jvmName
}.toList() - "registerNatives"
}
- private fun List<XMethodElement>.names() = map { it.name }
+ private fun List<XMethodElement>.names() = map { it.jvmName }
- private fun Sequence<XMethodElement>.names() = map { it.name }.toList()
+ private fun Sequence<XMethodElement>.names() = map { it.jvmName }.toList()
companion object {
@JvmStatic
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 ddbf0b1..57c1b26 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
@@ -154,7 +154,7 @@
) { dao, _ ->
assertThat(dao.queryMethods.size, `is`(1))
val method = dao.queryMethods.first()
- assertThat(method.name, `is`("getIds"))
+ assertThat(method.element.jvmName, `is`("getIds"))
}
}
@@ -170,7 +170,7 @@
) { dao, _ ->
assertThat(dao.queryMethods.size, `is`(1))
val method = dao.queryMethods.first()
- assertThat(method.name, `is`("getIds"))
+ assertThat(method.element.jvmName, `is`("getIds"))
}
}
@@ -188,10 +188,10 @@
) { dao, _ ->
assertThat(dao.queryMethods.size, `is`(1))
val method = dao.queryMethods.first()
- assertThat(method.name, `is`("getIds"))
+ assertThat(method.element.jvmName, `is`("getIds"))
assertThat(dao.insertionMethods.size, `is`(1))
val insertMethod = dao.insertionMethods.first()
- assertThat(insertMethod.name, `is`("insert"))
+ assertThat(insertMethod.element.jvmName, `is`("insert"))
}
}
@@ -207,7 +207,7 @@
) { dao, _ ->
assertThat(dao.queryMethods.size, `is`(1))
val method = dao.queryMethods.first()
- assertThat(method.name, `is`("getIds"))
+ assertThat(method.element.jvmName, `is`("getIds"))
}
}
@@ -385,7 +385,7 @@
) { dao, _ ->
assertThat(dao.queryMethods.size, `is`(1))
val method = dao.queryMethods.first()
- assertThat(method.name, `is`("deleteAllIds"))
+ assertThat(method.element.jvmName, `is`("deleteAllIds"))
}
}
@@ -401,7 +401,7 @@
) { dao, invocation ->
assertThat(dao.queryMethods.size, `is`(1))
val method = dao.queryMethods.first()
- assertThat(method.name, `is`("getAllIds"))
+ assertThat(method.element.jvmName, `is`("getAllIds"))
invocation.assertCompilationResult {
hasErrorContaining(
ProcessorErrors.cannotFindQueryResultAdapter(TypeName.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 579851f..169bdf9 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
@@ -225,7 +225,7 @@
) { db, _ ->
assertThat(db.daoMethods.size, `is`(2))
assertThat(db.entities.size, `is`(2))
- assertThat(db.daoMethods.map { it.name }, `is`(listOf("userDao", "bookDao")))
+ assertThat(db.daoMethods.map { it.element.jvmName }, `is`(listOf("userDao", "bookDao")))
assertThat(
db.entities.map { it.type.typeName.toString() },
`is`(listOf("foo.bar.User", "foo.bar.Book"))
@@ -825,11 +825,11 @@
USER, USER_DAO
) { db, _ ->
val userDao = db.daoMethods.first().dao
- val insertionMethod = userDao.insertionMethods.find { it.name == "insert" }
+ val insertionMethod = userDao.insertionMethods.find { it.element.jvmName == "insert" }
assertThat(insertionMethod, notNullValue())
val loadOne = userDao.queryMethods
.filterIsInstance<ReadQueryMethod>()
- .find { it.name == "loadOne" }
+ .find { it.element.jvmName == "loadOne" }
assertThat(loadOne, notNullValue())
val adapter = loadOne?.queryResultBinder?.adapter?.rowAdapters?.single()
assertThat("test sanity", adapter, instanceOf(EntityRowAdapter::class.java))
@@ -841,7 +841,7 @@
val withConverter = userDao.queryMethods
.filterIsInstance<ReadQueryMethod>()
- .find { it.name == "loadWithConverter" }
+ .find { it.element.jvmName == "loadWithConverter" }
assertThat(withConverter, notNullValue())
val convAdapter = withConverter?.queryResultBinder?.adapter?.rowAdapters?.single()
assertThat("test sanity", adapter, instanceOf(EntityRowAdapter::class.java))
@@ -870,7 +870,7 @@
val userDao = db.daoMethods.first().dao
val loadOne = userDao.queryMethods
.filterIsInstance<ReadQueryMethod>()
- .find { it.name == "loadOnePojo" }
+ .find { it.element.jvmName == "loadOnePojo" }
assertThat(loadOne, notNullValue())
val adapter = loadOne?.queryResultBinder?.adapter?.rowAdapters?.single()
assertThat("test sanity", adapter, instanceOf(PojoRowAdapter::class.java))
@@ -878,7 +878,7 @@
val loadAll = userDao.queryMethods
.filterIsInstance<ReadQueryMethod>()
- .find { it.name == "loadAllPojos" }
+ .find { it.element.jvmName == "loadAllPojos" }
assertThat(loadAll, notNullValue())
val loadAllAdapter = loadAll?.queryResultBinder?.adapter?.rowAdapters?.single()
assertThat("test sanity", loadAllAdapter, instanceOf(PojoRowAdapter::class.java))
@@ -888,7 +888,7 @@
val withConverter = userDao.queryMethods
.filterIsInstance<ReadQueryMethod>()
- .find { it.name == "loadPojoWithConverter" }
+ .find { it.element.jvmName == "loadPojoWithConverter" }
assertThat(withConverter, notNullValue())
val convAdapter = withConverter?.queryResultBinder?.adapter?.rowAdapters?.single()
assertThat("test sanity", adapter, instanceOf(PojoRowAdapter::class.java))
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/InsertionMethodProcessorTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/InsertionMethodProcessorTest.kt
index 20e7c8c..0a60819 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/InsertionMethodProcessorTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/InsertionMethodProcessorTest.kt
@@ -67,7 +67,7 @@
abstract public void foo();
"""
) { insertion, invocation ->
- assertThat(insertion.name, `is`("foo"))
+ assertThat(insertion.element.jvmName, `is`("foo"))
assertThat(insertion.parameters.size, `is`(0))
assertThat(insertion.returnType.typeName, `is`(TypeName.VOID))
assertThat(insertion.entities.size, `is`(0))
@@ -87,7 +87,7 @@
abstract public long foo(User user);
"""
) { insertion, _ ->
- assertThat(insertion.name, `is`("foo"))
+ assertThat(insertion.element.jvmName, `is`("foo"))
assertThat(insertion.parameters.size, `is`(1))
val param = insertion.parameters.first()
assertThat(param.type.typeName, `is`(USER_TYPE_NAME))
@@ -109,7 +109,7 @@
abstract public void foo(NotAnEntity notValid);
"""
) { insertion, invocation ->
- assertThat(insertion.name, `is`("foo"))
+ assertThat(insertion.element.jvmName, `is`("foo"))
assertThat(insertion.parameters.size, `is`(1))
assertThat(insertion.entities.size, `is`(0))
invocation.assertCompilationResult {
@@ -128,7 +128,7 @@
abstract public void foo(User u1, User u2);
"""
) { insertion, _ ->
- assertThat(insertion.name, `is`("foo"))
+ assertThat(insertion.element.jvmName, `is`("foo"))
assertThat(insertion.parameters.size, `is`(2))
insertion.parameters.forEach {
@@ -151,7 +151,7 @@
abstract public List<Long> insertUsers(List<User> users);
"""
) { insertion, _ ->
- assertThat(insertion.name, `is`("insertUsers"))
+ assertThat(insertion.element.jvmName, `is`("insertUsers"))
assertThat(insertion.parameters.size, `is`(1))
val param = insertion.parameters.first()
assertThat(
@@ -186,7 +186,7 @@
abstract public void insertUsers(User[] users);
"""
) { insertion, _ ->
- assertThat(insertion.name, `is`("insertUsers"))
+ assertThat(insertion.element.jvmName, `is`("insertUsers"))
assertThat(insertion.parameters.size, `is`(1))
val param = insertion.parameters.first()
assertThat(
@@ -209,7 +209,7 @@
abstract public void insertUsers(Set<User> users);
"""
) { insertion, _ ->
- assertThat(insertion.name, `is`("insertUsers"))
+ assertThat(insertion.element.jvmName, `is`("insertUsers"))
assertThat(insertion.parameters.size, `is`(1))
val param = insertion.parameters.first()
assertThat(
@@ -235,7 +235,7 @@
abstract public void insertUsers(Queue<User> users);
"""
) { insertion, _ ->
- assertThat(insertion.name, `is`("insertUsers"))
+ assertThat(insertion.element.jvmName, `is`("insertUsers"))
assertThat(insertion.parameters.size, `is`(1))
val param = insertion.parameters.first()
assertThat(
@@ -261,7 +261,7 @@
abstract public void insert(Iterable<User> users);
"""
) { insertion, _ ->
- assertThat(insertion.name, `is`("insert"))
+ assertThat(insertion.element.jvmName, `is`("insert"))
assertThat(insertion.parameters.size, `is`(1))
val param = insertion.parameters.first()
assertThat(
@@ -288,7 +288,7 @@
abstract public void insert(MyList<String, User> users);
"""
) { insertion, _ ->
- assertThat(insertion.name, `is`("insert"))
+ assertThat(insertion.element.jvmName, `is`("insert"))
assertThat(insertion.parameters.size, `is`(1))
val param = insertion.parameters.first()
assertThat(
@@ -572,7 +572,7 @@
""",
additionalSources = listOf(usernameSource)
) { insertion, _ ->
- assertThat(insertion.name, `is`("foo"))
+ assertThat(insertion.element.jvmName, `is`("foo"))
assertThat(insertion.parameters.size, `is`(1))
val param = insertion.parameters.first()
assertThat(param.type.typeName, `is`(USERNAME_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 98f36d2..0223913 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
@@ -108,7 +108,7 @@
abstract public int[] foo();
"""
) { parsedQuery, _ ->
- assertThat(parsedQuery.name, `is`("foo"))
+ assertThat(parsedQuery.element.jvmName, `is`("foo"))
assertThat(parsedQuery.parameters.size, `is`(0))
assertThat(
parsedQuery.returnType.typeName,
@@ -125,7 +125,7 @@
abstract public long foo(int x);
"""
) { parsedQuery, invocation ->
- assertThat(parsedQuery.name, `is`("foo"))
+ assertThat(parsedQuery.element.jvmName, `is`("foo"))
assertThat(parsedQuery.returnType.typeName, `is`(TypeName.LONG))
assertThat(parsedQuery.parameters.size, `is`(1))
val param = parsedQuery.parameters.first()
@@ -146,7 +146,7 @@
abstract public long foo(int... ids);
"""
) { parsedQuery, _ ->
- assertThat(parsedQuery.name, `is`("foo"))
+ assertThat(parsedQuery.element.jvmName, `is`("foo"))
assertThat(parsedQuery.returnType.typeName, `is`(TypeName.LONG))
assertThat(parsedQuery.parameters.size, `is`(1))
val param = parsedQuery.parameters.first()
@@ -465,7 +465,7 @@
abstract public int foo(int id);
"""
) { parsedQuery, _ ->
- assertThat(parsedQuery.name, `is`("foo"))
+ assertThat(parsedQuery.element.jvmName, `is`("foo"))
assertThat(parsedQuery.parameters.size, `is`(1))
assertThat(parsedQuery.returnType.typeName, `is`(TypeName.INT))
}
@@ -479,7 +479,7 @@
abstract public void foo(int id);
"""
) { parsedQuery, _ ->
- assertThat(parsedQuery.name, `is`("foo"))
+ assertThat(parsedQuery.element.jvmName, `is`("foo"))
assertThat(parsedQuery.parameters.size, `is`(1))
assertThat(parsedQuery.returnType.typeName, `is`(TypeName.VOID))
}
@@ -493,7 +493,7 @@
abstract public void updateAllNames(String name);
"""
) { parsedQuery, invocation ->
- assertThat(parsedQuery.name, `is`("updateAllNames"))
+ assertThat(parsedQuery.element.jvmName, `is`("updateAllNames"))
assertThat(parsedQuery.parameters.size, `is`(1))
assertThat(parsedQuery.returnType.typeName, `is`(TypeName.VOID))
assertThat(
@@ -511,7 +511,7 @@
abstract public void insertUsername(String name);
"""
) { parsedQuery, invocation ->
- assertThat(parsedQuery.name, `is`("insertUsername"))
+ assertThat(parsedQuery.element.jvmName, `is`("insertUsername"))
assertThat(parsedQuery.parameters.size, `is`(1))
assertThat(parsedQuery.returnType.typeName, `is`(TypeName.VOID))
assertThat(
@@ -529,7 +529,7 @@
abstract public long insertUsername(String name);
"""
) { parsedQuery, invocation ->
- assertThat(parsedQuery.name, `is`("insertUsername"))
+ assertThat(parsedQuery.element.jvmName, `is`("insertUsername"))
assertThat(parsedQuery.parameters.size, `is`(1))
assertThat(parsedQuery.returnType.typeName, `is`(TypeName.LONG))
assertThat(
@@ -774,7 +774,7 @@
abstract public int[] foo();
"""
) { parsedQuery, _ ->
- assertThat(parsedQuery.name, `is`("foo"))
+ assertThat(parsedQuery.element.jvmName, `is`("foo"))
assertThat(parsedQuery.parameters.size, `is`(0))
assertThat(
parsedQuery.returnType.typeName,
@@ -792,7 +792,7 @@
abstract NotAnEntity getPojo();
"""
) { parsedQuery, _ ->
- assertThat(parsedQuery.name, `is`("getPojo"))
+ assertThat(parsedQuery.element.jvmName, `is`("getPojo"))
assertThat(parsedQuery.parameters.size, `is`(0))
assertThat(
parsedQuery.returnType.typeName,
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/ShortcutMethodProcessorTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/ShortcutMethodProcessorTest.kt
index 2a7cd02..72e4704 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/ShortcutMethodProcessorTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/ShortcutMethodProcessorTest.kt
@@ -67,7 +67,7 @@
abstract public void foo();
"""
) { shortcut, invocation ->
- assertThat(shortcut.name, `is`("foo"))
+ assertThat(shortcut.element.jvmName, `is`("foo"))
assertThat(shortcut.parameters.size, `is`(0))
invocation.assertCompilationResult {
hasErrorContaining(noParamsError())
@@ -85,7 +85,7 @@
abstract public int foo(User user);
"""
) { shortcut, _ ->
- assertThat(shortcut.name, `is`("foo"))
+ 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))
@@ -104,7 +104,7 @@
abstract public void foo(NotAnEntity notValid);
"""
) { shortcut, invocation ->
- assertThat(shortcut.name, `is`("foo"))
+ assertThat(shortcut.element.jvmName, `is`("foo"))
assertThat(shortcut.parameters.size, `is`(1))
assertThat(shortcut.entities.size, `is`(0))
invocation.assertCompilationResult {
@@ -123,7 +123,7 @@
abstract public void foo(User u1, User u2);
"""
) { shortcut, _ ->
- assertThat(shortcut.name, `is`("foo"))
+ assertThat(shortcut.element.jvmName, `is`("foo"))
assertThat(shortcut.parameters.size, `is`(2))
shortcut.parameters.forEach {
@@ -159,7 +159,7 @@
abstract public $type users(List<User> users);
"""
) { shortcut, _ ->
- assertThat(shortcut.name, `is`("users"))
+ assertThat(shortcut.element.jvmName, `is`("users"))
assertThat(shortcut.parameters.size, `is`(1))
val param = shortcut.parameters.first()
assertThat(
@@ -185,7 +185,7 @@
abstract public void users(User[] users);
"""
) { shortcut, _ ->
- assertThat(shortcut.name, `is`("users"))
+ assertThat(shortcut.element.jvmName, `is`("users"))
assertThat(shortcut.parameters.size, `is`(1))
val param = shortcut.parameters.first()
assertThat(
@@ -207,7 +207,7 @@
abstract public void modifyUsers(Set<User> users);
"""
) { shortcut, _ ->
- assertThat(shortcut.name, `is`("modifyUsers"))
+ assertThat(shortcut.element.jvmName, `is`("modifyUsers"))
assertThat(shortcut.parameters.size, `is`(1))
val param = shortcut.parameters.first()
assertThat(
@@ -232,7 +232,7 @@
abstract public void modifyUsers(Iterable<User> users);
"""
) { shortcut, _ ->
- assertThat(shortcut.name, `is`("modifyUsers"))
+ assertThat(shortcut.element.jvmName, `is`("modifyUsers"))
assertThat(shortcut.parameters.size, `is`(1))
val param = shortcut.parameters.first()
assertThat(
@@ -258,7 +258,7 @@
abstract public void modifyUsers(MyList<String, User> users);
"""
) { shortcut, _ ->
- assertThat(shortcut.name, `is`("modifyUsers"))
+ assertThat(shortcut.element.jvmName, `is`("modifyUsers"))
assertThat(shortcut.parameters.size, `is`(1))
val param = shortcut.parameters.first()
assertThat(
@@ -362,7 +362,7 @@
""",
additionalSources = listOf(usernameSource)
) { shortcut, _ ->
- assertThat(shortcut.name, `is`("foo"))
+ assertThat(shortcut.element.jvmName, `is`("foo"))
assertThat(shortcut.parameters.size, `is`(1))
val param = shortcut.parameters.first()
assertThat(param.type.typeName, `is`(USERNAME_TYPE_NAME))
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 5ab5113..235d729 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
@@ -358,7 +358,7 @@
@Ignore public int id(){ return id; }
"""
) { entity, _ ->
- assertThat(entity.fields.first().getter.name, `is`("getId"))
+ assertThat(entity.fields.first().getter.jvmName, `is`("getId"))
}
}
@@ -373,7 +373,7 @@
protected int id(){ return id; }
"""
) { entity, _ ->
- assertThat(entity.fields.first().getter.name, `is`("getId"))
+ assertThat(entity.fields.first().getter.jvmName, `is`("getId"))
}
}
@@ -387,7 +387,7 @@
public int getId(){ return id; }
"""
) { entity, _ ->
- assertThat(entity.fields.first().getter.name, `is`("id"))
+ assertThat(entity.fields.first().getter.jvmName, `is`("id"))
assertThat(entity.fields.first().getter.callType, `is`(CallType.FIELD))
}
}
@@ -420,7 +420,7 @@
public int getId(){ return id; }
"""
) { entity, _ ->
- assertThat(entity.fields.first().setter.name, `is`("setId"))
+ assertThat(entity.fields.first().setter.jvmName, `is`("setId"))
}
}
@@ -435,7 +435,7 @@
public int getId(){ return id; }
"""
) { entity, _ ->
- assertThat(entity.fields.first().setter.name, `is`("setId"))
+ assertThat(entity.fields.first().setter.jvmName, `is`("setId"))
}
}
@@ -449,7 +449,7 @@
public int getId(){ return id; }
"""
) { entity, _ ->
- assertThat(entity.fields.first().setter.name, `is`("id"))
+ assertThat(entity.fields.first().setter.jvmName, `is`("id"))
assertThat(entity.fields.first().setter.callType, `is`(CallType.FIELD))
}
}
@@ -464,8 +464,8 @@
public int getId(){ return id; }
"""
) { entity, _ ->
- assertThat(entity.fields.first().setter.name, `is`("setId"))
- assertThat(entity.fields.first().getter.name, `is`("getId"))
+ assertThat(entity.fields.first().setter.jvmName, `is`("setId"))
+ assertThat(entity.fields.first().getter.jvmName, `is`("getId"))
}
}
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/TransactionMethodProcessorTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/TransactionMethodProcessorTest.kt
index 104394f..1dc88b9 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/TransactionMethodProcessorTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/TransactionMethodProcessorTest.kt
@@ -56,7 +56,7 @@
public String doInTransaction(int param) { return null; }
"""
) { transaction, _ ->
- assertThat(transaction.name, `is`("doInTransaction"))
+ assertThat(transaction.jvmName, `is`("doInTransaction"))
}
}
@@ -68,7 +68,7 @@
private String doInTransaction(int param) { return null; }
"""
) { transaction, invocation ->
- assertThat(transaction.name, `is`("doInTransaction"))
+ assertThat(transaction.jvmName, `is`("doInTransaction"))
invocation.assertCompilationResult {
hasErrorContaining(
ProcessorErrors.TRANSACTION_METHOD_MODIFIERS
@@ -85,7 +85,7 @@
public final String doInTransaction(int param) { return null; }
"""
) { transaction, invocation ->
- assertThat(transaction.name, `is`("doInTransaction"))
+ assertThat(transaction.jvmName, `is`("doInTransaction"))
invocation.assertCompilationResult {
hasErrorContaining(ProcessorErrors.TRANSACTION_METHOD_MODIFIERS)
}
@@ -102,7 +102,7 @@
}
"""
) { transaction, invocation ->
- assertThat(transaction.name, `is`("doInTransaction"))
+ assertThat(transaction.jvmName, `is`("doInTransaction"))
invocation.assertCompilationResult {
hasErrorContaining(
ProcessorErrors.transactionMethodAsync(
@@ -121,7 +121,7 @@
public LiveData<String> doInTransaction(int param) { return null; }
"""
) { transaction, invocation ->
- assertThat(transaction.name, `is`("doInTransaction"))
+ assertThat(transaction.jvmName, `is`("doInTransaction"))
invocation.assertCompilationResult {
hasErrorContaining(
ProcessorErrors.transactionMethodAsync(
@@ -140,7 +140,7 @@
public io.reactivex.Flowable<String> doInTransaction(int param) { return null; }
"""
) { transaction, invocation ->
- assertThat(transaction.name, `is`("doInTransaction"))
+ assertThat(transaction.jvmName, `is`("doInTransaction"))
invocation.assertCompilationResult {
hasErrorContaining(
ProcessorErrors.transactionMethodAsync(
@@ -161,7 +161,7 @@
}
"""
) { transaction, invocation ->
- assertThat(transaction.name, `is`("doInTransaction"))
+ assertThat(transaction.jvmName, `is`("doInTransaction"))
invocation.assertCompilationResult {
hasErrorContaining(
ProcessorErrors.transactionMethodAsync(
@@ -180,7 +180,7 @@
public io.reactivex.Completable doInTransaction(int param) { return null; }
"""
) { transaction, invocation ->
- assertThat(transaction.name, `is`("doInTransaction"))
+ assertThat(transaction.jvmName, `is`("doInTransaction"))
invocation.assertCompilationResult {
hasErrorContaining(
ProcessorErrors.transactionMethodAsync(
@@ -201,7 +201,7 @@
}
"""
) { transaction, invocation ->
- assertThat(transaction.name, `is`("doInTransaction"))
+ assertThat(transaction.jvmName, `is`("doInTransaction"))
invocation.assertCompilationResult {
hasErrorContaining(
ProcessorErrors.transactionMethodAsync(
@@ -220,7 +220,7 @@
public io.reactivex.Single<String> doInTransaction(int param) { return null; }
"""
) { transaction, invocation ->
- assertThat(transaction.name, `is`("doInTransaction"))
+ assertThat(transaction.jvmName, `is`("doInTransaction"))
invocation.assertCompilationResult {
hasErrorContaining(
ProcessorErrors.transactionMethodAsync(
@@ -241,7 +241,7 @@
}
"""
) { transaction, invocation ->
- assertThat(transaction.name, `is`("doInTransaction"))
+ assertThat(transaction.jvmName, `is`("doInTransaction"))
invocation.assertCompilationResult {
hasErrorContaining(
ProcessorErrors.transactionMethodAsync(
@@ -260,7 +260,7 @@
public ListenableFuture<String> doInTransaction(int param) { return null; }
"""
) { transaction, invocation ->
- assertThat(transaction.name, `is`("doInTransaction"))
+ assertThat(transaction.jvmName, `is`("doInTransaction"))
invocation.assertCompilationResult {
hasErrorContaining(
ProcessorErrors.transactionMethodAsync(
@@ -271,8 +271,8 @@
}
}
- private val TransactionMethod.name: String
- get() = element.name
+ private val TransactionMethod.jvmName: String
+ get() = element.jvmName
private fun singleTransactionMethod(
vararg input: String,