Use OverrideMemberChooserObject to generate also primary constructors

Relates to KT-27093 and similar problems
This commit is contained in:
Mikhail Glukhikh
2018-11-14 12:45:39 +03:00
parent cd041cca71
commit 90a2f70fd1
11 changed files with 60 additions and 27 deletions
@@ -216,6 +216,7 @@ private val ACTUAL_RENDERER = OVERRIDE_RENDERER.withOptions {
secondaryConstructorsAsPrimary = false
renderDefaultVisibility = false
renderDefaultModality = false
renderActualAnnotationPropertiesInPrimaryConstructor = true
}
private fun PropertyDescriptor.wrap(forceOverride: Boolean): PropertyDescriptor {
@@ -306,7 +307,13 @@ private fun generateFunction(
val factory = KtPsiFactory(project)
val functionText = renderer.render(newDescriptor) + body
return when (descriptor) {
is ClassConstructorDescriptor -> factory.createSecondaryConstructor(functionText)
is ClassConstructorDescriptor -> {
if (descriptor.isPrimary) {
factory.createPrimaryConstructor(functionText)
} else {
factory.createSecondaryConstructor(functionText)
}
}
else -> factory.createFunction(functionText)
}
}