DeprecatedCallableAddReplaceWithIntention: fixed for string templates in expression
This commit is contained in:
+18
-2
@@ -62,11 +62,27 @@ public class DeprecatedCallableAddReplaceWithIntention : JetSelfTargetingRangeIn
|
||||
val annotationEntry = element.deprecatedAnnotationWithNoReplaceWith()!!
|
||||
val psiFactory = JetPsiFactory(element)
|
||||
|
||||
val escapedText = replaceWith.expression
|
||||
var escapedText = replaceWith.expression
|
||||
.replace("\\", "\\\\")
|
||||
.replace("\"", "\\\"")
|
||||
|
||||
//TODO: escape $!
|
||||
// escape '$' if it's followed by a letter or '{'
|
||||
if (escapedText.contains('$')) {
|
||||
escapedText = StringBuilder {
|
||||
var i = 0
|
||||
val length = escapedText.length()
|
||||
while (i < length) {
|
||||
val c = escapedText[i++]
|
||||
if (c == '$' && i < length) {
|
||||
val c1 = escapedText[i]
|
||||
if (c1.isJavaIdentifierStart() || c1 == '{') {
|
||||
append('\\')
|
||||
}
|
||||
}
|
||||
append(c)
|
||||
}
|
||||
}.toString()
|
||||
}
|
||||
|
||||
val argumentText = StringBuilder {
|
||||
append("kotlin.ReplaceWith(\"")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<caret>@deprecated("")
|
||||
fun foo(p: Int) {
|
||||
bar("\"$p\"\n1\r2\t3")
|
||||
bar("\"\"\n1\r2\t3")
|
||||
}
|
||||
|
||||
fun bar(s: String){}
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
@deprecated("", ReplaceWith("bar(\"\\\"$p\\\"\\n1\\r2\\t3\")"))
|
||||
@deprecated("", ReplaceWith("bar(\"\\\"\\\"\\n1\\r2\\t3\")"))
|
||||
fun foo(p: Int) {
|
||||
bar("\"$p\"\n1\r2\t3")
|
||||
bar("\"\"\n1\r2\t3")
|
||||
}
|
||||
|
||||
fun bar(s: String){}
|
||||
@@ -0,0 +1,6 @@
|
||||
<caret>@deprecated("")
|
||||
fun foo(p: Int) {
|
||||
bar("$p ${p + 1} $0")
|
||||
}
|
||||
|
||||
fun bar(s: String){}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
@deprecated("", ReplaceWith("bar(\"\$p \${p + 1} $0\")"))
|
||||
fun foo(p: Int) {
|
||||
bar("$p ${p + 1} $0")
|
||||
}
|
||||
|
||||
fun bar(s: String){}
|
||||
@@ -4588,6 +4588,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("StringTemplate.kt")
|
||||
public void testStringTemplate() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/deprecatedCallableAddReplaceWith/StringTemplate.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("TwoStatements.kt")
|
||||
public void testTwoStatements() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/deprecatedCallableAddReplaceWith/TwoStatements.kt");
|
||||
|
||||
Reference in New Issue
Block a user