Introduct "Redundant 'with' call" inspection #KT-6633 Fixed

This commit is contained in:
Toshiaki Kameyama
2018-07-12 17:19:48 +09:00
committed by Natalia Selezneva
parent 58becffb1f
commit 4c34ced1fa
40 changed files with 493 additions and 0 deletions
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.inspections.RedundantWithInspection
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test() {
return <caret>with (1) {
}
}
@@ -0,0 +1,4 @@
// WITH_RUNTIME
fun test() {
return
}
@@ -0,0 +1,8 @@
// WITH_RUNTIME
fun test() {
<caret>with ("") {
with ("a") {
this
}
}
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun test() {
<caret>with ("a") {
this
}
}
@@ -0,0 +1,7 @@
// PROBLEM: none
// WITH_RUNTIME
fun test() {
<caret>with ("") {
this
}
}
@@ -0,0 +1,7 @@
// PROBLEM: none
// WITH_RUNTIME
fun test() {
<caret>with ("") {
this.length
}
}
@@ -0,0 +1,12 @@
// PROBLEM: none
// WITH_RUNTIME
fun test() {
val c = MyClass()
<caret>with(c) {
println(f())
}
}
class MyClass {
fun f(): String = ""
}
@@ -0,0 +1,7 @@
// PROBLEM: none
// WITH_RUNTIME
fun test() {
<caret>with ("") {
length
}
}
@@ -0,0 +1,8 @@
// PROBLEM: none
// WITH_RUNTIME
fun test() {
val b = 1 == <caret>with ("") {
println()
1
}
}
@@ -0,0 +1,6 @@
// PROBLEM: none
// WITH_RUNTIME
fun test() = <caret>with("") {
println()
1
}
@@ -0,0 +1,8 @@
// PROBLEM: none
// WITH_RUNTIME
fun test() {
val i = <caret>with ("") {
println()
1
}
}
@@ -0,0 +1,7 @@
// PROBLEM: none
// WITH_RUNTIME
val a: Int
get() = <caret>with("") {
println()
1
}
@@ -0,0 +1,8 @@
// PROBLEM: none
// WITH_RUNTIME
fun test(): Int {
return <caret>with ("") {
println()
1
}
}
@@ -0,0 +1,10 @@
// PROBLEM: none
// WITH_RUNTIME
fun foo(i: Int) {}
fun test() {
foo(<caret>with("") {
println()
1
})
}
@@ -0,0 +1,7 @@
// PROBLEM: none
// WITH_RUNTIME
fun test() {
<caret>with ("") {
return@with
}
}
@@ -0,0 +1,7 @@
// PROBLEM: none
// WITH_RUNTIME
fun test(): String {
<caret>with("") {
return this@with
}
}
@@ -0,0 +1,7 @@
// PROBLEM: none
// WITH_RUNTIME
fun test() {
<caret>with ("") {
this@with
}
}
@@ -0,0 +1,7 @@
// PROBLEM: none
// WITH_RUNTIME
fun test() {
<caret>with ("") {
this@with.length
}
}
@@ -0,0 +1,12 @@
// PROBLEM: none
// WITH_RUNTIME
fun test() {
val c = MyClass()
<caret>with(c) {
println(f())
}
}
class MyClass {
val f: () -> String = { "" }
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
fun test() {
<caret>with ("") {
println("1")
println("2")
}
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test() {
<caret>println("1")
println("2")
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
fun test(s: String) {
with<caret> (s, {
println("1")
println("2")
})
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(s: String) {
<caret>println("1")
println("2")
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun test(): Int {
return <caret>with (1) {
2
}
}
@@ -0,0 +1,4 @@
// WITH_RUNTIME
fun test(): Int {
return 2
}