diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/ReplaceJavaStaticMethodWithKotlinAnalogInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/ReplaceJavaStaticMethodWithKotlinAnalogInspection.kt index d0779f84758..f50c477ba29 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/ReplaceJavaStaticMethodWithKotlinAnalogInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/ReplaceJavaStaticMethodWithKotlinAnalogInspection.kt @@ -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"), diff --git a/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/binarySearch.kt b/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/binarySearch.kt new file mode 100644 index 00000000000..ef60cfd039a --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/binarySearch.kt @@ -0,0 +1,7 @@ +// WITH_RUNTIME +import java.util.Arrays + +fun test() { + val array = arrayOf(1, 2, 3) + val result = Arrays.binarySearch(array, 3) +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/binarySearch.kt.after b/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/binarySearch.kt.after new file mode 100644 index 00000000000..37c8e1e00fd --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/binarySearch.kt.after @@ -0,0 +1,7 @@ +// WITH_RUNTIME +import java.util.Arrays + +fun test() { + val array = arrayOf(1, 2, 3) + val result = array.binarySearch(3) +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/binarySearch2.kt b/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/binarySearch2.kt new file mode 100644 index 00000000000..84d6e7869af --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/binarySearch2.kt @@ -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.binarySearch(array, from, to, 3) +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/binarySearch2.kt.after b/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/binarySearch2.kt.after new file mode 100644 index 00000000000..5e0b380b26e --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/binarySearch2.kt.after @@ -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) +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/copyOfRange.kt b/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/copyOfRange.kt new file mode 100644 index 00000000000..91cf6a54c86 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/copyOfRange.kt @@ -0,0 +1,7 @@ +// WITH_RUNTIME +import java.util.Arrays + +fun test() { + val array = arrayOf(1, 2, 3) + val result = Arrays.copyOfRange(array, 3, 5) +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/copyOfRange.kt.after b/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/copyOfRange.kt.after new file mode 100644 index 00000000000..c9ace64ec40 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/copyOfRange.kt.after @@ -0,0 +1,7 @@ +// WITH_RUNTIME +import java.util.Arrays + +fun test() { + val array = arrayOf(1, 2, 3) + val result = array.copyOfRange(3, 5) +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/deepEquals.kt b/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/deepEquals.kt new file mode 100644 index 00000000000..3564c35aa3e --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/deepEquals.kt @@ -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.deepEquals(a, b) +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/deepEquals.kt.after b/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/deepEquals.kt.after new file mode 100644 index 00000000000..ac0cc113836 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/deepEquals.kt.after @@ -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) +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/deepHashCode.kt b/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/deepHashCode.kt new file mode 100644 index 00000000000..cfdf60203a3 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/deepHashCode.kt @@ -0,0 +1,7 @@ +// WITH_RUNTIME +import java.util.Arrays + +fun test() { + val a = arrayOf(1) + val hash = Arrays.deepHashCode(a) +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/deepHashCode.kt.after b/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/deepHashCode.kt.after new file mode 100644 index 00000000000..22edcc27814 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/deepHashCode.kt.after @@ -0,0 +1,7 @@ +// WITH_RUNTIME +import java.util.Arrays + +fun test() { + val a = arrayOf(1) + val hash = a.contentDeepHashCode() +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/deepToString.kt b/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/deepToString.kt new file mode 100644 index 00000000000..596dd271acc --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/deepToString.kt @@ -0,0 +1,7 @@ +// WITH_RUNTIME +import java.util.Arrays + +fun test() { + val a = arrayOf(1) + val hash = Arrays.deepToString(a) +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/deepToString.kt.after b/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/deepToString.kt.after new file mode 100644 index 00000000000..ac41db4a466 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/deepToString.kt.after @@ -0,0 +1,7 @@ +// WITH_RUNTIME +import java.util.Arrays + +fun test() { + val a = arrayOf(1) + val hash = a.contentDeepToString() +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/equals.kt b/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/equals.kt new file mode 100644 index 00000000000..f3ec9db7db6 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/equals.kt @@ -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.equals(a, b) +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/equals.kt.after b/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/equals.kt.after new file mode 100644 index 00000000000..e5daae8fc4d --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/equals.kt.after @@ -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) +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/hashCode.kt b/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/hashCode.kt new file mode 100644 index 00000000000..24ce17ba771 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/hashCode.kt @@ -0,0 +1,7 @@ +// WITH_RUNTIME +import java.util.Arrays + +fun test() { + val a = arrayOf(1) + val hash = Arrays.hashCode(a) +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/hashCode.kt.after b/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/hashCode.kt.after new file mode 100644 index 00000000000..c6d0d46945b --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/hashCode.kt.after @@ -0,0 +1,7 @@ +// WITH_RUNTIME +import java.util.Arrays + +fun test() { + val a = arrayOf(1) + val hash = a.contentHashCode() +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/toString.kt b/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/toString.kt new file mode 100644 index 00000000000..c4847718431 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/toString.kt @@ -0,0 +1,7 @@ +// WITH_RUNTIME +import java.util.Arrays + +fun test() { + val a = arrayOf(1) + val hash = Arrays.toString(a) +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/toString.kt.after b/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/toString.kt.after new file mode 100644 index 00000000000..60d0b232ad4 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/collections/toString.kt.after @@ -0,0 +1,7 @@ +// WITH_RUNTIME +import java.util.Arrays + +fun test() { + val a = arrayOf(1) + val hash = a.contentToString() +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/system/arraycopy.kt b/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/system/arraycopy.kt new file mode 100644 index 00000000000..72e255cabae --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/system/arraycopy.kt @@ -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.arraycopy(a, aOffset, b, bOffset, len) +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/system/arraycopy.kt.after b/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/system/arraycopy.kt.after new file mode 100644 index 00000000000..c888c46c89f --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceJavaStaticMethodWithKotlinAnalog/system/arraycopy.kt.after @@ -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) +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java index eb6dc3f0706..9988a93124d 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -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");