Convert concatenation to template: remove 'toString()' call #KT-6025 Fixed
This commit is contained in:
committed by
Vyacheslav Gerasimov
parent
825d1d8b35
commit
f1a0cefde0
@@ -79,7 +79,9 @@ open class ConvertToStringTemplateIntention : SelfTargetingOffsetIndependentInte
|
||||
|
||||
fun buildText(expr: KtExpression?, forceBraces: Boolean): String {
|
||||
if (expr == null) return ""
|
||||
val expression = KtPsiUtil.safeDeparenthesize(expr)
|
||||
val expression = KtPsiUtil.safeDeparenthesize(expr).let {
|
||||
if ((it as? KtDotQualifiedExpression)?.isToString() == true) it.receiverExpression else it
|
||||
}
|
||||
val expressionText = expression.text
|
||||
when (expression) {
|
||||
is KtConstantExpression -> {
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
fun test(a: Any, b: Any, c: Any): String {
|
||||
return "a:" <caret>+ a.toString() + ", b:" + b.toString() + "_ c:" + c.toString("")
|
||||
}
|
||||
fun Any.toString(s: String) = ""
|
||||
@@ -0,0 +1,4 @@
|
||||
fun test(a: Any, b: Any, c: Any): String {
|
||||
return "a:$a, b:${b}_ c:${c.toString("")}"
|
||||
}
|
||||
fun Any.toString(s: String) = ""
|
||||
@@ -7495,6 +7495,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
runTest("idea/testData/intentions/convertToStringTemplate/this3.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("toString.kt")
|
||||
public void testToString() throws Exception {
|
||||
runTest("idea/testData/intentions/convertToStringTemplate/toString.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("tricky.kt")
|
||||
public void testTricky() throws Exception {
|
||||
runTest("idea/testData/intentions/convertToStringTemplate/tricky.kt");
|
||||
|
||||
Reference in New Issue
Block a user