Fix incorrect quickfix "Replace with Kotlin analog" for conversion to an extension

where the first argument is an expression with an operation
 #KT-31341 Fixed
This commit is contained in:
Dmitry Gridin
2019-05-07 16:08:15 +07:00
parent b4a63794e5
commit 07e908f15f
4 changed files with 18 additions and 1 deletions
@@ -65,7 +65,9 @@ class ReplaceJavaStaticMethodWithKotlinAnalogInspection : AbstractKotlinInspecti
val valueArguments = call.valueArguments
val typeArguments = call.typeArgumentList?.text ?: ""
if (replacement.toExtensionFunction) {
val receiverText = valueArguments.first().text
val receiverText = valueArguments.first().getArgumentExpression()
?.run { if (this is KtOperationExpression) "($text)" else text }
?: valueArguments.first().text
val argumentsText = valueArguments.drop(1).joinToString(separator = ", ") { it.text }
dotQualified.replaced(psiFactory.createExpression("$receiverText.${replacement.kotlinFunctionShortName}$typeArguments($argumentsText)"))
file.resolveImportReference(FqName(replacement.kotlinFunctionFqName)).firstOrNull()?.let {
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun foo() {
Integer<caret>.toString(42 + 24, 16)
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun foo() {
(42 + 24).toString(16)
}
@@ -7661,6 +7661,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
public void testShortToString() throws Exception {
runTest("idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/toString/shortToString.kt");
}
@TestMetadata("toExtension.kt")
public void testToExtension() throws Exception {
runTest("idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/toString/toExtension.kt");
}
}
}