blob: a702c7bc64c11913bf74f8406bd32897ff902b4d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
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
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")
}
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 ErrorProcessorProvider : SymbolProcessorProvider {
override fun create(
env: SymbolProcessorEnvironment
): SymbolProcessor {
return ErrorProcessor().apply {
init(env.options, env.kotlinVersion, env.codeGenerator, env.logger)
}
}
}
|