forked from google/ksp
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a test that repro google#2072 via a TriggerExceptionProcessor
- Loading branch information
Showing
5 changed files
with
81 additions
and
0 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
3 changes: 3 additions & 0 deletions
3
...resources/kmp/annotations/src/commonMain/kotlin/com/example/TriggerExceptionAnnotation.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 | ||
|
||
annotation class TriggerExceptionAnnotation |
35 changes: 35 additions & 0 deletions
35
...-tests/src/test/resources/kmp/test-processor/src/main/kotlin/TriggerExceptionProcessor.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,35 @@ | ||
import com.google.devtools.ksp.processing.* | ||
import com.google.devtools.ksp.symbol.* | ||
import com.google.devtools.ksp.validate | ||
|
||
class TriggerExceptionProcessor(val codeGenerator: CodeGenerator, val logger: KSPLogger) : SymbolProcessor { | ||
var invoked = false | ||
|
||
override fun process(resolver: Resolver): List<KSAnnotated> { | ||
if (invoked) { | ||
return emptyList() | ||
} | ||
invoked = true | ||
|
||
val symbols = resolver.getSymbolsWithAnnotation("com.example.TriggerExceptionAnnotation") | ||
if (symbols.any()) { | ||
logger.error("Exception triggered") | ||
error("Exception triggered") | ||
} | ||
|
||
codeGenerator.createNewFile( | ||
Dependencies(true), | ||
"", | ||
"NoTrigger", | ||
"kt" | ||
) | ||
|
||
return emptyList() | ||
} | ||
} | ||
|
||
class TriggerExceptionProvider : SymbolProcessorProvider { | ||
override fun create(env: SymbolProcessorEnvironment): SymbolProcessor { | ||
return TriggerExceptionProcessor(env.codeGenerator, env.logger) | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
...in/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
TestProcessorProvider | ||
ValidateProcessorProvider | ||
ErrorProcessorProvider | ||
TriggerExceptionProvider | ||
|
4 changes: 4 additions & 0 deletions
4
...gration-tests/src/test/resources/kmp/workload/src/commonMain/kotlin/com/example/FooBar.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,4 @@ | ||
package com.example | ||
|
||
//@TriggerExceptionAnnotation | ||
class FooBar |