Add inspection to replace Java Map.forEach with Kotlin's forEach
#KT-17278 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
9c674cb7c3
commit
1a818970c3
@@ -0,0 +1,10 @@
|
||||
import java.util.HashMap;
|
||||
|
||||
class Test {
|
||||
void test(HashMap<String, String> map) {
|
||||
map.forEach((key, value) -> foo(key, value));
|
||||
}
|
||||
|
||||
void foo(String key, String value) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import java.util.HashMap
|
||||
|
||||
internal class Test {
|
||||
fun test(map: HashMap<String, String>) {
|
||||
map.forEach { (key, value) -> foo(key, value) }
|
||||
}
|
||||
|
||||
fun foo(key: String, value: String) {}
|
||||
}
|
||||
@@ -139,8 +139,13 @@ abstract class AbstractJavaToKotlinConverterSingleFileTest : AbstractJavaToKotli
|
||||
.trim()
|
||||
}
|
||||
|
||||
override fun getProjectDescriptor()
|
||||
= KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE
|
||||
override fun getProjectDescriptor(): KotlinWithJdkAndRuntimeLightProjectDescriptor {
|
||||
val testName = getTestName(false)
|
||||
return if (testName.contains("WithFullJdk") || testName.contains("withFullJdk"))
|
||||
KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE_FULL_JDK
|
||||
else
|
||||
KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE
|
||||
}
|
||||
|
||||
private fun String.removeFirstLine() = substringAfter('\n', "")
|
||||
|
||||
|
||||
+5
@@ -3794,6 +3794,11 @@ public class JavaToKotlinConverterForWebDemoTestGenerated extends AbstractJavaTo
|
||||
runTest("j2k/testData/fileOrElement/postProcessing/IfToSafeCall.java");
|
||||
}
|
||||
|
||||
@TestMetadata("java8MapForEachWithFullJdk.java")
|
||||
public void testJava8MapForEachWithFullJdk() throws Exception {
|
||||
runTest("j2k/testData/fileOrElement/postProcessing/java8MapForEachWithFullJdk.java");
|
||||
}
|
||||
|
||||
@TestMetadata("NotIs.java")
|
||||
public void testNotIs() throws Exception {
|
||||
runTest("j2k/testData/fileOrElement/postProcessing/NotIs.java");
|
||||
|
||||
+5
@@ -3794,6 +3794,11 @@ public class JavaToKotlinConverterSingleFileTestGenerated extends AbstractJavaTo
|
||||
runTest("j2k/testData/fileOrElement/postProcessing/IfToSafeCall.java");
|
||||
}
|
||||
|
||||
@TestMetadata("java8MapForEachWithFullJdk.java")
|
||||
public void testJava8MapForEachWithFullJdk() throws Exception {
|
||||
runTest("j2k/testData/fileOrElement/postProcessing/java8MapForEachWithFullJdk.java");
|
||||
}
|
||||
|
||||
@TestMetadata("NotIs.java")
|
||||
public void testNotIs() throws Exception {
|
||||
runTest("j2k/testData/fileOrElement/postProcessing/NotIs.java");
|
||||
|
||||
Reference in New Issue
Block a user