Forbid "move property to constructor" for expect classes #KT-28381 Fixed
This commit is contained in:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user