Create expect/actual class: fix inline class generation
#KT-28744 Fixed #KT-28745 Fixed
This commit is contained in:
@@ -187,7 +187,7 @@ interface DescriptorRendererOptions {
|
||||
var renderDefaultVisibility: Boolean
|
||||
var renderDefaultModality: Boolean
|
||||
var renderConstructorDelegation: Boolean
|
||||
var renderAnnotationPropertiesInPrimaryConstructor: Boolean
|
||||
var renderPrimaryConstructorParametersAsProperties: Boolean
|
||||
var actualPropertiesInPrimaryConstructor: Boolean
|
||||
var uninferredTypeParameterAsName: Boolean
|
||||
var overrideRenderingPolicy: OverrideRenderingPolicy
|
||||
|
||||
@@ -22,7 +22,6 @@ import org.jetbrains.kotlin.resolve.constants.ConstantValue
|
||||
import org.jetbrains.kotlin.resolve.constants.KClassValue
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.annotationClass
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.declaresOrInheritsDefaultValue
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isAnnotationConstructor
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.ErrorUtils.UninferredParameterTypeConstructor
|
||||
import org.jetbrains.kotlin.types.TypeUtils.CANT_INFER_FUNCTION_PARAM_TYPE
|
||||
@@ -815,7 +814,9 @@ internal class DescriptorRendererImpl(
|
||||
renderModifier(builder, valueParameter.isCrossinline, "crossinline")
|
||||
renderModifier(builder, valueParameter.isNoinline, "noinline")
|
||||
|
||||
if (renderAnnotationPropertiesInPrimaryConstructor && valueParameter.containingDeclaration.isAnnotationConstructor()) {
|
||||
if (renderPrimaryConstructorParametersAsProperties &&
|
||||
(valueParameter.containingDeclaration as? ClassConstructorDescriptor)?.isPrimary == true
|
||||
) {
|
||||
renderModifier(builder, actualPropertiesInPrimaryConstructor, "actual")
|
||||
renderModifier(builder, true, "val")
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ internal class DescriptorRendererOptionsImpl : DescriptorRendererOptions {
|
||||
override var renderDefaultVisibility by property(true)
|
||||
override var renderDefaultModality by property(true)
|
||||
override var renderConstructorDelegation by property(false)
|
||||
override var renderAnnotationPropertiesInPrimaryConstructor by property(false)
|
||||
override var renderPrimaryConstructorParametersAsProperties by property(false)
|
||||
override var actualPropertiesInPrimaryConstructor: Boolean by property(false)
|
||||
override var uninferredTypeParameterAsName by property(false)
|
||||
override var includePropertyConstant by property(false)
|
||||
|
||||
+9
-4
@@ -139,10 +139,16 @@ fun OverrideMemberChooserObject.generateMember(
|
||||
else -> bodyType
|
||||
}
|
||||
|
||||
val renderer = when {
|
||||
val renderer = if (!forceActual && !forceExpect) OVERRIDE_RENDERER else when {
|
||||
forceActual -> ACTUAL_RENDERER
|
||||
forceExpect -> EXPECT_RENDERER
|
||||
else -> OVERRIDE_RENDERER
|
||||
else -> EXPECT_RENDERER
|
||||
}.withOptions {
|
||||
if (descriptor is ClassConstructorDescriptor && descriptor.isPrimary) {
|
||||
val containingClass = descriptor.containingDeclaration
|
||||
if (containingClass.kind == ClassKind.ANNOTATION_CLASS || containingClass.isInline) {
|
||||
renderPrimaryConstructorParametersAsProperties = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (preferConstructorParameter && descriptor is PropertyDescriptor) {
|
||||
@@ -214,7 +220,6 @@ private val EXPECT_RENDERER = OVERRIDE_RENDERER.withOptions {
|
||||
secondaryConstructorsAsPrimary = false
|
||||
renderDefaultVisibility = false
|
||||
renderDefaultModality = false
|
||||
renderAnnotationPropertiesInPrimaryConstructor = true
|
||||
renderTypeExpansions = true
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<caret>expect inline class InlineMe(val x: Int)
|
||||
@@ -0,0 +1,4 @@
|
||||
// "Create expected class in common module testModule_Common" "true"
|
||||
// DISABLE-ERRORS
|
||||
|
||||
actual inline class Inline<caret>Me actual constructor(val x: Int)
|
||||
@@ -0,0 +1,4 @@
|
||||
// "Create expected class in common module testModule_Common" "true"
|
||||
// DISABLE-ERRORS
|
||||
|
||||
actual inline class InlineMe actual constructor(val x: Int)
|
||||
@@ -0,0 +1,3 @@
|
||||
// "Create actual class for module testModule_JVM (JVM)" "true"
|
||||
|
||||
expect inline class Inline<caret>Me(val x: Int)
|
||||
@@ -0,0 +1,3 @@
|
||||
// "Create actual class for module testModule_JVM (JVM)" "true"
|
||||
|
||||
expect inline class InlineMe(val x: Int)
|
||||
@@ -0,0 +1 @@
|
||||
actual inline class InlineMe actual constructor(actual val x: Int)
|
||||
+10
@@ -379,6 +379,11 @@ public class QuickFixMultiModuleTestGenerated extends AbstractQuickFixMultiModul
|
||||
runTest("idea/testData/multiModuleQuickFix/expectFunction/");
|
||||
}
|
||||
|
||||
@TestMetadata("expectInlineClass")
|
||||
public void testExpectInlineClass() throws Exception {
|
||||
runTest("idea/testData/multiModuleQuickFix/expectInlineClass/");
|
||||
}
|
||||
|
||||
@TestMetadata("expectNestedClass")
|
||||
public void testExpectNestedClass() throws Exception {
|
||||
runTest("idea/testData/multiModuleQuickFix/expectNestedClass/");
|
||||
@@ -499,6 +504,11 @@ public class QuickFixMultiModuleTestGenerated extends AbstractQuickFixMultiModul
|
||||
runTest("idea/testData/multiModuleQuickFix/importFunInCommon/");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineClass")
|
||||
public void testInlineClass() throws Exception {
|
||||
runTest("idea/testData/multiModuleQuickFix/inlineClass/");
|
||||
}
|
||||
|
||||
@TestMetadata("interface")
|
||||
public void testInterface() throws Exception {
|
||||
runTest("idea/testData/multiModuleQuickFix/interface/");
|
||||
|
||||
Reference in New Issue
Block a user