compiler-plugin / arrow.meta.quotes.nameddeclaration.stub / Parameter / <init>
Parameter(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))
””” $name : $type””“.classParameter
A template destructuring Scope for a KtParameter
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
)
}
)
}
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
)
}
)
}
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
)
}
)
}
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
)
}
)
}
Do you like Arrow?
✖