KT-4820: Intention to introduce/remove indices from a for-loop (update to modern Kotlin)

This commit is contained in:
Dmitry Jemerov
2015-07-02 13:16:34 +02:00
parent 7f3f834011
commit 21e25e8509
19 changed files with 184 additions and 80 deletions
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.intentions.AddForLoopIndicesIntention
@@ -1,7 +1,7 @@
//IS_APPLICABLE: FALSE
// WITH_RUNTIME
fun b(c: List<String>) {
for ((<caret>indexVariable, d) in c.withIndices()) {
for ((<caret>indexVariable, d) in c.withIndex()) {
}
}
@@ -1,6 +1,6 @@
// WITH_RUNTIME
// IS_APPLICABLE: FALSE
fun String.withIndices(): Int = 42
fun String.withIndex(): Int = 42
fun foo(s: String) {
for (<caret>a in s) {
@@ -1,6 +1,6 @@
//WITH_RUNTIME
fun foo(bar: IntArray) {
for ((index, a) in bar.withIndices()) {
for ((index, a) in bar.withIndex()) {
}
}
@@ -1,6 +1,6 @@
//WITH_RUNTIME
fun foo(bar: Iterable<Int>) {
for ((index, a) in bar.withIndices()) {
for ((index, a) in bar.withIndex()) {
}
}
@@ -1,7 +1,7 @@
// WITH_RUNTIME
fun a() {
val b = listOf(1,2,3,4,5)
for ((index, c : Int) in b.withIndices()) {
for ((index, c : Int) in b.withIndex()) {
}
}
@@ -1,6 +1,6 @@
//WITH_RUNTIME
fun foo(bar: Array<Object>) {
for ((index, a) in bar.withIndices()) {
for ((index, a) in bar.withIndex()) {
}
}
@@ -1,7 +1,7 @@
// WITH_RUNTIME
fun a() {
val b = listOf(1,2,3,4,5)
for ((index, c) in b.withIndices()) {
for ((index, c) in b.withIndex()) {
}
}
@@ -1,6 +1,6 @@
//WITH_RUNTIME
fun foo(bar: Stream<String>) {
for ((index, a) in bar.withIndices()) {
for ((index, a) in bar.withIndex()) {
}
}
@@ -1,6 +1,6 @@
//WITH_RUNTIME
fun foo(bar: String) {
for ((index, a) in bar.withIndices()) {
for ((index, a) in bar.withIndex()) {
}
}
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.intentions.RemoveForLoopIndicesIntention
@@ -2,7 +2,7 @@
//WITH_RUNTIME
fun foo(b: List<Int>) : Int {
for ((i, <caret>c) in b.withIndices()) {
for ((i, <caret>c) in b.withIndex()) {
return i
}
return 0
@@ -1,11 +1,10 @@
// WITH_RUNTIME
// IS_APPLICABLE: FALSE
import java.util.LinkedList
fun Int.withIndices(): List<Pair<Int, Int>> = LinkedList<Pair<Int, Int>>()
fun Int.withIndex(): List<Pair<Int, Int>> = linkedListOf<Pair<Int, Int>>()
fun foo(s: Int) {
for ((index<caret>, a) in s.withIndices()) {
for ((index<caret>, a) in s.withIndex()) {
}
}
@@ -1,6 +1,6 @@
//WITH_RUNTIME
fun foo(bar: List<Int>) {
for ((i : <caret>Int, b: Int) in bar.withIndices()) {
for ((i : <caret>Int, b: Int) in bar.withIndex()) {
}
}
@@ -1,6 +1,6 @@
//WITH_RUNTIME
fun foo(bar: List<String>) {
for ((i,<caret>a) in bar.withIndices()) {
for ((i,<caret>a) in bar.withIndex()) {
}
}