Forbid "introduce backing property" for expect classes #KT-28382 Fixed
This commit is contained in:
@@ -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.getResolutionFacade
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall
|
import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall
|
||||||
import org.jetbrains.kotlin.idea.util.hasJvmFieldAnnotation
|
import org.jetbrains.kotlin.idea.util.hasJvmFieldAnnotation
|
||||||
|
import org.jetbrains.kotlin.idea.util.isExpectDeclaration
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
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
|
if (bindingContext.get(BindingContext.BACKING_FIELD_REQUIRED, descriptor) == false) return false
|
||||||
|
|
||||||
val containingClass = property.getStrictParentOfType<KtClassOrObject>() ?: 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) {
|
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");
|
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")
|
@TestMetadata("inapplicableAbstractProperty.kt")
|
||||||
public void testInapplicableAbstractProperty() throws Exception {
|
public void testInapplicableAbstractProperty() throws Exception {
|
||||||
runTest("idea/testData/intentions/introduceBackingProperty/inapplicableAbstractProperty.kt");
|
runTest("idea/testData/intentions/introduceBackingProperty/inapplicableAbstractProperty.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user