Does anyone have a small example besides SQLdeligh...
# multiplatform
i
Does anyone have a small example besides SQLdelight on how to generate Kotlin files with PSI ?
d
PSI?
r
@Dominaezzz that's IntelliJ's framework for working with code representation: https://www.jetbrains.org/intellij/sdk/docs/basics/architectural_overview/psi.html
a
SQLDelight is the only library I know of that does this
Only other possibility would be intellij source code - maybe some of the old java features for generating getters and setters
l
Is there a reason you used PSI and not Square's own KotlinPoet to generate Kotlin code in SQLDelight?
a
We use kotlinpoet
PSI is the AST abstraction for parsing sql
Lint is another tool that uses it, but for static analysis and not codegen
Most tools use APT for their AST layer instead of PSI
i
Yeah, but I just need a small example something along the lines of
ExampleClass.kt
Copy code
data class ExampleClass(val hello:String = "Hello"){
  companion object {}
}
How can I get all the information of this class with PSI and generate for instance a generic function foo which prints the hello variable to the console?
@r4zzz4k Do you have a more descriptive docu
r
@Imran/Malic no, I didn't work with it myself yet.
i
ok
Hi @alec, I am working through your psi lib. Can you explain, how or where you tell an annotation that it has a processor in MPP, so not the google service API.
I tried this: annotation:
Copy code
@Retention(RUNTIME)
@Target(CLASS)
@MustBeDocumented
annotation class higherkind
processor:
Copy code
abstract class HigherKindProcessor : Annotator {
    override fun annotate(element: PsiElement, holder: AnnotationHolder) {
        val tree = element.containingFile.children
        tree.forEach { println(it.text) }
    }
}
I want to do some codegen later on, but even that snippet within the annotation methode is not executed, if I create an object of an class
a
how are you loading a PSI environment? There's no direct api to do that, you have to start one up manually using a
MockApplication