compiler-plugin / arrow.meta.plugins.helloWorld / helloWorld


val Meta.helloWorld: CliPlugin

The following example shows a Hello World Compiler Plugin.

The Hello World plugin auto implements the helloWorld function by rewriting the Kotlin AST before the compiler proceeds.

val Meta.helloWorld: CliPlugin get() =
  "Hello World" {
      namedFunction(this, { name == "helloWorld" }) { c ->  // <-- namedFunction(...) {...}
          replacing = c,
          newDeclaration = """|fun helloWorld(): Unit =
                              |  println("Hello ΛRROW Meta!")

For any user code whose function name is helloWorld, our compiler plugin will replace the matching function for a function that returns Unit and prints our message.

-fun helloWorld(): Unit = TODO()
+fun helloWorld(): Unit =
+  println("Hello ΛRROW Meta!")

Take a look at the arrow-meta-examples repository for more details.

Do you like Arrow?

Arrow Org