com.lightningkite.khrysalis.util.ResolvedCall.ext.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-compiler-plugin-common Show documentation
Show all versions of kotlin-compiler-plugin-common Show documentation
Common translational tools between Typescript and Swift.
The newest version!
package com.lightningkite.khrysalis.util
import com.lightningkite.khrysalis.replacements.TemplatePart
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.resolve.calls.components.isVararg
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
fun List.withBetween(separator: Any?, start: Any? = null, end: Any? = null): List {
val list = ArrayList(this.size * 2 - 1 + if (start != null) 1 else 0 + if (end != null) 1 else 0)
if (start != null) list.add(start)
this.forEachBetween(
forItem = { list.add(it) },
between = { list.add(separator) }
)
if (end != null) list.add(end)
return list
}
val ResolvedCall.template_parameter
get() = { n: TemplatePart.Parameter ->
this.valueArguments.entries.find { it.key.name.asString() == n.name }?.let {
if (it.key.isVararg)
it.value.arguments.map { it.getArgumentExpression() }.withBetween(", ")
else
it.value.arguments.firstOrNull()?.getArgumentExpression()
} ?: "nil"
}
val ResolvedCall.template_typeParameter get() = { n: TemplatePart.TypeParameter -> this.typeArguments.entries.find { it.key.name.asString() == n.name }?.value }
val ResolvedCall.template_parameterByIndex
get() = { n: TemplatePart.ParameterByIndex ->
this.valueArguments.entries.find { it.key.index == n.index }?.let {
if (it.key.isVararg)
it.value.arguments.map { it.getArgumentExpression() }.withBetween(", ")
else
it.value.arguments.firstOrNull()?.getArgumentExpression()
} ?: "nil"
}
val ResolvedCall.template_typeParameterByIndex get() = { n: TemplatePart.TypeParameterByIndex -> this.typeArguments.entries.find { it.key.index == n.index }?.value }
© 2015 - 2024 Weber Informatics LLC | Privacy Policy