Fix Math.min with coerceAtMost intention inside qualified expression
So #KT-19232 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
a82f66cf45
commit
5290553184
+4
-7
@@ -18,18 +18,15 @@ package org.jetbrains.kotlin.idea.intentions
|
||||
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import org.jetbrains.kotlin.idea.core.replaced
|
||||
import org.jetbrains.kotlin.psi.KtCallExpression
|
||||
import org.jetbrains.kotlin.psi.KtDotQualifiedExpression
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||
import org.jetbrains.kotlin.psi.createExpressionByPattern
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedExpressionForSelectorOrThis
|
||||
|
||||
abstract class ReplaceMathMethodsWithKotlinNativeMethodsIntention(
|
||||
text: String, val replacedMethodName: String, val mathMethodName: String
|
||||
text: String, private val replacedMethodName: String, private val mathMethodName: String
|
||||
) : SelfTargetingOffsetIndependentIntention<KtCallExpression>(KtCallExpression::class.java, text) {
|
||||
|
||||
override fun applyTo(element: KtCallExpression, editor: Editor?) {
|
||||
val target = element.getStrictParentOfType<KtDotQualifiedExpression>() ?: element
|
||||
val target = element.getQualifiedExpressionForSelectorOrThis()
|
||||
val valueArguments = element.valueArguments
|
||||
val methodName = replacedMethodName
|
||||
val newExpression = KtPsiFactory(element).createExpressionByPattern("$0.$methodName($1)",
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import java.lang.Math.max
|
||||
|
||||
fun foo() {
|
||||
Pair(<caret>max(1, 3), max(2, 4)).let { println(it) }
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import java.lang.Math.max
|
||||
|
||||
fun foo() {
|
||||
Pair(<caret>1.coerceAtLeast(3), max(2, 4)).let { println(it) }
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo() {
|
||||
Pair(Math.max(1, 3)<caret>, Math.max(2, 4)).let { println(it) }
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo() {
|
||||
Pair(1.coerceAtLeast(3)<caret>, Math.max(2, 4)).let { println(it) }
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// WITH_RUNTIME
|
||||
import java.lang.Math.max
|
||||
|
||||
fun foo() {
|
||||
Math.max(max(1, 3)<caret>, max(2, 4))
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// WITH_RUNTIME
|
||||
import java.lang.Math.max
|
||||
|
||||
fun foo() {
|
||||
Math.max(1.coerceAtLeast(3), max(2, 4))
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import java.lang.Math.min
|
||||
|
||||
fun foo() {
|
||||
Pair(<caret>min(1, 3), min(2, 4)).let { println(it) }
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import java.lang.Math.min
|
||||
|
||||
fun foo() {
|
||||
Pair(<caret>1.coerceAtMost(3), min(2, 4)).let { println(it) }
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo() {
|
||||
Pair(Math.min(1, 3)<caret>, Math.min(2, 4)).let { println(it) }
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo() {
|
||||
Pair(1.coerceAtMost(3)<caret>, Math.min(2, 4)).let { println(it) }
|
||||
}
|
||||
@@ -13454,6 +13454,24 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("KT-19232-1.kt")
|
||||
public void testKT_19232_1() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceMathMaxWithCoerceAtLeast/KT-19232-1.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("KT-19232-2.kt")
|
||||
public void testKT_19232_2() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceMathMaxWithCoerceAtLeast/KT-19232-2.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("maxInMax.kt")
|
||||
public void testMaxInMax() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceMathMaxWithCoerceAtLeast/maxInMax.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("moreThan2ValueArg.kt")
|
||||
public void testMoreThan2ValueArg() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceMathMaxWithCoerceAtLeast/moreThan2ValueArg.kt");
|
||||
@@ -13499,6 +13517,18 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("KT-19232-1.kt")
|
||||
public void testKT_19232_1() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceMathMinWithCoerceAtMost/KT-19232-1.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("KT-19232-2.kt")
|
||||
public void testKT_19232_2() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceMathMinWithCoerceAtMost/KT-19232-2.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("moreThan2ValueArg.kt")
|
||||
public void testMoreThan2ValueArg() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceMathMinWithCoerceAtMost/moreThan2ValueArg.kt");
|
||||
|
||||
Reference in New Issue
Block a user