Follow-up tests for aosp/1798027
Bug: 194706278
Test: XExecutableElementTest
Change-Id: I83f1c91817374c3cc3aac7d70b8e5e4a6c6d2358
diff --git a/room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/dao/BooksDao.kt b/room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/dao/BooksDao.kt
index 49ee2911..7842512 100644
--- a/room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/dao/BooksDao.kt
+++ b/room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/dao/BooksDao.kt
@@ -433,4 +433,7 @@
}
suspend fun concreteSuspendFunctionWithParams(num: Int, text: String) = "$num - $text"
+
+ // This is a private method to validate b/194706278
+ private fun getNullAuthor(): Author? = null
}
diff --git a/room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/dao/DerivedDao.kt b/room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/dao/DerivedDao.kt
index c9a874b..7084bfc 100644
--- a/room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/dao/DerivedDao.kt
+++ b/room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/dao/DerivedDao.kt
@@ -25,7 +25,4 @@
@Query("SELECT * FROM author WHERE authorId = :authorId")
fun getAuthor(authorId: String): Author
-
- // This is a private method to validate b/194706278
- private fun getNullAuthor(): Author? = null
}
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 fd7b102..26ad213 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
@@ -68,8 +68,8 @@
override fun hasKotlinDefaultImpl(): Boolean {
val parentDeclaration = declaration.parentDeclaration
- // if parent declaration is an interface and we are not marked as an abstract method,
- // we should have a default implementation
+ // if parent declaration is an interface and we are not marked as an abstract method nor
+ // we are a private function, then we should have a default implementation
return parentDeclaration is KSClassDeclaration &&
parentDeclaration.classKind == ClassKind.INTERFACE &&
!declaration.isAbstract &&
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 027a529..1c8c910 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
@@ -128,26 +128,29 @@
val subject = Source.kotlin(
"Baz.kt",
"""
- package foo.bar;
- import java.util.List;
+ package foo.bar
+
interface Baz {
fun noDefault()
fun withDefault(): Int {
- return 3;
+ return 3
}
fun nameMatch()
fun nameMatch(param:Int) {}
fun withDefaultWithParams(param1:Int, param2:String) {}
fun withDefaultWithTypeArgs(param1: List<String>): String {
- return param1.first();
+ return param1.first()
+ }
+ private fun privateWithDefault(): String {
+ return ""
}
}
""".trimIndent()
)
runProcessorTest(
sources = listOf(subject)
- ) {
- val element = it.processingEnv.requireTypeElement("foo.bar.Baz")
+ ) { invocation ->
+ val element = invocation.processingEnv.requireTypeElement("foo.bar.Baz")
element.getDeclaredMethod("noDefault").let { method ->
assertThat(method.hasKotlinDefaultImpl()).isFalse()
}
@@ -173,6 +176,12 @@
element.getDeclaredMethod("withDefaultWithTypeArgs").let { method ->
assertThat(method.hasKotlinDefaultImpl()).isTrue()
}
+ // private functions in interfaces don't appear in kapt stubs
+ if (invocation.isKsp) {
+ element.getDeclaredMethod("privateWithDefault").let { method ->
+ assertThat(method.hasKotlinDefaultImpl()).isFalse()
+ }
+ }
}
}