DescriptorRenderedImpl: fix order of val & vararg modifier for actual class

#KT-31921 Fixed
This commit is contained in:
Dmitry Gridin
2019-07-26 16:40:48 +03:00
parent a2f937e282
commit 3ea195e1a2
6 changed files with 34 additions and 11 deletions
@@ -821,14 +821,13 @@ internal class DescriptorRendererImpl(
renderModifier(builder, valueParameter.isCrossinline, "crossinline")
renderModifier(builder, valueParameter.isNoinline, "noinline")
if (renderPrimaryConstructorParametersAsProperties &&
(valueParameter.containingDeclaration as? ClassConstructorDescriptor)?.isPrimary == true
) {
val isPrimaryConstructor = renderPrimaryConstructorParametersAsProperties &&
(valueParameter.containingDeclaration as? ClassConstructorDescriptor)?.isPrimary == true
if (isPrimaryConstructor) {
renderModifier(builder, actualPropertiesInPrimaryConstructor, "actual")
renderModifier(builder, true, "val")
}
renderVariable(valueParameter, includeName, builder, topLevel)
renderVariable(valueParameter, includeName, builder, topLevel, isPrimaryConstructor)
val withDefaultValue =
defaultParameterValueRenderer != null &&
@@ -838,21 +837,27 @@ internal class DescriptorRendererImpl(
}
}
private fun renderValVarPrefix(variable: VariableDescriptor, builder: StringBuilder) {
if (variable !is ValueParameterDescriptor) {
private fun renderValVarPrefix(variable: VariableDescriptor, builder: StringBuilder, isInPrimaryConstructor: Boolean = false) {
if (isInPrimaryConstructor || variable !is ValueParameterDescriptor) {
builder.append(renderKeyword(if (variable.isVar) "var" else "val")).append(" ")
}
}
private fun renderVariable(variable: VariableDescriptor, includeName: Boolean, builder: StringBuilder, topLevel: Boolean) {
private fun renderVariable(
variable: VariableDescriptor,
includeName: Boolean,
builder: StringBuilder,
topLevel: Boolean,
isInPrimaryConstructor: Boolean = false
) {
val realType = variable.type
val varargElementType = (variable as? ValueParameterDescriptor)?.varargElementType
val typeToRender = varargElementType ?: realType
renderModifier(builder, varargElementType != null, "vararg")
if (topLevel && !startFromName) {
renderValVarPrefix(variable, builder)
if (isInPrimaryConstructor || topLevel && !startFromName) {
renderValVarPrefix(variable, builder, isInPrimaryConstructor)
}
if (includeName) {
@@ -0,0 +1,2 @@
// My: to be implemented
// DISABLE-ERRORS
@@ -0,0 +1,3 @@
// My: to be implemented
// DISABLE-ERRORS
expect annotation class My(vararg val arg: String)
@@ -0,0 +1,4 @@
// "Create expected annotation class in common module testModule_Common" "true"
// DISABLE-ERRORS
actual annotation class <caret>My actual constructor(actual vararg val arg: String)
@@ -0,0 +1,4 @@
// "Create expected annotation class in common module testModule_Common" "true"
// DISABLE-ERRORS
actual annotation class My actual constructor(actual vararg val arg: String)
@@ -364,6 +364,11 @@ public class QuickFixMultiModuleTestGenerated extends AbstractQuickFixMultiModul
runTest("idea/testData/multiModuleQuickFix/expectClassWithSupertype/");
}
@TestMetadata("expectClassWithVararg")
public void testExpectClassWithVararg() throws Exception {
runTest("idea/testData/multiModuleQuickFix/expectClassWithVararg/");
}
@TestMetadata("expectCompanion")
public void testExpectCompanion() throws Exception {
runTest("idea/testData/multiModuleQuickFix/expectCompanion/");