Skip to content

Commit

Permalink
Test @JvmName on annotation property getters
Browse files Browse the repository at this point in the history
(cherry picked from commit c11ac8d)
  • Loading branch information
kuanyingchou authored and KSP Auto Pick committed Oct 18, 2024
1 parent d2b8f11 commit 057675d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
15 changes: 12 additions & 3 deletions kotlin-analysis-api/testData/jvmName.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,32 @@
// (getX, setX), (getY, null)
// stringParameter
// stringParameter
// stringParameter
// JvmName: stringParameter
// JvmName: stringParameter
// END
// MODULE: lib
// FILE: Lib.kt
data class TestLibDataClass(var x: Int, val y: String)
// FILE: MyAnnotation.kt
annotation class MyAnnotation(
// FILE: MyAnnotationLib.kt
annotation class MyAnnotationLib(
@get:JvmName("stringParameter")
val stringParam: String
)
// FILE: MyAnnotationUserLib.java
@MyAnnotation(stringParameter = "foo")
@MyAnnotationLib(stringParameter = "foo")
class MyAnnotationUserLib {}

// MODULE: main(lib)
// FILE: MyAnnotation.kt
annotation class MyAnnotation(
@get:JvmName("stringParameter")
val stringParam: String
)
// FILE: K.kt
data class TestDataClass(var x: Int, val y: String)
// FILE: MyAnnotationUser.java
@MyAnnotationLib(stringParameter = "foo")
@MyAnnotation(stringParameter = "foo")
class MyAnnotationUser {}

Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,18 @@ class JvmNameProcessor : AbstractTestProcessor() {
}
listOf("MyAnnotationUser", "MyAnnotationUserLib").forEach { clsName ->
resolver.getClassDeclarationByName(clsName)!!.let { cls ->
cls.annotations.single().let { annotation ->
cls.annotations.forEach { annotation ->
results.add(annotation.arguments.joinToString { it.name!!.asString() })
}
}
}
listOf("MyAnnotation", "MyAnnotationLib").forEach { clsName ->
resolver.getClassDeclarationByName(clsName)!!.getAllProperties().forEach { p ->
p.getter?.let {
results.add("JvmName: ${resolver.getJvmName(it)}")
}
}
}
return emptyList()
}
}
15 changes: 12 additions & 3 deletions test-utils/testData/api/jvmName.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,32 @@
// (getX, setX), (getY, null)
// stringParameter
// stringParameter
// stringParameter
// JvmName: stringParameter
// JvmName: stringParameter
// END
// MODULE: lib
// FILE: Lib.kt
data class TestLibDataClass(var x: Int, val y: String)
// FILE: MyAnnotation.kt
annotation class MyAnnotation(
// FILE: MyAnnotationLib.kt
annotation class MyAnnotationLib(
@get:JvmName("stringParameter")
val stringParam: String
)
// FILE: MyAnnotationUserLib.java
@MyAnnotation(stringParameter = "foo")
@MyAnnotationLib(stringParameter = "foo")
class MyAnnotationUserLib {}

// MODULE: main(lib)
// FILE: K.kt
// FILE: MyAnnotation.kt
annotation class MyAnnotation(
@get:JvmName("stringParameter")
val stringParam: String
)
data class TestDataClass(var x: Int, val y: String)
// FILE: MyAnnotationUser.java
@MyAnnotationLib(stringParameter = "foo")
@MyAnnotation(stringParameter = "foo")
class MyAnnotationUser {}

0 comments on commit 057675d

Please sign in to comment.