diff --git a/idea/resources/intentionDescriptions/ReplaceSubstringWithIndexingOperationIntention/after.kt.template b/idea/resources/intentionDescriptions/ReplaceSubstringWithIndexingOperationIntention/after.kt.template new file mode 100644 index 00000000000..22c48684a98 --- /dev/null +++ b/idea/resources/intentionDescriptions/ReplaceSubstringWithIndexingOperationIntention/after.kt.template @@ -0,0 +1 @@ +"abc"[0] \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/ReplaceSubstringWithIndexingOperationIntention/before.kt.template b/idea/resources/intentionDescriptions/ReplaceSubstringWithIndexingOperationIntention/before.kt.template new file mode 100644 index 00000000000..105aae985f4 --- /dev/null +++ b/idea/resources/intentionDescriptions/ReplaceSubstringWithIndexingOperationIntention/before.kt.template @@ -0,0 +1 @@ +"abc".substring(0, 1) \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/ReplaceSubstringWithIndexingOperationIntention/description.html b/idea/resources/intentionDescriptions/ReplaceSubstringWithIndexingOperationIntention/description.html new file mode 100644 index 00000000000..81eb501db45 --- /dev/null +++ b/idea/resources/intentionDescriptions/ReplaceSubstringWithIndexingOperationIntention/description.html @@ -0,0 +1,5 @@ + + +This intention replaces call like "abc".substring(0, 1) with "abc"[0] call. + + \ No newline at end of file diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index 1e2daceba9e..a21f6452d3a 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -1526,6 +1526,11 @@ Kotlin + + org.jetbrains.kotlin.idea.intentions.ReplaceSubstringWithIndexingOperationIntention + Kotlin + + (1, 2) +} \ No newline at end of file diff --git a/idea/testData/intentions/replaceSubstringWithIndexingOperation/oneFirstTwoSecondArgument.kt.after b/idea/testData/intentions/replaceSubstringWithIndexingOperation/oneFirstTwoSecondArgument.kt.after new file mode 100644 index 00000000000..0e14f2d452c --- /dev/null +++ b/idea/testData/intentions/replaceSubstringWithIndexingOperation/oneFirstTwoSecondArgument.kt.after @@ -0,0 +1,5 @@ +// WITH_RUNTIME + +fun foo() { + "abc"[1] +} \ No newline at end of file diff --git a/idea/testData/intentions/replaceSubstringWithIndexingOperation/simple.kt b/idea/testData/intentions/replaceSubstringWithIndexingOperation/simple.kt new file mode 100644 index 00000000000..1edde927a12 --- /dev/null +++ b/idea/testData/intentions/replaceSubstringWithIndexingOperation/simple.kt @@ -0,0 +1,5 @@ +// WITH_RUNTIME + +fun foo() { + "abc".substring(0, 1) +} \ No newline at end of file diff --git a/idea/testData/intentions/replaceSubstringWithIndexingOperation/simple.kt.after b/idea/testData/intentions/replaceSubstringWithIndexingOperation/simple.kt.after new file mode 100644 index 00000000000..4257c1f9b5a --- /dev/null +++ b/idea/testData/intentions/replaceSubstringWithIndexingOperation/simple.kt.after @@ -0,0 +1,5 @@ +// WITH_RUNTIME + +fun foo() { + "abc"[0] +} \ No newline at end of file diff --git a/idea/testData/intentions/replaceSubstringWithIndexingOperation/zeroFirstTenSecondArgument.kt b/idea/testData/intentions/replaceSubstringWithIndexingOperation/zeroFirstTenSecondArgument.kt new file mode 100644 index 00000000000..4c9b7eec66b --- /dev/null +++ b/idea/testData/intentions/replaceSubstringWithIndexingOperation/zeroFirstTenSecondArgument.kt @@ -0,0 +1,6 @@ +// IS_APPLICABLE: false +// WITH_RUNTIME + +fun foo() { + "abc".substring(0, 10) +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java index cfe11acb873..ae4b3155106 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -14056,6 +14056,33 @@ public class IntentionTestGenerated extends AbstractIntentionTest { } } + @TestMetadata("idea/testData/intentions/replaceSubstringWithIndexingOperation") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class ReplaceSubstringWithIndexingOperation extends AbstractIntentionTest { + public void testAllFilesPresentInReplaceSubstringWithIndexingOperation() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/replaceSubstringWithIndexingOperation"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + } + + @TestMetadata("oneFirstTwoSecondArgument.kt") + public void testOneFirstTwoSecondArgument() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSubstringWithIndexingOperation/oneFirstTwoSecondArgument.kt"); + doTest(fileName); + } + + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSubstringWithIndexingOperation/simple.kt"); + doTest(fileName); + } + + @TestMetadata("zeroFirstTenSecondArgument.kt") + public void testZeroFirstTenSecondArgument() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSubstringWithIndexingOperation/zeroFirstTenSecondArgument.kt"); + doTest(fileName); + } + } + @TestMetadata("idea/testData/intentions/replaceSubstringWithSubstringAfter") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)