Add name to argument: do not remove necessary backticks

#KT-30894 Fixed
This commit is contained in:
Toshiaki Kameyama
2019-12-01 21:17:51 +09:00
committed by Yan Zhulanow
parent a492fe7757
commit b56272dc64
10 changed files with 75 additions and 1 deletions
@@ -19,6 +19,7 @@ import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.psiUtil.isIdentifier
import org.jetbrains.kotlin.resolve.ImportPath
import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments
import org.jetbrains.kotlin.utils.checkWithAttachment
@@ -531,7 +532,12 @@ class KtPsiFactory @JvmOverloads constructor(private val project: Project, val m
appendFixedText("(")
if (name != null) {
appendName(name)
val asString = name.asString()
if (asString.isIdentifier()) {
appendName(name)
} else {
appendFixedText("`$asString`")
}
appendFixedText(" = ")
}
@@ -0,0 +1,6 @@
fun foo(`1`: Int, `fun`: Int) {
}
fun main() {
foo(1, 2<caret>)
}
@@ -0,0 +1,6 @@
fun foo(`1`: Int, `fun`: Int) {
}
fun main() {
foo(1, `fun` = 2)
}
@@ -0,0 +1,6 @@
fun foo(`1`: Int, `2`: Int) {
}
fun main() {
foo(1, 2<caret>)
}
@@ -0,0 +1,6 @@
fun foo(`1`: Int, `2`: Int) {
}
fun main() {
foo(1, `2` = 2)
}
@@ -0,0 +1,6 @@
fun foo(`1`: Int, `2a`: Int) {
}
fun main() {
foo(1, 2<caret>)
}
@@ -0,0 +1,6 @@
fun foo(`1`: Int, `2a`: Int) {
}
fun main() {
foo(1, `2a` = 2)
}
@@ -0,0 +1,6 @@
fun foo(`1`: Int, `a`: Int) {
}
fun main() {
foo(1, 2<caret>)
}
@@ -0,0 +1,6 @@
fun foo(`1`: Int, `a`: Int) {
}
fun main() {
foo(1, a = 2)
}
@@ -1253,6 +1253,26 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
runTest("idea/testData/intentions/addNameToArgument/ambiguousCall.kt");
}
@TestMetadata("backtickedArgument.kt")
public void testBacktickedArgument() throws Exception {
runTest("idea/testData/intentions/addNameToArgument/backtickedArgument.kt");
}
@TestMetadata("backtickedArgument2.kt")
public void testBacktickedArgument2() throws Exception {
runTest("idea/testData/intentions/addNameToArgument/backtickedArgument2.kt");
}
@TestMetadata("backtickedArgument3.kt")
public void testBacktickedArgument3() throws Exception {
runTest("idea/testData/intentions/addNameToArgument/backtickedArgument3.kt");
}
@TestMetadata("backtickedArgument4.kt")
public void testBacktickedArgument4() throws Exception {
runTest("idea/testData/intentions/addNameToArgument/backtickedArgument4.kt");
}
@TestMetadata("beforeOtherNamed.kt")
public void testBeforeOtherNamed() throws Exception {
runTest("idea/testData/intentions/addNameToArgument/beforeOtherNamed.kt");