From f22c4ff5c2bdea4621753acf567c89de5b3c5c2a Mon Sep 17 00:00:00 2001 From: Jiaxiang Chen Date: Tue, 11 Jun 2024 22:57:30 -0700 Subject: [PATCH] include synthetic accessors for checked exception --- .../com/google/devtools/ksp/impl/ResolverAAImpl.kt | 2 +- .../devtools/ksp/processor/ThrowListProcessor.kt | 12 ++++++++++++ test-utils/testData/api/throwList.kt | 12 ++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) 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 0a4c4b1b2e..88b3883759 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 @@ -428,7 +428,7 @@ class ResolverAAImpl( override fun getJvmCheckedException(accessor: KSPropertyAccessor): Sequence { return when (accessor.origin) { - Origin.KOTLIN -> { + Origin.KOTLIN, Origin.SYNTHETIC -> { extractThrowsAnnotation(accessor) } Origin.KOTLIN_LIB, Origin.JAVA_LIB -> { diff --git a/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/ThrowListProcessor.kt b/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/ThrowListProcessor.kt index ee2ca76dee..e31f355c33 100644 --- a/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/ThrowListProcessor.kt +++ b/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/ThrowListProcessor.kt @@ -48,6 +48,12 @@ class ThrowListProcessor : AbstractTestProcessor() { val propertyA = klass.declarations.single { it.simpleName.asString() == "a" } as KSPropertyDeclaration result.add(resolver.getJvmCheckedException(propertyA.getter!!).toResult()) result.add(resolver.getJvmCheckedException(propertyA.setter!!).toResult()) + klass.declarations.filter { it.simpleName.asString() == "syntheticAccessors" }.map { + resolver.getJvmCheckedException((it as KSPropertyDeclaration).getter!!).toResult() + }.sorted().forEach { result.add(it) } + klass.declarations.filter { it.simpleName.asString() == "syntheticAccessors" }.map { + resolver.getJvmCheckedException((it as KSPropertyDeclaration).setter!!).toResult() + }.sorted().forEach { result.add(it) } val jlib = resolver.getClassDeclarationByName("JavaLib")!! val klib = resolver.getClassDeclarationByName("KtLib")!! klib.declarations.filter { it.simpleName.asString() == "throwsLibKt" }.map { @@ -65,6 +71,12 @@ class ThrowListProcessor : AbstractTestProcessor() { klib.declarations.filter { it.simpleName.asString() == "bothThrows" }.map { resolver.getJvmCheckedException((it as KSPropertyDeclaration).setter!!).toResult() }.sorted().forEach { result.add(it) } + klib.declarations.filter { it.simpleName.asString() == "syntheticAccessors" }.map { + resolver.getJvmCheckedException((it as KSPropertyDeclaration).getter!!).toResult() + }.sorted().forEach { result.add(it) } + klib.declarations.filter { it.simpleName.asString() == "syntheticAccessors" }.map { + resolver.getJvmCheckedException((it as KSPropertyDeclaration).setter!!).toResult() + }.sorted().forEach { result.add(it) } jlib.declarations.filter { it.simpleName.asString() == "foo" }.map { resolver.getJvmCheckedException(it as KSFunctionDeclaration).toResult() }.sorted().forEach { result.add(it) } diff --git a/test-utils/testData/api/throwList.kt b/test-utils/testData/api/throwList.kt index fc18a9e1f1..62e1c26abd 100644 --- a/test-utils/testData/api/throwList.kt +++ b/test-utils/testData/api/throwList.kt @@ -23,6 +23,8 @@ // ThrowsException.method.T // java.io.IOException,java.util.NoSuchElementException // java.lang.IndexOutOfBoundsException +// java.util.NoSuchElementException +// java.lang.IndexOutOfBoundsException // java.io.IOException // java.io.IOException,java.lang.IndexOutOfBoundsException // java.lang.IndexOutOfBoundsException @@ -30,6 +32,8 @@ // java.lang.IllegalStateException // java.io.IOException // java.lang.IllegalStateException,java.lang.IllegalArgumentException +// java.util.NoSuchElementException +// java.lang.IndexOutOfBoundsException // java.io.IOException // java.io.IOException,java.lang.IndexOutOfBoundsException // java.lang.IndexOutOfBoundsException @@ -80,6 +84,10 @@ class KtLib { @get:Throws(IOException::class) @set:Throws(IllegalStateException::class, IllegalArgumentException::class) var bothThrows: Int = 3 + + @set:Throws(java.lang.IndexOutOfBoundsException::class) + @get:Throws(java.util.NoSuchElementException::class) + var syntheticAccessors: Int = 0 } // MODULE: main(lib) // FILE: ThrowsException.java @@ -107,4 +115,8 @@ class ThrowsKt { set(a: Int) { } + + @set:Throws(java.lang.IndexOutOfBoundsException::class) + @get:Throws(java.util.NoSuchElementException::class) + var syntheticAccessors: Int }