diff --git a/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/ResolverAAImpl.kt b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/ResolverAAImpl.kt index 344050f455..f78a84577c 100644 --- a/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/ResolverAAImpl.kt +++ b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/ResolverAAImpl.kt @@ -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 diff --git a/kotlin-analysis-api/testData/jvmName.kt b/kotlin-analysis-api/testData/jvmName.kt index 591684d550..1f05af27fc 100644 --- a/kotlin-analysis-api/testData/jvmName.kt +++ b/kotlin-analysis-api/testData/jvmName.kt @@ -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 @@ -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") @@ -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") diff --git a/test-utils/testData/api/jvmName.kt b/test-utils/testData/api/jvmName.kt index 7fab74a5f6..4393e29a47 100644 --- a/test-utils/testData/api/jvmName.kt +++ b/test-utils/testData/api/jvmName.kt @@ -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 @@ -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") @@ -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")