Add/remove argument name intentions to work for super class constructor call
This commit is contained in:
@@ -63,7 +63,7 @@ class AddNameToArgumentIntention
|
||||
val argumentList = argument.parent as? KtValueArgumentList ?: return null
|
||||
if (argument != argumentList.arguments.last { !it.isNamed() }) return null
|
||||
|
||||
val callExpr = argumentList.parent as? KtExpression ?: return null
|
||||
val callExpr = argumentList.parent as? KtCallElement ?: return null
|
||||
val resolvedCall = callExpr.getResolvedCall(callExpr.analyze(BodyResolveMode.PARTIAL)) ?: return null
|
||||
val argumentMatch = resolvedCall.getArgumentMapping(argument) as? ArgumentMatch ?: return null
|
||||
if (argumentMatch.status != ArgumentMatchStatus.SUCCESS) return null
|
||||
|
||||
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.idea.intentions
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.psi.KtCallElement
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||
import org.jetbrains.kotlin.psi.KtValueArgument
|
||||
import org.jetbrains.kotlin.psi.KtValueArgumentList
|
||||
@@ -38,7 +38,7 @@ class RemoveArgumentNameIntention
|
||||
val arguments = argumentList.arguments
|
||||
if (arguments.takeWhile { it != element }.any { it.isNamed() }) return null
|
||||
|
||||
val callExpr = argumentList.parent as? KtExpression ?: return null
|
||||
val callExpr = argumentList.parent as? KtCallElement ?: return null
|
||||
val resolvedCall = callExpr.getResolvedCall(callExpr.analyze(BodyResolveMode.PARTIAL)) ?: return null
|
||||
val argumentMatch = resolvedCall.getArgumentMapping(element) as? ArgumentMatch ?: return null
|
||||
if (argumentMatch.valueParameter.index != arguments.indexOf(element)) return null
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
open class C(p1: Int, p2: Int)
|
||||
|
||||
class D : C(1, <caret>2)
|
||||
@@ -0,0 +1,3 @@
|
||||
open class C(p1: Int, p2: Int)
|
||||
|
||||
class D : C(1, p2 = 2)
|
||||
@@ -0,0 +1,3 @@
|
||||
open class C(p1: Int, p2: Int)
|
||||
|
||||
class D : C(1, <caret>p2 = 2)
|
||||
@@ -0,0 +1,3 @@
|
||||
open class C(p1: Int, p2: Int)
|
||||
|
||||
class D : C(1, <caret>2)
|
||||
@@ -292,6 +292,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("superClassConstructor.kt")
|
||||
public void testSuperClassConstructor() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/addNameToArgument/superClassConstructor.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("vararg1.kt")
|
||||
public void testVararg1() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/addNameToArgument/vararg1.kt");
|
||||
@@ -6973,6 +6979,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeArgumentName/star.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("superClassConstructor.kt")
|
||||
public void testSuperClassConstructor() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeArgumentName/superClassConstructor.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/intentions/removeBraces")
|
||||
|
||||
Reference in New Issue
Block a user