Convert "lift return / assignment" intentions into a single inspection
Also includes minor test fix, related to KT-14900
This commit is contained in:
committed by
Mikhail Glukhikh
parent
8f33bd0768
commit
2d1abda9a1
@@ -1 +0,0 @@
|
||||
org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions.FoldIfToAssignmentIntention
|
||||
@@ -1,18 +0,0 @@
|
||||
// WITH_RUNTIME
|
||||
fun test(x: Any) {
|
||||
var res: String
|
||||
<caret>if (x is String)
|
||||
when {
|
||||
x.length > 3 -> res = "long string"
|
||||
else -> res = "short string"
|
||||
}
|
||||
else if (x is Int)
|
||||
when {
|
||||
x > 999 || x < -99 -> res = "long int"
|
||||
else -> res = "short int"
|
||||
}
|
||||
else if (x is Long)
|
||||
TODO()
|
||||
else
|
||||
res = "I don't know"
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
// WITH_RUNTIME
|
||||
fun test(x: Any) {
|
||||
var res: String
|
||||
<caret>res = if (x is String)
|
||||
when {
|
||||
x.length > 3 -> "long string"
|
||||
else -> "short string"
|
||||
}
|
||||
else if (x is Int)
|
||||
when {
|
||||
x > 999 || x < -99 -> "long int"
|
||||
else -> "short int"
|
||||
}
|
||||
else if (x is Long)
|
||||
TODO()
|
||||
else
|
||||
"I don't know"
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
// IS_APPLICABLE: false
|
||||
|
||||
fun test(n: Int) {
|
||||
var a: String = ""
|
||||
<caret>if (n == 1)
|
||||
a = "one"
|
||||
else if (n == 2)
|
||||
a = "two"
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
fun test(n: Int) {
|
||||
val a: String
|
||||
<caret>if (n == 1)
|
||||
a = "one"
|
||||
else if (n == 2)
|
||||
a = "two"
|
||||
else
|
||||
a = "three"
|
||||
}
|
||||
-9
@@ -1,9 +0,0 @@
|
||||
fun test(n: Int) {
|
||||
val a: String
|
||||
<caret>a = if (n == 1)
|
||||
"one"
|
||||
else if (n == 2)
|
||||
"two"
|
||||
else
|
||||
"three"
|
||||
}
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
// IS_APPLICABLE: false
|
||||
|
||||
fun test(n: Int) {
|
||||
val a: String
|
||||
val b: String
|
||||
<caret>if (n == 1)
|
||||
a = "one"
|
||||
else if (n == 2)
|
||||
a = "two"
|
||||
else
|
||||
b = "three"
|
||||
}
|
||||
-23
@@ -1,23 +0,0 @@
|
||||
fun <T> doSomething(a: T) {}
|
||||
|
||||
fun test(n: Int): String {
|
||||
var res: String
|
||||
|
||||
if (n == 1) {
|
||||
<caret>if (3 > 2) {
|
||||
doSomething("***")
|
||||
res = "one"
|
||||
} else {
|
||||
doSomething("***")
|
||||
res = "???"
|
||||
}
|
||||
} else if (n == 2) {
|
||||
doSomething("***")
|
||||
res = "two"
|
||||
} else {
|
||||
doSomething("***")
|
||||
res = "too many"
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
-23
@@ -1,23 +0,0 @@
|
||||
fun <T> doSomething(a: T) {}
|
||||
|
||||
fun test(n: Int): String {
|
||||
var res: String
|
||||
|
||||
if (n == 1) {
|
||||
<caret>res = if (3 > 2) {
|
||||
doSomething("***")
|
||||
"one"
|
||||
} else {
|
||||
doSomething("***")
|
||||
"???"
|
||||
}
|
||||
} else if (n == 2) {
|
||||
doSomething("***")
|
||||
res = "two"
|
||||
} else {
|
||||
doSomething("***")
|
||||
res = "too many"
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
fun test(n: Int): String {
|
||||
var res: String
|
||||
|
||||
<caret>if (n == 1) res = "one" else res = "two"
|
||||
|
||||
return res
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
fun test(n: Int): String {
|
||||
var res: String
|
||||
|
||||
<caret>res = if (n == 1) "one" else "two"
|
||||
|
||||
return res
|
||||
}
|
||||
Vendored
-7
@@ -1,7 +0,0 @@
|
||||
fun test(n: Int): String {
|
||||
var res: String = "!"
|
||||
|
||||
<caret>if (n == 1) res += "one" else res += "two"
|
||||
|
||||
return res
|
||||
}
|
||||
Vendored
-7
@@ -1,7 +0,0 @@
|
||||
fun test(n: Int): String {
|
||||
var res: String = "!"
|
||||
|
||||
<caret>res += if (n == 1) "one" else "two"
|
||||
|
||||
return res
|
||||
}
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
fun <T> doSomething(a: T) {}
|
||||
|
||||
fun test(n: Int): String {
|
||||
var res: String
|
||||
|
||||
<caret>if (n == 1) {
|
||||
doSomething("***")
|
||||
res = "one"
|
||||
} else {
|
||||
doSomething("***")
|
||||
res = "two"
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
fun <T> doSomething(a: T) {}
|
||||
|
||||
fun test(n: Int): String {
|
||||
var res: String
|
||||
|
||||
<caret>res = if (n == 1) {
|
||||
doSomething("***")
|
||||
"one"
|
||||
} else {
|
||||
doSomething("***")
|
||||
"two"
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
// IS_APPLICABLE: false
|
||||
fun <T> doSomething(a: T) {}
|
||||
|
||||
fun test(n: Int): String {
|
||||
var res: String = ""
|
||||
|
||||
<caret>if (n == 1) {
|
||||
doSomething("***")
|
||||
res = "one"
|
||||
} else {
|
||||
var res: String
|
||||
|
||||
doSomething("***")
|
||||
res = "two"
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
Vendored
-12
@@ -1,12 +0,0 @@
|
||||
// IS_APPLICABLE: false
|
||||
fun test(s: String): Int {
|
||||
var n: Int = 1;
|
||||
|
||||
<caret>if (s.equals("add")) {
|
||||
n += 1
|
||||
} else {
|
||||
n -= 1
|
||||
}
|
||||
|
||||
return n
|
||||
}
|
||||
Vendored
-13
@@ -1,13 +0,0 @@
|
||||
// IS_APPLICABLE: false
|
||||
fun test(n: Int): String {
|
||||
var res: String = ""
|
||||
var res2: String = ""
|
||||
|
||||
<caret>if (n == 1) {
|
||||
res = "one"
|
||||
} else {
|
||||
res2 = "two"
|
||||
}
|
||||
|
||||
return res + res2
|
||||
}
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
// IS_APPLICABLE: false
|
||||
fun <T> doSomething(a: T) {}
|
||||
|
||||
fun test(n: Int): String {
|
||||
var res: String = ""
|
||||
|
||||
<caret>if (n == 1) {
|
||||
doSomething("***")
|
||||
res = "one"
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
Vendored
-16
@@ -1,16 +0,0 @@
|
||||
// IS_APPLICABLE: false
|
||||
fun <T> doSomething(a: T) {}
|
||||
|
||||
fun test(n: Int): String {
|
||||
var res: String
|
||||
|
||||
<caret>if (n == 1) {
|
||||
res = "one"
|
||||
doSomething("***")
|
||||
} else {
|
||||
doSomething("***")
|
||||
res = "two"
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions.FoldIfToReturnIntention
|
||||
@@ -1,17 +0,0 @@
|
||||
// WITH_RUNTIME
|
||||
fun test(x: Any): String {
|
||||
<caret>if (x is String)
|
||||
when {
|
||||
x.length > 3 -> return "long string"
|
||||
else -> return "short string"
|
||||
}
|
||||
else if (x is Int)
|
||||
when {
|
||||
x > 999 || x < -99 -> return "long int"
|
||||
else -> return "short int"
|
||||
}
|
||||
else if (x is Long)
|
||||
TODO()
|
||||
else
|
||||
return "I don't know"
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
// WITH_RUNTIME
|
||||
fun test(x: Any): String {
|
||||
<caret>return if (x is String)
|
||||
when {
|
||||
x.length > 3 -> "long string"
|
||||
else -> "short string"
|
||||
}
|
||||
else if (x is Int)
|
||||
when {
|
||||
x > 999 || x < -99 -> "long int"
|
||||
else -> "short int"
|
||||
}
|
||||
else if (x is Long)
|
||||
TODO()
|
||||
else
|
||||
"I don't know"
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
// IS_APPLICABLE: false
|
||||
|
||||
fun test(n: Int): String {
|
||||
<caret>if (n == 1)
|
||||
return "one"
|
||||
else if (n == 2)
|
||||
return "two"
|
||||
|
||||
return "three"
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
fun test(n: Int): String {
|
||||
<caret>if (n == 1)
|
||||
return "one"
|
||||
else if (n == 2)
|
||||
return "two"
|
||||
else
|
||||
return "three"
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
fun test(n: Int): String {
|
||||
<caret>return if (n == 1)
|
||||
"one"
|
||||
else if (n == 2)
|
||||
"two"
|
||||
else
|
||||
"three"
|
||||
}
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
// IS_APPLICABLE: false
|
||||
|
||||
fun test(n: Int): String {
|
||||
val a: String
|
||||
<caret>if (n == 1)
|
||||
return "one"
|
||||
else if (n == 2)
|
||||
return "two"
|
||||
else
|
||||
a = "three"
|
||||
return a
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
fun <T> doSomething(a: T) {}
|
||||
|
||||
fun test(n: Int): String {
|
||||
if (n == 1) {
|
||||
<caret>if (3 > 2) {
|
||||
doSomething("***")
|
||||
return "one"
|
||||
} else {
|
||||
doSomething("***")
|
||||
return "???"
|
||||
}
|
||||
} else if (n == 2) {
|
||||
doSomething("***")
|
||||
return "two"
|
||||
} else {
|
||||
doSomething("***")
|
||||
return "too many"
|
||||
}
|
||||
}
|
||||
-19
@@ -1,19 +0,0 @@
|
||||
fun <T> doSomething(a: T) {}
|
||||
|
||||
fun test(n: Int): String {
|
||||
if (n == 1) {
|
||||
<caret>return if (3 > 2) {
|
||||
doSomething("***")
|
||||
"one"
|
||||
} else {
|
||||
doSomething("***")
|
||||
"???"
|
||||
}
|
||||
} else if (n == 2) {
|
||||
doSomething("***")
|
||||
return "two"
|
||||
} else {
|
||||
doSomething("***")
|
||||
return "too many"
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
fun test(n: Int): String {
|
||||
<caret>if (n == 1)
|
||||
return "one"
|
||||
else
|
||||
return "two"
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
fun test(n: Int): String {
|
||||
<caret>return if (n == 1)
|
||||
"one"
|
||||
else
|
||||
"two"
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fun <T> doSomething(a: T) {}
|
||||
|
||||
fun test(n: Int): String {
|
||||
<caret>if (n == 1) {
|
||||
doSomething("***")
|
||||
return "one"
|
||||
} else {
|
||||
doSomething("***")
|
||||
return "two"
|
||||
}
|
||||
}
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
fun <T> doSomething(a: T) {}
|
||||
|
||||
fun test(n: Int): String {
|
||||
<caret>return if (n == 1) {
|
||||
doSomething("***")
|
||||
"one"
|
||||
} else {
|
||||
doSomething("***")
|
||||
"two"
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions.FoldWhenToAssignmentIntention
|
||||
@@ -1,16 +0,0 @@
|
||||
// WITH_RUNTIME
|
||||
fun test(x: Any) {
|
||||
var res: String
|
||||
<caret>when (x) {
|
||||
is String ->
|
||||
if (x.length > 3) res = "long string"
|
||||
else res = "short string"
|
||||
is Int ->
|
||||
if (x > 999 || x < -99) res = "long int"
|
||||
else res = "short int"
|
||||
is Long ->
|
||||
TODO()
|
||||
else ->
|
||||
res = "I don't know"
|
||||
}
|
||||
}
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
// WITH_RUNTIME
|
||||
fun test(x: Any) {
|
||||
var res: String
|
||||
<caret>res = when (x) {
|
||||
is String ->
|
||||
if (x.length > 3) "long string"
|
||||
else "short string"
|
||||
is Int ->
|
||||
if (x > 999 || x < -99) "long int"
|
||||
else "short int"
|
||||
is Long ->
|
||||
TODO()
|
||||
else ->
|
||||
"I don't know"
|
||||
}
|
||||
}
|
||||
-23
@@ -1,23 +0,0 @@
|
||||
fun <T> doSomething(a: T) {}
|
||||
|
||||
fun test(n: Int): String {
|
||||
var res: String
|
||||
|
||||
if (3 > 2) {
|
||||
<caret>when (n) {
|
||||
1 -> {
|
||||
doSomething("***")
|
||||
res = "one"
|
||||
}
|
||||
else -> {
|
||||
doSomething("***")
|
||||
res = "two"
|
||||
}
|
||||
}
|
||||
} else {
|
||||
doSomething("***")
|
||||
res = "???"
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
-23
@@ -1,23 +0,0 @@
|
||||
fun <T> doSomething(a: T) {}
|
||||
|
||||
fun test(n: Int): String {
|
||||
var res: String
|
||||
|
||||
if (3 > 2) {
|
||||
<caret>res = when (n) {
|
||||
1 -> {
|
||||
doSomething("***")
|
||||
"one"
|
||||
}
|
||||
else -> {
|
||||
doSomething("***")
|
||||
"two"
|
||||
}
|
||||
}
|
||||
} else {
|
||||
doSomething("***")
|
||||
res = "???"
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
fun foo(): Int {
|
||||
var res = 0
|
||||
loop@ while (true) {
|
||||
<caret>when (1) {
|
||||
1 -> res += 1
|
||||
2 -> throw Exception()
|
||||
3 -> break@loop
|
||||
4 -> continue@loop
|
||||
else -> return -1
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
fun foo(): Int {
|
||||
var res = 0
|
||||
loop@ while (true) {
|
||||
res += when (1) {
|
||||
1 -> 1
|
||||
2 -> throw Exception()
|
||||
3 -> break@loop
|
||||
4 -> continue@loop
|
||||
else -> return -1
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
fun test(n: Int): String {
|
||||
var res: String
|
||||
|
||||
<caret>when (n) {
|
||||
1 -> res = "one"
|
||||
else -> res = "two"
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
fun test(n: Int): String {
|
||||
var res: String
|
||||
|
||||
<caret>res = when (n) {
|
||||
1 -> "one"
|
||||
else -> "two"
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
fun <T> doSomething(a: T) {}
|
||||
|
||||
fun test(n: Int): String {
|
||||
var res: String
|
||||
|
||||
<caret>when (n) {
|
||||
1 -> {
|
||||
doSomething("***")
|
||||
res = "one"
|
||||
}
|
||||
else -> {
|
||||
doSomething("***")
|
||||
res = "two"
|
||||
}
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
fun <T> doSomething(a: T) {}
|
||||
|
||||
fun test(n: Int): String {
|
||||
var res: String
|
||||
|
||||
<caret>res = when (n) {
|
||||
1 -> {
|
||||
doSomething("***")
|
||||
"one"
|
||||
}
|
||||
else -> {
|
||||
doSomething("***")
|
||||
"two"
|
||||
}
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
-21
@@ -1,21 +0,0 @@
|
||||
// IS_APPLICABLE: false
|
||||
fun <T> doSomething(a: T) {}
|
||||
|
||||
fun test(n: Int): String {
|
||||
var res: String = ""
|
||||
|
||||
<caret>when (n) {
|
||||
1 -> {
|
||||
doSomething("***")
|
||||
res = "one"
|
||||
}
|
||||
else -> {
|
||||
var res: String
|
||||
|
||||
res = "two"
|
||||
doSomething("***")
|
||||
}
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
Vendored
-20
@@ -1,20 +0,0 @@
|
||||
// IS_APPLICABLE: false
|
||||
fun <T> doSomething(a: T) {}
|
||||
|
||||
fun test(n: Int): String {
|
||||
var res: String = ""
|
||||
var res2: String = ""
|
||||
|
||||
<caret>when (n) {
|
||||
1 -> {
|
||||
doSomething("***")
|
||||
res = "one"
|
||||
}
|
||||
else -> {
|
||||
doSomething("***")
|
||||
res2 = "two"
|
||||
}
|
||||
}
|
||||
|
||||
return res + res2
|
||||
}
|
||||
idea/testData/intentions/branched/folding/whenToAssignment/simpleWhenWithoutTerminatingAssignment.kt
Vendored
-19
@@ -1,19 +0,0 @@
|
||||
// IS_APPLICABLE: false
|
||||
fun <T> doSomething(a: T) {}
|
||||
|
||||
fun test(n: Int): String {
|
||||
var res: String
|
||||
|
||||
<caret>when (n) {
|
||||
1 -> {
|
||||
doSomething("***")
|
||||
res = "one"
|
||||
}
|
||||
else -> {
|
||||
res = "two"
|
||||
doSomething("***")
|
||||
}
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions.FoldWhenToReturnIntention
|
||||
@@ -1,15 +0,0 @@
|
||||
// WITH_RUNTIME
|
||||
fun test(x: Any): String {
|
||||
<caret>when (x) {
|
||||
is String ->
|
||||
if (x.length > 3) return "long string"
|
||||
else return "short string"
|
||||
is Int ->
|
||||
if (x > 999 || x < -99) return "long int"
|
||||
else return "short int"
|
||||
is Long ->
|
||||
TODO()
|
||||
else ->
|
||||
return "I don't know"
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
// WITH_RUNTIME
|
||||
fun test(x: Any): String {
|
||||
<caret>return when (x) {
|
||||
is String ->
|
||||
if (x.length > 3) "long string"
|
||||
else "short string"
|
||||
is Int ->
|
||||
if (x > 999 || x < -99) "long int"
|
||||
else "short int"
|
||||
is Long ->
|
||||
TODO()
|
||||
else ->
|
||||
"I don't know"
|
||||
}
|
||||
}
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
fun <T> doSomething(a: T) {}
|
||||
|
||||
fun test(n: Int): String {
|
||||
if (3 > 2) {
|
||||
<caret>when (n) {
|
||||
1 -> return "one"
|
||||
else -> return "two"
|
||||
}
|
||||
} else {
|
||||
doSomething("***")
|
||||
return "???"
|
||||
}
|
||||
}
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
fun <T> doSomething(a: T) {}
|
||||
|
||||
fun test(n: Int): String {
|
||||
if (3 > 2) {
|
||||
<caret>return when (n) {
|
||||
1 -> "one"
|
||||
else -> "two"
|
||||
}
|
||||
} else {
|
||||
doSomething("***")
|
||||
return "???"
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
fun foo(): Int {
|
||||
loop@ while (true) {
|
||||
<caret>when (1) {
|
||||
1 -> return 1
|
||||
2 -> throw Exception()
|
||||
3 -> break@loop
|
||||
4 -> continue@loop
|
||||
else -> return -1
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
fun foo(): Int {
|
||||
loop@ while (true) {
|
||||
return when (1) {
|
||||
1 -> 1
|
||||
2 -> throw Exception()
|
||||
3 -> break@loop
|
||||
4 -> continue@loop
|
||||
else -> -1
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
fun test(n: Int): String {
|
||||
<caret>when (n) {
|
||||
1 -> return "one"
|
||||
else -> return "two"
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
fun test(n: Int): String {
|
||||
<caret>return when (n) {
|
||||
1 -> "one"
|
||||
else -> "two"
|
||||
}
|
||||
}
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
fun <T> doSomething(a: T) {}
|
||||
|
||||
fun test(n: Int): String {
|
||||
<caret>when (n) {
|
||||
1 -> {
|
||||
doSomething("***")
|
||||
return "one"
|
||||
}
|
||||
else -> {
|
||||
doSomething("***")
|
||||
return "two"
|
||||
}
|
||||
}
|
||||
}
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
fun <T> doSomething(a: T) {}
|
||||
|
||||
fun test(n: Int): String {
|
||||
<caret>return when (n) {
|
||||
1 -> {
|
||||
doSomething("***")
|
||||
"one"
|
||||
}
|
||||
else -> {
|
||||
doSomething("***")
|
||||
"two"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user