Add name to argument: support old-style comment deletion
This commit is contained in:
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.idea.intentions
|
||||
|
||||
import com.intellij.codeInsight.intention.LowPriorityAction
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.psi.PsiComment
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
@@ -28,6 +29,7 @@ import org.jetbrains.kotlin.idea.conversion.copy.start
|
||||
import org.jetbrains.kotlin.idea.project.languageVersionSettings
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getPrevSiblingIgnoringWhitespace
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ArgumentMatch
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ArgumentMatchStatus.ARGUMENT_HAS_NO_TYPE
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ArgumentMatchStatus.SUCCESS
|
||||
@@ -63,6 +65,12 @@ class AddNameToArgumentIntention : SelfTargetingIntention<KtValueArgument>(
|
||||
fun apply(element: KtValueArgument, givenResolvedCall: ResolvedCall<*>? = null): Boolean {
|
||||
val name = detectNameToAdd(element, shouldBeLastUnnamed = false, givenResolvedCall = givenResolvedCall) ?: return false
|
||||
val argumentExpression = element.getArgumentExpression() ?: return false
|
||||
|
||||
val prevSibling = element.getPrevSiblingIgnoringWhitespace()
|
||||
if (prevSibling is PsiComment && """/\*\s*$name\s*=\s*\*/""".toRegex().matches(prevSibling.text)) {
|
||||
prevSibling.delete()
|
||||
}
|
||||
|
||||
val newArgument = KtPsiFactory(element).createArgument(argumentExpression, name, element.getSpreadElement() != null)
|
||||
element.replace(newArgument)
|
||||
return true
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// INTENTION_TEXT: "Add 'b =' to argument"
|
||||
|
||||
fun foo(s: String, b: Boolean){}
|
||||
|
||||
fun bar() {
|
||||
foo("", /* b = */ true<caret>)
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// INTENTION_TEXT: "Add 'b =' to argument"
|
||||
|
||||
fun foo(s: String, b: Boolean){}
|
||||
|
||||
fun bar() {
|
||||
foo("", b = true<caret>)
|
||||
}
|
||||
@@ -1280,6 +1280,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
public void testVararg3() throws Exception {
|
||||
runTest("idea/testData/intentions/addNameToArgument/vararg3.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("withComment.kt")
|
||||
public void testWithComment() throws Exception {
|
||||
runTest("idea/testData/intentions/addNameToArgument/withComment.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/intentions/addNamesToCallArguments")
|
||||
|
||||
Reference in New Issue
Block a user