Add intention to replace "Map.getOrDefault"

#KT-21503 Fixed
This commit is contained in:
Toshiaki Kameyama
2019-08-02 12:29:54 +09:00
committed by Ilya Kirillov
parent e09ae645b3
commit f5c0a30c51
16 changed files with 146 additions and 1 deletions
@@ -220,7 +220,8 @@ private val inspectionLikePostProcessingGroup =
generalInspectionBasedProcessing(LiftReturnOrAssignmentInspection(skipLongExpressions = false)),
intentionBasedProcessing(RemoveEmptyPrimaryConstructorIntention()),
generalInspectionBasedProcessing(MayBeConstantInspection()),
RemoveForExpressionLoopParameterTypeProcessing()
RemoveForExpressionLoopParameterTypeProcessing(),
intentionBasedProcessing(ReplaceMapGetOrDefaultIntention())
)
@@ -0,0 +1,8 @@
// RUNTIME_WITH_FULL_JDK
import java.util.Map;
class C {
String foo(Map<Integer, String> map) {
return map.getOrDefault(1, "bar");
}
}
@@ -0,0 +1,5 @@
internal class C {
fun foo(map: Map<Int, String>): String {
return map[1] ?: "bar"
}
}
@@ -4102,6 +4102,11 @@ public class NewJavaToKotlinConverterSingleFileTestGenerated extends AbstractNew
runTest("nj2k/testData/newJ2k/postProcessing/java8MapForEachWithFullJdk.java");
}
@TestMetadata("MapGetOrDefault.java")
public void testMapGetOrDefault() throws Exception {
runTest("nj2k/testData/newJ2k/postProcessing/MapGetOrDefault.java");
}
@TestMetadata("NotIs.java")
public void testNotIs() throws Exception {
runTest("nj2k/testData/newJ2k/postProcessing/NotIs.java");