Fix problem with appending literal to variable omitting braces #KT-13336 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
223fd9fad0
commit
42969271ab
@@ -123,12 +123,19 @@ class ConvertToStringTemplateIntention : SelfTargetingOffsetIndependentIntention
|
||||
else {
|
||||
StringUtil.unquoteString(expressionText)
|
||||
}
|
||||
if (forceBraces && base.endsWith('$')) {
|
||||
return base.dropLast(1) + "\\$"
|
||||
}
|
||||
else {
|
||||
return base
|
||||
|
||||
if (forceBraces) {
|
||||
if (base.endsWith('$')) {
|
||||
return base.dropLast(1) + "\\$"
|
||||
}
|
||||
else {
|
||||
val lastPart = expression.children.lastOrNull()
|
||||
if (lastPart is KtSimpleNameStringTemplateEntry) {
|
||||
return base.dropLast(lastPart.textLength) + "\${" + lastPart.text.drop(1) + "}"
|
||||
}
|
||||
}
|
||||
}
|
||||
return base
|
||||
}
|
||||
|
||||
is KtNameReferenceExpression ->
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
fun foo() {
|
||||
val nv1 = 1
|
||||
val nv2 = "prefix $nv1" + <caret>"postfix"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
fun foo() {
|
||||
val nv1 = 1
|
||||
val nv2 = "prefix ${nv1}postfix"
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
fun foo() {
|
||||
val prefix = "prefix"
|
||||
val nv2 = prefix + <caret>"postfix"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
fun foo() {
|
||||
val prefix = "prefix"
|
||||
val nv2 = "${prefix}postfix"
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
fun foo() {
|
||||
val nv1 = 1
|
||||
val nv2 = "$nv1" + <caret>"postfix"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
fun foo() {
|
||||
val nv1 = 1
|
||||
val nv2 = "${nv1}postfix"
|
||||
}
|
||||
@@ -5254,6 +5254,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("longTemplatePlusStringLiteral.kt")
|
||||
public void testLongTemplatePlusStringLiteral() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertToStringTemplate/longTemplatePlusStringLiteral.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("multilineString.kt")
|
||||
public void testMultilineString() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertToStringTemplate/multilineString.kt");
|
||||
@@ -5320,6 +5326,18 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("stringPlusStringLiteral.kt")
|
||||
public void testStringPlusStringLiteral() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertToStringTemplate/stringPlusStringLiteral.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("templatePlusStringLiteral.kt")
|
||||
public void testTemplatePlusStringLiteral() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertToStringTemplate/templatePlusStringLiteral.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("tricky.kt")
|
||||
public void testTricky() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertToStringTemplate/tricky.kt");
|
||||
|
||||
Reference in New Issue
Block a user