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:
+3
-1
@@ -65,7 +65,9 @@ class ReplaceJavaStaticMethodWithKotlinAnalogInspection : AbstractKotlinInspecti
|
|||||||
val valueArguments = call.valueArguments
|
val valueArguments = call.valueArguments
|
||||||
val typeArguments = call.typeArgumentList?.text ?: ""
|
val typeArguments = call.typeArgumentList?.text ?: ""
|
||||||
if (replacement.toExtensionFunction) {
|
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 }
|
val argumentsText = valueArguments.drop(1).joinToString(separator = ", ") { it.text }
|
||||||
dotQualified.replaced(psiFactory.createExpression("$receiverText.${replacement.kotlinFunctionShortName}$typeArguments($argumentsText)"))
|
dotQualified.replaced(psiFactory.createExpression("$receiverText.${replacement.kotlinFunctionShortName}$typeArguments($argumentsText)"))
|
||||||
file.resolveImportReference(FqName(replacement.kotlinFunctionFqName)).firstOrNull()?.let {
|
file.resolveImportReference(FqName(replacement.kotlinFunctionFqName)).firstOrNull()?.let {
|
||||||
|
|||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
Integer<caret>.toString(42 + 24, 16)
|
||||||
|
}
|
||||||
idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/toString/toExtension.kt.after
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
(42 + 24).toString(16)
|
||||||
|
}
|
||||||
+5
@@ -7661,6 +7661,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
|||||||
public void testShortToString() throws Exception {
|
public void testShortToString() throws Exception {
|
||||||
runTest("idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/toString/shortToString.kt");
|
runTest("idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/toString/shortToString.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("toExtension.kt")
|
||||||
|
public void testToExtension() throws Exception {
|
||||||
|
runTest("idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/toString/toExtension.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user