Don't suggest Add val/var to parameter at expect class constructor

#KT-29731 Fixed
This commit is contained in:
Dmitry Gridin
2019-05-15 15:34:01 +07:00
parent af9d9eacb1
commit 1097bc76af
6 changed files with 30 additions and 2 deletions
@@ -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?) {
+2
View File
@@ -0,0 +1,2 @@
// ERROR: The feature "multi platform projects" is experimental and should be enabled explicitly
actual class A(<caret>a: Int)
@@ -0,0 +1,2 @@
// ERROR: The feature "multi platform projects" is experimental and should be enabled explicitly
actual class A(val<caret> a: Int)
+3
View File
@@ -0,0 +1,3 @@
// IS_APPLICABLE: false
// ERROR: The feature "multi platform projects" is experimental and should be enabled explicitly
expect class A(<caret>a: Int)
+5
View File
@@ -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(<caret>b: String)
}
@@ -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");