In my current project, we need to create a Kotlin file with several constants containing strings extracted from the FIR analysis. These constants will also be used in the source code.
We are considering two approaches:
• Generating the
.kt
file with Kotlin Poet, which isn’t recognized in the source set and causes the initial build to fail (though a second build recognizes the generated file because it already exists).
• Creating a function declaration in the FIR stage using
FirDeclarationGenerationExtension
, then implementing the function body during the IR stage using
AbstractTransformerForGenerator
. However, this approach produces generated code that’s less transparent than a
.kt
file, making it harder to view the content easily. Additionally, we face challenges passing information from FIR to IR—*how can we facilitate communication between them?*