Fixed EA-73613
This commit is contained in:
Generated
+1
@@ -17,6 +17,7 @@
|
|||||||
<w>renderers</w>
|
<w>renderers</w>
|
||||||
<w>rparenth</w>
|
<w>rparenth</w>
|
||||||
<w>selectioner</w>
|
<w>selectioner</w>
|
||||||
|
<w>summand</w>
|
||||||
<w>unpluralize</w>
|
<w>unpluralize</w>
|
||||||
<w>weighers</w>
|
<w>weighers</w>
|
||||||
</words>
|
</words>
|
||||||
|
|||||||
@@ -56,11 +56,19 @@ class ConvertToStringTemplateIntention : SelfTargetingOffsetIndependentIntention
|
|||||||
|
|
||||||
private fun isApplicableToNoParentCheck(expression: KtBinaryExpression): Boolean {
|
private fun isApplicableToNoParentCheck(expression: KtBinaryExpression): Boolean {
|
||||||
if (expression.operationToken != KtTokens.PLUS) return false
|
if (expression.operationToken != KtTokens.PLUS) return false
|
||||||
if (!KotlinBuiltIns.isString(expression.analyze().getType(expression))) return false
|
val expressionType = expression.analyze(BodyResolveMode.PARTIAL).getType(expression)
|
||||||
|
if (!KotlinBuiltIns.isString(expressionType)) return false
|
||||||
|
return isSuitable(expression)
|
||||||
|
}
|
||||||
|
|
||||||
val left = expression.left ?: return false
|
private fun isSuitable(expression: KtExpression): Boolean {
|
||||||
val right = expression.right ?: return false
|
if (expression is KtBinaryExpression && expression.operationToken == KtTokens.PLUS) {
|
||||||
return !PsiUtilCore.hasErrorElementChild(left) && !PsiUtilCore.hasErrorElementChild(right)
|
return isSuitable(expression.left ?: return false) && isSuitable(expression.right ?: return false)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PsiUtilCore.hasErrorElementChild(expression)) return false
|
||||||
|
if (expression.textContains('\n')) return false
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildReplacement(expression: KtBinaryExpression): KtStringTemplateExpression {
|
private fun buildReplacement(expression: KtBinaryExpression): KtStringTemplateExpression {
|
||||||
@@ -121,6 +129,6 @@ class ConvertToStringTemplateIntention : SelfTargetingOffsetIndependentIntention
|
|||||||
return "$" + (if (forceBraces) "{$expressionText}" else expressionText)
|
return "$" + (if (forceBraces) "{$expressionText}" else expressionText)
|
||||||
}
|
}
|
||||||
|
|
||||||
return "\${" + expressionText.replace("\n+".toRegex(), " ") + "}"
|
return "\${$expressionText}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// IS_APPLICABLE: false
|
||||||
fun main(args: Array<String>){
|
fun main(args: Array<String>){
|
||||||
val x = "foo" +<caret> """bar\n
|
val x = "foo" +<caret> """bar\n
|
||||||
"""
|
"""
|
||||||
|
|||||||
-3
@@ -1,3 +0,0 @@
|
|||||||
fun main(args: Array<String>){
|
|
||||||
val x = "foobar\\n\n "
|
|
||||||
}
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
val v = "a" + (<caret>1.hashCode() /*comment*/ * 2)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
val v = "a${1.hashCode() /*comment*/ * 2}"
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
|
// IS_APPLICABLE: false
|
||||||
fun main(args: Array<String>){
|
fun main(args: Array<String>){
|
||||||
val y = "abcd" +<caret> listOf( 1,
|
val y = "abcd" +<caret> listOf( 1,
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
// WITH_RUNTIME
|
|
||||||
fun main(args: Array<String>){
|
|
||||||
val y = "abcd${listOf(1, 2)}"
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
// IS_APPLICABLE: false
|
||||||
|
val v = "a" + (<caret>1.hashCode() // comment
|
||||||
|
* 2)
|
||||||
+3
-3
@@ -1,9 +1,9 @@
|
|||||||
<problems>
|
<problems>
|
||||||
<problem>
|
<problem>
|
||||||
<file>multilineString.kt</file>
|
<file>simple.kt</file>
|
||||||
<line>3</line>
|
<line>2</line>
|
||||||
<module>light_idea_test_case</module>
|
<module>light_idea_test_case</module>
|
||||||
<entry_point TYPE="file" FQNAME="multilineString.kt" />
|
<entry_point TYPE="file" FQNAME="simple.kt" />
|
||||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Convert string concatenation to string template</problem_class>
|
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Convert string concatenation to string template</problem_class>
|
||||||
<description>Convert concatenation to template</description>
|
<description>Convert concatenation to template</description>
|
||||||
</problem>
|
</problem>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
|
// IS_APPLICABLE: false
|
||||||
fun main(args: Array<String>){
|
fun main(args: Array<String>){
|
||||||
val y = "abcd" +<caret> listOf( 1,
|
val y = "abcd" +<caret> listOf( 1,
|
||||||
2 )
|
2 )
|
||||||
|
|||||||
-4
@@ -1,4 +0,0 @@
|
|||||||
// WITH_RUNTIME
|
|
||||||
fun main(args: Array<String>){
|
|
||||||
val y = "abcd${listOf(1, 2)}"
|
|
||||||
}
|
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// IS_APPLICABLE: false
|
||||||
fun main(args: Array<String>){
|
fun main(args: Array<String>){
|
||||||
var r = "a"
|
var r = "a"
|
||||||
val x = "foo" +<caret> """bar
|
val x = "foo" +<caret> """bar
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
fun main(args: Array<String>){
|
|
||||||
var r = "a"
|
|
||||||
val x = "foobar\n $r"
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(p: Int) {
|
||||||
|
val v = <caret>"(" + p + ")"
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(p: Int) {
|
||||||
|
val v = <caret>"($p)"
|
||||||
|
}
|
||||||
@@ -4561,6 +4561,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("comment.kt")
|
||||||
|
public void testComment() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertToStringTemplate/comment.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("consecutiveNewlines.kt")
|
@TestMetadata("consecutiveNewlines.kt")
|
||||||
public void testConsecutiveNewlines() throws Exception {
|
public void testConsecutiveNewlines() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertToStringTemplate/consecutiveNewlines.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertToStringTemplate/consecutiveNewlines.kt");
|
||||||
@@ -4579,6 +4585,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("endOfLineComment.kt")
|
||||||
|
public void testEndOfLineComment() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertToStringTemplate/endOfLineComment.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("insertBracesForSimpleNamedExpression.kt")
|
@TestMetadata("insertBracesForSimpleNamedExpression.kt")
|
||||||
public void testInsertBracesForSimpleNamedExpression() throws Exception {
|
public void testInsertBracesForSimpleNamedExpression() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertToStringTemplate/insertBracesForSimpleNamedExpression.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertToStringTemplate/insertBracesForSimpleNamedExpression.kt");
|
||||||
@@ -4699,6 +4711,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("simple.kt")
|
||||||
|
public void testSimple() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertToStringTemplate/simple.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("specialCharsInCharLiteral.kt")
|
@TestMetadata("specialCharsInCharLiteral.kt")
|
||||||
public void testSpecialCharsInCharLiteral() throws Exception {
|
public void testSpecialCharsInCharLiteral() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertToStringTemplate/specialCharsInCharLiteral.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertToStringTemplate/specialCharsInCharLiteral.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user