compiler-plugin / arrow.meta.quotes / Transform / Replace

Replace

data class Replace<out K : KtElement> : Transform<K>

A Transform that replaces some element in AST. See below:

import arrow.meta.Meta
import arrow.meta.CliPlugin
import arrow.meta.invoke
import arrow.meta.quotes.Transform
import arrow.meta.quotes.namedFunction

val Meta.replacePlugin: CliPlugin
 get() =
  "Replace Transform" {
    meta(
     namedFunction(this, { element.name == "helloWorld" }) { (c, d) ->
       Transform.replace(
         replacing = c,
         newDeclaration =
         """|fun helloWorld(): Unit =
            |  println("Hello ΛRROW Meta!")
            |""".function(d).syntheticScope
       )
     }
    )
  }

Parameters

replacing - the element to be replaced

newDeclarations - are the elements that will replace

Constructors

<init> A Transform that replaces some element in AST. See below:Replace(replacing: PsiElement, newDeclarations: List<Scope<KtElement>>, replacementId: String? = null)

Properties

newDeclarations are the elements that will replaceval newDeclarations: List<Scope<KtElement>>
replacementId val replacementId: String?
replacing the element to be replacedval replacing: PsiElement

Do you like Arrow?

Arrow Org
<