Skip to content

Commit 057675d

Browse files
kuanyingchouKSP Auto Pick
authored andcommitted
Test @JvmName on annotation property getters
(cherry picked from commit c11ac8d)
1 parent d2b8f11 commit 057675d

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

kotlin-analysis-api/testData/jvmName.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,32 @@
44
// (getX, setX), (getY, null)
55
// stringParameter
66
// stringParameter
7+
// stringParameter
8+
// JvmName: stringParameter
9+
// JvmName: stringParameter
710
// END
811
// MODULE: lib
912
// FILE: Lib.kt
1013
data class TestLibDataClass(var x: Int, val y: String)
11-
// FILE: MyAnnotation.kt
12-
annotation class MyAnnotation(
14+
// FILE: MyAnnotationLib.kt
15+
annotation class MyAnnotationLib(
1316
@get:JvmName("stringParameter")
1417
val stringParam: String
1518
)
1619
// FILE: MyAnnotationUserLib.java
17-
@MyAnnotation(stringParameter = "foo")
20+
@MyAnnotationLib(stringParameter = "foo")
1821
class MyAnnotationUserLib {}
1922

2023
// MODULE: main(lib)
24+
// FILE: MyAnnotation.kt
25+
annotation class MyAnnotation(
26+
@get:JvmName("stringParameter")
27+
val stringParam: String
28+
)
2129
// FILE: K.kt
2230
data class TestDataClass(var x: Int, val y: String)
2331
// FILE: MyAnnotationUser.java
32+
@MyAnnotationLib(stringParameter = "foo")
2433
@MyAnnotation(stringParameter = "foo")
2534
class MyAnnotationUser {}
2635

test-utils/src/main/kotlin/com/google/devtools/ksp/processor/JvmNameProcessor.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,18 @@ class JvmNameProcessor : AbstractTestProcessor() {
2525
}
2626
listOf("MyAnnotationUser", "MyAnnotationUserLib").forEach { clsName ->
2727
resolver.getClassDeclarationByName(clsName)!!.let { cls ->
28-
cls.annotations.single().let { annotation ->
28+
cls.annotations.forEach { annotation ->
2929
results.add(annotation.arguments.joinToString { it.name!!.asString() })
3030
}
3131
}
3232
}
33+
listOf("MyAnnotation", "MyAnnotationLib").forEach { clsName ->
34+
resolver.getClassDeclarationByName(clsName)!!.getAllProperties().forEach { p ->
35+
p.getter?.let {
36+
results.add("JvmName: ${resolver.getJvmName(it)}")
37+
}
38+
}
39+
}
3340
return emptyList()
3441
}
3542
}

test-utils/testData/api/jvmName.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,32 @@
44
// (getX, setX), (getY, null)
55
// stringParameter
66
// stringParameter
7+
// stringParameter
8+
// JvmName: stringParameter
9+
// JvmName: stringParameter
710
// END
811
// MODULE: lib
912
// FILE: Lib.kt
1013
data class TestLibDataClass(var x: Int, val y: String)
11-
// FILE: MyAnnotation.kt
12-
annotation class MyAnnotation(
14+
// FILE: MyAnnotationLib.kt
15+
annotation class MyAnnotationLib(
1316
@get:JvmName("stringParameter")
1417
val stringParam: String
1518
)
1619
// FILE: MyAnnotationUserLib.java
17-
@MyAnnotation(stringParameter = "foo")
20+
@MyAnnotationLib(stringParameter = "foo")
1821
class MyAnnotationUserLib {}
1922

2023
// MODULE: main(lib)
2124
// FILE: K.kt
25+
// FILE: MyAnnotation.kt
26+
annotation class MyAnnotation(
27+
@get:JvmName("stringParameter")
28+
val stringParam: String
29+
)
2230
data class TestDataClass(var x: Int, val y: String)
2331
// FILE: MyAnnotationUser.java
32+
@MyAnnotationLib(stringParameter = "foo")
2433
@MyAnnotation(stringParameter = "foo")
2534
class MyAnnotationUser {}
2635

0 commit comments

Comments
 (0)