1

I'm trying to print a call to superclass' constructor using KotlinPoet. My current (not compiling) output is:

open class NameOfASubclass : NameOfSuperclass {
}

In order to make my code compile I need to (somehow) either print

open class NameOfASubclass : NameOfSuperclass() {
}

or

open class NameOfASubclass : NameOfSuperclass {
constructor()
}

I cannot achieve it using KotlinPoet. Any ideas?

Egor
  • 39,695
  • 10
  • 113
  • 130
hhg
  • 649
  • 1
  • 11
  • 20
  • Can you post your Poet generation code? – guenhter Jul 11 '17 at 13:42
  • sure `PACKAGE_NAME = resolvePackageName(classModel) val className = resolveDataModelClassName(classModel.className) val builder = KotlinFile.builder(PACKAGE_NAME, className) builder.addType(TypeSpec.classBuilder(className).addModifiers(KModifier.OPEN).primaryConstructor(FunSpec.constructorBuilder().build()) .superclass(resolveSuperClass(classModel)).build())` – hhg Jul 11 '17 at 13:57

2 Answers2

3

This is a bug. Here's the issue for it and here is the commit that fixes it.

There hasn't been a new release since this commit (16 of June), the last stable version is 0.3.0 (11th of June). Hopefully a new release is coming soon - there's been lots of work done since the previous one.

zsmb13
  • 85,752
  • 11
  • 221
  • 226
1

indeed in Kotlin Poet the problem is solved in v.0.4.0

hhg
  • 649
  • 1
  • 11
  • 20