Hello everyone, I want to add a inner class using ...
# compiler
m
Hello everyone, I want to add a inner class using SyntheticResolveExtension, thus I need to add a constructor to the class. But I don't know how to add it successfully.
Copy code
private fun trackableSubClass(
  thisDescriptor: ClassDescriptor
): ClassDescriptorImpl = object : ClassDescriptorImpl(
  thisDescriptor,
  Name.identifier(SUBCLASS_NAME),
  Modality.FINAL,
  ClassKind.CLASS,
  emptyList<KotlinType>(),
  thisDescriptor.source,
  false,
  LockBasedStorageManager.NO_LOCKS
) {

}.apply {

  val a = ClassConstructorDescriptorImpl.create(
    this,
    Annotations.EMPTY,
    true,
    this.source
  )
  val b = a.initialize(
    emptyList(),
    DescriptorVisibilities.PUBLIC,
    emptyList(),
  )
Copy code
this.initialize(
    // 内部类的成员范围 MemberScope.Empty
    MemberScope.Empty,
    // 构造方法集合
    emptySet(),
    b
  )
}
d
You can do it with generateSyntheticSecondaryConstructors method Check how it's done in kotlinx.serialization pluigin