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

Fix JVM names for properties starting with 'is' #2185

Merged
merged 4 commits into from
Nov 1, 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 @@ -458,16 +458,18 @@ class ResolverAAImpl(
return accessor.receiver.simpleName.asString()
}

val prefix = if (accessor is KSPropertyGetter) {
"get"
} else {
"set"
val name = accessor.receiver.simpleName.asString()
val uppercasedName = name.replaceFirstChar(Char::uppercaseChar)
// https://kotlinlang.org/docs/java-to-kotlin-interop.html#properties
val prefixedName = when (accessor) {
is KSPropertyGetter -> if (name.startsWith("is")) name else "get$uppercasedName"
is KSPropertySetter -> if (name.startsWith("is")) "set${name.removePrefix("is")}" else "set$uppercasedName"
else -> ""
}

val name = accessor.receiver.simpleName.asString().replaceFirstChar(Char::uppercaseChar)
val inlineSuffix = symbol?.inlineSuffix ?: ""
val mangledName = symbol?.internalSuffix ?: ""
return "$prefix$name$inlineSuffix$mangledName"
return "$prefixedName$inlineSuffix$mangledName"
}

// TODO: handle library symbols
Expand Down
10 changes: 5 additions & 5 deletions kotlin-analysis-api/testData/jvmName.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// TEST PROCESSOR: JvmNameProcessor
// EXPECTED:
// (getX, setX), (getY, null)
// (getX, setX), (getY, null)
// (getX, setX), (getY, null), (isOpen, setOpen)
// (getX, setX), (getY, null), (isOpen, setOpen)
// stringParameter
// stringParameter
// stringParameter
Expand All @@ -10,7 +10,7 @@
// END
// MODULE: lib
// FILE: Lib.kt
data class TestLibDataClass(var x: Int, val y: String)
data class TestLibDataClass(var x: Int, val y: String, var isOpen: String)
// FILE: MyAnnotationLib.kt
annotation class MyAnnotationLib(
@get:JvmName("stringParameter")
Expand All @@ -21,13 +21,13 @@ annotation class MyAnnotationLib(
class MyAnnotationUserLib {}

// MODULE: main(lib)
// FILE: K.kt
// FILE: MyAnnotation.kt
annotation class MyAnnotation(
@get:JvmName("stringParameter")
val stringParam: String
)
// FILE: K.kt
data class TestDataClass(var x: Int, val y: String)
data class TestDataClass(var x: Int, val y: String, var isOpen: String)
// FILE: MyAnnotationUser.java
@MyAnnotationLib(stringParameter = "foo")
@MyAnnotation(stringParameter = "foo")
Expand Down
8 changes: 4 additions & 4 deletions test-utils/testData/api/jvmName.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// TEST PROCESSOR: JvmNameProcessor
// EXPECTED:
// (getX, setX), (getY, null)
// (getX, setX), (getY, null)
// (getX, setX), (getY, null), (isOpen, setOpen)
// (isOpen, setOpen), (getX, setX), (getY, null)
// stringParameter
// stringParameter
// stringParameter
Expand All @@ -10,7 +10,7 @@
// END
// MODULE: lib
// FILE: Lib.kt
data class TestLibDataClass(var x: Int, val y: String)
data class TestLibDataClass(var x: Int, val y: String, var isOpen: String)
// FILE: MyAnnotationLib.kt
annotation class MyAnnotationLib(
@get:JvmName("stringParameter")
Expand All @@ -27,7 +27,7 @@ annotation class MyAnnotation(
@get:JvmName("stringParameter")
val stringParam: String
)
data class TestDataClass(var x: Int, val y: String)
data class TestDataClass(var x: Int, val y: String, var isOpen: String)
// FILE: MyAnnotationUser.java
@MyAnnotationLib(stringParameter = "foo")
@MyAnnotation(stringParameter = "foo")
Expand Down
Loading