Minor improvement in convert to string template inspection: no highlighting when the expression is split onto multiple lines

This commit is contained in:
Valentin Kipyatkov
2016-03-24 19:39:34 +03:00
parent c32881e41b
commit 602de317d6
4 changed files with 17 additions and 2 deletions
@@ -49,9 +49,10 @@ class ConvertToStringTemplateIntention : SelfTargetingOffsetIndependentIntention
fun shouldSuggestToConvert(expression: KtBinaryExpression): Boolean {
val entries = buildReplacement(expression).entries
return entries.none { it is KtBlockStringTemplateEntry } &&
!entries.all { it is KtLiteralStringTemplateEntry || it is KtEscapeStringTemplateEntry }
return entries.none { it is KtBlockStringTemplateEntry }
&& !entries.all { it is KtLiteralStringTemplateEntry || it is KtEscapeStringTemplateEntry }
&& entries.count { it is KtLiteralStringTemplateEntry } > 1
&& !expression.textContains('\n')
}
private fun isApplicableToNoParentCheck(expression: KtBinaryExpression): Boolean {
@@ -0,0 +1,5 @@
fun foo(p: Int) {
val v = <caret>"line 1\n" +
"line 2: " + p + "\n" +
"line 3"
}
@@ -0,0 +1,3 @@
fun foo(p: Int) {
val v = "line 1\nline 2: $p\nline 3"
}
@@ -4795,6 +4795,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
doTest(fileName);
}
@TestMetadata("onMultipleLines.kt")
public void testOnMultipleLines() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertToStringTemplate/onMultipleLines.kt");
doTest(fileName);
}
@TestMetadata("onlyForConcat.kt")
public void testOnlyForConcat() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertToStringTemplate/onlyForConcat.kt");