Introduce "Lift return out of try" intention #KT-18830 Fixed

This commit is contained in:
Toshiaki Kameyama
2017-07-08 18:24:31 +03:00
committed by Mikhail Glukhikh
parent 8f9b680fc6
commit 8cc9330e63
38 changed files with 601 additions and 7 deletions
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.inspections.LiftReturnOrAssignmentInspection
@@ -0,0 +1,11 @@
// HIGHLIGHT: INFORMATION
fun test() {
var res: String? = null
<caret>try {
res = "success"
} catch (e: Exception) {
throw e
}
}
@@ -0,0 +1,11 @@
// HIGHLIGHT: INFORMATION
fun test() {
var res: String? = null
<caret>res = try {
"success"
} catch (e: Exception) {
throw e
}
}
@@ -0,0 +1,15 @@
// HIGHLIGHT: GENERIC_ERROR_OR_WARNING
fun doSomething() {}
fun test() {
var res: String? = null
<caret>try {
doSomething()
res = "success"
} catch (e: Exception) {
doSomething()
res = "failure"
}
}
@@ -0,0 +1,15 @@
// HIGHLIGHT: GENERIC_ERROR_OR_WARNING
fun doSomething() {}
fun test() {
var res: String? = null
<caret>res = try {
doSomething()
"success"
} catch (e: Exception) {
doSomething()
"failure"
}
}
@@ -0,0 +1,18 @@
// WITH_RUNTIME
fun test() {
var res: String? = null
<caret>try {
try {
res = "success"
} catch (e: Exception) {
TODO()
}
} catch (e: Exception) {
try {
TODO()
} catch (e: Exception) {
res = "failure"
}
}
}
@@ -0,0 +1,18 @@
// WITH_RUNTIME
fun test() {
var res: String? = null
<caret>res = try {
try {
"success"
} catch (e: Exception) {
TODO()
}
} catch (e: Exception) {
try {
TODO()
} catch (e: Exception) {
"failure"
}
}
}
@@ -0,0 +1,13 @@
fun doSomething() {}
fun test() {
var res: String? = null
<caret>try {
res = "success"
} catch (e: Exception) {
res = "failure"
} finally {
doSomething()
}
}
@@ -0,0 +1,13 @@
fun doSomething() {}
fun test() {
var res: String? = null
<caret>res = try {
"success"
} catch (e: Exception) {
"failure"
} finally {
doSomething()
}
}
@@ -0,0 +1,12 @@
// PROBLEM: none
fun test() {
var res: String? = null
<caret>try {
res = "success"
} catch (e: Exception) {
res = "failure"
} finally {
res = "finally"
}
}
@@ -0,0 +1,17 @@
// PROBLEM: none
fun doSomething() {}
fun test(n: Int) {
var res: String? = null
<caret>try {
res = "success"
} catch (e: Exception) {
throw e
} finally {
if (n == 1)
doSomething()
else
res = "finally"
}
}
@@ -0,0 +1,17 @@
fun doSomething() {}
fun test(n: Int) {
var res: String? = null
var foo: String? = null
<caret>try {
res = "success"
} catch (e: Exception) {
throw e
} finally {
if (n == 1)
doSomething()
else
foo = "finally"
}
}
@@ -0,0 +1,17 @@
fun doSomething() {}
fun test(n: Int) {
var res: String? = null
var foo: String? = null
<caret>res = try {
"success"
} catch (e: Exception) {
throw e
} finally {
if (n == 1)
doSomething()
else
foo = "finally"
}
}
@@ -0,0 +1,12 @@
fun test() {
var res: String? = null
var foo: String? = null
<caret>try {
res = "success"
} catch (e: Exception) {
res = "failure"
} finally {
foo = "finally"
}
}
@@ -0,0 +1,12 @@
fun test() {
var res: String? = null
var foo: String? = null
<caret>res = try {
"success"
} catch (e: Exception) {
"failure"
} finally {
foo = "finally"
}
}
@@ -0,0 +1,14 @@
fun test(n: Int) {
var res: String? = null
if (n == 1) {
<caret>try {
res = "success"
} catch (e: Exception) {
throw e
}
}
else {
res = "else"
}
}
@@ -0,0 +1,14 @@
fun test(n: Int) {
var res: String? = null
if (n == 1) {
<caret>res = try {
"success"
} catch (e: Exception) {
throw e
}
}
else {
res = "else"
}
}
@@ -0,0 +1,11 @@
// PROBLEM: none
fun test() {
var res: String? = null
var foo: String? = null
<caret>try {
res = "success"
} catch (e: Exception) {
foo = "exception"
}
}
@@ -0,0 +1,13 @@
// PROBLEM: none
fun doSomething() {}
fun test() {
var res: String? = null
<caret>try {
res = "success"
} catch (e: Exception) {
res = "failure"
doSomething()
}
}