ReplaceJavaStaticMethodWithKotlinAnalogInspection: add more cases for Arrays
#KT-32512 Fixed #KT-30124 Fixed
This commit is contained in:
+17
-1
@@ -127,7 +127,8 @@ class ReplaceJavaStaticMethodWithKotlinAnalogInspection : AbstractKotlinInspecti
|
||||
)
|
||||
|
||||
private val JAVA_SYSTEM = listOf(
|
||||
Replacement("java.lang.System.exit", "kotlin.system.exitProcess")
|
||||
Replacement("java.lang.System.exit", "kotlin.system.exitProcess"),
|
||||
Replacement("java.lang.System.arraycopy", "kotlin.collections.copyInto", toExtensionFunction = true) // TODO: mapping
|
||||
)
|
||||
|
||||
private val JAVA_MATH = listOf(
|
||||
@@ -171,6 +172,21 @@ class ReplaceJavaStaticMethodWithKotlinAnalogInspection : AbstractKotlinInspecti
|
||||
Replacement("java.util.Arrays.copyOf", "kotlin.collections.copyOf", toExtensionFunction = true) {
|
||||
it.valueArguments.size == 2
|
||||
},
|
||||
Replacement("java.util.Arrays.copyOfRange", "kotlin.collections.copyOfRange", toExtensionFunction = true),
|
||||
Replacement("java.util.Arrays.binarySearch", "kotlin.collections.binarySearch", toExtensionFunction = true), // TODO: mapping
|
||||
Replacement("java.util.Arrays.equals", "kotlin.collections.contentEquals", toExtensionFunction = true),
|
||||
Replacement("java.util.Arrays.deepEquals", "kotlin.collections.contentDeepEquals", toExtensionFunction = true),
|
||||
Replacement("java.util.Arrays.fill", "kotlin.collections.fill", toExtensionFunction = true), // TODO: mapping
|
||||
Replacement("java.util.Arrays.sort", "kotlin.collections.sort", toExtensionFunction = true) {
|
||||
it.valueArguments.size == 3
|
||||
}, //TODO: mapping?
|
||||
Replacement("java.util.Arrays.sort", "kotlin.collections.sortWith", toExtensionFunction = true) {
|
||||
it.valueArguments.size != 3
|
||||
},
|
||||
Replacement("java.util.Arrays.deepHashCode", "kotlin.collections.contentDeepHashCode", toExtensionFunction = true),
|
||||
Replacement("java.util.Arrays.hashCode", "kotlin.collections.contentHashCode", toExtensionFunction = true),
|
||||
Replacement("java.util.Arrays.deepToString", "kotlin.collections.contentDeepToString", toExtensionFunction = true),
|
||||
Replacement("java.util.Arrays.toString", "kotlin.collections.contentToString", toExtensionFunction = true),
|
||||
Replacement("java.util.Arrays.asList", "kotlin.collections.listOf"),
|
||||
Replacement("java.util.Arrays.asList", "kotlin.collections.mutableListOf"),
|
||||
Replacement("java.util.Set.of", "kotlin.collections.setOf"),
|
||||
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
import java.util.Arrays
|
||||
|
||||
fun test() {
|
||||
val array = arrayOf(1, 2, 3)
|
||||
val result = Arrays.<caret>binarySearch(array, 3)
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
import java.util.Arrays
|
||||
|
||||
fun test() {
|
||||
val array = arrayOf(1, 2, 3)
|
||||
val result = array.binarySearch(3)
|
||||
}
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
// WITH_RUNTIME
|
||||
import java.util.Arrays
|
||||
|
||||
fun test() {
|
||||
val array = arrayOf(1, 2, 3)
|
||||
val from = 1
|
||||
val to = 4
|
||||
val result = Arrays.<caret>binarySearch(array, from, to, 3)
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// WITH_RUNTIME
|
||||
import java.util.Arrays
|
||||
|
||||
fun test() {
|
||||
val array = arrayOf(1, 2, 3)
|
||||
val key = 3
|
||||
val from = 1
|
||||
val to = 4
|
||||
val result = array.binarySearch(key, from, to)
|
||||
}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
import java.util.Arrays
|
||||
|
||||
fun test() {
|
||||
val array = arrayOf(1, 2, 3)
|
||||
val result = Arrays.<caret>copyOfRange(array, 3, 5)
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
import java.util.Arrays
|
||||
|
||||
fun test() {
|
||||
val array = arrayOf(1, 2, 3)
|
||||
val result = array.copyOfRange(3, 5)
|
||||
}
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
// WITH_RUNTIME
|
||||
import java.util.Arrays
|
||||
|
||||
fun test() {
|
||||
val a = arrayOf(1, 2, 3)
|
||||
val b = arrayOf(1, 2, 3)
|
||||
val result = Arrays.<caret>deepEquals(a, b)
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// WITH_RUNTIME
|
||||
import java.util.Arrays
|
||||
|
||||
fun test() {
|
||||
val a = arrayOf(1, 2, 3)
|
||||
val b = arrayOf(1, 2, 3)
|
||||
val result = a.contentDeepEquals(b)
|
||||
}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
import java.util.Arrays
|
||||
|
||||
fun test() {
|
||||
val a = arrayOf(1)
|
||||
val hash = Arrays.<caret>deepHashCode(a)
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
import java.util.Arrays
|
||||
|
||||
fun test() {
|
||||
val a = arrayOf(1)
|
||||
val hash = a.contentDeepHashCode()
|
||||
}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
import java.util.Arrays
|
||||
|
||||
fun test() {
|
||||
val a = arrayOf(1)
|
||||
val hash = Arrays.<caret>deepToString(a)
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
import java.util.Arrays
|
||||
|
||||
fun test() {
|
||||
val a = arrayOf(1)
|
||||
val hash = a.contentDeepToString()
|
||||
}
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
// WITH_RUNTIME
|
||||
import java.util.Arrays
|
||||
|
||||
fun test() {
|
||||
val a = arrayOf(1, 2, 3)
|
||||
val b = arrayOf(1, 2, 3)
|
||||
val result = Arrays.<caret>equals(a, b)
|
||||
}
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
// WITH_RUNTIME
|
||||
import java.util.Arrays
|
||||
|
||||
fun test() {
|
||||
val a = arrayOf(1, 2, 3)
|
||||
val b = arrayOf(1, 2, 3)
|
||||
val result = a.contentEquals(b)
|
||||
}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
import java.util.Arrays
|
||||
|
||||
fun test() {
|
||||
val a = arrayOf(1)
|
||||
val hash = Arrays.<caret>hashCode(a)
|
||||
}
|
||||
idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/hashCode.kt.after
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
import java.util.Arrays
|
||||
|
||||
fun test() {
|
||||
val a = arrayOf(1)
|
||||
val hash = a.contentHashCode()
|
||||
}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
import java.util.Arrays
|
||||
|
||||
fun test() {
|
||||
val a = arrayOf(1)
|
||||
val hash = Arrays.<caret>toString(a)
|
||||
}
|
||||
idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/toString.kt.after
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
import java.util.Arrays
|
||||
|
||||
fun test() {
|
||||
val a = arrayOf(1)
|
||||
val hash = a.contentToString()
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// WITH_RUNTIME
|
||||
fun test() {
|
||||
val a = arrayOf(2)
|
||||
val b = arrayOf(4)
|
||||
val aOffset = 1
|
||||
val bOffset = 2
|
||||
val len = 5
|
||||
java.lang.System.<caret>arraycopy(a, aOffset, b, bOffset, len)
|
||||
}
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
// WITH_RUNTIME
|
||||
fun test() {
|
||||
val a = arrayOf(2)
|
||||
val b = arrayOf(4)
|
||||
val aOffset = 1
|
||||
val bOffset = 2
|
||||
val len = 5
|
||||
a.copyInto(b, bOffset, aOffset, len + aOffset)
|
||||
}
|
||||
+50
@@ -9061,11 +9061,51 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
||||
runTest("idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/asList.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("binarySearch.kt")
|
||||
public void testBinarySearch() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/binarySearch.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("binarySearch2.kt")
|
||||
public void testBinarySearch2() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/binarySearch2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("copyOf.kt")
|
||||
public void testCopyOf() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/copyOf.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("copyOfRange.kt")
|
||||
public void testCopyOfRange() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/copyOfRange.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("deepEquals.kt")
|
||||
public void testDeepEquals() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/deepEquals.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("deepHashCode.kt")
|
||||
public void testDeepHashCode() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/deepHashCode.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("deepToString.kt")
|
||||
public void testDeepToString() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/deepToString.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("equals.kt")
|
||||
public void testEquals() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/equals.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("hashCode.kt")
|
||||
public void testHashCode() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/hashCode.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("mutableListOf.kt")
|
||||
public void testMutableListOf() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/mutableListOf.kt");
|
||||
@@ -9100,6 +9140,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
||||
public void testSetOf2() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/setOf2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("toString.kt")
|
||||
public void testToString() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/toString.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/compare")
|
||||
@@ -9383,6 +9428,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/system"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("arraycopy.kt")
|
||||
public void testArraycopy() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/system/arraycopy.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("exit.kt")
|
||||
public void testExit() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/system/exit.kt");
|
||||
|
||||
Reference in New Issue
Block a user