aboutsummaryrefslogtreecommitdiff
path: root/integration-tests/src/test/resources/on-error/on-error-processor/src/main/kotlin/ErrorProcessor.kt
diff options
context:
space:
mode:
Diffstat (limited to 'integration-tests/src/test/resources/on-error/on-error-processor/src/main/kotlin/ErrorProcessor.kt')
-rw-r--r--integration-tests/src/test/resources/on-error/on-error-processor/src/main/kotlin/ErrorProcessor.kt70
1 files changed, 70 insertions, 0 deletions
diff --git a/integration-tests/src/test/resources/on-error/on-error-processor/src/main/kotlin/ErrorProcessor.kt b/integration-tests/src/test/resources/on-error/on-error-processor/src/main/kotlin/ErrorProcessor.kt
new file mode 100644
index 00000000..976019bf
--- /dev/null
+++ b/integration-tests/src/test/resources/on-error/on-error-processor/src/main/kotlin/ErrorProcessor.kt
@@ -0,0 +1,70 @@
+import com.google.devtools.ksp.processing.*
+import com.google.devtools.ksp.symbol.*
+import java.io.OutputStream
+
+class ErrorProcessor : SymbolProcessor {
+ lateinit var codeGenerator: CodeGenerator
+ lateinit var logger: KSPLogger
+ lateinit var file: OutputStream
+ var rounds = 0
+ lateinit var exception: String
+
+ fun init(
+ options: Map<String, String>,
+ kotlinVersion: KotlinVersion,
+ codeGenerator: CodeGenerator,
+ logger: KSPLogger
+ ) {
+ exception = if (options.containsKey("exception")) {
+ options["exception"]!!
+ } else {
+ ""
+ }
+ if (exception == "init") {
+ throw Exception("Test Exception in init")
+ }
+ this.logger = logger
+ this.codeGenerator = codeGenerator
+ }
+
+ override fun process(resolver: Resolver): List<KSAnnotated> {
+ if (exception == "createTwice") {
+ codeGenerator.createNewFile(Dependencies.ALL_FILES, "create", "Twice").write("".toByteArray())
+ return emptyList()
+ }
+ if (exception == "process") {
+ throw Exception("Test Exception in process")
+ }
+ rounds++
+ if (rounds == 2) {
+ if (exception == "" || exception == "error") {
+ logger.error("Error processor: errored at $rounds")
+ }
+ } else {
+ codeGenerator.createNewFile(Dependencies.ALL_FILES, "test", "error", "log")
+ }
+ return emptyList()
+ }
+
+ override fun finish() {
+ if (exception == "finish") {
+ throw Exception("Test Exception in finish")
+ }
+ }
+
+ override fun onError() {
+ if (exception == "error") {
+ throw Exception("Test Exception in error")
+ }
+ }
+}
+
+class TestProcessorProvider : SymbolProcessorProvider {
+ override fun create(
+ env: SymbolProcessorEnvironment
+ ): SymbolProcessor {
+ return ErrorProcessor().apply {
+ init(env.options, env.kotlinVersion, env.codeGenerator, env.logger)
+ }
+ }
+}