Add replacement intentions for operator functions

Add intentions for replacing attribute calls that correspond to
overloadable operators with their respective operators.

This commit includes call replacements for:
 * Binary Infix Operators: plus, minus, times, rangeTo, mod, div
 * Unary Prefix Operators: plus, minus, not
 * Array Index Operator: get
 * In Operator: contains
This commit is contained in:
Steven Allen
2014-02-27 15:57:51 -05:00
parent 08a8d17e97
commit 84a8911822
152 changed files with 1922 additions and 1 deletions
@@ -0,0 +1,7 @@
fun test() {
class Test{
fun plus(a: Int, vararg b: Int, c: Int = 0) : Int = 0
}
val test = Test()
test.p<caret>lus(1)
}
@@ -0,0 +1,7 @@
fun test() {
class Test{
fun plus(a: Int, vararg b: Int, c: Int = 0) : Int = 0
}
val test = Test()
test + 1
}
@@ -0,0 +1,7 @@
fun test() {
class Test{
fun plus(vararg b: Int, c: Int = 0) : Int = 0
}
val test = Test()
test.p<caret>lus(1)
}
@@ -0,0 +1,7 @@
fun test() {
class Test{
fun plus(vararg b: Int, c: Int = 0) : Int = 0
}
val test = Test()
test + 1
}
@@ -0,0 +1,7 @@
fun test() {
class Test {
fun plus(a: Int, b: Int=5): Test = Test()
}
val test = Test()
test.pl<caret>us(1)
}
@@ -0,0 +1,7 @@
fun test() {
class Test {
fun plus(a: Int, b: Int=5): Test = Test()
}
val test = Test()
test + 1
}
@@ -0,0 +1,8 @@
// INTENTION_TEXT: Replace with '/' operator
fun test() {
class Test {
fun div(a: Int): Test = Test()
}
val test = Test()
test.div<caret>(1)
}
@@ -0,0 +1,8 @@
// INTENTION_TEXT: Replace with '/' operator
fun test() {
class Test {
fun div(a: Int): Test = Test()
}
val test = Test()
test / 1
}
@@ -0,0 +1,6 @@
fun test() {
class Test()
fun Test.div(a: Int): Test = Test()
val test = Test()
test.div<caret>(1)
}
@@ -0,0 +1,6 @@
fun test() {
class Test()
fun Test.div(a: Int): Test = Test()
val test = Test()
test / 1
}
@@ -0,0 +1,9 @@
fun test() {
class Test {
fun plus(fn: () -> Test): Test = fn()
}
val test = Test()
test.pl<caret>us {
Test()
}
}
@@ -0,0 +1,9 @@
fun test() {
class Test {
fun plus(fn: () -> Test): Test = fn()
}
val test = Test()
test + {
Test()
}
}
@@ -0,0 +1,8 @@
// INTENTION_TEXT: Replace with '-' operator
fun test() {
class Test {
fun minus(a: Int): Test = Test()
}
val test = Test()
test.min<caret>us(1)
}
@@ -0,0 +1,8 @@
// INTENTION_TEXT: Replace with '-' operator
fun test() {
class Test {
fun minus(a: Int): Test = Test()
}
val test = Test()
test - 1
}
@@ -0,0 +1,8 @@
// SHOULD_FAIL_WITH: skipped.defaults
fun test() {
class Test{
fun plus(a: Int=1, b: Int=2) : Int = 0
}
val test = Test()
test.p<caret>lus(b=3)
}
@@ -0,0 +1,8 @@
// INTENTION_TEXT: Replace with '%' operator
fun test() {
class Test {
fun mod(a: Int): Test = Test()
}
val test = Test()
test.mod<caret>(1)
}
@@ -0,0 +1,8 @@
// INTENTION_TEXT: Replace with '%' operator
fun test() {
class Test {
fun mod(a: Int): Test = Test()
}
val test = Test()
test % 1
}
@@ -0,0 +1,8 @@
// IS_APPLICABLE: false
fun test() {
class Test {
fun plus(a: Int, b: Int): Test = Test()
}
val test = Test()
test.pl<caret>us(1, 2)
}
@@ -0,0 +1,8 @@
// INTENTION_TEXT: Replace with '+' operator
fun test() {
class Test {
fun plus(a: Int): Test = Test()
}
val test = Test()
test.pl<caret>us(1)
}
@@ -0,0 +1,8 @@
// INTENTION_TEXT: Replace with '+' operator
fun test() {
class Test {
fun plus(a: Int): Test = Test()
}
val test = Test()
test + 1
}
@@ -0,0 +1,8 @@
// INTENTION_TEXT: Replace with '..' operator
fun test() {
class Test {
fun rangeTo(a: Int): Test = Test()
}
val test = Test()
test.rangeTo<caret>(1)
}
@@ -0,0 +1,8 @@
// INTENTION_TEXT: Replace with '..' operator
fun test() {
class Test {
fun rangeTo(a: Int): Test = Test()
}
val test = Test()
test..1
}
@@ -0,0 +1,8 @@
// INTENTION_TEXT: Replace with '*' operator
fun test() {
class Test {
fun times(a: Int): Test = Test()
}
val test = Test()
test.time<caret>s(1)
}
@@ -0,0 +1,8 @@
// INTENTION_TEXT: Replace with '*' operator
fun test() {
class Test {
fun times(a: Int): Test = Test()
}
val test = Test()
test * 1
}
@@ -0,0 +1,8 @@
// IS_APPLICABLE: false
fun test() {
class Test {
fun div<T>(a: Test): T? = a as? T
}
val test = Test()
test.div<caret><Int>(Test())
}
@@ -0,0 +1,8 @@
// SHOULD_FAIL_WITH: vararg.not.last
fun test() {
class Test{
fun plus(vararg b: Int, c: Int = 0): Int = 0
}
val test = Test()
test.plus<caret>(c=5)
}
@@ -0,0 +1,8 @@
// IS_APPLICABLE: false
fun test() {
class Test{
fun plus(vararg b: Int, c: Int = 0): Int = 0
}
val test = Test()
test.plus<caret>(0, 1)
}
@@ -0,0 +1,7 @@
fun test() {
class Test {
fun plus(a: Int): Test = Test()
}
val test = Test()
test.pl<caret>us(a=1)
}
@@ -0,0 +1,7 @@
fun test() {
class Test {
fun plus(a: Int): Test = Test()
}
val test = Test()
test + 1
}
@@ -0,0 +1,7 @@
fun test() {
class Test{
fun contains(vararg a: Int, b: Int = 0): Boolean = true
}
val test = Test()
test.contai<caret>ns(1)
}
@@ -0,0 +1,7 @@
fun test() {
class Test{
fun contains(vararg a: Int, b: Int = 0): Boolean = true
}
val test = Test()
1 in test
}
@@ -0,0 +1,7 @@
fun test() {
class Test{
fun contains(c: Int, vararg a: Int, b: Int = 0): Boolean = true
}
val test = Test()
test.contai<caret>ns(1)
}
@@ -0,0 +1,7 @@
fun test() {
class Test{
fun contains(c: Int, vararg a: Int, b: Int = 0): Boolean = true
}
val test = Test()
1 in test
}
@@ -0,0 +1,7 @@
fun test() {
class Test{
fun contains(a: Int, b: Int=5) : Boolean = true
}
val test = Test()
test.c<caret>ontains(1)
}
@@ -0,0 +1,7 @@
fun test() {
class Test{
fun contains(a: Int, b: Int=5) : Boolean = true
}
val test = Test()
1 in test
}
@@ -0,0 +1,7 @@
fun test() {
class Test{
fun contains(a: Int) : Boolean = true
}
val test = Test()
println(test.c<caret>ontains(0).toString())
}
@@ -0,0 +1,7 @@
fun test() {
class Test{
fun contains(a: Int) : Boolean = true
}
val test = Test()
println((0 in test).toString())
}
@@ -0,0 +1,6 @@
fun test() {
class Test()
fun Test.contains(a: Int) : Boolean = true
val test = Test()
test.c<caret>ontains(1)
}
@@ -0,0 +1,6 @@
fun test() {
class Test()
fun Test.contains(a: Int) : Boolean = true
val test = Test()
1 in test
}
@@ -0,0 +1,9 @@
fun test() {
class Test{
fun contains(fn: () -> Boolean) : Boolean = true
}
val test = Test()
test.c<caret>ontains {
true
}
}
@@ -0,0 +1,9 @@
fun test() {
class Test{
fun contains(fn: () -> Boolean) : Boolean = true
}
val test = Test();
{
true
} in test
}
@@ -0,0 +1,9 @@
fun test() {
class Test{
fun contains(fn: () -> Boolean) : Boolean = true
}
val test = Test();
test.c<caret>ontains {
true
}
}
@@ -0,0 +1,9 @@
fun test() {
class Test{
fun contains(fn: () -> Boolean) : Boolean = true
}
val test = Test();
{
true
} in test
}
@@ -0,0 +1,11 @@
fun test() {
class Test{
fun contains(fn: () -> Boolean) : Boolean = true
}
val test = Test()
if (true) {
test.c<caret>ontains {
true
}
}
}
@@ -0,0 +1,11 @@
fun test() {
class Test{
fun contains(fn: () -> Boolean) : Boolean = true
}
val test = Test()
if (true) {
{
true
} in test
}
}
@@ -0,0 +1,7 @@
fun test() {
class Test{
fun contains(fn: () -> Boolean) : Boolean = true
}
val test = Test()
println(test.c<caret>ontains { true }.toString())
}
@@ -0,0 +1,7 @@
fun test() {
class Test{
fun contains(fn: () -> Boolean) : Boolean = true
}
val test = Test()
println(({ true } in test).toString())
}
@@ -0,0 +1,8 @@
// SHOULD_FAIL_WITH: invalid.arguments
fun test() {
class Test{
fun contains(a: Int=1, b: Int=2): Boolean = true
}
val test = Test()
test.c<caret>ontains(c=3)
}
@@ -0,0 +1,8 @@
// SHOULD_FAIL_WITH: duplicate.or.missing.arguments
fun test() {
class Test{
fun contains(a: Int, b: Int): Boolean = true
}
val test = Test()
test.cont<caret>ains(0)
}
@@ -0,0 +1,8 @@
// SHOULD_FAIL_WITH: skipped.defaults
fun test() {
class Test{
fun contains(a: Int=1, b: Int=2) : Boolean = true
}
val test = Test()
test.contai<caret>ns(b=3)
}
@@ -0,0 +1,8 @@
// IS_APPLICABLE: false
fun test() {
class Test{
fun contains(a: Int, b: Int) : Boolean = true
}
val test = Test()
test.c<caret>ontains(1, 2)
}
@@ -0,0 +1,7 @@
fun test() {
class Test{
fun contains(a: Int) : Boolean = true
}
val test = Test()
test.c<caret>ontains(1)
}
@@ -0,0 +1,7 @@
fun test() {
class Test{
fun contains(a: Int) : Boolean = true
}
val test = Test()
1 in test
}
@@ -0,0 +1,7 @@
fun test() {
class Test{
fun contains<T>(a: T): Boolean = false
}
val test = Test()
test.contai<caret>ns<Int>(1)
}
@@ -0,0 +1,7 @@
fun test() {
class Test{
fun contains<T>(a: T): Boolean = false
}
val test = Test()
1 in test
}
@@ -0,0 +1,8 @@
// SHOULD_FAIL_WITH: vararg.not.last
fun test() {
class Test{
fun contains(vararg b: Int, c: Int = 0): Boolean = true
}
val test = Test()
test.contains<caret>(c=5)
}
@@ -0,0 +1,8 @@
// IS_APPLICABLE: false
fun test() {
class Test{
fun contains(vararg b: Int, c: Int = 0): Boolean = true
}
val test = Test()
test.contains<caret>(0, 1)
}
@@ -0,0 +1,7 @@
fun test() {
class Test{
fun contains(a: Int=1, b: Int=2) : Boolean = true
}
val test = Test()
test.c<caret>ontains(a=5)
}
@@ -0,0 +1,7 @@
fun test() {
class Test{
fun contains(a: Int=1, b: Int=2) : Boolean = true
}
val test = Test()
5 in test
}
@@ -0,0 +1,7 @@
fun test() {
class Test{
fun get(a: Int, vararg b: Int, c: Int = 0) : Int = 0
}
val test = Test()
test.g<caret>et(1, 3, 4, 5)
}
@@ -0,0 +1,7 @@
fun test() {
class Test{
fun get(a: Int, vararg b: Int, c: Int = 0) : Int = 0
}
val test = Test()
test[1, 3, 4, 5]
}
@@ -0,0 +1,9 @@
fun test() {
class Test{
fun get(a: Int, b: Int, fn: (i: Int) -> Int) : Int = 0
}
val test = Test()
test.g<caret>et(1, 2) { i ->
i
}
}
@@ -0,0 +1,9 @@
fun test() {
class Test{
fun get(a: Int, b: Int, fn: (i: Int) -> Int) : Int = 0
}
val test = Test()
test[1, 2, { i ->
i
}]
}
@@ -0,0 +1,8 @@
// SHOULD_FAIL_WITH: duplicate.or.missing.arguments
fun test() {
class Test{
fun get(a: Int, b: Int) : Int = 0
}
val test = Test()
test.g<caret>et(a=0, a=1)
}
@@ -0,0 +1,7 @@
fun test() {
class Test()
fun Test.get(i: Int) : Int = 0
val test = Test()
test.g<caret>et(0)
}
@@ -0,0 +1,7 @@
fun test() {
class Test()
fun Test.get(i: Int) : Int = 0
val test = Test()
test[0]
}
@@ -0,0 +1,9 @@
fun test() {
class Test{
fun get(fn: (i: Int) -> Int) : Int = 0
}
val test = Test()
test.g<caret>et() { i ->
i
}
}
@@ -0,0 +1,9 @@
fun test() {
class Test{
fun get(fn: (i: Int) -> Int) : Int = 0
}
val test = Test()
test[{ i ->
i
}]
}
@@ -0,0 +1,8 @@
// SHOULD_FAIL_WITH: invalid.arguments
fun test() {
class Test{
fun get(a: Int=1, b: Int=2) : Int = 0
}
val test = Test()
test.g<caret>et(c=3)
}
@@ -0,0 +1,8 @@
// SHOULD_FAIL_WITH: duplicate.or.missing.arguments
fun test() {
class Test{
fun get(a: Int, b: Int) : Int = 0
}
val test = Test()
test.g<caret>et(0)
}
@@ -0,0 +1,8 @@
// SHOULD_FAIL_WITH: skipped.defaults
fun test() {
class Test{
fun get(a: Int=1, b: Int=2) : Int = 0
}
val test = Test()
test.g<caret>et(b=3)
}
@@ -0,0 +1,7 @@
fun test() {
class Test{
fun get(a: Int, b: Int) : Int = 0
}
val test = Test()
test.g<caret>et(1, 2)
}
@@ -0,0 +1,7 @@
fun test() {
class Test{
fun get(a: Int, b: Int) : Int = 0
}
val test = Test()
test[1, 2]
}
@@ -0,0 +1,9 @@
fun test() {
class Test{
fun get(a: Int, b: Int, c: Int = 1, d: Int = 1 fn: (i: Int) -> Int) : Int = 0
}
val test = Test()
test.g<caret>et(1, c=3, b=2) { i ->
i
}
}
@@ -0,0 +1,9 @@
fun test() {
class Test{
fun get(a: Int, b: Int, c: Int = 1, d: Int = 1 fn: (i: Int) -> Int) : Int = 0
}
val test = Test()
test[1, 2, 3, { i ->
i
}]
}
@@ -0,0 +1,8 @@
// IS_APPLICABLE: false
fun test() {
class Test{
fun get() : Int = 0
}
val test = Test()
test.g<caret>et()
}
@@ -0,0 +1,8 @@
// IS_APPLICABLE: false
fun test() {
class Test{
fun get(i: Int) : Int = 0
}
val test = Test()
test.g<caret>ot(0)
}
@@ -0,0 +1,7 @@
fun test() {
class Test{
fun get(i: Int) : Int = 0
}
val test = Test()
test.g<caret>et(0)
}
@@ -0,0 +1,7 @@
fun test() {
class Test{
fun get(i: Int) : Int = 0
}
val test = Test()
test[0]
}
@@ -0,0 +1,7 @@
fun test() {
class Test{
fun get(a: Int) : Int = 0
}
val test = Test()
test.g<caret>et(a=1)
}
@@ -0,0 +1,7 @@
fun test() {
class Test{
fun get(a: Int) : Int = 0
}
val test = Test()
test[1]
}
@@ -0,0 +1,8 @@
// SHOULD_FAIL_WITH: vararg.not.last
fun test() {
class Test{
fun get(a: Int, vararg b: Int, c: Int = 0) : Int = 0
}
val test = Test()
test.g<caret>et(1, 3, 4, c=5)
}
@@ -0,0 +1,7 @@
fun test() {
class Test{
fun get(a: Int = 0, b: Int = 1, c: Int = 2, d: Int = 3) : Int = 0
}
val test = Test()
test.g<caret>et(1, c=3, b=2)
}
@@ -0,0 +1,7 @@
fun test() {
class Test{
fun get(a: Int = 0, b: Int = 1, c: Int = 2, d: Int = 3) : Int = 0
}
val test = Test()
test[1, 2, 3]
}
@@ -0,0 +1,8 @@
fun test() {
class Test()
fun Test.invoke(): Unit = Unit.VALUE
val test = Test()
test.i<caret>nvoke()
}
@@ -0,0 +1,8 @@
fun test() {
class Test()
fun Test.invoke(): Unit = Unit.VALUE
val test = Test()
test()
}
@@ -0,0 +1,9 @@
fun test() {
class Test {
fun invoke(fn: () -> Unit) {}
}
val test = Test()
test.i<caret>nvoke {
}
}
@@ -0,0 +1,9 @@
fun test() {
class Test {
fun invoke(fn: () -> Unit) {}
}
val test = Test()
test {
}
}
@@ -0,0 +1,7 @@
fun test() {
class Test {
fun invoke(a: Int, vararg b: String, fn: () -> Unit): String = "test"
}
val test = Test()
println(test.i<caret>nvoke(1, "a", "b") { })
}
@@ -0,0 +1,7 @@
fun test() {
class Test {
fun invoke(a: Int, vararg b: String, fn: () -> Unit): String = "test"
}
val test = Test()
println(test(1, "a", "b") { })
}
@@ -0,0 +1,7 @@
fun test() {
class Test {
fun invoke(a: Int, b: String) {}
}
val test = Test()
test.i<caret>nvoke(b = "s", a = 1)
}
@@ -0,0 +1,7 @@
fun test() {
class Test {
fun invoke(a: Int, b: String) {}
}
val test = Test()
test(b = "s", a = 1)
}
@@ -0,0 +1,7 @@
fun test() {
class Test {
fun invoke() {}
}
val test = Test()
test.i<caret>nvoke()
}
@@ -0,0 +1,7 @@
fun test() {
class Test {
fun invoke() {}
}
val test = Test()
test()
}
@@ -0,0 +1,7 @@
fun test() {
class Test {
fun invoke<T>(a: Int) {}
}
val test = Test()
test.i<caret>nvoke<Int>(0)
}
@@ -0,0 +1,7 @@
fun test() {
class Test {
fun invoke<T>(a: Int) {}
}
val test = Test()
test<Int>(0)
}
@@ -0,0 +1,7 @@
fun test() {
class Test {
fun invoke<T>(fn: () -> T) {}
}
val test = Test()
test.i<caret>nvoke<Int> { 0 }
}
@@ -0,0 +1,7 @@
fun test() {
class Test {
fun invoke<T>(fn: () -> T) {}
}
val test = Test()
test<Int> { 0 }
}
@@ -0,0 +1,9 @@
fun test() {
class Test {
fun invoke(a: Int, fn: () -> Unit) {}
}
val test = Test()
test.i<caret>nvoke(0) {
}
}
@@ -0,0 +1,9 @@
fun test() {
class Test {
fun invoke(a: Int, fn: () -> Unit) {}
}
val test = Test()
test(0) {
}
}

Some files were not shown because too many files have changed in this diff Show More