If to when: label break / continue if necessary #KT-11427 Fixed
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun testIf(xs: List<Any>) {
|
||||
for (x in xs) {
|
||||
<caret>if (x is String) {
|
||||
for (c in x) {
|
||||
continue // do not change
|
||||
}
|
||||
}
|
||||
else if (x is Int) {
|
||||
break
|
||||
}
|
||||
else {
|
||||
println(x)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun testIf(xs: List<Any>) {
|
||||
loop@ for (x in xs) {
|
||||
when (x) {
|
||||
is String -> for (c in x) {
|
||||
continue // do not change
|
||||
}
|
||||
is Int -> break@loop
|
||||
else -> println(x)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun testIf(x: Any) {
|
||||
<caret>if (x is String) {
|
||||
println(x)
|
||||
for (c in x) {
|
||||
if (c == ' ')
|
||||
break // do not change
|
||||
}
|
||||
}
|
||||
else {
|
||||
println(x)
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun testIf(x: Any) {
|
||||
when (x) {
|
||||
is String -> {
|
||||
println(x)
|
||||
for (c in x) {
|
||||
if (c == ' ')
|
||||
break // do not change
|
||||
}
|
||||
}
|
||||
else -> println(x)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
fun test() {
|
||||
for (i in -2..2) {
|
||||
<caret>if (i > 0) i.hashCode()
|
||||
else continue
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fun test() {
|
||||
loop@ for (i in -2..2) {
|
||||
when {
|
||||
i > 0 -> i.hashCode()
|
||||
else -> continue@loop
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
fun test() {
|
||||
loop@ while (true) {
|
||||
for (i in -10..10) {
|
||||
<caret>if (i < 0) {
|
||||
if (i < -5) {
|
||||
break
|
||||
} else {
|
||||
continue@loop
|
||||
}
|
||||
} else {
|
||||
if (i == 0) {
|
||||
i.hashCode()
|
||||
break
|
||||
} else if (i > 5) {
|
||||
i.hashCode()
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
fun test() {
|
||||
loop@ while (true) {
|
||||
loop1@ for (i in -10..10) {
|
||||
when {
|
||||
i < 0 -> if (i < -5) {
|
||||
break@loop1
|
||||
} else {
|
||||
continue@loop
|
||||
}
|
||||
else -> if (i == 0) {
|
||||
i.hashCode()
|
||||
break@loop1
|
||||
} else if (i > 5) {
|
||||
i.hashCode()
|
||||
} else {
|
||||
continue@loop1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
fun test() {
|
||||
// Comment 1
|
||||
loop@ while (true) {
|
||||
// Comment 2
|
||||
for (i in -10..10) {
|
||||
// Comment 3
|
||||
if (i < 0) {
|
||||
// Comment 4
|
||||
if (i < -5) {
|
||||
break
|
||||
} else {
|
||||
// Comment 5
|
||||
continue@loop
|
||||
}
|
||||
} else {
|
||||
// Comment 6
|
||||
<caret>if (i == 0) {
|
||||
i.hashCode()
|
||||
// Comment 7
|
||||
break
|
||||
} else if (i > 5) {
|
||||
// Comment 8
|
||||
i.hashCode()
|
||||
} else {
|
||||
// Comment 9
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
fun test() {
|
||||
// Comment 1
|
||||
loop@ while (true) {
|
||||
// Comment 2
|
||||
loop1@ for (i in -10..10) {
|
||||
// Comment 3
|
||||
if (i < 0) {
|
||||
// Comment 4
|
||||
if (i < -5) {
|
||||
break
|
||||
} else {
|
||||
// Comment 5
|
||||
continue@loop
|
||||
}
|
||||
} else {
|
||||
// Comment 6
|
||||
when {
|
||||
i == 0 -> {
|
||||
i.hashCode()
|
||||
// Comment 7
|
||||
break@loop1
|
||||
}
|
||||
i > 5 -> // Comment 8
|
||||
i.hashCode()
|
||||
else -> // Comment 9
|
||||
continue@loop1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
fun test() {
|
||||
myLoop@ for (i in -2..2) {
|
||||
<caret>if (i > 0) i.hashCode()
|
||||
else continue
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fun test() {
|
||||
myLoop@ for (i in -2..2) {
|
||||
when {
|
||||
i > 0 -> i.hashCode()
|
||||
else -> continue@myLoop
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun testIf(xs: List<Any>) {
|
||||
for (x in xs) {
|
||||
<caret>if (x is String) continue
|
||||
else if (x is Int) break
|
||||
else println(x)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun testIf(xs: List<Any>) {
|
||||
loop@ for (x in xs) {
|
||||
when (x) {
|
||||
is String -> continue@loop
|
||||
is Int -> break@loop
|
||||
else -> println(x)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
fun test() {
|
||||
// Loop comment
|
||||
for (i in -2..2) {
|
||||
// Some comment
|
||||
<caret>if (i < 0) {
|
||||
// Very important comment
|
||||
break
|
||||
}
|
||||
else {
|
||||
// More comments
|
||||
i.hashCode()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fun test() {
|
||||
// Loop comment
|
||||
loop@ for (i in -2..2) {
|
||||
// Some comment
|
||||
when {
|
||||
i < 0 -> // Very important comment
|
||||
break@loop
|
||||
else -> // More comments
|
||||
i.hashCode()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user