Merge branch 'rr/valentin/for-loop-indices'

This commit is contained in:
Valentin Kipyatkov
2015-07-22 09:48:18 +03:00
44 changed files with 536 additions and 2 deletions
+1
View File
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.intentions.AddForLoopIndicesIntention
@@ -0,0 +1,7 @@
// WITH_RUNTIME
fun a() {
val b = listOf(1,2,3,4,5)
for (<caret>c : Int in b) {
}
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
fun a() {
val b = listOf(1,2,3,4,5)
for ((index, c : Int) in b.withIndex()) {<caret>
}
}
@@ -0,0 +1,7 @@
// IS_APPLICABLE: false
// WITH_RUNTIME
fun b(c: List<String>) {
for ((<caret>indexVariable, d) in c.withIndex()) {
}
}
@@ -0,0 +1,7 @@
// IS_APPLICABLE: false
// WITH_RUNTIME
fun foo() {
for (a in listOf(1, 2, 3)) {<caret>
}
}
@@ -0,0 +1,7 @@
// IS_APPLICABLE: FALSE
// WITH_RUNTIME
fun foo(bar: Map<String, String>) {
for (a <caret>in bar) {
}
}
@@ -0,0 +1,9 @@
// WITH_RUNTIME
// IS_APPLICABLE: FALSE
fun String.withIndex(): Int = 42
fun foo(s: String) {
for (<caret>a in s) {
}
}
@@ -0,0 +1,7 @@
// IS_APPLICABLE: false
// ERROR: Unresolved reference: b
fun foo() {
for (a <caret>in b) {
}
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun foo(bar: IntArray) {
for (<caret>a in bar) {
}
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun foo(bar: IntArray) {
for ((index, a) in bar.withIndex()) {<caret>
}
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun foo(bar: Iterable<Int>) {
for (<caret>a in bar) {
}
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun foo(bar: Iterable<Int>) {
for ((index, a) in bar.withIndex()) {<caret>
}
}
+4
View File
@@ -0,0 +1,4 @@
// WITH_RUNTIME
fun foo(bar: IntArray) {
for (<caret>a in bar)
}
@@ -0,0 +1,4 @@
// WITH_RUNTIME
fun foo(bar: IntArray) {
for ((index, a) in bar.withIndex())<caret>
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun foo(bar: Array<Object>) {
for (<caret>a in bar) {
}
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun foo(bar: Array<Object>) {
for ((index, a) in bar.withIndex()) {<caret>
}
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun foo(bar: Sequence<String>) {
for (<caret>a in bar)
print(a)
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun foo(bar: Sequence<String>) {
for ((index, a) in bar.withIndex())
<caret>print(a)
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
fun a() {
val b = listOf(1,2,3,4,5)
for (<caret>c in b) {
}
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
fun a() {
val b = listOf(1,2,3,4,5)
for ((index, c) in b.withIndex()) {<caret>
}
}
+6
View File
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun foo(bar: String) {
for (<caret>a in bar) {
print(a)
}
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun foo(bar: String) {
for ((index, a) in bar.withIndex()) {
<caret>print(a)
}
}
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.intentions.RemoveForLoopIndicesIntention
@@ -0,0 +1,6 @@
// IS_APPLICABLE: false
fun foo(bar: List<String>) {
for (<caret>a in bar) {
}
}
@@ -0,0 +1,9 @@
// IS_APPLICABLE: FALSE
// WITH_RUNTIME
fun foo(b: List<Int>) : Int {
for ((<caret>i, c) in b.withIndex()) {
return i
}
return 0
}
@@ -0,0 +1,10 @@
// WITH_RUNTIME
// IS_APPLICABLE: FALSE
fun Int.withIndex(): List<Pair<Int, Int>> = linkedListOf<Pair<Int, Int>>()
fun foo(s: Int) {
for ((index<caret>, a) in s.withIndex()) {
}
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun foo(bar: List<Int>) {
for ((i<caret> : Int, b: Int) in bar.withIndex()) {
}
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun foo(bar: List<Int>) {
for (b: Int in bar) {
}
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun foo(bar: List<String>) {
for ((i<caret>,a) in bar.withIndex()) {
}
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun foo(bar: List<String>) {
for (a in bar) {
}
}