Add quick-fix "Replace with safe call & elvis" #KT-17815 Fixed

This commit is contained in:
Toshiaki Kameyama
2017-06-23 11:53:08 +03:00
committed by Mikhail Glukhikh
parent c2707bb81b
commit af53a0ecd5
24 changed files with 309 additions and 28 deletions
@@ -0,0 +1,7 @@
// "Replace with safe (?.) call" "true"
// WITH_RUNTIME
fun foo(array: Array<String>?) {
var s = ""
s = array[0]<caret>
}
@@ -0,0 +1,7 @@
// "Replace with safe (?.) call" "true"
// WITH_RUNTIME
fun foo(array: Array<String>?) {
var s = ""
s = array?.get(0) ?: <caret>
}
@@ -0,0 +1,7 @@
// "Replace with safe (?.) call" "true"
// WITH_RUNTIME
fun foo(bar: Int?) {
var i: Int = 1
i = bar +<caret> 1
}
@@ -0,0 +1,7 @@
// "Replace with safe (?.) call" "true"
// WITH_RUNTIME
fun foo(bar: Int?) {
var i: Int = 1
i = bar?.plus(1) ?: <caret>
}
@@ -0,0 +1,8 @@
// "Replace with safe (?.) call" "true"
// WITH_RUNTIME
fun bar() {
val fff: (() -> Int)? = { 1 }
var i: Int = 1
i = fff<caret>()
}
@@ -0,0 +1,8 @@
// "Replace with safe (?.) call" "true"
// WITH_RUNTIME
fun bar() {
val fff: (() -> Int)? = { 1 }
var i: Int = 1
i = fff?.invoke() ?: <caret>
}
@@ -0,0 +1,7 @@
// "Replace with safe (?.) call" "true"
// WITH_RUNTIME
fun foo(list: List<String>?) {
var s = ""
s = list[0]<caret>
}
@@ -0,0 +1,7 @@
// "Replace with safe (?.) call" "true"
// WITH_RUNTIME
fun foo(list: List<String>?) {
var s = ""
s = list?.get(0) ?: <caret>
}
@@ -0,0 +1,7 @@
// "Replace with safe (?.) call" "true"
// WITH_RUNTIME
var i = 0
fun foo(s: String?) {
i = s<caret>.length
}
@@ -0,0 +1,7 @@
// "Replace with safe (?.) call" "true"
// WITH_RUNTIME
var i = 0
fun foo(s: String?) {
i = s?.length ?: <caret>
}
@@ -0,0 +1,9 @@
// "Replace with safe (this?.) call" "true"
// WITH_RUNTIME
var i = 0
fun foo(a: String?) {
a.run {
i = <caret>length
}
}
@@ -0,0 +1,9 @@
// "Replace with safe (this?.) call" "true"
// WITH_RUNTIME
var i = 0
fun foo(a: String?) {
a.run {
i = this?.length ?: <caret>
}
}
@@ -0,0 +1,7 @@
// "Replace with safe (?.) call" "true"
// WITH_RUNTIME
var i: Int? = 0
fun foo(s: String?) {
i = s<caret>.length
}
@@ -0,0 +1,7 @@
// "Replace with safe (?.) call" "true"
// WITH_RUNTIME
var i: Int? = 0
fun foo(s: String?) {
i = s?.length
}
@@ -0,0 +1,5 @@
// "Replace with safe (?.) call" "true"
// WITH_RUNTIME
class T(s: String?) {
var i: Int = s<caret>.length
}
@@ -0,0 +1,5 @@
// "Replace with safe (?.) call" "true"
// WITH_RUNTIME
class T(s: String?) {
var i: Int = s?.length ?: <caret>
}
@@ -0,0 +1,5 @@
// "Replace with safe (?.) call" "true"
// WITH_RUNTIME
fun foo(s: String?) {
1 + s<caret>.length
}
@@ -0,0 +1,5 @@
// "Replace with safe (?.) call" "true"
// WITH_RUNTIME
fun foo(s: String?) {
1 + (s?.length ?: <caret>)
}
@@ -0,0 +1,9 @@
// "Replace scope function with safe (?.) call" "true"
// WITH_RUNTIME
var i = 0
fun foo(a: String?) {
i = a.run {
length<caret>
}
}
@@ -0,0 +1,9 @@
// "Replace scope function with safe (?.) call" "true"
// WITH_RUNTIME
var i = 0
fun foo(a: String?) {
i = a?.run {
length
} ?: <caret>
}