diff --git a/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/KotlinSymbolProcessing.kt b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/KotlinSymbolProcessing.kt index 46c57a5a30..4b1f3a21d6 100644 --- a/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/KotlinSymbolProcessing.kt +++ b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/KotlinSymbolProcessing.kt @@ -541,10 +541,6 @@ class KotlinSymbolProcessing( } } - if (logger.hasError || codeGenerator.generatedFile.isEmpty()) { - break - } - // Drop caches KotlinGlobalModificationService.getInstance(project).publishGlobalSourceModuleStateModification() KtAnalysisSessionProvider.getInstance(project).clearCaches() @@ -553,6 +549,10 @@ class KotlinSymbolProcessing( KSObjectCacheManager.clear() + if (logger.hasError || codeGenerator.generatedFile.isEmpty()) { + break + } + newKSFiles = prepareNewKSFiles( kotlinCoreProjectEnvironment, javaFileManager, diff --git a/kotlin-analysis-api/src/test/kotlin/com/google/devtools/ksp/test/KSPAATest.kt b/kotlin-analysis-api/src/test/kotlin/com/google/devtools/ksp/test/KSPAATest.kt index 8ec4704fb9..18e8058a37 100644 --- a/kotlin-analysis-api/src/test/kotlin/com/google/devtools/ksp/test/KSPAATest.kt +++ b/kotlin-analysis-api/src/test/kotlin/com/google/devtools/ksp/test/KSPAATest.kt @@ -145,16 +145,16 @@ class KSPAATest : AbstractKSPAATest() { runTest("../test-utils/testData/api/builtInTypes.kt") } - @TestMetadata("A.kt") + @TestMetadata("objCacheA.kt") @Test - fun testA() { - runTest("../test-utils/testData/api/A.kt") + fun testObjCacheA() { + runTest("../test-utils/testData/api/objCacheA.kt") } - @TestMetadata("B.kt") + @TestMetadata("objCacheB.kt") @Test - fun testB() { - runTest("../test-utils/testData/api/B.kt") + fun testObjCacheB() { + runTest("../test-utils/testData/api/objCacheB.kt") } @Disabled diff --git a/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/AProcessor.kt b/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/ObjCacheAProcessor.kt similarity index 78% rename from test-utils/src/main/kotlin/com/google/devtools/ksp/processor/AProcessor.kt rename to test-utils/src/main/kotlin/com/google/devtools/ksp/processor/ObjCacheAProcessor.kt index f4d3a4a6bd..b51ff8cd8e 100644 --- a/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/AProcessor.kt +++ b/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/ObjCacheAProcessor.kt @@ -6,7 +6,7 @@ import com.google.devtools.ksp.getDeclaredProperties import com.google.devtools.ksp.processing.Resolver import com.google.devtools.ksp.symbol.KSAnnotated -open class AProcessor : AbstractTestProcessor() { +open class ObjCacheAProcessor : AbstractTestProcessor() { val results = mutableListOf() override fun toResult(): List { return results @@ -15,7 +15,7 @@ open class AProcessor : AbstractTestProcessor() { @OptIn(KspExperimental::class) override fun process(resolver: Resolver): List { resolver.getClassDeclarationByName("BaseClass")!!.let { cls -> - println(cls.getDeclaredProperties().map { "${it.simpleName.asString()}(${it.hasBackingField})" }.toList()) + results.addAll(cls.getDeclaredProperties().map { "${it.simpleName.asString()}(${it.hasBackingField})" }) } return emptyList() } diff --git a/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/BProcessor.kt b/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/ObjCacheBProcessor.kt similarity index 68% rename from test-utils/src/main/kotlin/com/google/devtools/ksp/processor/BProcessor.kt rename to test-utils/src/main/kotlin/com/google/devtools/ksp/processor/ObjCacheBProcessor.kt index c95a81fa5b..daf08284bf 100644 --- a/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/BProcessor.kt +++ b/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/ObjCacheBProcessor.kt @@ -6,7 +6,7 @@ import com.google.devtools.ksp.getDeclaredProperties import com.google.devtools.ksp.processing.Resolver import com.google.devtools.ksp.symbol.KSAnnotated -open class BProcessor : AbstractTestProcessor() { +open class ObjCacheBProcessor : AbstractTestProcessor() { val results = mutableListOf() override fun toResult(): List { return results @@ -15,8 +15,7 @@ open class BProcessor : AbstractTestProcessor() { @OptIn(KspExperimental::class) override fun process(resolver: Resolver): List { resolver.getClassDeclarationByName("BaseClass")!!.let { cls -> - println(cls.getDeclaredProperties().map { "${it.simpleName.asString()}(${it.hasBackingField})" }.toList()) - // `hasBackingField` is true when running the test individually but is false when running the whole KSPAATest. + results.addAll(cls.getDeclaredProperties().map { "${it.simpleName.asString()}(${it.hasBackingField})" }) } return emptyList() } diff --git a/test-utils/testData/api/A.kt b/test-utils/testData/api/objCacheA.kt similarity index 94% rename from test-utils/testData/api/A.kt rename to test-utils/testData/api/objCacheA.kt index 4f91fbef75..b1d894895d 100644 --- a/test-utils/testData/api/A.kt +++ b/test-utils/testData/api/objCacheA.kt @@ -16,8 +16,9 @@ */ // WITH_RUNTIME -// TEST PROCESSOR: AProcessor +// TEST PROCESSOR: ObjCacheAProcessor // EXPECTED: +// genericProp(true) // END // MODULE: lib // FILE: Test.kt diff --git a/test-utils/testData/api/B.kt b/test-utils/testData/api/objCacheB.kt similarity index 94% rename from test-utils/testData/api/B.kt rename to test-utils/testData/api/objCacheB.kt index 2f898b3fc1..d88605bbb2 100644 --- a/test-utils/testData/api/B.kt +++ b/test-utils/testData/api/objCacheB.kt @@ -16,8 +16,9 @@ */ // WITH_RUNTIME -// TEST PROCESSOR: BProcessor +// TEST PROCESSOR: ObjCacheBProcessor // EXPECTED: +// value(true) // END // MODULE: lib // FILE: Test.kt