Made convert to string template inspection less eager
This commit is contained in:
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluat
|
||||
|
||||
public class ConvertToStringTemplateInspection : IntentionBasedInspection<JetBinaryExpression>(
|
||||
ConvertToStringTemplateIntention(),
|
||||
{ ConvertToStringTemplateIntention().isConversionResultSimple(it) }
|
||||
{ ConvertToStringTemplateIntention().shouldSuggestToConvert(it) }
|
||||
)
|
||||
|
||||
public class ConvertToStringTemplateIntention : JetSelfTargetingOffsetIndependentIntention<JetBinaryExpression>(javaClass(), "Convert concatenation to template") {
|
||||
@@ -50,8 +50,9 @@ public class ConvertToStringTemplateIntention : JetSelfTargetingOffsetIndependen
|
||||
return element.replaced(buildReplacement(element))
|
||||
}
|
||||
|
||||
public fun isConversionResultSimple(expression: JetBinaryExpression): Boolean {
|
||||
return buildReplacement(expression).getEntries().none { it is JetBlockStringTemplateEntry }
|
||||
public fun shouldSuggestToConvert(expression: JetBinaryExpression): Boolean {
|
||||
val entries = buildReplacement(expression).entries
|
||||
return entries.none { it is JetBlockStringTemplateEntry } && entries.count { it is JetLiteralStringTemplateEntry } > 1
|
||||
}
|
||||
|
||||
private fun isApplicableToNoParentCheck(expression: JetBinaryExpression): Boolean {
|
||||
|
||||
@@ -148,7 +148,7 @@ object J2KPostProcessingRegistrar {
|
||||
private val intention = ConvertToStringTemplateIntention()
|
||||
|
||||
override fun createAction(element: JetElement, diagnostics: Diagnostics): (() -> Unit)? {
|
||||
if (element is JetBinaryExpression && intention.isApplicableTo(element) && intention.isConversionResultSimple(element)) {
|
||||
if (element is JetBinaryExpression && intention.isApplicableTo(element) && intention.shouldSuggestToConvert(element)) {
|
||||
return { intention.applyTo(element) }
|
||||
}
|
||||
else {
|
||||
|
||||
+1
-96
@@ -1,20 +1,4 @@
|
||||
<problems>
|
||||
<problem>
|
||||
<file>noBracesSimpleFollowedByDot.kt</file>
|
||||
<line>3</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="noBracesSimpleFollowedByDot.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Convert string concatenation to string template</problem_class>
|
||||
<description>Convert concatenation to template</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>noBracesForLastSimpleExpression.kt</file>
|
||||
<line>3</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="noBracesForLastSimpleExpression.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Convert string concatenation to string template</problem_class>
|
||||
<description>Convert concatenation to template</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>multilineString.kt</file>
|
||||
<line>3</line>
|
||||
@@ -23,78 +7,7 @@
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Convert string concatenation to string template</problem_class>
|
||||
<description>Convert concatenation to template</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>interpolateStringWithInt.kt</file>
|
||||
<line>2</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="interpolateStringWithInt.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Convert string concatenation to string template</problem_class>
|
||||
<description>Convert concatenation to template</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>interpolateStringWithFloat.kt</file>
|
||||
<line>2</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="interpolateStringWithFloat.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Convert string concatenation to string template</problem_class>
|
||||
<description>Convert concatenation to template</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>interpolateDollarSign.kt</file>
|
||||
<line>2</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="interpolateDollarSign.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Convert string concatenation to string template</problem_class>
|
||||
<description>Convert concatenation to template</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>interpolateChar.kt</file>
|
||||
<line>2</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="interpolateChar.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Convert string concatenation to string template</problem_class>
|
||||
<description>Convert concatenation to template</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>interpolate2Vals.kt</file>
|
||||
<line>4</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="interpolate2Vals.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Convert string concatenation to string template</problem_class>
|
||||
<description>Convert concatenation to template</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>interpolate2StringConstants.kt</file>
|
||||
<line>2</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="interpolate2StringConstants.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Convert string concatenation to string template</problem_class>
|
||||
<description>Convert concatenation to template</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>combinesNonStringsAsStrings2.kt</file>
|
||||
<line>2</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="combinesNonStringsAsStrings2.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Convert string concatenation to string template</problem_class>
|
||||
<description>Convert concatenation to template</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>combinesNonStringsAsStrings.kt</file>
|
||||
<line>2</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="combinesNonStringsAsStrings.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Convert string concatenation to string template</problem_class>
|
||||
<description>Convert concatenation to template</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>combineEmptyStrings.kt</file>
|
||||
<line>2</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="combineEmptyStrings.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Convert string concatenation to string template</problem_class>
|
||||
<description>Convert concatenation to template</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>backslashNMultilineString.kt</file>
|
||||
<line>2</line>
|
||||
@@ -103,12 +16,4 @@
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Convert string concatenation to string template</problem_class>
|
||||
<description>Convert concatenation to template</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>doesNotCorruptExistingTemplate.kt</file>
|
||||
<line>4</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="doesNotCorruptExistingTemplate.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Convert string concatenation to string template</problem_class>
|
||||
<description>Convert concatenation to template</description>
|
||||
</problem>
|
||||
</problems>
|
||||
@@ -1 +1 @@
|
||||
assert(true) { "string details:$x" }
|
||||
assert(true) { "string details:" + x }
|
||||
+2
-2
@@ -3,9 +3,9 @@ package demo
|
||||
object Test {
|
||||
fun subListRangeCheck(fromIndex: Int, toIndex: Int, size: Int) {
|
||||
if (fromIndex < 0)
|
||||
throw IndexOutOfBoundsException("fromIndex = $fromIndex")
|
||||
throw IndexOutOfBoundsException("fromIndex = " + fromIndex)
|
||||
if (toIndex > size)
|
||||
throw IndexOutOfBoundsException("toIndex = $toIndex")
|
||||
throw IndexOutOfBoundsException("toIndex = " + toIndex)
|
||||
if (fromIndex > toIndex)
|
||||
throw IllegalArgumentException("fromIndex($fromIndex) > toIndex($toIndex)")
|
||||
}
|
||||
|
||||
+1
-1
@@ -30,6 +30,6 @@ class A {
|
||||
}
|
||||
|
||||
public fun f(p: Int) {
|
||||
println("p = $p")
|
||||
println("p = " + p)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ interface I {
|
||||
|
||||
open class A : I {
|
||||
override fun foo(i: Int, c: Char, s: String) {
|
||||
println("foo$i$c$s")
|
||||
println("foo" + i + c + s)
|
||||
}
|
||||
|
||||
public fun foo(i: Int, c: Char) {
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
class A {
|
||||
JvmOverloads fun foo(i: Int, c: Char = 'a', s: String = "") {
|
||||
println("foo$i$c$s")
|
||||
println("foo" + i + c + s)
|
||||
}
|
||||
|
||||
JvmOverloads fun bar(s: String? = null): Int {
|
||||
|
||||
Reference in New Issue
Block a user