Forbid "move property to constructor" for expect classes #KT-28381 Fixed

This commit is contained in:
Mikhail Glukhikh
2018-11-22 18:10:56 +03:00
parent f960ed9a46
commit 10cc4959cc
3 changed files with 17 additions and 3 deletions
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.idea.core.ShortenReferences
import org.jetbrains.kotlin.idea.search.usagesSearch.descriptor
import org.jetbrains.kotlin.idea.util.CommentSaver
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
import org.jetbrains.kotlin.idea.util.isExpectDeclaration
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
import org.jetbrains.kotlin.lexer.KtTokens.LATEINIT_KEYWORD
import org.jetbrains.kotlin.lexer.KtTokens.VARARG_KEYWORD
@@ -54,9 +55,9 @@ class MovePropertyToConstructorIntention :
}
override fun isApplicableTo(element: KtProperty, caretOffset: Int): Boolean {
fun KtProperty.isDeclaredInClass(): Boolean {
fun KtProperty.isDeclaredInSupportedClass(): Boolean {
val parent = getStrictParentOfType<KtClassOrObject>()
return parent is KtClass && !parent.isInterface()
return parent is KtClass && !parent.isInterface() && !parent.isExpectDeclaration()
}
return !element.isLocal
@@ -64,7 +65,7 @@ class MovePropertyToConstructorIntention :
&& element.getter == null
&& element.setter == null
&& !element.hasModifier(LATEINIT_KEYWORD)
&& (element.isDeclaredInClass())
&& (element.isDeclaredInSupportedClass())
&& (element.initializer?.isValidInConstructor() ?: true)
}
@@ -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
}
}
@@ -12020,6 +12020,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
runTest("idea/testData/intentions/movePropertyToConstructor/delegated.kt");
}
@TestMetadata("expectClass.kt")
public void testExpectClass() throws Exception {
runTest("idea/testData/intentions/movePropertyToConstructor/expectClass.kt");
}
@TestMetadata("functionReference.kt")
public void testFunctionReference() throws Exception {
runTest("idea/testData/intentions/movePropertyToConstructor/functionReference.kt");