KT-14779 Inspection to replace String.format with string templates (#1645)
* Add inspection to replace String.format with string templates #KT-14779 Fixed * KT-14779 Fixed
This commit is contained in:
committed by
Vyacheslav Gerasimov
parent
e41a34af88
commit
6675d7814c
@@ -0,0 +1 @@
|
||||
org.jetbrains.kotlin.idea.inspections.ReplaceStringFormatWithLiteralInspection
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// PROBLEM: none
|
||||
// RUNTIME_WITH_FULL_JDK
|
||||
|
||||
import java.util.*
|
||||
|
||||
fun test() {
|
||||
val foo = Foo(1)
|
||||
val bar = 2
|
||||
|
||||
<caret>String.format("foo is %s, bar is %s.", foo, bar)
|
||||
}
|
||||
|
||||
class Foo(private val value: Int) : Formattable {
|
||||
override fun formatTo(formatter: Formatter?, flags: Int, width: Int, precision: Int) {
|
||||
formatter?.out()?.append("[$value]")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// PROBLEM: none
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test() {
|
||||
val foo = 1
|
||||
|
||||
<caret>String.format("foo is %s, bar is %s.", foo)
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// RUNTIME_WITH_FULL_JDK
|
||||
|
||||
fun test() {
|
||||
val foo = 1
|
||||
val bar = 2
|
||||
|
||||
<caret>java.lang.String.format("foo is %s, bar is %s.", foo, bar)
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// RUNTIME_WITH_FULL_JDK
|
||||
|
||||
fun test() {
|
||||
val foo = 1
|
||||
val bar = 2
|
||||
|
||||
"foo is $foo, bar is $bar."
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// RUNTIME_WITH_FULL_JDK
|
||||
|
||||
import java.lang.String.format
|
||||
|
||||
fun test() {
|
||||
val foo = 1
|
||||
val bar = 2
|
||||
|
||||
<caret>format("foo is %s, bar is %s.", foo, bar)
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// RUNTIME_WITH_FULL_JDK
|
||||
|
||||
import java.lang.String.format
|
||||
|
||||
fun test() {
|
||||
val foo = 1
|
||||
val bar = 2
|
||||
|
||||
"foo is $foo, bar is $bar."
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// PROBLEM: none
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test() {
|
||||
<caret>String.format("%%")
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// PROBLEM: none
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test() {
|
||||
val foo = 1
|
||||
val bar = 2
|
||||
|
||||
<caret>String.format("foo is %s, bar is %d.", foo, bar)
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// PROBLEM: none
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test() {
|
||||
val foo = 1
|
||||
val bar = 2
|
||||
|
||||
<caret>String.format("foo is %s, bar is %s.%n", foo, bar)
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// PROBLEM: none
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test() {
|
||||
val foo = 1
|
||||
val bar = 2
|
||||
|
||||
<caret>String.format("""foo is %s, bar is %s.%n""", foo, bar)
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// WITH_RUNTIME
|
||||
// HIGHLIGHT: INFORMATION
|
||||
|
||||
fun test() {
|
||||
val foo = 1
|
||||
|
||||
<caret>String.format("foo is %s, bar is %s.", foo, Bar().value)
|
||||
}
|
||||
|
||||
class Bar {
|
||||
val value = 2
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// WITH_RUNTIME
|
||||
// HIGHLIGHT: INFORMATION
|
||||
|
||||
fun test() {
|
||||
val foo = 1
|
||||
|
||||
"foo is $foo, bar is ${Bar().value}."
|
||||
}
|
||||
|
||||
class Bar {
|
||||
val value = 2
|
||||
}
|
||||
Reference in New Issue
Block a user