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
@@ -4,31 +4,47 @@
<line>2</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Can be replaced with comparison</problem_class>
<description>Replace with '==' operator</description>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Can be replaced with binary operator</problem_class>
<description>Call replaceable with binary operator</description>
</problem>
<problem>
<file>test.kt</file>
<line>3</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Can be replaced with comparison</problem_class>
<description>Replace with '!=' operator</description>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Can be replaced with binary operator</problem_class>
<description>Call replaceable with binary operator</description>
</problem>
<problem>
<file>test.kt</file>
<line>6</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Can be replaced with comparison</problem_class>
<description>Replace with '&gt;' operator</description>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Can be replaced with binary operator</problem_class>
<description>Call replaceable with binary operator</description>
</problem>
<problem>
<file>test.kt</file>
<line>7</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Can be replaced with comparison</problem_class>
<description>Replace with '&lt;=' operator</description>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Can be replaced with binary operator</problem_class>
<description>Call replaceable with binary operator</description>
</problem>
<problem>
<file>test.kt</file>
<line>8</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Can be replaced with binary operator</problem_class>
<description>Call replaceable with binary operator</description>
</problem>
<problem>
<file>test.kt</file>
<line>9</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Can be replaced with binary operator</problem_class>
<description>Call replaceable with binary operator</description>
</problem>
</problems>
@@ -1 +1 @@
// INSPECTION_CLASS: org.jetbrains.kotlin.idea.intentions.conventionNameCalls.ReplaceCallWithComparisonInspection
// INSPECTION_CLASS: org.jetbrains.kotlin.idea.inspections.conventionNameCalls.ReplaceCallWithBinaryOperatorInspection
@@ -5,6 +5,6 @@ fun foo() {
1.compareTo(1) == 0 // NO
2.compareTo(1) > 0 // YES
0 >= 1.compareTo(2) // YES
2.plus(2) // NO
2.times(2) // NO
2.plus(2) // YES (information)
2.times(2) // YES (information)
}
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.inspections.conventionNameCalls.ReplaceCallWithBinaryOperatorInspection
@@ -1,8 +1,8 @@
// INTENTION_TEXT: Replace with '/' operator
// FIX: Replace with '/' operator
fun test() {
class Test {
operator fun div(a: Int): Test = Test()
}
val test = Test()
test.div<caret>(1)
test.<caret>div(1)
}
@@ -1,4 +1,4 @@
// INTENTION_TEXT: Replace with '/' operator
// FIX: Replace with '/' operator
fun test() {
class Test {
operator fun div(a: Int): Test = Test()
@@ -0,0 +1,3 @@
// FIX: Replace with '==' operator
val x = 2.<caret>equals(2)
@@ -0,0 +1,3 @@
// FIX: Replace with '==' operator
val x = 2 == 2
@@ -2,5 +2,5 @@ fun test() {
class Test()
operator fun Test.div(a: Int): Test = Test()
val test = Test()
test.div<caret>(1)
test.<caret>div(1)
}
@@ -0,0 +1,3 @@
// FIX: Replace with '>' operator
val x = 3.compare<caret>To(2) > 0
@@ -0,0 +1,3 @@
// FIX: Replace with '>' operator
val x = 3 > 2
@@ -0,0 +1,3 @@
// FIX: Replace with '<=' operator
val x = 0 >= 4.compare<caret>To(5)
@@ -0,0 +1,3 @@
// FIX: Replace with '<=' operator
val x = 4 <= 5
@@ -1,4 +1,4 @@
// INTENTION_TEXT: Replace with '-' operator
// FIX: Replace with '-' operator
fun test() {
class Test {
operator fun minus(a: Int): Test = Test()
@@ -1,4 +1,4 @@
// INTENTION_TEXT: Replace with '-' operator
// FIX: Replace with '-' operator
fun test() {
class Test {
operator fun minus(a: Int): Test = Test()
@@ -1,4 +1,4 @@
// IS_APPLICABLE: false
// PROBLEM: none
// ERROR: 'operator' modifier is inapplicable on this function: must have a single value parameter
fun test() {
class Test{
@@ -1,10 +1,9 @@
// INTENTION_TEXT: Replace with '%' operator
// IS_APPLICABLE: false
// PROBLEM: none
fun test() {
class Test {
operator fun mod(a: Int): Test = Test()
}
val test = Test()
test % 1
test.<caret>mod(1)
}
@@ -1,4 +1,4 @@
// IS_APPLICABLE: false
// PROBLEM: none
// ERROR: 'operator' modifier is inapplicable on this function: must have a single value parameter
fun test() {
class Test {
@@ -0,0 +1,3 @@
// FIX: Replace with '!=' operator
val x = !2.eq<caret>uals(3)
@@ -0,0 +1,3 @@
// FIX: Replace with '!=' operator
val x = 2 != 3
@@ -0,0 +1,3 @@
// FIX: Replace with '!=' operator
val x = !(2.<caret>equals(3))
@@ -0,0 +1,3 @@
// FIX: Replace with '!=' operator
val x = 2 != 3
@@ -0,0 +1,3 @@
// FIX: Replace with '==' operator
val x = !(2.equ<caret>als(3) && 4.equals(5))
@@ -0,0 +1,3 @@
// FIX: Replace with '==' operator
val x = !(2 == 3 && 4.equals(5))
@@ -1,4 +1,4 @@
// INTENTION_TEXT: Replace with '+' operator
// FIX: Replace with '+' operator
fun test() {
class Test {
operator fun plus(a: Int): Test = Test()
@@ -1,4 +1,4 @@
// INTENTION_TEXT: Replace with '+' operator
// FIX: Replace with '+' operator
fun test() {
class Test {
operator fun plus(a: Int): Test = Test()
@@ -1,8 +1,8 @@
// INTENTION_TEXT: Replace with '..' operator
// FIX: Replace with '..' operator
fun test() {
class Test {
operator fun rangeTo(a: Int): Test = Test()
}
val test = Test()
test.rangeTo<caret>(1)
test.range<caret>To(1)
}
@@ -1,4 +1,4 @@
// INTENTION_TEXT: Replace with '..' operator
// FIX: Replace with '..' operator
fun test() {
class Test {
operator fun rangeTo(a: Int): Test = Test()
@@ -1,9 +1,9 @@
// INTENTION_TEXT: Replace with '%' operator
// FIX: Replace with '%' operator
fun test() {
class Test {
operator fun rem(a: Int): Test = Test()
}
val test = Test()
test.rem<caret>(1)
test.<caret>rem(1)
}
@@ -1,4 +1,4 @@
// INTENTION_TEXT: Replace with '%' operator
// FIX: Replace with '%' operator
fun test() {
class Test {
@@ -1,4 +1,4 @@
// IS_APPLICABLE: false
// 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
@@ -1,4 +1,4 @@
// IS_APPLICABLE: false
// PROBLEM: none
open class Base {
open operator fun plus(s: String) = ""
@@ -1,4 +1,4 @@
// INTENTION_TEXT: Replace with '*' operator
// FIX: Replace with '*' operator
fun test() {
class Test {
operator fun times(a: Int): Test = Test()
@@ -1,4 +1,4 @@
// INTENTION_TEXT: Replace with '*' operator
// FIX: Replace with '*' operator
fun test() {
class Test {
operator fun times(a: Int): Test = Test()
@@ -1,4 +1,4 @@
// IS_APPLICABLE: false
// PROBLEM: none
fun test() {
class Test {
operator fun <T> div(a: Test): T? = a as? T
@@ -1,4 +1,4 @@
// IS_APPLICABLE: false
// PROBLEM: none
// ERROR: 'operator' modifier is inapplicable on this function: must have a single value parameter
fun test() {
class Test{
@@ -1,4 +1,4 @@
// IS_APPLICABLE: false
// PROBLEM: none
// ERROR: 'operator' modifier is inapplicable on this function: must have a single value parameter
fun test() {
class Test{
@@ -1 +0,0 @@
org.jetbrains.kotlin.idea.intentions.conventionNameCalls.ReplaceCallWithBinaryOperatorIntention
@@ -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 @@
// 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,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,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))