KT-12100 convert try / finally to use: 'this' cases, implementation via resolved call
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
// WITH_RUNTIME
|
||||
import java.io.File
|
||||
import java.io.BufferedReader
|
||||
|
||||
fun BufferedReader.foo() {
|
||||
try {
|
||||
readLine()
|
||||
}
|
||||
<caret>finally {
|
||||
close()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
import java.io.File
|
||||
import java.io.BufferedReader
|
||||
|
||||
fun BufferedReader.foo() {
|
||||
use { readLine() }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// WITH_RUNTIME
|
||||
import java.io.File
|
||||
import java.io.BufferedReader
|
||||
|
||||
fun foo(reader: BufferedReader) {
|
||||
try {
|
||||
reader.readLine()
|
||||
}
|
||||
<caret>finally {
|
||||
reader.close()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
import java.io.File
|
||||
import java.io.BufferedReader
|
||||
|
||||
fun foo(reader: BufferedReader) {
|
||||
reader.use { reader -> reader.readLine() }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// IS_APPLICABLE: false
|
||||
// WITH_RUNTIME
|
||||
import java.io.File
|
||||
import java.io.BufferedReader
|
||||
|
||||
fun foo(reader: BufferedReader?) {
|
||||
try {
|
||||
reader?.readLine()
|
||||
}
|
||||
<caret>finally {
|
||||
reader?.close()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// WITH_RUNTIME
|
||||
import java.io.File
|
||||
import java.io.BufferedReader
|
||||
|
||||
fun BufferedReader.foo() {
|
||||
try {
|
||||
this.readLine()
|
||||
}
|
||||
<caret>finally {
|
||||
this.close()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
import java.io.File
|
||||
import java.io.BufferedReader
|
||||
|
||||
fun BufferedReader.foo() {
|
||||
use { this.readLine() }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import java.io.Closeable
|
||||
|
||||
class MyCloseable : Closeable {
|
||||
override fun close() {}
|
||||
|
||||
fun process(x: Int) = x
|
||||
|
||||
fun Int.foo() {
|
||||
try {
|
||||
this@MyCloseable.process(this)
|
||||
}
|
||||
<caret>finally {
|
||||
this@MyCloseable.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import java.io.Closeable
|
||||
|
||||
class MyCloseable : Closeable {
|
||||
override fun close() {}
|
||||
|
||||
fun process(x: Int) = x
|
||||
|
||||
fun Int.foo() {
|
||||
use { this@MyCloseable.process(this) }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user