From 41b75346fe2551b574d1f0bb6ccf35f77f08ba2e Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Thu, 22 Nov 2018 18:17:56 +0300 Subject: [PATCH] Forbid "introduce backing property" for expect classes #KT-28382 Fixed --- .../idea/intentions/IntroduceBackingPropertyIntention.kt | 4 +++- .../intentions/introduceBackingProperty/expectClass.kt | 8 ++++++++ .../kotlin/idea/intentions/IntentionTestGenerated.java | 5 +++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 idea/testData/intentions/introduceBackingProperty/expectClass.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/IntroduceBackingPropertyIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/IntroduceBackingPropertyIntention.kt index 4318b12cde3..ef4d26b7f3c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/IntroduceBackingPropertyIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/IntroduceBackingPropertyIntention.kt @@ -22,6 +22,7 @@ import org.jetbrains.kotlin.descriptors.impl.SyntheticFieldDescriptor import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall import org.jetbrains.kotlin.idea.util.hasJvmFieldAnnotation +import org.jetbrains.kotlin.idea.util.isExpectDeclaration import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType @@ -48,7 +49,8 @@ class IntroduceBackingPropertyIntention : SelfTargetingIntention(KtP if (bindingContext.get(BindingContext.BACKING_FIELD_REQUIRED, descriptor) == false) return false val containingClass = property.getStrictParentOfType() ?: return false - return containingClass.declarations.none { it is KtProperty && it.name == "_" + name } + if (containingClass.isExpectDeclaration()) return false + return containingClass.declarations.none { it is KtProperty && it.name == "_$name" } } fun introduceBackingProperty(property: KtProperty) { diff --git a/idea/testData/intentions/introduceBackingProperty/expectClass.kt b/idea/testData/intentions/introduceBackingProperty/expectClass.kt new file mode 100644 index 00000000000..e8f4c34d43e --- /dev/null +++ b/idea/testData/intentions/introduceBackingProperty/expectClass.kt @@ -0,0 +1,8 @@ +// IS_APPLICABLE: false +// ERROR: The feature "multi platform projects" is experimental and should be enabled explicitly + +expect class Outer { + class Nested { + val x: Int + } +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java index 430b5c61e7a..2e01713e76b 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -9299,6 +9299,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest { runTest("idea/testData/intentions/introduceBackingProperty/const.kt"); } + @TestMetadata("expectClass.kt") + public void testExpectClass() throws Exception { + runTest("idea/testData/intentions/introduceBackingProperty/expectClass.kt"); + } + @TestMetadata("inapplicableAbstractProperty.kt") public void testInapplicableAbstractProperty() throws Exception { runTest("idea/testData/intentions/introduceBackingProperty/inapplicableAbstractProperty.kt");