Add inspection to replace Java Map.forEach with Kotlin's forEach

#KT-17278 Fixed
This commit is contained in:
Toshiaki Kameyama
2019-02-01 06:37:54 +03:00
committed by Mikhail Glukhikh
parent 9c674cb7c3
commit 1a818970c3
19 changed files with 214 additions and 2 deletions
@@ -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', "")
@@ -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");
@@ -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");