diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/AddValVarToConstructorParameterAction.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/AddValVarToConstructorParameterAction.kt index 6ad63685ee7..18f74214e88 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/AddValVarToConstructorParameterAction.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/AddValVarToConstructorParameterAction.kt @@ -27,10 +27,10 @@ import org.jetbrains.kotlin.diagnostics.Errors import org.jetbrains.kotlin.idea.quickfix.KotlinQuickFixAction import org.jetbrains.kotlin.idea.quickfix.KotlinSingleIntentionActionFactory import org.jetbrains.kotlin.idea.refactoring.ValVarExpression +import org.jetbrains.kotlin.idea.util.isExpectDeclaration import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.createSmartPointer import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType -import org.jetbrains.kotlin.psi.psiUtil.hasExpectModifier import org.jetbrains.kotlin.psi.psiUtil.startOffset interface AddValVarToConstructorParameterAction { @@ -41,7 +41,8 @@ interface AddValVarToConstructorParameterAction { fun getActionText(element: KtParameter) = "Add val/var to parameter '${element.name ?: ""}'" fun canInvoke(element: KtParameter): Boolean { - return element.valOrVarKeyword == null && (element.parent as? KtParameterList)?.parent is KtPrimaryConstructor + return element.valOrVarKeyword == null && ((element.parent as? KtParameterList)?.parent as? KtPrimaryConstructor) + ?.takeUnless(KtDeclaration::isExpectDeclaration) != null } fun invoke(element: KtParameter, editor: Editor?) { diff --git a/idea/testData/intentions/addValOrVar/actualClass.kt b/idea/testData/intentions/addValOrVar/actualClass.kt new file mode 100644 index 00000000000..48887269f93 --- /dev/null +++ b/idea/testData/intentions/addValOrVar/actualClass.kt @@ -0,0 +1,2 @@ +// ERROR: The feature "multi platform projects" is experimental and should be enabled explicitly +actual class A(a: Int) \ No newline at end of file diff --git a/idea/testData/intentions/addValOrVar/actualClass.kt.after b/idea/testData/intentions/addValOrVar/actualClass.kt.after new file mode 100644 index 00000000000..9e9600e9989 --- /dev/null +++ b/idea/testData/intentions/addValOrVar/actualClass.kt.after @@ -0,0 +1,2 @@ +// ERROR: The feature "multi platform projects" is experimental and should be enabled explicitly +actual class A(val a: Int) \ No newline at end of file diff --git a/idea/testData/intentions/addValOrVar/expectClass.kt b/idea/testData/intentions/addValOrVar/expectClass.kt new file mode 100644 index 00000000000..424307c465a --- /dev/null +++ b/idea/testData/intentions/addValOrVar/expectClass.kt @@ -0,0 +1,3 @@ +// IS_APPLICABLE: false +// ERROR: The feature "multi platform projects" is experimental and should be enabled explicitly +expect class A(a: Int) \ No newline at end of file diff --git a/idea/testData/intentions/addValOrVar/expectClass2.kt b/idea/testData/intentions/addValOrVar/expectClass2.kt new file mode 100644 index 00000000000..e8bca2b4134 --- /dev/null +++ b/idea/testData/intentions/addValOrVar/expectClass2.kt @@ -0,0 +1,5 @@ +// IS_APPLICABLE: false +// ERROR: The feature "multi platform projects" is experimental and should be enabled explicitly +expect class A(a: Int) { + class B(b: String) +} \ 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 54387155385..fc86aa9388f 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -1912,6 +1912,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest { KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); } + @TestMetadata("actualClass.kt") + public void testActualClass() throws Exception { + runTest("idea/testData/intentions/addValOrVar/actualClass.kt"); + } + @TestMetadata("addVal.kt") public void testAddVal() throws Exception { runTest("idea/testData/intentions/addValOrVar/addVal.kt"); @@ -1926,6 +1931,16 @@ public class IntentionTestGenerated extends AbstractIntentionTest { runTest("idea/testData/intentions/addValOrVar/dataClass.kt"); } + @TestMetadata("expectClass.kt") + public void testExpectClass() throws Exception { + runTest("idea/testData/intentions/addValOrVar/expectClass.kt"); + } + + @TestMetadata("expectClass2.kt") + public void testExpectClass2() throws Exception { + runTest("idea/testData/intentions/addValOrVar/expectClass2.kt"); + } + @TestMetadata("funParameter.kt") public void testFunParameter() throws Exception { runTest("idea/testData/intentions/addValOrVar/funParameter.kt");