compiler-plugin / arrow.meta.quotes.nameddeclaration.stub / Parameter

Parameter

class Parameter : Scope<KtParameter>

””” $name : $type””“.classParameter

A template destructuring Scope for a KtParameter

Parameter Formatting:

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

val Meta.reformatParameter: CliPlugin
 get() =
  "ReformatParameter" {
   meta(
    parameter(this, { true }) { param ->
     Transform.replace(
      replacing = param,
      newDeclaration = " $name: $type = EnvironmentRepository()".classParameter
     )
     }
    )
   }

Class Parameter:

A loop parameter may be found within a ClassDeclaration. For example, we can change:

class A(val environmentRepository: Repository)

to:

class A(val environmentRepository: Repository = EnvironmentRepository())

By working with loop parameters:

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

val Meta.assignEnvironmentRepositoryConstructorParameterADefaultValue: CliPlugin
 get() =
  "Make all environment constructor parameters open" {
   meta(
    parameter(this, { name == "environmentRepository" }) { param ->
     Transform.replace(
      replacing = param,
      newDeclaration = " $name: $type = EnvironmentRepository()".classParameter
     )
     }
    )
   }

Loop Parameter:

A loop parameter may be found within a ForExpression. For example, we can change

for (i in list) { ... }

to:

for (row in list) { ... }

By working with loop parameters:

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

val Meta.renameLoopParameter: CliPlugin
 get() =
  "RenameLoopParameter" {
   meta(
    parameter(this, { name == "i" }) { param ->
     Transform.replace(
      replacing = param,
      newDeclaration = "row".loopParameter
     )
     }
    )
   }

Destructuring Parameter:

A destructuring parameter may be found within a FunctionLiteral. For example, we can change:

someFunction(x) { func -> ... }

to:

someFunction(x) { function -> ... }

By working with destructuring parameters:

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

val Meta.renameDestructuringParameter: CliPlugin
 get() =
  "RenameDestructuringParameter" {
   meta(
     parameter(this, { typeReference?.name == "func" }) { param ->
     Transform.replace(
      replacing = param,
      newDeclaration = "function".destructuringDeclaration
     )
     }
    )
   }

Constructors

| <init> | “”” $name : $type””“.classParameterParameter(value: KtParameter?, name: Name? = value?.nameAsName, type: TypeReference = TypeReference(value?.typeReference), (typeParams): ScopedList<KtTypeParameter> = ScopedList(prefix = "<", value = value?.typeParameters ?: listOf(), postfix = ">"), defaultValue: Scope<KtExpression> = Scope(value?.defaultValue), valOrVar: Name = when { value?.hasValOrVar() == true && value.isMutable -> "var" value?.hasValOrVar() == true && !value.isMutable -> "val" value?.isVarArg == true -> "vararg" else -> "" }.let(Name::identifier), destructuringDeclaration: DestructuringDeclaration = DestructuringDeclaration(value?.destructuringDeclaration)) |

Properties

(typeParams) val (typeParams): ScopedList<KtTypeParameter>
defaultValue val defaultValue: Scope<KtExpression>
destructuringDeclaration val destructuringDeclaration: DestructuringDeclaration
name val name: Name?
type val type: TypeReference
valOrVar val valOrVar: Name
value val value: KtParameter?

Extension Functions

map fun <K : KtElement> Scope<K>.map(f: (K) -> K): Scope<K>
orEmpty fun <K : KtElement> Scope<K>?.orEmpty(): Scope<K>

Do you like Arrow?

Arrow Org
<