Skip to content

Commit

Permalink
Clear caches before early exit
Browse files Browse the repository at this point in the history
  • Loading branch information
ting-yuan committed Jul 3, 2024
1 parent ad8a047 commit dc38b13
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -541,10 +541,6 @@ class KotlinSymbolProcessing(
}
}

if (logger.hasError || codeGenerator.generatedFile.isEmpty()) {
break
}

// Drop caches
KotlinGlobalModificationService.getInstance(project).publishGlobalSourceModuleStateModification()
KtAnalysisSessionProvider.getInstance(project).clearCaches()
Expand All @@ -553,6 +549,10 @@ class KotlinSymbolProcessing(

KSObjectCacheManager.clear()

if (logger.hasError || codeGenerator.generatedFile.isEmpty()) {
break
}

newKSFiles = prepareNewKSFiles(
kotlinCoreProjectEnvironment,
javaFileManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>()
override fun toResult(): List<String> {
return results
Expand All @@ -15,7 +15,7 @@ open class AProcessor : AbstractTestProcessor() {
@OptIn(KspExperimental::class)
override fun process(resolver: Resolver): List<KSAnnotated> {
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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>()
override fun toResult(): List<String> {
return results
Expand All @@ -15,8 +15,7 @@ open class BProcessor : AbstractTestProcessor() {
@OptIn(KspExperimental::class)
override fun process(resolver: Resolver): List<KSAnnotated> {
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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
*/

// WITH_RUNTIME
// TEST PROCESSOR: AProcessor
// TEST PROCESSOR: ObjCacheAProcessor
// EXPECTED:
// genericProp(true)
// END
// MODULE: lib
// FILE: Test.kt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
*/

// WITH_RUNTIME
// TEST PROCESSOR: BProcessor
// TEST PROCESSOR: ObjCacheBProcessor
// EXPECTED:
// value(true)
// END
// MODULE: lib
// FILE: Test.kt
Expand Down

0 comments on commit dc38b13

Please sign in to comment.