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

Many

data class Many<K : KtElement> : Transform<K>

A Transform that allows transformations combining. See below:

import arrow.meta.Meta
import arrow.meta.CliPlugin
import arrow.meta.invoke
import arrow.meta.phases.CompilerContext
import arrow.meta.quotes.classorobject.ClassDeclaration
import arrow.meta.quotes.Transform
import arrow.meta.quotes.classDeclaration
import arrow.meta.quotes.plus
import org.jetbrains.kotlin.psi.KtClass

val Meta.transformManySimpleCase: CliPlugin
 get() = "Transform Many" {
  meta(
     classDeclaration(this, { name == "ManySimpleCase" }) { c ->
      changeClassVisibility("ManySimpleCase", c, this) + removeFooPrint(c, this)
    }
   )
  }

fun CompilerContext.changeClassVisibility(className: String, context: KtClass, declaration: ClassDeclaration): Transform<KtClass> = declaration.run { Transform.replace(
  replacing = context,
  newDeclaration = """
  | private class $className {
  |   $body
  | } """.`class`.syntheticScope
)}

fun CompilerContext.removeFooPrint(context: KtClass, declaration: ClassDeclaration): Transform<KtClass> = declaration.run { Transform.remove(
  removeIn = context,
  declaration = """ fun printFirst() = println("Foo") """.expressionIn(context)
)}

Parameters

transforms - list of transformations

Constructors

<init> A Transform that allows transformations combining. See below:Many(transforms: <ERROR CLASS><Transform<K>>)

Properties

transforms list of transformationsval transforms: <ERROR CLASS><Transform<K>>

Do you like Arrow?

Arrow Org
<