commonMain.co.touchlab.skie.kir.irbuilder.DeclarationBuilder.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-compiler-linker-plugin-kgp_1.9.20 Show documentation
Show all versions of kotlin-compiler-linker-plugin-kgp_1.9.20 Show documentation
Kotlin compiler plugin that improves Swift interface of a Kotlin Multiplatform framework.
The newest version!
package co.touchlab.skie.kir.irbuilder
import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.name.SpecialNames
interface DeclarationBuilder {
fun getCustomNamespace(name: String): Namespace
fun getClassNamespace(classDescriptor: ClassDescriptor): Namespace
fun getPackageNamespace(existingMember: FunctionDescriptor): Namespace
fun createFunction(
name: Name,
namespace: Namespace<*>,
annotations: Annotations,
builder: FunctionBuilder.() -> Unit,
): FunctionDescriptor
fun createSecondaryConstructor(
name: Name = SpecialNames.INIT,
namespace: Namespace,
annotations: Annotations,
builder: SecondaryConstructorBuilder.() -> Unit,
): ClassConstructorDescriptor
}
fun DeclarationBuilder.getNamespace(function: FunctionDescriptor): Namespace<*> =
when (val containingDeclaration = function.containingDeclaration) {
is ClassDescriptor -> getClassNamespace(containingDeclaration)
is PackageFragmentDescriptor -> getPackageNamespace(function)
else -> throw UnsupportedDeclarationDescriptorException(containingDeclaration)
}
fun DeclarationBuilder.getNamespace(constructor: ClassConstructorDescriptor): Namespace =
getClassNamespace(constructor.containingDeclaration)
fun DeclarationBuilder.createFunction(
name: String,
namespace: Namespace<*>,
annotations: Annotations,
builder: FunctionBuilder.() -> Unit,
): FunctionDescriptor = createFunction(Name.identifier(name), namespace, annotations, builder)
fun DeclarationBuilder.createSecondaryConstructor(
name: String = SpecialNames.INIT.asString(),
namespace: Namespace,
annotations: Annotations,
builder: SecondaryConstructorBuilder.() -> Unit,
): ClassConstructorDescriptor = createSecondaryConstructor(Name.special(name), namespace, annotations, builder)