Add intention to replace Math.max/min with coerceAtLeast/coerceAtMost #KT-13945 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
4522d2c7da
commit
3aedf0d79f
@@ -0,0 +1 @@
|
||||
org.jetbrains.kotlin.idea.intentions.ReplaceMathMaxWithCoerceAtLeastIntention
|
||||
@@ -0,0 +1,10 @@
|
||||
// WITH_RUNTIME
|
||||
// IS_APPLICABLE: false
|
||||
|
||||
fun foo() {
|
||||
Math.max(1, 2)<caret>
|
||||
}
|
||||
|
||||
object Math {
|
||||
fun max(a: Int, b: Int) = 0
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import java.lang.Math.max
|
||||
|
||||
fun foo() {
|
||||
max(1.1, 1.2)<caret>
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import java.lang.Math.max
|
||||
|
||||
fun foo() {
|
||||
1.1.coerceAtLeast(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 max(p0: Double, p1: Double): Double defined in java.lang.Math<br>public open fun max(p0: Float, p1: Float): Float defined in java.lang.Math<br>public open fun max(p0: Int, p1: Int): Int defined in java.lang.Math<br>public open fun max(p0: Long, p1: Long): Long defined in java.lang.Math
|
||||
|
||||
import java.lang.Math.max
|
||||
|
||||
fun foo() {
|
||||
max(1.1, 1.2, 1.3)<caret>
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo() {
|
||||
Math.max(2, 1)<caret>
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo() {
|
||||
2.coerceAtLeast(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 max(p0: Double, p1: Double): Double defined in java.lang.Math<br>public open fun max(p0: Float, p1: Float): Float defined in java.lang.Math<br>public open fun max(p0: Int, p1: Int): Int defined in java.lang.Math<br>public open fun max(p0: Long, p1: Long): Long defined in java.lang.Math
|
||||
|
||||
import java.lang.Math.max
|
||||
|
||||
fun foo() {
|
||||
max(1.1)<caret>
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import java.lang.Math.max
|
||||
|
||||
fun foo() {
|
||||
max(1, 2)<caret>
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import java.lang.Math.max
|
||||
|
||||
fun foo() {
|
||||
1.coerceAtLeast(2)
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user