Forbid "introduce backing property" for expect classes #KT-28382 Fixed

This commit is contained in:
Mikhail Glukhikh
2018-11-22 18:17:56 +03:00
parent 10cc4959cc
commit 41b75346fe
3 changed files with 16 additions and 1 deletions
@@ -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<KtProperty>(KtP
if (bindingContext.get(BindingContext.BACKING_FIELD_REQUIRED, descriptor) == false) return false
val containingClass = property.getStrictParentOfType<KtClassOrObject>() ?: 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) {
@@ -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 <caret>x: Int
}
}
@@ -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");