ReplaceJavaStaticMethodWithKotlinAnalogInspection: don't report for Character.toString(int)
#KT-34859 Fixed
This commit is contained in:
committed by
Yan Zhulanow
parent
b008e6c9be
commit
ef5335ba99
+6
-1
@@ -21,7 +21,9 @@ import org.jetbrains.kotlin.psi.KtSimpleNameExpression
|
||||
import org.jetbrains.kotlin.psi.callExpressionVisitor
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getReceiverExpression
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getType
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.types.typeUtil.isChar
|
||||
|
||||
class ReplaceJavaStaticMethodWithKotlinAnalogInspection : AbstractKotlinInspection() {
|
||||
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean) = callExpressionVisitor(fun(call) {
|
||||
@@ -81,7 +83,10 @@ class ReplaceJavaStaticMethodWithKotlinAnalogInspection : AbstractKotlinInspecti
|
||||
"kotlin.primitives.$kotlinPrimitive.toString",
|
||||
ToExtensionFunctionWithNullableReceiver
|
||||
) {
|
||||
it.valueArguments.size == 1
|
||||
val valueArguments = it.valueArguments
|
||||
if (valueArguments.size != 1) return@Replacement false
|
||||
javaPrimitive != "Character" ||
|
||||
valueArguments.first().getArgumentExpression()?.getType(it.analyze(BodyResolveMode.PARTIAL))?.isChar() == true
|
||||
},
|
||||
Replacement(
|
||||
"java.lang.$javaPrimitive.compare",
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// PROBLEM: none
|
||||
// DISABLE-ERRORS
|
||||
fun foo() {
|
||||
val codePoint = "1D41E".toInt(16)
|
||||
val t = java.lang.Character.<caret>toString(codePoint)
|
||||
}
|
||||
+5
@@ -11275,6 +11275,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
||||
runTest("idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/toString/charToString.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("charToStringWithInt.kt")
|
||||
public void testCharToStringWithInt() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/toString/charToStringWithInt.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("doubleToString.kt")
|
||||
public void testDoubleToString() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/toString/doubleToString.kt");
|
||||
|
||||
Reference in New Issue
Block a user