Add intention to replace Math.max/min with coerceAtLeast/coerceAtMost #KT-13945 Fixed

This commit is contained in:
shiraji
2016-09-23 13:33:58 +09:00
committed by Mikhail Glukhikh
parent 4522d2c7da
commit 3aedf0d79f
33 changed files with 339 additions and 6 deletions
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.intentions.ReplaceMathMinWithCoerceAtMostIntention
@@ -0,0 +1,10 @@
// WITH_RUNTIME
// IS_APPLICABLE: false
fun foo() {
Math.min(1, 2)<caret>
}
object Math {
fun min(a: Int, b: Int) = 0
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
import java.lang.Math.min
fun foo() {
min(1.1, 1.2)<caret>
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
import java.lang.Math.min
fun foo() {
1.1.coerceAtMost(1.2)
}
@@ -0,0 +1,9 @@
// WITH_RUNTIME
// IS_APPLICABLE: false
// ERROR: None of the following functions can be called with the arguments supplied: <br>public open fun min(p0: Double, p1: Double): Double defined in java.lang.Math<br>public open fun min(p0: Float, p1: Float): Float defined in java.lang.Math<br>public open fun min(p0: Int, p1: Int): Int defined in java.lang.Math<br>public open fun min(p0: Long, p1: Long): Long defined in java.lang.Math
import java.lang.Math.min
fun foo() {
min(1.1, 1.2, 1.3)<caret>
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun foo() {
Math.min(2, 1)<caret>
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun foo() {
2.coerceAtMost(1)
}
@@ -0,0 +1,9 @@
// WITH_RUNTIME
// IS_APPLICABLE: false
// ERROR: None of the following functions can be called with the arguments supplied: <br>public open fun min(p0: Double, p1: Double): Double defined in java.lang.Math<br>public open fun min(p0: Float, p1: Float): Float defined in java.lang.Math<br>public open fun min(p0: Int, p1: Int): Int defined in java.lang.Math<br>public open fun min(p0: Long, p1: Long): Long defined in java.lang.Math
import java.lang.Math.min
fun foo() {
min(1.1)<caret>
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
import java.lang.Math.min
fun foo() {
min(1, 2)<caret>
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
import java.lang.Math.min
fun foo() {
1.coerceAtMost(2)
}