Refactoring: make "replace call with binary operator" an inspection

This commit is contained in:
Mikhail Glukhikh
2017-12-20 16:02:15 +03:00
parent 6d4b5bc48f
commit ada7287c66
69 changed files with 320 additions and 321 deletions
@@ -1 +0,0 @@
org.jetbrains.kotlin.idea.intentions.conventionNameCalls.ReplaceCallWithBinaryOperatorIntention
@@ -1,8 +0,0 @@
// INTENTION_TEXT: Replace with '/' operator
fun test() {
class Test {
operator fun div(a: Int): Test = Test()
}
val test = Test()
test.div<caret>(1)
}
@@ -1,8 +0,0 @@
// INTENTION_TEXT: Replace with '/' operator
fun test() {
class Test {
operator fun div(a: Int): Test = Test()
}
val test = Test()
test / 1
}
@@ -1,3 +0,0 @@
// INTENTION_TEXT: Replace with '==' operator
val x = 2.equals<caret>(2)
@@ -1,3 +0,0 @@
// INTENTION_TEXT: Replace with '==' operator
val x = 2 == 2
@@ -1,3 +0,0 @@
// IS_APPLICABLE: false
val x = 2.compareTo<caret>(2) == 0
@@ -1,11 +0,0 @@
// IS_APPLICABLE: false
class Foo
fun Foo?.equals(other: Foo?) = true
fun bar(f1: Foo?, f2: Foo?) {
if (f1.equals<caret>(f2)) {
}
}
@@ -1,6 +0,0 @@
fun test() {
class Test()
operator fun Test.div(a: Int): Test = Test()
val test = Test()
test.div<caret>(1)
}
@@ -1,6 +0,0 @@
fun test() {
class Test()
operator fun Test.div(a: Int): Test = Test()
val test = Test()
test / 1
}
@@ -1,9 +0,0 @@
fun test() {
class Test {
operator fun plus(fn: () -> Test): Test = fn()
}
val test = Test()
test.pl<caret>us {
Test()
}
}
@@ -1,9 +0,0 @@
fun test() {
class Test {
operator fun plus(fn: () -> Test): Test = fn()
}
val test = Test()
test + {
Test()
}
}
@@ -1,3 +0,0 @@
// INTENTION_TEXT: Replace with '>' operator
val x = 3.compareTo<caret>(2) > 0
@@ -1,3 +0,0 @@
// INTENTION_TEXT: Replace with '>' operator
val x = 3 > 2
@@ -1,3 +0,0 @@
// INTENTION_TEXT: Replace with '<=' operator
val x = 0 >= 4.compareTo<caret>(5)
@@ -1,3 +0,0 @@
// INTENTION_TEXT: Replace with '<=' operator
val x = 4 <= 5
@@ -1,8 +0,0 @@
// INTENTION_TEXT: Replace with '-' operator
fun test() {
class Test {
operator fun minus(a: Int): Test = Test()
}
val test = Test()
test.min<caret>us(1)
}
@@ -1,8 +0,0 @@
// INTENTION_TEXT: Replace with '-' operator
fun test() {
class Test {
operator fun minus(a: Int): Test = Test()
}
val test = Test()
test - 1
}
@@ -1,9 +0,0 @@
// IS_APPLICABLE: false
// ERROR: 'operator' modifier is inapplicable on this function: must have a single value parameter
fun test() {
class Test{
operator fun plus(a: Int=1, b: Int=2) : Int = 0
}
val test = Test()
test.p<caret>lus(b=3)
}
@@ -1,10 +0,0 @@
// INTENTION_TEXT: Replace call with binary operator
// IS_APPLICABLE: false
fun test() {
class Test {
operator fun mod(a: Int): Test = Test()
}
val test = Test()
test.mod<caret>(1)
}
@@ -1,10 +0,0 @@
// INTENTION_TEXT: Replace with '%' operator
// IS_APPLICABLE: false
fun test() {
class Test {
operator fun mod(a: Int): Test = Test()
}
val test = Test()
test % 1
}
@@ -1,9 +0,0 @@
// IS_APPLICABLE: false
// ERROR: 'operator' modifier is inapplicable on this function: must have a single value parameter
fun test() {
class Test {
operator fun plus(a: Int, b: Int): Test = Test()
}
val test = Test()
test.pl<caret>us(1, 2)
}
@@ -1,3 +0,0 @@
// INTENTION_TEXT: Replace with '!=' operator
val x = !2.equals<caret>(3)
@@ -1,3 +0,0 @@
// INTENTION_TEXT: Replace with '!=' operator
val x = 2 != 3
@@ -1,3 +0,0 @@
// INTENTION_TEXT: Replace with '!=' operator
val x = !(2.equals<caret>(3))
@@ -1,3 +0,0 @@
// INTENTION_TEXT: Replace with '!=' operator
val x = 2 != 3
@@ -1,3 +0,0 @@
// INTENTION_TEXT: Replace with '==' operator
val x = !(2.equals<caret>(3) && 4.equals(5))
@@ -1,3 +0,0 @@
// INTENTION_TEXT: Replace with '==' operator
val x = !(2 == 3 && 4.equals(5))
@@ -1,8 +0,0 @@
// INTENTION_TEXT: Replace with '+' operator
fun test() {
class Test {
operator fun plus(a: Int): Test = Test()
}
val test = Test()
test.pl<caret>us(1)
}
@@ -1,8 +0,0 @@
// INTENTION_TEXT: Replace with '+' operator
fun test() {
class Test {
operator fun plus(a: Int): Test = Test()
}
val test = Test()
test + 1
}
@@ -1,9 +0,0 @@
class C {
companion object {
operator fun plus(s: String): C = C()
}
}
fun foo() {
C.<caret>plus("x")
}
@@ -1,9 +0,0 @@
class C {
companion object {
operator fun plus(s: String): C = C()
}
}
fun foo() {
C + "x"
}
@@ -1,8 +0,0 @@
// INTENTION_TEXT: Replace with '..' operator
fun test() {
class Test {
operator fun rangeTo(a: Int): Test = Test()
}
val test = Test()
test.rangeTo<caret>(1)
}
@@ -1,8 +0,0 @@
// INTENTION_TEXT: Replace with '..' operator
fun test() {
class Test {
operator fun rangeTo(a: Int): Test = Test()
}
val test = Test()
test..1
}
@@ -1,9 +0,0 @@
// INTENTION_TEXT: Replace with '%' operator
fun test() {
class Test {
operator fun rem(a: Int): Test = Test()
}
val test = Test()
test.rem<caret>(1)
}
@@ -1,9 +0,0 @@
// INTENTION_TEXT: Replace with '%' operator
fun test() {
class Test {
operator fun rem(a: Int): Test = Test()
}
val test = Test()
test % 1
}
@@ -1,5 +0,0 @@
// IS_APPLICABLE: false
// ERROR: Operator call corresponds to a dot-qualified call 'nullable?.compareTo(1).compareTo(0)' which is not allowed on a nullable receiver 'nullable?.compareTo(1)'.
val nullable: Int? = null
val x = nullable?.compareTo<caret>(1) >= 0
@@ -1,11 +0,0 @@
// IS_APPLICABLE: false
open class Base {
open operator fun plus(s: String) = ""
}
class C : Base() {
override fun plus(s: String): String {
return super.<caret>plus(s)
}
}
@@ -1,8 +0,0 @@
// INTENTION_TEXT: Replace with '*' operator
fun test() {
class Test {
operator fun times(a: Int): Test = Test()
}
val test = Test()
test.time<caret>s(1)
}
@@ -1,8 +0,0 @@
// INTENTION_TEXT: Replace with '*' operator
fun test() {
class Test {
operator fun times(a: Int): Test = Test()
}
val test = Test()
test * 1
}
@@ -1,8 +0,0 @@
// IS_APPLICABLE: false
fun test() {
class Test {
operator fun <T> div(a: Test): T? = a as? T
}
val test = Test()
test.div<caret><Int>(Test())
}
@@ -1,9 +0,0 @@
// IS_APPLICABLE: false
// ERROR: 'operator' modifier is inapplicable on this function: must have a single value parameter
fun test() {
class Test{
operator fun plus(vararg b: Int, c: Int = 0): Int = 0
}
val test = Test()
test.plus<caret>(c=5)
}
@@ -1,9 +0,0 @@
// IS_APPLICABLE: false
// ERROR: 'operator' modifier is inapplicable on this function: must have a single value parameter
fun test() {
class Test{
operator fun plus(vararg b: Int, c: Int = 0): Int = 0
}
val test = Test()
test.plus<caret>(0, 1)
}
@@ -1,7 +0,0 @@
fun test() {
class Test {
operator fun plus(a: Int): Test = Test()
}
val test = Test()
test.pl<caret>us(a=1)
}
@@ -1,7 +0,0 @@
fun test() {
class Test {
operator fun plus(a: Int): Test = Test()
}
val test = Test()
test + 1
}