From 2ce1abc3702374d37b3feb2ca960f9dd2d102fe0 Mon Sep 17 00:00:00 2001 From: Jon Amireh Date: Thu, 31 Oct 2024 10:46:16 -0700 Subject: [PATCH 1/4] Check for properties starting with 'is' --- .../com/google/devtools/ksp/impl/ResolverAAImpl.kt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) 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..3dfaa123be 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 From 60ac796db804744244c6f7fdec2398b021261993 Mon Sep 17 00:00:00 2001 From: Jon Amireh Date: Thu, 31 Oct 2024 12:12:56 -0700 Subject: [PATCH 2/4] Add tests --- .../com/google/devtools/ksp/test/AbstractKSPTest.kt | 4 ++++ kotlin-analysis-api/testData/jvmName.kt | 10 +++++----- test-utils/testData/api/jvmName.kt | 8 ++++---- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/kotlin-analysis-api/src/test/kotlin/com/google/devtools/ksp/test/AbstractKSPTest.kt b/kotlin-analysis-api/src/test/kotlin/com/google/devtools/ksp/test/AbstractKSPTest.kt index 826f5eff8c..f9f3592151 100644 --- a/kotlin-analysis-api/src/test/kotlin/com/google/devtools/ksp/test/AbstractKSPTest.kt +++ b/kotlin-analysis-api/src/test/kotlin/com/google/devtools/ksp/test/AbstractKSPTest.kt @@ -227,6 +227,10 @@ abstract class AbstractKSPTest(frontend: FrontendKind<*>) : DisposableTest() { .map { it.substring(3).trim() } val results = runTest(testServices, mainModule, libModules, testProcessor) + val expected = expectedResults.joinToString("\n") + val actual = results.joinToString("\n") + println(expected) + println(actual) Assertions.assertEquals(expectedResults.joinToString("\n"), results.joinToString("\n")) } } 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") From d0a64d7340e3844a0a19c900fa41a5f3a3a34a13 Mon Sep 17 00:00:00 2001 From: Jon Amireh Date: Thu, 31 Oct 2024 12:13:36 -0700 Subject: [PATCH 3/4] Revert unnecessary change --- .../kotlin/com/google/devtools/ksp/test/AbstractKSPTest.kt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/kotlin-analysis-api/src/test/kotlin/com/google/devtools/ksp/test/AbstractKSPTest.kt b/kotlin-analysis-api/src/test/kotlin/com/google/devtools/ksp/test/AbstractKSPTest.kt index f9f3592151..826f5eff8c 100644 --- a/kotlin-analysis-api/src/test/kotlin/com/google/devtools/ksp/test/AbstractKSPTest.kt +++ b/kotlin-analysis-api/src/test/kotlin/com/google/devtools/ksp/test/AbstractKSPTest.kt @@ -227,10 +227,6 @@ abstract class AbstractKSPTest(frontend: FrontendKind<*>) : DisposableTest() { .map { it.substring(3).trim() } val results = runTest(testServices, mainModule, libModules, testProcessor) - val expected = expectedResults.joinToString("\n") - val actual = results.joinToString("\n") - println(expected) - println(actual) Assertions.assertEquals(expectedResults.joinToString("\n"), results.joinToString("\n")) } } From d67f83040e2d27fbb31da5b4b8b4aa7e8a10528c Mon Sep 17 00:00:00 2001 From: Jon Amireh Date: Fri, 1 Nov 2024 09:09:53 -0700 Subject: [PATCH 4/4] Lint --- .../kotlin/com/google/devtools/ksp/impl/ResolverAAImpl.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 3dfaa123be..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 @@ -461,9 +461,9 @@ class ResolverAAImpl( 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" + 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 -> "" }