Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle JvmName in annotation classes #2151

Merged
merged 2 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -469,10 +469,6 @@ class ResolverAAImpl(

// TODO: handle library symbols
override fun getJvmName(accessor: KSPropertyAccessor): String {
if (accessor.receiver.closestClassDeclaration()?.classKind == ClassKind.ANNOTATION_CLASS) {
return accessor.receiver.simpleName.asString()
}

val symbol: KaPropertyAccessorSymbol? = when (accessor) {
is KSPropertyAccessorImpl -> accessor.ktPropertyAccessorSymbol
else -> null
Expand All @@ -482,6 +478,10 @@ class ResolverAAImpl(
return it
}

if (accessor.receiver.closestClassDeclaration()?.classKind == ClassKind.ANNOTATION_CLASS) {
return accessor.receiver.simpleName.asString()
}

val prefix = if (accessor is KSPropertyGetter) {
"get"
} else {
Expand Down
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 {}

Loading