I would like to write a compiler extension and/or annotation processor that does the following:
-
is triggered by the presence of a specific annotation on a lambda:
@Target(AnnotationTarget.FUNCTION) annotation class MyAnnotation val someLambda = @MyAnnotation { n: Int -> n + 1 }
-
can inspect (read-only) the Kotlin AST of the lambda;
-
can fail the compilation with an error, for example if the code inside the lambda contains a Kotlin feature that is not supported by my library;
-
generates data (not code!) that will be used by a runtime library, either by creating new source files or (better) by storing the data as further annotations to the lambda being compiled.
Iām looking at the interfaces in org.jetbrains.kotlin.extensions, but they are somewhat complicated and undocumented.
Can anybody recommend the simplest way to achieve the points above?