Introduce "Lift return out of try" intention #KT-18830 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
8f9b680fc6
commit
8cc9330e63
@@ -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()
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// PROBLEM: none
|
||||
fun test() {
|
||||
var res: String? = null
|
||||
|
||||
<caret>try {
|
||||
res = "success"
|
||||
} catch (e: Exception) {
|
||||
res = "failure"
|
||||
} finally {
|
||||
res = "finally"
|
||||
}
|
||||
}
|
||||
+17
@@ -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"
|
||||
}
|
||||
}
|
||||
Vendored
+17
@@ -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"
|
||||
}
|
||||
}
|
||||
+17
@@ -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"
|
||||
}
|
||||
}
|
||||
+12
@@ -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"
|
||||
}
|
||||
}
|
||||
Vendored
+12
@@ -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"
|
||||
}
|
||||
}
|
||||
+11
@@ -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"
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// PROBLEM: none
|
||||
fun doSomething() {}
|
||||
|
||||
fun test() {
|
||||
var res: String? = null
|
||||
|
||||
<caret>try {
|
||||
res = "success"
|
||||
} catch (e: Exception) {
|
||||
res = "failure"
|
||||
doSomething()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user