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 {
|
else {
|
||||||
StringUtil.unquoteString(expressionText)
|
StringUtil.unquoteString(expressionText)
|
||||||
}
|
}
|
||||||
if (forceBraces && base.endsWith('$')) {
|
|
||||||
return base.dropLast(1) + "\\$"
|
if (forceBraces) {
|
||||||
}
|
if (base.endsWith('$')) {
|
||||||
else {
|
return base.dropLast(1) + "\\$"
|
||||||
return base
|
}
|
||||||
|
else {
|
||||||
|
val lastPart = expression.children.lastOrNull()
|
||||||
|
if (lastPart is KtSimpleNameStringTemplateEntry) {
|
||||||
|
return base.dropLast(lastPart.textLength) + "\${" + lastPart.text.drop(1) + "}"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return base
|
||||||
}
|
}
|
||||||
|
|
||||||
is KtNameReferenceExpression ->
|
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);
|
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")
|
@TestMetadata("multilineString.kt")
|
||||||
public void testMultilineString() throws Exception {
|
public void testMultilineString() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertToStringTemplate/multilineString.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertToStringTemplate/multilineString.kt");
|
||||||
@@ -5320,6 +5326,18 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("tricky.kt")
|
||||||
public void testTricky() throws Exception {
|
public void testTricky() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertToStringTemplate/tricky.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertToStringTemplate/tricky.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user