-
Notifications
You must be signed in to change notification settings - Fork 287
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Incremental processing: support getSealedSubclasses from multiple files
There isn't a simple way to associate symbols with their supertypes without resolution, because of typealias. Therefore, all sealed classes / interfaces on which getSealedSubclasses is called are invalidated.
- Loading branch information
Showing
7 changed files
with
159 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
integration-tests/src/test/kotlin/com/google/devtools/ksp/test/GetSealedSubclassesIncIT.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.google.devtools.ksp.test | ||
|
||
import org.gradle.testkit.runner.GradleRunner | ||
import org.junit.Assert | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import java.io.File | ||
|
||
class GetSealedSubclassesIncIT { | ||
@Rule | ||
@JvmField | ||
val project: TemporaryTestProject = TemporaryTestProject("sealed-subclasses", "test-processor") | ||
|
||
@Test | ||
fun testGetSealedSubclassesInc() { | ||
val gradleRunner = GradleRunner.create().withProjectDir(project.root) | ||
|
||
val expected2 = listOf( | ||
"w: [ksp] Processing Impl1.kt", | ||
"w: [ksp] Impl1 : []", | ||
"w: [ksp] Processing Impl2.kt", | ||
"w: [ksp] Impl2 : []", | ||
"w: [ksp] Processing Sealed.kt", | ||
"w: [ksp] Sealed : [Impl1, Impl2]", | ||
) | ||
|
||
val expected3 = listOf( | ||
"w: [ksp] Processing Impl1.kt", | ||
"w: [ksp] Impl1 : []", | ||
"w: [ksp] Processing Impl2.kt", | ||
"w: [ksp] Impl2 : []", | ||
"w: [ksp] Processing Impl3.kt", | ||
"w: [ksp] Impl3 : []", | ||
"w: [ksp] Processing Sealed.kt", | ||
"w: [ksp] Sealed : [Impl1, Impl2, Impl3]", | ||
) | ||
|
||
gradleRunner.withArguments("assemble").build().let { result -> | ||
val outputs = result.output.split("\n").filter { it.startsWith("w: [ksp]")} | ||
Assert.assertEquals(expected2, outputs) | ||
} | ||
|
||
File(project.root, "workload/src/main/kotlin/com/example/Impl3.kt").appendText("package com.example\n\n") | ||
File(project.root, "workload/src/main/kotlin/com/example/Impl3.kt").appendText("class Impl3 : Sealed()\n") | ||
gradleRunner.withArguments("assemble").build().let { result -> | ||
val outputs = result.output.split("\n").filter { it.startsWith("w: [ksp]")} | ||
Assert.assertEquals(expected3, outputs) | ||
} | ||
|
||
File(project.root, "workload/src/main/kotlin/com/example/Impl3.kt").delete() | ||
gradleRunner.withArguments("assemble").build().let { result -> | ||
val outputs = result.output.split("\n").filter { it.startsWith("w: [ksp]")} | ||
Assert.assertEquals(expected2, outputs) | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...ests/src/test/resources/sealed-subclasses/test-processor/src/main/kotlin/TestProcessor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import com.google.devtools.ksp.processing.* | ||
import com.google.devtools.ksp.symbol.* | ||
|
||
|
||
class TestProcessor( | ||
val codeGenerator: CodeGenerator, | ||
val logger: KSPLogger | ||
) : SymbolProcessor { | ||
override fun process(resolver: Resolver): List<KSAnnotated> { | ||
resolver.getNewFiles().forEach { f -> | ||
logger.warn("Processing ${f.fileName}") | ||
f.declarations.forEach { | ||
if (it is KSClassDeclaration) { | ||
val subs = it.getSealedSubclasses().map { it.simpleName.asString() }.toList() | ||
logger.warn("${it.simpleName.asString()} : $subs") | ||
} | ||
} | ||
} | ||
return emptyList() | ||
} | ||
} | ||
|
||
class TestProcessorProvider : SymbolProcessorProvider { | ||
override fun create( | ||
options: Map<String, String>, | ||
kotlinVersion: KotlinVersion, | ||
codeGenerator: CodeGenerator, | ||
logger: KSPLogger | ||
): SymbolProcessor { | ||
return TestProcessor(codeGenerator, logger) | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...-tests/src/test/resources/sealed-subclasses/workload/src/main/kotlin/com/example/Impl1.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.example | ||
|
||
class Impl1 : Sealed() |
3 changes: 3 additions & 0 deletions
3
...-tests/src/test/resources/sealed-subclasses/workload/src/main/kotlin/com/example/Impl2.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.example | ||
|
||
class Impl2 : Sealed() |
3 changes: 3 additions & 0 deletions
3
...tests/src/test/resources/sealed-subclasses/workload/src/main/kotlin/com/example/Sealed.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.example | ||
|
||
sealed class Sealed |