Refactoring: make "replace call with binary operator" an inspection
This commit is contained in:
Vendored
+1
@@ -0,0 +1 @@
|
||||
org.jetbrains.kotlin.idea.inspections.conventionNameCalls.ReplaceCallWithBinaryOperatorInspection
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
// FIX: Replace with '/' operator
|
||||
fun test() {
|
||||
class Test {
|
||||
operator fun div(a: Int): Test = Test()
|
||||
}
|
||||
val test = Test()
|
||||
test.<caret>div(1)
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// FIX: Replace with '/' operator
|
||||
fun test() {
|
||||
class Test {
|
||||
operator fun div(a: Int): Test = Test()
|
||||
}
|
||||
val test = Test()
|
||||
test / 1
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
// FIX: Replace with '==' operator
|
||||
|
||||
val x = 2.<caret>equals(2)
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
// FIX: Replace with '==' operator
|
||||
|
||||
val x = 2 == 2
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
// PROBLEM: none
|
||||
|
||||
val x = 2.compareTo<caret>(2) == 0
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// PROBLEM: none
|
||||
|
||||
class Foo
|
||||
|
||||
fun Foo?.equals(other: Foo?) = true
|
||||
|
||||
fun bar(f1: Foo?, f2: Foo?) {
|
||||
if (f1.equals<caret>(f2)) {
|
||||
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
fun test() {
|
||||
class Test()
|
||||
operator fun Test.div(a: Int): Test = Test()
|
||||
val test = Test()
|
||||
test.<caret>div(1)
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
fun test() {
|
||||
class Test()
|
||||
operator fun Test.div(a: Int): Test = Test()
|
||||
val test = Test()
|
||||
test / 1
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
fun test() {
|
||||
class Test {
|
||||
operator fun plus(fn: () -> Test): Test = fn()
|
||||
}
|
||||
val test = Test()
|
||||
test.pl<caret>us {
|
||||
Test()
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
fun test() {
|
||||
class Test {
|
||||
operator fun plus(fn: () -> Test): Test = fn()
|
||||
}
|
||||
val test = Test()
|
||||
test + {
|
||||
Test()
|
||||
}
|
||||
}
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
// FIX: Replace with '>' operator
|
||||
|
||||
val x = 3.compare<caret>To(2) > 0
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
// FIX: Replace with '>' operator
|
||||
|
||||
val x = 3 > 2
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
// FIX: Replace with '<=' operator
|
||||
|
||||
val x = 0 >= 4.compare<caret>To(5)
|
||||
idea/testData/inspectionsLocal/conventionNameCalls/replaceCallWithBinaryOperator/lessEquals.kt.after
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
// FIX: Replace with '<=' operator
|
||||
|
||||
val x = 4 <= 5
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
// FIX: Replace with '-' operator
|
||||
fun test() {
|
||||
class Test {
|
||||
operator fun minus(a: Int): Test = Test()
|
||||
}
|
||||
val test = Test()
|
||||
test.min<caret>us(1)
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// FIX: Replace with '-' operator
|
||||
fun test() {
|
||||
class Test {
|
||||
operator fun minus(a: Int): Test = Test()
|
||||
}
|
||||
val test = Test()
|
||||
test - 1
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// PROBLEM: none
|
||||
// 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)
|
||||
}
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
// PROBLEM: none
|
||||
|
||||
fun test() {
|
||||
class Test {
|
||||
operator fun mod(a: Int): Test = Test()
|
||||
}
|
||||
val test = Test()
|
||||
test.<caret>mod(1)
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// PROBLEM: none
|
||||
// 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)
|
||||
}
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
// FIX: Replace with '!=' operator
|
||||
|
||||
val x = !2.eq<caret>uals(3)
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
// FIX: Replace with '!=' operator
|
||||
|
||||
val x = 2 != 3
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
// FIX: Replace with '!=' operator
|
||||
|
||||
val x = !(2.<caret>equals(3))
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
// FIX: Replace with '!=' operator
|
||||
|
||||
val x = 2 != 3
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
// FIX: Replace with '==' operator
|
||||
|
||||
val x = !(2.equ<caret>als(3) && 4.equals(5))
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
// FIX: Replace with '==' operator
|
||||
|
||||
val x = !(2 == 3 && 4.equals(5))
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
// FIX: Replace with '+' operator
|
||||
fun test() {
|
||||
class Test {
|
||||
operator fun plus(a: Int): Test = Test()
|
||||
}
|
||||
val test = Test()
|
||||
test.pl<caret>us(1)
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// FIX: Replace with '+' operator
|
||||
fun test() {
|
||||
class Test {
|
||||
operator fun plus(a: Int): Test = Test()
|
||||
}
|
||||
val test = Test()
|
||||
test + 1
|
||||
}
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
class C {
|
||||
companion object {
|
||||
operator fun plus(s: String): C = C()
|
||||
}
|
||||
}
|
||||
|
||||
fun foo() {
|
||||
C.<caret>plus("x")
|
||||
}
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
class C {
|
||||
companion object {
|
||||
operator fun plus(s: String): C = C()
|
||||
}
|
||||
}
|
||||
|
||||
fun foo() {
|
||||
C + "x"
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// FIX: Replace with '..' operator
|
||||
fun test() {
|
||||
class Test {
|
||||
operator fun rangeTo(a: Int): Test = Test()
|
||||
}
|
||||
val test = Test()
|
||||
test.range<caret>To(1)
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// FIX: Replace with '..' operator
|
||||
fun test() {
|
||||
class Test {
|
||||
operator fun rangeTo(a: Int): Test = Test()
|
||||
}
|
||||
val test = Test()
|
||||
test..1
|
||||
}
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
// FIX: Replace with '%' operator
|
||||
|
||||
fun test() {
|
||||
class Test {
|
||||
operator fun rem(a: Int): Test = Test()
|
||||
}
|
||||
val test = Test()
|
||||
test.<caret>rem(1)
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// FIX: Replace with '%' operator
|
||||
|
||||
fun test() {
|
||||
class Test {
|
||||
operator fun rem(a: Int): Test = Test()
|
||||
}
|
||||
val test = Test()
|
||||
test % 1
|
||||
}
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
// PROBLEM: none
|
||||
// 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
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// PROBLEM: none
|
||||
|
||||
open class Base {
|
||||
open operator fun plus(s: String) = ""
|
||||
}
|
||||
|
||||
class C : Base() {
|
||||
override fun plus(s: String): String {
|
||||
return super.<caret>plus(s)
|
||||
}
|
||||
}
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
// FIX: Replace with '*' operator
|
||||
fun test() {
|
||||
class Test {
|
||||
operator fun times(a: Int): Test = Test()
|
||||
}
|
||||
val test = Test()
|
||||
test.time<caret>s(1)
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// FIX: Replace with '*' operator
|
||||
fun test() {
|
||||
class Test {
|
||||
operator fun times(a: Int): Test = Test()
|
||||
}
|
||||
val test = Test()
|
||||
test * 1
|
||||
}
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
// PROBLEM: none
|
||||
fun test() {
|
||||
class Test {
|
||||
operator fun <T> div(a: Test): T? = a as? T
|
||||
}
|
||||
val test = Test()
|
||||
test.div<caret><Int>(Test())
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// PROBLEM: none
|
||||
// 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)
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// PROBLEM: none
|
||||
// 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)
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
fun test() {
|
||||
class Test {
|
||||
operator fun plus(a: Int): Test = Test()
|
||||
}
|
||||
val test = Test()
|
||||
test.pl<caret>us(a=1)
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
fun test() {
|
||||
class Test {
|
||||
operator fun plus(a: Int): Test = Test()
|
||||
}
|
||||
val test = Test()
|
||||
test + 1
|
||||
}
|
||||
Reference in New Issue
Block a user