Convert concatenation to template: omit braces when converting 'this' #KT-7555 Fixed

This commit is contained in:
Toshiaki Kameyama
2018-11-05 12:59:35 +09:00
committed by Mikhail Glukhikh
parent 7a9effe30d
commit 4a82f50e79
8 changed files with 42 additions and 0 deletions
@@ -120,6 +120,9 @@ open class ConvertToStringTemplateIntention : SelfTargetingOffsetIndependentInte
is KtNameReferenceExpression ->
return "$" + (if (forceBraces) "{$expressionText}" else expressionText)
is KtThisExpression ->
return "$" + (if (forceBraces || expression.labelQualifier != null) "{$expressionText}" else expressionText)
}
return "\${$expressionText}"
@@ -0,0 +1,3 @@
class A {
val s = ""<caret> + this
}
@@ -0,0 +1,3 @@
class A {
val s = "$this"
}
@@ -0,0 +1,4 @@
class A {
val i = 1
val s = ""<caret> + this.i
}
@@ -0,0 +1,4 @@
class A {
val i = 1
val s = "${this.i}"
}
@@ -0,0 +1,5 @@
class A {
inner class B {
val s = ""<caret> + this@A
}
}
@@ -0,0 +1,5 @@
class A {
inner class B {
val s = "${this@A}"
}
}
@@ -7450,6 +7450,21 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
runTest("idea/testData/intentions/convertToStringTemplate/templatePlusStringLiteral.kt");
}
@TestMetadata("this.kt")
public void testThis() throws Exception {
runTest("idea/testData/intentions/convertToStringTemplate/this.kt");
}
@TestMetadata("this2.kt")
public void testThis2() throws Exception {
runTest("idea/testData/intentions/convertToStringTemplate/this2.kt");
}
@TestMetadata("this3.kt")
public void testThis3() throws Exception {
runTest("idea/testData/intentions/convertToStringTemplate/this3.kt");
}
@TestMetadata("tricky.kt")
public void testTricky() throws Exception {
runTest("idea/testData/intentions/convertToStringTemplate/tricky.kt");