From 8988b4b344344a80e209b7ce5963ab0dcc093dc8 Mon Sep 17 00:00:00 2001 From: Dmitry Gridin Date: Mon, 27 May 2019 19:49:59 +0700 Subject: [PATCH] Convert ReplaceSubstringIntention to ReplaceSubstringInspection Relates to #KT-31502 --- .../AbstractApplicabilityBasedInspection.kt | 32 +-- idea/resources/META-INF/plugin-common.xml | 70 ++++--- .../ReplaceSubstringWithDropLast.html | 5 + ...ReplaceSubstringWithIndexingOperation.html | 5 + .../ReplaceSubstringWithSubstringAfter.html | 5 + .../ReplaceSubstringWithSubstringBefore.html | 5 + .../ReplaceSubstringWithTake.html | 5 + .../after.kt.template | 1 - .../before.kt.template | 1 - .../description.html | 5 - .../after.kt.template | 1 - .../before.kt.template | 1 - .../description.html | 5 - .../after.kt.template | 1 - .../before.kt.template | 1 - .../description.html | 5 - .../after.kt.template | 1 - .../before.kt.template | 1 - .../description.html | 5 - .../after.kt.template | 1 - .../before.kt.template | 1 - .../description.html | 5 - .../substring/ReplaceSubstringInspection.kt} | 51 ++--- .../ReplaceSubstringWithDropLastInspection.kt | 45 +++++ ...bstringWithIndexingOperationInspection.kt} | 47 ++--- ...tringWithSubstringBeforeAfterIntentions.kt | 58 ++++++ .../ReplaceSubstringWithTakeInspection.kt | 29 +++ .../ReplaceSubstringWithDropLastIntention.kt | 56 ------ ...tringWithSubstringBeforeAfterIntentions.kt | 64 ------ .../ReplaceSubstringWithTakeIntention.kt | 36 ---- .../replaceSubstring/withDropLast/.inspection | 1 + .../withDropLast}/immutableProperty.kt | 0 .../withDropLast}/immutableProperty.kt.after | 0 .../withDropLast}/methodCallReceiver.kt | 2 +- .../withDropLast}/nonZeroFirstArgument.kt | 2 +- .../withDropLast}/replaceWithDropLast.kt | 0 .../replaceWithDropLast.kt.after | 0 .../withDropLast}/semicolon.kt | 0 .../withDropLast}/semicolon.kt.after | 0 .../withIndexingOperation/.inspection | 1 + .../oneFirstTwoSecondArgument.kt | 0 .../oneFirstTwoSecondArgument.kt.after | 0 .../withIndexingOperation}/simple.kt | 0 .../withIndexingOperation}/simple.kt.after | 0 .../zeroFirstTenSecondArgument.kt | 2 +- .../withSubstringAfter/.inspection | 1 + .../withSubstringAfter}/immutableProperty.kt | 0 .../immutableProperty.kt.after | 0 .../withSubstringAfter}/methodCallReceiver.kt | 2 +- .../replaceWithSubstringAfter.kt | 0 .../replaceWithSubstringAfter.kt.after | 0 .../withSubstringAfter}/semicolon.kt | 0 .../withSubstringAfter}/semicolon.kt.after | 0 .../withSubstringBefore/.inspection | 1 + .../withSubstringBefore}/immutableProperty.kt | 0 .../immutableProperty.kt.after | 0 .../methodCallReceiver.kt | 2 +- .../nonZeroFirstArgument.kt | 2 +- .../replaceWithSubstringBefore.kt | 0 .../replaceWithSubstringBefore.kt.after | 0 .../withSubstringBefore}/semicolon.kt | 0 .../withSubstringBefore}/semicolon.kt.after | 0 .../replaceSubstring/withTake/.inspection | 1 + .../withTake}/constantAsFirstArgument.kt | 2 +- .../withTake}/expressionAsFirstArgument.kt | 2 +- .../withTake}/nonZeroFirstArgument.kt | 2 +- .../withTake}/replaceWithTake.kt | 0 .../withTake}/replaceWithTake.kt.after | 0 .../replaceSubstring/withTake}/semicolon.kt | 0 .../withTake}/semicolon.kt.after | 0 .../replaceSubstringWithDropLast/.intention | 1 - .../.intention | 1 - .../.intention | 1 - .../.intention | 1 - .../replaceSubstringWithTake/.intention | 1 - .../LocalInspectionTestGenerated.java | 188 ++++++++++++++++++ .../intentions/IntentionTestGenerated.java | 175 ---------------- 77 files changed, 463 insertions(+), 476 deletions(-) create mode 100644 idea/resources/inspectionDescriptions/ReplaceSubstringWithDropLast.html create mode 100644 idea/resources/inspectionDescriptions/ReplaceSubstringWithIndexingOperation.html create mode 100644 idea/resources/inspectionDescriptions/ReplaceSubstringWithSubstringAfter.html create mode 100644 idea/resources/inspectionDescriptions/ReplaceSubstringWithSubstringBefore.html create mode 100644 idea/resources/inspectionDescriptions/ReplaceSubstringWithTake.html delete mode 100644 idea/resources/intentionDescriptions/ReplaceSubstringWithDropLastIntention/after.kt.template delete mode 100644 idea/resources/intentionDescriptions/ReplaceSubstringWithDropLastIntention/before.kt.template delete mode 100644 idea/resources/intentionDescriptions/ReplaceSubstringWithDropLastIntention/description.html delete mode 100644 idea/resources/intentionDescriptions/ReplaceSubstringWithIndexingOperationIntention/after.kt.template delete mode 100644 idea/resources/intentionDescriptions/ReplaceSubstringWithIndexingOperationIntention/before.kt.template delete mode 100644 idea/resources/intentionDescriptions/ReplaceSubstringWithIndexingOperationIntention/description.html delete mode 100644 idea/resources/intentionDescriptions/ReplaceSubstringWithSubstringAfterIntention/after.kt.template delete mode 100644 idea/resources/intentionDescriptions/ReplaceSubstringWithSubstringAfterIntention/before.kt.template delete mode 100644 idea/resources/intentionDescriptions/ReplaceSubstringWithSubstringAfterIntention/description.html delete mode 100644 idea/resources/intentionDescriptions/ReplaceSubstringWithSubstringBeforeIntention/after.kt.template delete mode 100644 idea/resources/intentionDescriptions/ReplaceSubstringWithSubstringBeforeIntention/before.kt.template delete mode 100644 idea/resources/intentionDescriptions/ReplaceSubstringWithSubstringBeforeIntention/description.html delete mode 100644 idea/resources/intentionDescriptions/ReplaceSubstringWithTakeIntention/after.kt.template delete mode 100644 idea/resources/intentionDescriptions/ReplaceSubstringWithTakeIntention/before.kt.template delete mode 100644 idea/resources/intentionDescriptions/ReplaceSubstringWithTakeIntention/description.html rename idea/src/org/jetbrains/kotlin/idea/{intentions/ReplaceSubstringIntention.kt => inspections/substring/ReplaceSubstringInspection.kt} (54%) create mode 100644 idea/src/org/jetbrains/kotlin/idea/inspections/substring/ReplaceSubstringWithDropLastInspection.kt rename idea/src/org/jetbrains/kotlin/idea/{intentions/ReplaceSubstringWithIndexingOperationIntention.kt => inspections/substring/ReplaceSubstringWithIndexingOperationInspection.kt} (50%) create mode 100644 idea/src/org/jetbrains/kotlin/idea/inspections/substring/ReplaceSubstringWithSubstringBeforeAfterIntentions.kt create mode 100644 idea/src/org/jetbrains/kotlin/idea/inspections/substring/ReplaceSubstringWithTakeInspection.kt delete mode 100644 idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceSubstringWithDropLastIntention.kt delete mode 100644 idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceSubstringWithSubstringBeforeAfterIntentions.kt delete mode 100644 idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceSubstringWithTakeIntention.kt create mode 100644 idea/testData/inspectionsLocal/replaceSubstring/withDropLast/.inspection rename idea/testData/{intentions/replaceSubstringWithDropLast => inspectionsLocal/replaceSubstring/withDropLast}/immutableProperty.kt (100%) rename idea/testData/{intentions/replaceSubstringWithDropLast => inspectionsLocal/replaceSubstring/withDropLast}/immutableProperty.kt.after (100%) rename idea/testData/{intentions/replaceSubstringWithDropLast => inspectionsLocal/replaceSubstring/withDropLast}/methodCallReceiver.kt (84%) rename idea/testData/{intentions/replaceSubstringWithDropLast => inspectionsLocal/replaceSubstring/withDropLast}/nonZeroFirstArgument.kt (76%) rename idea/testData/{intentions/replaceSubstringWithDropLast => inspectionsLocal/replaceSubstring/withDropLast}/replaceWithDropLast.kt (100%) rename idea/testData/{intentions/replaceSubstringWithDropLast => inspectionsLocal/replaceSubstring/withDropLast}/replaceWithDropLast.kt.after (100%) rename idea/testData/{intentions/replaceSubstringWithDropLast => inspectionsLocal/replaceSubstring/withDropLast}/semicolon.kt (100%) rename idea/testData/{intentions/replaceSubstringWithDropLast => inspectionsLocal/replaceSubstring/withDropLast}/semicolon.kt.after (100%) create mode 100644 idea/testData/inspectionsLocal/replaceSubstring/withIndexingOperation/.inspection rename idea/testData/{intentions/replaceSubstringWithIndexingOperation => inspectionsLocal/replaceSubstring/withIndexingOperation}/oneFirstTwoSecondArgument.kt (100%) rename idea/testData/{intentions/replaceSubstringWithIndexingOperation => inspectionsLocal/replaceSubstring/withIndexingOperation}/oneFirstTwoSecondArgument.kt.after (100%) rename idea/testData/{intentions/replaceSubstringWithIndexingOperation => inspectionsLocal/replaceSubstring/withIndexingOperation}/simple.kt (100%) rename idea/testData/{intentions/replaceSubstringWithIndexingOperation => inspectionsLocal/replaceSubstring/withIndexingOperation}/simple.kt.after (100%) rename idea/testData/{intentions/replaceSubstringWithIndexingOperation => inspectionsLocal/replaceSubstring/withIndexingOperation}/zeroFirstTenSecondArgument.kt (72%) create mode 100644 idea/testData/inspectionsLocal/replaceSubstring/withSubstringAfter/.inspection rename idea/testData/{intentions/replaceSubstringWithSubstringAfter => inspectionsLocal/replaceSubstring/withSubstringAfter}/immutableProperty.kt (100%) rename idea/testData/{intentions/replaceSubstringWithSubstringAfter => inspectionsLocal/replaceSubstring/withSubstringAfter}/immutableProperty.kt.after (100%) rename idea/testData/{intentions/replaceSubstringWithSubstringAfter => inspectionsLocal/replaceSubstring/withSubstringAfter}/methodCallReceiver.kt (84%) rename idea/testData/{intentions/replaceSubstringWithSubstringAfter => inspectionsLocal/replaceSubstring/withSubstringAfter}/replaceWithSubstringAfter.kt (100%) rename idea/testData/{intentions/replaceSubstringWithSubstringAfter => inspectionsLocal/replaceSubstring/withSubstringAfter}/replaceWithSubstringAfter.kt.after (100%) rename idea/testData/{intentions/replaceSubstringWithSubstringAfter => inspectionsLocal/replaceSubstring/withSubstringAfter}/semicolon.kt (100%) rename idea/testData/{intentions/replaceSubstringWithSubstringAfter => inspectionsLocal/replaceSubstring/withSubstringAfter}/semicolon.kt.after (100%) create mode 100644 idea/testData/inspectionsLocal/replaceSubstring/withSubstringBefore/.inspection rename idea/testData/{intentions/replaceSubstringWithSubstringBefore => inspectionsLocal/replaceSubstring/withSubstringBefore}/immutableProperty.kt (100%) rename idea/testData/{intentions/replaceSubstringWithSubstringBefore => inspectionsLocal/replaceSubstring/withSubstringBefore}/immutableProperty.kt.after (100%) rename idea/testData/{intentions/replaceSubstringWithSubstringBefore => inspectionsLocal/replaceSubstring/withSubstringBefore}/methodCallReceiver.kt (84%) rename idea/testData/{intentions/replaceSubstringWithSubstringBefore => inspectionsLocal/replaceSubstring/withSubstringBefore}/nonZeroFirstArgument.kt (77%) rename idea/testData/{intentions/replaceSubstringWithSubstringBefore => inspectionsLocal/replaceSubstring/withSubstringBefore}/replaceWithSubstringBefore.kt (100%) rename idea/testData/{intentions/replaceSubstringWithSubstringBefore => inspectionsLocal/replaceSubstring/withSubstringBefore}/replaceWithSubstringBefore.kt.after (100%) rename idea/testData/{intentions/replaceSubstringWithSubstringBefore => inspectionsLocal/replaceSubstring/withSubstringBefore}/semicolon.kt (100%) rename idea/testData/{intentions/replaceSubstringWithSubstringBefore => inspectionsLocal/replaceSubstring/withSubstringBefore}/semicolon.kt.after (100%) create mode 100644 idea/testData/inspectionsLocal/replaceSubstring/withTake/.inspection rename idea/testData/{intentions/replaceSubstringWithTake => inspectionsLocal/replaceSubstring/withTake}/constantAsFirstArgument.kt (78%) rename idea/testData/{intentions/replaceSubstringWithTake => inspectionsLocal/replaceSubstring/withTake}/expressionAsFirstArgument.kt (75%) rename idea/testData/{intentions/replaceSubstringWithTake => inspectionsLocal/replaceSubstring/withTake}/nonZeroFirstArgument.kt (74%) rename idea/testData/{intentions/replaceSubstringWithTake => inspectionsLocal/replaceSubstring/withTake}/replaceWithTake.kt (100%) rename idea/testData/{intentions/replaceSubstringWithTake => inspectionsLocal/replaceSubstring/withTake}/replaceWithTake.kt.after (100%) rename idea/testData/{intentions/replaceSubstringWithTake => inspectionsLocal/replaceSubstring/withTake}/semicolon.kt (100%) rename idea/testData/{intentions/replaceSubstringWithTake => inspectionsLocal/replaceSubstring/withTake}/semicolon.kt.after (100%) delete mode 100644 idea/testData/intentions/replaceSubstringWithDropLast/.intention delete mode 100644 idea/testData/intentions/replaceSubstringWithIndexingOperation/.intention delete mode 100644 idea/testData/intentions/replaceSubstringWithSubstringAfter/.intention delete mode 100644 idea/testData/intentions/replaceSubstringWithSubstringBefore/.intention delete mode 100644 idea/testData/intentions/replaceSubstringWithTake/.intention diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/AbstractApplicabilityBasedInspection.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/AbstractApplicabilityBasedInspection.kt index 84b1e943214..acc85b736da 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/AbstractApplicabilityBasedInspection.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/AbstractApplicabilityBasedInspection.kt @@ -19,38 +19,42 @@ package org.jetbrains.kotlin.idea.inspections import com.intellij.codeInspection.* import com.intellij.openapi.editor.Editor import com.intellij.openapi.project.Project +import com.intellij.openapi.util.TextRange import com.intellij.psi.PsiElement import org.jetbrains.kotlin.psi.KtElement import org.jetbrains.kotlin.psi.KtVisitorVoid -abstract class AbstractApplicabilityBasedInspection( - val elementType: Class +abstract class AbstractApplicabilityBasedInspection( + val elementType: Class ) : AbstractKotlinInspection() { final override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean, session: LocalInspectionToolSession) = - object : KtVisitorVoid() { - override fun visitKtElement(element: KtElement) { - super.visitKtElement(element) + object : KtVisitorVoid() { + override fun visitKtElement(element: KtElement) { + super.visitKtElement(element) - if (!elementType.isInstance(element) || element.textLength == 0) return - @Suppress("UNCHECKED_CAST") - visitTargetElement(element as TElement, holder, isOnTheFly) - } + if (!elementType.isInstance(element) || element.textLength == 0) return + @Suppress("UNCHECKED_CAST") + visitTargetElement(element as TElement, holder, isOnTheFly) } + } // This function should be called from visitor built by a derived inspection protected fun visitTargetElement(element: TElement, holder: ProblemsHolder, isOnTheFly: Boolean) { if (!isApplicable(element)) return holder.registerProblemWithoutOfflineInformation( - inspectionTarget(element), - inspectionText(element), - isOnTheFly, - inspectionHighlightType(element), - LocalFix(fixText(element)) + inspectionTarget(element), + inspectionText(element), + isOnTheFly, + inspectionHighlightType(element), + inspectionRange(element), + LocalFix(fixText(element)) ) } + open fun inspectionRange(element: TElement): TextRange? = null + open fun inspectionTarget(element: TElement): PsiElement = element open fun inspectionHighlightType(element: TElement): ProblemHighlightType = ProblemHighlightType.GENERIC_ERROR_OR_WARNING diff --git a/idea/resources/META-INF/plugin-common.xml b/idea/resources/META-INF/plugin-common.xml index 33343e44dfa..8c4d61f8bfc 100644 --- a/idea/resources/META-INF/plugin-common.xml +++ b/idea/resources/META-INF/plugin-common.xml @@ -1053,26 +1053,6 @@ Kotlin - - org.jetbrains.kotlin.idea.intentions.ReplaceSubstringWithDropLastIntention - Kotlin - - - - org.jetbrains.kotlin.idea.intentions.ReplaceSubstringWithSubstringAfterIntention - Kotlin - - - - org.jetbrains.kotlin.idea.intentions.ReplaceSubstringWithSubstringBeforeIntention - Kotlin - - - - org.jetbrains.kotlin.idea.intentions.ReplaceSubstringWithTakeIntention - Kotlin - - org.jetbrains.kotlin.idea.intentions.RemoveBracesIntention Kotlin @@ -1578,11 +1558,6 @@ Kotlin - - org.jetbrains.kotlin.idea.intentions.ReplaceSubstringWithIndexingOperationIntention - Kotlin - - org.jetbrains.kotlin.idea.intentions.ConvertUnsafeCastCallToUnsafeCastIntention Kotlin @@ -2072,6 +2047,51 @@ language="kotlin" /> + + + + + + + + + + + +This inspection reports calls like s.substring(0, s.length - x) replaceable with s.dropLast(x). + + diff --git a/idea/resources/inspectionDescriptions/ReplaceSubstringWithIndexingOperation.html b/idea/resources/inspectionDescriptions/ReplaceSubstringWithIndexingOperation.html new file mode 100644 index 00000000000..51c1d56fb59 --- /dev/null +++ b/idea/resources/inspectionDescriptions/ReplaceSubstringWithIndexingOperation.html @@ -0,0 +1,5 @@ + + +This inspection reports calls like "abc".substring(0, 1) replaceable with "abc"[0]. + + \ No newline at end of file diff --git a/idea/resources/inspectionDescriptions/ReplaceSubstringWithSubstringAfter.html b/idea/resources/inspectionDescriptions/ReplaceSubstringWithSubstringAfter.html new file mode 100644 index 00000000000..0743aaadafa --- /dev/null +++ b/idea/resources/inspectionDescriptions/ReplaceSubstringWithSubstringAfter.html @@ -0,0 +1,5 @@ + + +This inspection reports calls like s.substring(s.indexOf(x)) replaceable with s.substringAfter(x). + + diff --git a/idea/resources/inspectionDescriptions/ReplaceSubstringWithSubstringBefore.html b/idea/resources/inspectionDescriptions/ReplaceSubstringWithSubstringBefore.html new file mode 100644 index 00000000000..7c201c0e9f5 --- /dev/null +++ b/idea/resources/inspectionDescriptions/ReplaceSubstringWithSubstringBefore.html @@ -0,0 +1,5 @@ + + +This inspection reports calls like s.substring(0, s.indexOf(x)) replaceable with s.substringBefore(x). + + diff --git a/idea/resources/inspectionDescriptions/ReplaceSubstringWithTake.html b/idea/resources/inspectionDescriptions/ReplaceSubstringWithTake.html new file mode 100644 index 00000000000..643ac66fd90 --- /dev/null +++ b/idea/resources/inspectionDescriptions/ReplaceSubstringWithTake.html @@ -0,0 +1,5 @@ + + +This inspection reports calls like s.substring(0, x) replaceable with s.take(x). + + diff --git a/idea/resources/intentionDescriptions/ReplaceSubstringWithDropLastIntention/after.kt.template b/idea/resources/intentionDescriptions/ReplaceSubstringWithDropLastIntention/after.kt.template deleted file mode 100644 index b6c185a07d9..00000000000 --- a/idea/resources/intentionDescriptions/ReplaceSubstringWithDropLastIntention/after.kt.template +++ /dev/null @@ -1 +0,0 @@ -s.dropLast(5) \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/ReplaceSubstringWithDropLastIntention/before.kt.template b/idea/resources/intentionDescriptions/ReplaceSubstringWithDropLastIntention/before.kt.template deleted file mode 100644 index c9da37c9725..00000000000 --- a/idea/resources/intentionDescriptions/ReplaceSubstringWithDropLastIntention/before.kt.template +++ /dev/null @@ -1 +0,0 @@ -s.substring(0, s.length - 5) \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/ReplaceSubstringWithDropLastIntention/description.html b/idea/resources/intentionDescriptions/ReplaceSubstringWithDropLastIntention/description.html deleted file mode 100644 index 773bd91a99e..00000000000 --- a/idea/resources/intentionDescriptions/ReplaceSubstringWithDropLastIntention/description.html +++ /dev/null @@ -1,5 +0,0 @@ - - -This intention replaces calls like s.substring(0, s.length - x) with s.dropLast(x). - - diff --git a/idea/resources/intentionDescriptions/ReplaceSubstringWithIndexingOperationIntention/after.kt.template b/idea/resources/intentionDescriptions/ReplaceSubstringWithIndexingOperationIntention/after.kt.template deleted file mode 100644 index 22c48684a98..00000000000 --- a/idea/resources/intentionDescriptions/ReplaceSubstringWithIndexingOperationIntention/after.kt.template +++ /dev/null @@ -1 +0,0 @@ -"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 deleted file mode 100644 index 105aae985f4..00000000000 --- a/idea/resources/intentionDescriptions/ReplaceSubstringWithIndexingOperationIntention/before.kt.template +++ /dev/null @@ -1 +0,0 @@ -"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 deleted file mode 100644 index 90737a69caf..00000000000 --- a/idea/resources/intentionDescriptions/ReplaceSubstringWithIndexingOperationIntention/description.html +++ /dev/null @@ -1,5 +0,0 @@ - - -This intention replaces calls like "abc".substring(0, 1) with "abc"[0]. - - \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/ReplaceSubstringWithSubstringAfterIntention/after.kt.template b/idea/resources/intentionDescriptions/ReplaceSubstringWithSubstringAfterIntention/after.kt.template deleted file mode 100644 index 969bc06ec1b..00000000000 --- a/idea/resources/intentionDescriptions/ReplaceSubstringWithSubstringAfterIntention/after.kt.template +++ /dev/null @@ -1 +0,0 @@ -s.substringAfter('x') \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/ReplaceSubstringWithSubstringAfterIntention/before.kt.template b/idea/resources/intentionDescriptions/ReplaceSubstringWithSubstringAfterIntention/before.kt.template deleted file mode 100644 index a4812c12b19..00000000000 --- a/idea/resources/intentionDescriptions/ReplaceSubstringWithSubstringAfterIntention/before.kt.template +++ /dev/null @@ -1 +0,0 @@ -s.substring(s.indexOf('x')) \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/ReplaceSubstringWithSubstringAfterIntention/description.html b/idea/resources/intentionDescriptions/ReplaceSubstringWithSubstringAfterIntention/description.html deleted file mode 100644 index 5817fa374d9..00000000000 --- a/idea/resources/intentionDescriptions/ReplaceSubstringWithSubstringAfterIntention/description.html +++ /dev/null @@ -1,5 +0,0 @@ - - -This intention replaces calls like s.substring(s.indexOf(x)) with s.substringAfter(x). - - diff --git a/idea/resources/intentionDescriptions/ReplaceSubstringWithSubstringBeforeIntention/after.kt.template b/idea/resources/intentionDescriptions/ReplaceSubstringWithSubstringBeforeIntention/after.kt.template deleted file mode 100644 index 730dca58149..00000000000 --- a/idea/resources/intentionDescriptions/ReplaceSubstringWithSubstringBeforeIntention/after.kt.template +++ /dev/null @@ -1 +0,0 @@ -s.substringBefore('x') \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/ReplaceSubstringWithSubstringBeforeIntention/before.kt.template b/idea/resources/intentionDescriptions/ReplaceSubstringWithSubstringBeforeIntention/before.kt.template deleted file mode 100644 index dccf11d3f0a..00000000000 --- a/idea/resources/intentionDescriptions/ReplaceSubstringWithSubstringBeforeIntention/before.kt.template +++ /dev/null @@ -1 +0,0 @@ -s.substring(0, s.indexOf('x')) \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/ReplaceSubstringWithSubstringBeforeIntention/description.html b/idea/resources/intentionDescriptions/ReplaceSubstringWithSubstringBeforeIntention/description.html deleted file mode 100644 index ba2ee54a5dc..00000000000 --- a/idea/resources/intentionDescriptions/ReplaceSubstringWithSubstringBeforeIntention/description.html +++ /dev/null @@ -1,5 +0,0 @@ - - -This intention replaces calls like s.substring(0, s.indexOf(x)) with s.substringBefore(x). - - diff --git a/idea/resources/intentionDescriptions/ReplaceSubstringWithTakeIntention/after.kt.template b/idea/resources/intentionDescriptions/ReplaceSubstringWithTakeIntention/after.kt.template deleted file mode 100644 index 0af9fef8882..00000000000 --- a/idea/resources/intentionDescriptions/ReplaceSubstringWithTakeIntention/after.kt.template +++ /dev/null @@ -1 +0,0 @@ -s.take(10) \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/ReplaceSubstringWithTakeIntention/before.kt.template b/idea/resources/intentionDescriptions/ReplaceSubstringWithTakeIntention/before.kt.template deleted file mode 100644 index d6b5230cc5a..00000000000 --- a/idea/resources/intentionDescriptions/ReplaceSubstringWithTakeIntention/before.kt.template +++ /dev/null @@ -1 +0,0 @@ -s.substring(0, 10) \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/ReplaceSubstringWithTakeIntention/description.html b/idea/resources/intentionDescriptions/ReplaceSubstringWithTakeIntention/description.html deleted file mode 100644 index 6fedf7fbe3f..00000000000 --- a/idea/resources/intentionDescriptions/ReplaceSubstringWithTakeIntention/description.html +++ /dev/null @@ -1,5 +0,0 @@ - - -This intention replaces calls like s.substring(0, x) with s.take(x). - - diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceSubstringIntention.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/substring/ReplaceSubstringInspection.kt similarity index 54% rename from idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceSubstringIntention.kt rename to idea/src/org/jetbrains/kotlin/idea/inspections/substring/ReplaceSubstringInspection.kt index 9d72c3a9ad3..7c5a1a1b3a9 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceSubstringIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/substring/ReplaceSubstringInspection.kt @@ -1,46 +1,43 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ -package org.jetbrains.kotlin.idea.intentions +package org.jetbrains.kotlin.idea.inspections.substring import com.intellij.openapi.util.TextRange import org.jetbrains.kotlin.idea.caches.resolve.analyze +import org.jetbrains.kotlin.idea.inspections.AbstractApplicabilityBasedInspection import org.jetbrains.kotlin.idea.intentions.branchedTransformations.evaluatesTo import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isStableSimpleExpression +import org.jetbrains.kotlin.idea.intentions.callExpression +import org.jetbrains.kotlin.idea.intentions.toResolvedCall import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.psi.psiUtil.startOffset import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode -abstract class ReplaceSubstringIntention(text: String) : SelfTargetingRangeIntention(KtDotQualifiedExpression::class.java, text) { - protected abstract fun applicabilityRangeInner(element: KtDotQualifiedExpression): TextRange? +abstract class ReplaceSubstringInspection : + AbstractApplicabilityBasedInspection(KtDotQualifiedExpression::class.java) { + protected abstract fun isApplicableInner(element: KtDotQualifiedExpression): Boolean + protected open val isAlwaysStable: Boolean = false - override fun applicabilityRange(element: KtDotQualifiedExpression): TextRange? { - if (element.receiverExpression.isStableSimpleExpression() && element.isMethodCall("kotlin.text.substring")) { - return applicabilityRangeInner(element) - } - return null - } + final override fun isApplicable(element: KtDotQualifiedExpression): Boolean = + if ((isAlwaysStable || element.receiverExpression.isStableSimpleExpression()) && element.isMethodCall("kotlin.text.substring")) { + isApplicableInner(element) + } else + false + + override fun inspectionRange(element: KtDotQualifiedExpression): TextRange? = + element.callExpression?.calleeExpression?.textRange?.shiftLeft(element.startOffset) protected fun isIndexOfCall(expression: KtExpression?, expectedReceiver: KtExpression): Boolean { return expression is KtDotQualifiedExpression - && expression.isMethodCall("kotlin.text.indexOf") - && expression.receiverExpression.evaluatesTo(expectedReceiver) - && expression.callExpression!!.valueArguments.size == 1 + && expression.isMethodCall("kotlin.text.indexOf") + && expression.receiverExpression.evaluatesTo(expectedReceiver) + && expression.callExpression!!.valueArguments.size == 1 } private fun KtDotQualifiedExpression.isMethodCall(fqMethodName: String): Boolean { @@ -58,10 +55,6 @@ abstract class ReplaceSubstringIntention(text: String) : SelfTargetingRangeInten return constant.getValue(constantType) == 0 } - protected fun getTextRange(element: KtDotQualifiedExpression): TextRange? { - return element.callExpression?.textRange - } - protected fun KtDotQualifiedExpression.replaceWith(pattern: String, argument: KtExpression) { val psiFactory = KtPsiFactory(this) replace(psiFactory.createExpressionByPattern(pattern, receiverExpression, argument)) diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/substring/ReplaceSubstringWithDropLastInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/substring/ReplaceSubstringWithDropLastInspection.kt new file mode 100644 index 00000000000..04d78558746 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/substring/ReplaceSubstringWithDropLastInspection.kt @@ -0,0 +1,45 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.idea.inspections.substring + +import com.intellij.openapi.editor.Editor +import com.intellij.openapi.project.Project +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.idea.intentions.branchedTransformations.evaluatesTo +import org.jetbrains.kotlin.idea.intentions.callExpression +import org.jetbrains.kotlin.lexer.KtTokens +import org.jetbrains.kotlin.psi.KtBinaryExpression +import org.jetbrains.kotlin.psi.KtDotQualifiedExpression +import org.jetbrains.kotlin.psi.KtExpression +import org.jetbrains.kotlin.psi.KtNameReferenceExpression + +class ReplaceSubstringWithDropLastInspection : ReplaceSubstringInspection() { + override fun inspectionText(element: KtDotQualifiedExpression): String = "Replace 'substring' call with 'dropLast' call" + override val defaultFixText: String = "Replace 'substring' call with 'dropLast' call" + + override fun applyTo(element: PsiElement, project: Project, editor: Editor?) { + if (element !is KtDotQualifiedExpression) return + val argument = element.callExpression!!.valueArguments[1].getArgumentExpression()!! + val rightExpression = (argument as KtBinaryExpression).right!! + + element.replaceWith("$0.dropLast($1)", rightExpression) + } + + override fun isApplicableInner(element: KtDotQualifiedExpression): Boolean { + val arguments = element.callExpression?.valueArguments ?: return false + if (arguments.size != 2 || !element.isFirstArgumentZero()) return false + + val secondArgumentExpression = arguments[1].getArgumentExpression() as? KtBinaryExpression ?: return false + + if (secondArgumentExpression.operationReference.getReferencedNameElementType() != KtTokens.MINUS) return false + return isLengthAccess(secondArgumentExpression.left, element.receiverExpression) + } + + private fun isLengthAccess(expression: KtExpression?, expectedReceiver: KtExpression): Boolean = + expression is KtDotQualifiedExpression + && expression.selectorExpression.let { it is KtNameReferenceExpression && it.getReferencedName() == "length" } + && expression.receiverExpression.evaluatesTo(expectedReceiver) +} diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceSubstringWithIndexingOperationIntention.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/substring/ReplaceSubstringWithIndexingOperationInspection.kt similarity index 50% rename from idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceSubstringWithIndexingOperationIntention.kt rename to idea/src/org/jetbrains/kotlin/idea/inspections/substring/ReplaceSubstringWithIndexingOperationInspection.kt index 53a01fcc7b9..47ecc0c7122 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceSubstringWithIndexingOperationIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/substring/ReplaceSubstringWithIndexingOperationInspection.kt @@ -1,48 +1,39 @@ /* - * Copyright 2000-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ -package org.jetbrains.kotlin.idea.intentions +package org.jetbrains.kotlin.idea.inspections.substring import com.intellij.openapi.editor.Editor -import com.intellij.openapi.util.TextRange +import com.intellij.openapi.project.Project +import com.intellij.psi.PsiElement import org.jetbrains.kotlin.idea.caches.resolve.analyze +import org.jetbrains.kotlin.idea.intentions.callExpression import org.jetbrains.kotlin.psi.KtConstantExpression import org.jetbrains.kotlin.psi.KtDotQualifiedExpression import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator -import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe -import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode -class ReplaceSubstringWithIndexingOperationIntention : ReplaceSubstringIntention("Replace 'substring' call with indexing operation call") { - override fun applicabilityRange(element: KtDotQualifiedExpression): TextRange? { - if (element.isSubstringMethod()) { - return applicabilityRangeInner(element) - } +class ReplaceSubstringWithIndexingOperationInspection : + ReplaceSubstringInspection() { + override fun inspectionText(element: KtDotQualifiedExpression): String = "Replace 'substring' call with indexing operation call" + override val defaultFixText: String = "Replace 'substring' call with indexing operation call" + override val isAlwaysStable: Boolean = true - return null - } - - override fun applicabilityRangeInner(element: KtDotQualifiedExpression): TextRange? { - val arguments = element.callExpression?.valueArguments ?: return null - if (arguments.size != 2) return null - - val arg1 = element.getValueArgument(0) ?: return null - val arg2 = element.getValueArgument(1) ?: return null - if (arg1 + 1 != arg2) return null - - return getTextRange(element) - } - - override fun applyTo(element: KtDotQualifiedExpression, editor: Editor?) { + override fun applyTo(element: PsiElement, project: Project, editor: Editor?) { + if (element !is KtDotQualifiedExpression) return val expression = element.callExpression?.valueArguments?.firstOrNull()?.getArgumentExpression() ?: return element.replaceWith("$0[$1]", expression) } - private fun KtDotQualifiedExpression.isSubstringMethod(): Boolean { - val resolvedCall = toResolvedCall(BodyResolveMode.PARTIAL) ?: return false - return (resolvedCall.resultingDescriptor.fqNameUnsafe.asString() == "kotlin.text.substring") + override fun isApplicableInner(element: KtDotQualifiedExpression): Boolean { + val arguments = element.callExpression?.valueArguments ?: return false + if (arguments.size != 2) return false + + val arg1 = element.getValueArgument(0) ?: return false + val arg2 = element.getValueArgument(1) ?: return false + return arg1 + 1 == arg2 } private fun KtDotQualifiedExpression.getValueArgument(index: Int): Int? { diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/substring/ReplaceSubstringWithSubstringBeforeAfterIntentions.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/substring/ReplaceSubstringWithSubstringBeforeAfterIntentions.kt new file mode 100644 index 00000000000..335fd66cb77 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/substring/ReplaceSubstringWithSubstringBeforeAfterIntentions.kt @@ -0,0 +1,58 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.idea.inspections.substring + +import com.intellij.openapi.editor.Editor +import com.intellij.openapi.project.Project +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.idea.intentions.callExpression +import org.jetbrains.kotlin.psi.KtDotQualifiedExpression +import org.jetbrains.kotlin.psi.KtExpression + +class ReplaceSubstringWithSubstringAfterInspection : ReplaceSubstringInspection() { + override fun inspectionText(element: KtDotQualifiedExpression): String = "Replace 'substring' call with 'substringAfter' call" + + override val defaultFixText: String = "Replace 'substring' call with 'substringAfter' call" + + override fun applyTo(element: PsiElement, project: Project, editor: Editor?) { + if (element !is KtDotQualifiedExpression) return + element.replaceWith( + "$0.substringAfter($1)", + (element.getArgumentExpression(0) as KtDotQualifiedExpression).getArgumentExpression(0) + ) + } + + override fun isApplicableInner(element: KtDotQualifiedExpression): Boolean { + val arguments = element.callExpression?.valueArguments ?: return false + return arguments.size == 1 && isIndexOfCall(arguments[0].getArgumentExpression(), element.receiverExpression) + } +} + +class ReplaceSubstringWithSubstringBeforeInspection : ReplaceSubstringInspection() { + override fun inspectionText(element: KtDotQualifiedExpression): String = "Replace 'substring' call with 'substringBefore' call" + + override val defaultFixText: String = "Replace 'substring' call with 'substringBefore' call" + + override fun applyTo(element: PsiElement, project: Project, editor: Editor?) { + if (element !is KtDotQualifiedExpression) return + element.replaceWith( + "$0.substringBefore($1)", + (element.getArgumentExpression(1) as KtDotQualifiedExpression).getArgumentExpression(0) + ) + } + + override fun isApplicableInner(element: KtDotQualifiedExpression): Boolean { + val arguments = element.callExpression?.valueArguments ?: return false + + return arguments.size == 2 + && element.isFirstArgumentZero() + && isIndexOfCall(arguments[1].getArgumentExpression(), element.receiverExpression) + } +} + +private fun KtDotQualifiedExpression.getArgumentExpression(index: Int): KtExpression { + return callExpression!!.valueArguments[index].getArgumentExpression()!! +} diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/substring/ReplaceSubstringWithTakeInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/substring/ReplaceSubstringWithTakeInspection.kt new file mode 100644 index 00000000000..5eebe57fcbe --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/substring/ReplaceSubstringWithTakeInspection.kt @@ -0,0 +1,29 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.idea.inspections.substring + +import com.intellij.openapi.editor.Editor +import com.intellij.openapi.project.Project +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.idea.intentions.callExpression +import org.jetbrains.kotlin.psi.KtDotQualifiedExpression + +class ReplaceSubstringWithTakeInspection : ReplaceSubstringInspection() { + override fun inspectionText(element: KtDotQualifiedExpression): String = "Replace 'substring' call with 'take' call" + + override val defaultFixText: String = "Replace 'substring' call with 'take' call" + + override fun applyTo(element: PsiElement, project: Project, editor: Editor?) { + if (element !is KtDotQualifiedExpression) return + val argument = element.callExpression!!.valueArguments[1].getArgumentExpression()!! + element.replaceWith("$0.take($1)", argument) + } + + override fun isApplicableInner(element: KtDotQualifiedExpression): Boolean { + val arguments = element.callExpression?.valueArguments ?: return false + return arguments.size == 2 && element.isFirstArgumentZero() + } +} diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceSubstringWithDropLastIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceSubstringWithDropLastIntention.kt deleted file mode 100644 index 3ef5a22c594..00000000000 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceSubstringWithDropLastIntention.kt +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2010-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.idea.intentions - -import com.intellij.openapi.editor.Editor -import com.intellij.openapi.util.TextRange -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.evaluatesTo -import org.jetbrains.kotlin.lexer.KtTokens -import org.jetbrains.kotlin.psi.KtBinaryExpression -import org.jetbrains.kotlin.psi.KtDotQualifiedExpression -import org.jetbrains.kotlin.psi.KtExpression -import org.jetbrains.kotlin.psi.KtNameReferenceExpression - -class ReplaceSubstringWithDropLastIntention : ReplaceSubstringIntention("Replace 'substring' call with 'dropLast' call") { - override fun applicabilityRangeInner(element: KtDotQualifiedExpression): TextRange? { - val arguments = element.callExpression?.valueArguments ?: return null - if (arguments.size != 2 || !element.isFirstArgumentZero()) return null - - val secondArgumentExpression = arguments[1].getArgumentExpression() - - if (secondArgumentExpression !is KtBinaryExpression) return null - if (secondArgumentExpression.operationReference.getReferencedNameElementType() != KtTokens.MINUS) return null - if (isLengthAccess(secondArgumentExpression.left, element.receiverExpression)) { - return getTextRange(element) - } - - return null - } - - override fun applyTo(element: KtDotQualifiedExpression, editor: Editor?) { - val argument = element.callExpression!!.valueArguments[1].getArgumentExpression()!! - val rightExpression = (argument as KtBinaryExpression).right!! - - element.replaceWith("$0.dropLast($1)", rightExpression) - } - - private fun isLengthAccess(expression: KtExpression?, expectedReceiver: KtExpression): Boolean { - return expression is KtDotQualifiedExpression - && expression.selectorExpression.let { it is KtNameReferenceExpression && it.getReferencedName() == "length" } - && expression.receiverExpression.evaluatesTo(expectedReceiver) - } -} diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceSubstringWithSubstringBeforeAfterIntentions.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceSubstringWithSubstringBeforeAfterIntentions.kt deleted file mode 100644 index 50be07a3397..00000000000 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceSubstringWithSubstringBeforeAfterIntentions.kt +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2010-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.idea.intentions - -import com.intellij.openapi.editor.Editor -import com.intellij.openapi.util.TextRange -import org.jetbrains.kotlin.psi.KtDotQualifiedExpression -import org.jetbrains.kotlin.psi.KtExpression - -class ReplaceSubstringWithSubstringAfterIntention : ReplaceSubstringIntention("Replace 'substring' call with 'substringAfter' call") { - override fun applicabilityRangeInner(element: KtDotQualifiedExpression): TextRange? { - val arguments = element.callExpression?.valueArguments ?: return null - - if (arguments.size == 1 && isIndexOfCall(arguments[0].getArgumentExpression(), element.receiverExpression)) { - return getTextRange(element) - } - - return null - } - - override fun applyTo(element: KtDotQualifiedExpression, editor: Editor?) { - element.replaceWith( - "$0.substringAfter($1)", - (element.getArgumentExpression(0) as KtDotQualifiedExpression).getArgumentExpression(0)) - } -} - -class ReplaceSubstringWithSubstringBeforeIntention : ReplaceSubstringIntention("Replace 'substring' call with 'substringBefore' call") { - override fun applicabilityRangeInner(element: KtDotQualifiedExpression): TextRange? { - val arguments = element.callExpression?.valueArguments ?: return null - - if (arguments.size == 2 - && element.isFirstArgumentZero() - && isIndexOfCall(arguments[1].getArgumentExpression(), element.receiverExpression)) { - return getTextRange(element) - } - - return null - } - - override fun applyTo(element: KtDotQualifiedExpression, editor: Editor?) { - element.replaceWith( - "$0.substringBefore($1)", - (element.getArgumentExpression(1) as KtDotQualifiedExpression).getArgumentExpression(0)) - } -} - -private fun KtDotQualifiedExpression.getArgumentExpression(index: Int): KtExpression { - return callExpression!!.valueArguments[index].getArgumentExpression()!! -} diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceSubstringWithTakeIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceSubstringWithTakeIntention.kt deleted file mode 100644 index 0702a652d22..00000000000 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceSubstringWithTakeIntention.kt +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2010-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.idea.intentions - -import com.intellij.openapi.editor.Editor -import com.intellij.openapi.util.TextRange -import org.jetbrains.kotlin.psi.KtDotQualifiedExpression - -class ReplaceSubstringWithTakeIntention : ReplaceSubstringIntention("Replace 'substring' call with 'take' call") { - override fun applicabilityRangeInner(element: KtDotQualifiedExpression): TextRange? { - val arguments = element.callExpression?.valueArguments ?: return null - if (arguments.size == 2 && element.isFirstArgumentZero()) { - return getTextRange(element) - } - return null - } - - override fun applyTo(element: KtDotQualifiedExpression, editor: Editor?) { - val argument = element.callExpression!!.valueArguments[1].getArgumentExpression()!! - element.replaceWith("$0.take($1)", argument) - } -} diff --git a/idea/testData/inspectionsLocal/replaceSubstring/withDropLast/.inspection b/idea/testData/inspectionsLocal/replaceSubstring/withDropLast/.inspection new file mode 100644 index 00000000000..de96d24e3c3 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceSubstring/withDropLast/.inspection @@ -0,0 +1 @@ +org.jetbrains.kotlin.idea.inspections.substring.ReplaceSubstringWithDropLastInspection \ No newline at end of file diff --git a/idea/testData/intentions/replaceSubstringWithDropLast/immutableProperty.kt b/idea/testData/inspectionsLocal/replaceSubstring/withDropLast/immutableProperty.kt similarity index 100% rename from idea/testData/intentions/replaceSubstringWithDropLast/immutableProperty.kt rename to idea/testData/inspectionsLocal/replaceSubstring/withDropLast/immutableProperty.kt diff --git a/idea/testData/intentions/replaceSubstringWithDropLast/immutableProperty.kt.after b/idea/testData/inspectionsLocal/replaceSubstring/withDropLast/immutableProperty.kt.after similarity index 100% rename from idea/testData/intentions/replaceSubstringWithDropLast/immutableProperty.kt.after rename to idea/testData/inspectionsLocal/replaceSubstring/withDropLast/immutableProperty.kt.after diff --git a/idea/testData/intentions/replaceSubstringWithDropLast/methodCallReceiver.kt b/idea/testData/inspectionsLocal/replaceSubstring/withDropLast/methodCallReceiver.kt similarity index 84% rename from idea/testData/intentions/replaceSubstringWithDropLast/methodCallReceiver.kt rename to idea/testData/inspectionsLocal/replaceSubstring/withDropLast/methodCallReceiver.kt index cf2ef46af17..f0637c2d01a 100644 --- a/idea/testData/intentions/replaceSubstringWithDropLast/methodCallReceiver.kt +++ b/idea/testData/inspectionsLocal/replaceSubstring/withDropLast/methodCallReceiver.kt @@ -1,5 +1,5 @@ // WITH_RUNTIME -// IS_APPLICABLE: false +// PROBLEM: none class A() { fun bar(): String = null!! diff --git a/idea/testData/intentions/replaceSubstringWithDropLast/nonZeroFirstArgument.kt b/idea/testData/inspectionsLocal/replaceSubstring/withDropLast/nonZeroFirstArgument.kt similarity index 76% rename from idea/testData/intentions/replaceSubstringWithDropLast/nonZeroFirstArgument.kt rename to idea/testData/inspectionsLocal/replaceSubstring/withDropLast/nonZeroFirstArgument.kt index de78eac2f86..b1bc0a96778 100644 --- a/idea/testData/intentions/replaceSubstringWithDropLast/nonZeroFirstArgument.kt +++ b/idea/testData/inspectionsLocal/replaceSubstring/withDropLast/nonZeroFirstArgument.kt @@ -1,4 +1,4 @@ -// IS_APPLICABLE: false +// PROBLEM: none // WITH_RUNTIME fun foo(s: String) { diff --git a/idea/testData/intentions/replaceSubstringWithDropLast/replaceWithDropLast.kt b/idea/testData/inspectionsLocal/replaceSubstring/withDropLast/replaceWithDropLast.kt similarity index 100% rename from idea/testData/intentions/replaceSubstringWithDropLast/replaceWithDropLast.kt rename to idea/testData/inspectionsLocal/replaceSubstring/withDropLast/replaceWithDropLast.kt diff --git a/idea/testData/intentions/replaceSubstringWithDropLast/replaceWithDropLast.kt.after b/idea/testData/inspectionsLocal/replaceSubstring/withDropLast/replaceWithDropLast.kt.after similarity index 100% rename from idea/testData/intentions/replaceSubstringWithDropLast/replaceWithDropLast.kt.after rename to idea/testData/inspectionsLocal/replaceSubstring/withDropLast/replaceWithDropLast.kt.after diff --git a/idea/testData/intentions/replaceSubstringWithDropLast/semicolon.kt b/idea/testData/inspectionsLocal/replaceSubstring/withDropLast/semicolon.kt similarity index 100% rename from idea/testData/intentions/replaceSubstringWithDropLast/semicolon.kt rename to idea/testData/inspectionsLocal/replaceSubstring/withDropLast/semicolon.kt diff --git a/idea/testData/intentions/replaceSubstringWithDropLast/semicolon.kt.after b/idea/testData/inspectionsLocal/replaceSubstring/withDropLast/semicolon.kt.after similarity index 100% rename from idea/testData/intentions/replaceSubstringWithDropLast/semicolon.kt.after rename to idea/testData/inspectionsLocal/replaceSubstring/withDropLast/semicolon.kt.after diff --git a/idea/testData/inspectionsLocal/replaceSubstring/withIndexingOperation/.inspection b/idea/testData/inspectionsLocal/replaceSubstring/withIndexingOperation/.inspection new file mode 100644 index 00000000000..ca96400d80d --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceSubstring/withIndexingOperation/.inspection @@ -0,0 +1 @@ +org.jetbrains.kotlin.idea.inspections.substring.ReplaceSubstringWithIndexingOperationInspection \ No newline at end of file diff --git a/idea/testData/intentions/replaceSubstringWithIndexingOperation/oneFirstTwoSecondArgument.kt b/idea/testData/inspectionsLocal/replaceSubstring/withIndexingOperation/oneFirstTwoSecondArgument.kt similarity index 100% rename from idea/testData/intentions/replaceSubstringWithIndexingOperation/oneFirstTwoSecondArgument.kt rename to idea/testData/inspectionsLocal/replaceSubstring/withIndexingOperation/oneFirstTwoSecondArgument.kt diff --git a/idea/testData/intentions/replaceSubstringWithIndexingOperation/oneFirstTwoSecondArgument.kt.after b/idea/testData/inspectionsLocal/replaceSubstring/withIndexingOperation/oneFirstTwoSecondArgument.kt.after similarity index 100% rename from idea/testData/intentions/replaceSubstringWithIndexingOperation/oneFirstTwoSecondArgument.kt.after rename to idea/testData/inspectionsLocal/replaceSubstring/withIndexingOperation/oneFirstTwoSecondArgument.kt.after diff --git a/idea/testData/intentions/replaceSubstringWithIndexingOperation/simple.kt b/idea/testData/inspectionsLocal/replaceSubstring/withIndexingOperation/simple.kt similarity index 100% rename from idea/testData/intentions/replaceSubstringWithIndexingOperation/simple.kt rename to idea/testData/inspectionsLocal/replaceSubstring/withIndexingOperation/simple.kt diff --git a/idea/testData/intentions/replaceSubstringWithIndexingOperation/simple.kt.after b/idea/testData/inspectionsLocal/replaceSubstring/withIndexingOperation/simple.kt.after similarity index 100% rename from idea/testData/intentions/replaceSubstringWithIndexingOperation/simple.kt.after rename to idea/testData/inspectionsLocal/replaceSubstring/withIndexingOperation/simple.kt.after diff --git a/idea/testData/intentions/replaceSubstringWithIndexingOperation/zeroFirstTenSecondArgument.kt b/idea/testData/inspectionsLocal/replaceSubstring/withIndexingOperation/zeroFirstTenSecondArgument.kt similarity index 72% rename from idea/testData/intentions/replaceSubstringWithIndexingOperation/zeroFirstTenSecondArgument.kt rename to idea/testData/inspectionsLocal/replaceSubstring/withIndexingOperation/zeroFirstTenSecondArgument.kt index 4c9b7eec66b..497787b00ad 100644 --- a/idea/testData/intentions/replaceSubstringWithIndexingOperation/zeroFirstTenSecondArgument.kt +++ b/idea/testData/inspectionsLocal/replaceSubstring/withIndexingOperation/zeroFirstTenSecondArgument.kt @@ -1,4 +1,4 @@ -// IS_APPLICABLE: false +// PROBLEM: none // WITH_RUNTIME fun foo() { diff --git a/idea/testData/inspectionsLocal/replaceSubstring/withSubstringAfter/.inspection b/idea/testData/inspectionsLocal/replaceSubstring/withSubstringAfter/.inspection new file mode 100644 index 00000000000..9e24c98d9bd --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceSubstring/withSubstringAfter/.inspection @@ -0,0 +1 @@ +org.jetbrains.kotlin.idea.inspections.substring.ReplaceSubstringWithSubstringAfterInspection \ No newline at end of file diff --git a/idea/testData/intentions/replaceSubstringWithSubstringAfter/immutableProperty.kt b/idea/testData/inspectionsLocal/replaceSubstring/withSubstringAfter/immutableProperty.kt similarity index 100% rename from idea/testData/intentions/replaceSubstringWithSubstringAfter/immutableProperty.kt rename to idea/testData/inspectionsLocal/replaceSubstring/withSubstringAfter/immutableProperty.kt diff --git a/idea/testData/intentions/replaceSubstringWithSubstringAfter/immutableProperty.kt.after b/idea/testData/inspectionsLocal/replaceSubstring/withSubstringAfter/immutableProperty.kt.after similarity index 100% rename from idea/testData/intentions/replaceSubstringWithSubstringAfter/immutableProperty.kt.after rename to idea/testData/inspectionsLocal/replaceSubstring/withSubstringAfter/immutableProperty.kt.after diff --git a/idea/testData/intentions/replaceSubstringWithSubstringAfter/methodCallReceiver.kt b/idea/testData/inspectionsLocal/replaceSubstring/withSubstringAfter/methodCallReceiver.kt similarity index 84% rename from idea/testData/intentions/replaceSubstringWithSubstringAfter/methodCallReceiver.kt rename to idea/testData/inspectionsLocal/replaceSubstring/withSubstringAfter/methodCallReceiver.kt index 4885d5ee9d0..5ee72dfd4b2 100644 --- a/idea/testData/intentions/replaceSubstringWithSubstringAfter/methodCallReceiver.kt +++ b/idea/testData/inspectionsLocal/replaceSubstring/withSubstringAfter/methodCallReceiver.kt @@ -1,5 +1,5 @@ // WITH_RUNTIME -// IS_APPLICABLE: false +// PROBLEM: none class A() { fun bar(): String = null!! diff --git a/idea/testData/intentions/replaceSubstringWithSubstringAfter/replaceWithSubstringAfter.kt b/idea/testData/inspectionsLocal/replaceSubstring/withSubstringAfter/replaceWithSubstringAfter.kt similarity index 100% rename from idea/testData/intentions/replaceSubstringWithSubstringAfter/replaceWithSubstringAfter.kt rename to idea/testData/inspectionsLocal/replaceSubstring/withSubstringAfter/replaceWithSubstringAfter.kt diff --git a/idea/testData/intentions/replaceSubstringWithSubstringAfter/replaceWithSubstringAfter.kt.after b/idea/testData/inspectionsLocal/replaceSubstring/withSubstringAfter/replaceWithSubstringAfter.kt.after similarity index 100% rename from idea/testData/intentions/replaceSubstringWithSubstringAfter/replaceWithSubstringAfter.kt.after rename to idea/testData/inspectionsLocal/replaceSubstring/withSubstringAfter/replaceWithSubstringAfter.kt.after diff --git a/idea/testData/intentions/replaceSubstringWithSubstringAfter/semicolon.kt b/idea/testData/inspectionsLocal/replaceSubstring/withSubstringAfter/semicolon.kt similarity index 100% rename from idea/testData/intentions/replaceSubstringWithSubstringAfter/semicolon.kt rename to idea/testData/inspectionsLocal/replaceSubstring/withSubstringAfter/semicolon.kt diff --git a/idea/testData/intentions/replaceSubstringWithSubstringAfter/semicolon.kt.after b/idea/testData/inspectionsLocal/replaceSubstring/withSubstringAfter/semicolon.kt.after similarity index 100% rename from idea/testData/intentions/replaceSubstringWithSubstringAfter/semicolon.kt.after rename to idea/testData/inspectionsLocal/replaceSubstring/withSubstringAfter/semicolon.kt.after diff --git a/idea/testData/inspectionsLocal/replaceSubstring/withSubstringBefore/.inspection b/idea/testData/inspectionsLocal/replaceSubstring/withSubstringBefore/.inspection new file mode 100644 index 00000000000..ffb512587db --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceSubstring/withSubstringBefore/.inspection @@ -0,0 +1 @@ +org.jetbrains.kotlin.idea.inspections.substring.ReplaceSubstringWithSubstringBeforeInspection \ No newline at end of file diff --git a/idea/testData/intentions/replaceSubstringWithSubstringBefore/immutableProperty.kt b/idea/testData/inspectionsLocal/replaceSubstring/withSubstringBefore/immutableProperty.kt similarity index 100% rename from idea/testData/intentions/replaceSubstringWithSubstringBefore/immutableProperty.kt rename to idea/testData/inspectionsLocal/replaceSubstring/withSubstringBefore/immutableProperty.kt diff --git a/idea/testData/intentions/replaceSubstringWithSubstringBefore/immutableProperty.kt.after b/idea/testData/inspectionsLocal/replaceSubstring/withSubstringBefore/immutableProperty.kt.after similarity index 100% rename from idea/testData/intentions/replaceSubstringWithSubstringBefore/immutableProperty.kt.after rename to idea/testData/inspectionsLocal/replaceSubstring/withSubstringBefore/immutableProperty.kt.after diff --git a/idea/testData/intentions/replaceSubstringWithSubstringBefore/methodCallReceiver.kt b/idea/testData/inspectionsLocal/replaceSubstring/withSubstringBefore/methodCallReceiver.kt similarity index 84% rename from idea/testData/intentions/replaceSubstringWithSubstringBefore/methodCallReceiver.kt rename to idea/testData/inspectionsLocal/replaceSubstring/withSubstringBefore/methodCallReceiver.kt index 74f9dde72a4..a2330fdd2b7 100644 --- a/idea/testData/intentions/replaceSubstringWithSubstringBefore/methodCallReceiver.kt +++ b/idea/testData/inspectionsLocal/replaceSubstring/withSubstringBefore/methodCallReceiver.kt @@ -1,5 +1,5 @@ // WITH_RUNTIME -// IS_APPLICABLE: false +// PROBLEM: none class A() { fun bar(): String = null!! diff --git a/idea/testData/intentions/replaceSubstringWithSubstringBefore/nonZeroFirstArgument.kt b/idea/testData/inspectionsLocal/replaceSubstring/withSubstringBefore/nonZeroFirstArgument.kt similarity index 77% rename from idea/testData/intentions/replaceSubstringWithSubstringBefore/nonZeroFirstArgument.kt rename to idea/testData/inspectionsLocal/replaceSubstring/withSubstringBefore/nonZeroFirstArgument.kt index ddce1dcb825..cec71f8ff66 100644 --- a/idea/testData/intentions/replaceSubstringWithSubstringBefore/nonZeroFirstArgument.kt +++ b/idea/testData/inspectionsLocal/replaceSubstring/withSubstringBefore/nonZeroFirstArgument.kt @@ -1,4 +1,4 @@ -// IS_APPLICABLE: false +// PROBLEM: none // WITH_RUNTIME fun foo(s: String) { diff --git a/idea/testData/intentions/replaceSubstringWithSubstringBefore/replaceWithSubstringBefore.kt b/idea/testData/inspectionsLocal/replaceSubstring/withSubstringBefore/replaceWithSubstringBefore.kt similarity index 100% rename from idea/testData/intentions/replaceSubstringWithSubstringBefore/replaceWithSubstringBefore.kt rename to idea/testData/inspectionsLocal/replaceSubstring/withSubstringBefore/replaceWithSubstringBefore.kt diff --git a/idea/testData/intentions/replaceSubstringWithSubstringBefore/replaceWithSubstringBefore.kt.after b/idea/testData/inspectionsLocal/replaceSubstring/withSubstringBefore/replaceWithSubstringBefore.kt.after similarity index 100% rename from idea/testData/intentions/replaceSubstringWithSubstringBefore/replaceWithSubstringBefore.kt.after rename to idea/testData/inspectionsLocal/replaceSubstring/withSubstringBefore/replaceWithSubstringBefore.kt.after diff --git a/idea/testData/intentions/replaceSubstringWithSubstringBefore/semicolon.kt b/idea/testData/inspectionsLocal/replaceSubstring/withSubstringBefore/semicolon.kt similarity index 100% rename from idea/testData/intentions/replaceSubstringWithSubstringBefore/semicolon.kt rename to idea/testData/inspectionsLocal/replaceSubstring/withSubstringBefore/semicolon.kt diff --git a/idea/testData/intentions/replaceSubstringWithSubstringBefore/semicolon.kt.after b/idea/testData/inspectionsLocal/replaceSubstring/withSubstringBefore/semicolon.kt.after similarity index 100% rename from idea/testData/intentions/replaceSubstringWithSubstringBefore/semicolon.kt.after rename to idea/testData/inspectionsLocal/replaceSubstring/withSubstringBefore/semicolon.kt.after diff --git a/idea/testData/inspectionsLocal/replaceSubstring/withTake/.inspection b/idea/testData/inspectionsLocal/replaceSubstring/withTake/.inspection new file mode 100644 index 00000000000..67c08e98417 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceSubstring/withTake/.inspection @@ -0,0 +1 @@ +org.jetbrains.kotlin.idea.inspections.substring.ReplaceSubstringWithTakeInspection \ No newline at end of file diff --git a/idea/testData/intentions/replaceSubstringWithTake/constantAsFirstArgument.kt b/idea/testData/inspectionsLocal/replaceSubstring/withTake/constantAsFirstArgument.kt similarity index 78% rename from idea/testData/intentions/replaceSubstringWithTake/constantAsFirstArgument.kt rename to idea/testData/inspectionsLocal/replaceSubstring/withTake/constantAsFirstArgument.kt index 5a69215aebc..c5190be7d18 100644 --- a/idea/testData/intentions/replaceSubstringWithTake/constantAsFirstArgument.kt +++ b/idea/testData/inspectionsLocal/replaceSubstring/withTake/constantAsFirstArgument.kt @@ -1,4 +1,4 @@ -// IS_APPLICABLE: false +// PROBLEM: none // WITH_RUNTIME const val x = 0 diff --git a/idea/testData/intentions/replaceSubstringWithTake/expressionAsFirstArgument.kt b/idea/testData/inspectionsLocal/replaceSubstring/withTake/expressionAsFirstArgument.kt similarity index 75% rename from idea/testData/intentions/replaceSubstringWithTake/expressionAsFirstArgument.kt rename to idea/testData/inspectionsLocal/replaceSubstring/withTake/expressionAsFirstArgument.kt index 36e5ccf7af2..e03f99b7b4b 100644 --- a/idea/testData/intentions/replaceSubstringWithTake/expressionAsFirstArgument.kt +++ b/idea/testData/inspectionsLocal/replaceSubstring/withTake/expressionAsFirstArgument.kt @@ -1,4 +1,4 @@ -// IS_APPLICABLE: false +// PROBLEM: none // WITH_RUNTIME fun foo(s: String) { diff --git a/idea/testData/intentions/replaceSubstringWithTake/nonZeroFirstArgument.kt b/idea/testData/inspectionsLocal/replaceSubstring/withTake/nonZeroFirstArgument.kt similarity index 74% rename from idea/testData/intentions/replaceSubstringWithTake/nonZeroFirstArgument.kt rename to idea/testData/inspectionsLocal/replaceSubstring/withTake/nonZeroFirstArgument.kt index eb6a50f3fea..18126789a94 100644 --- a/idea/testData/intentions/replaceSubstringWithTake/nonZeroFirstArgument.kt +++ b/idea/testData/inspectionsLocal/replaceSubstring/withTake/nonZeroFirstArgument.kt @@ -1,4 +1,4 @@ -// IS_APPLICABLE: false +// PROBLEM: none // WITH_RUNTIME fun foo(s: String) { diff --git a/idea/testData/intentions/replaceSubstringWithTake/replaceWithTake.kt b/idea/testData/inspectionsLocal/replaceSubstring/withTake/replaceWithTake.kt similarity index 100% rename from idea/testData/intentions/replaceSubstringWithTake/replaceWithTake.kt rename to idea/testData/inspectionsLocal/replaceSubstring/withTake/replaceWithTake.kt diff --git a/idea/testData/intentions/replaceSubstringWithTake/replaceWithTake.kt.after b/idea/testData/inspectionsLocal/replaceSubstring/withTake/replaceWithTake.kt.after similarity index 100% rename from idea/testData/intentions/replaceSubstringWithTake/replaceWithTake.kt.after rename to idea/testData/inspectionsLocal/replaceSubstring/withTake/replaceWithTake.kt.after diff --git a/idea/testData/intentions/replaceSubstringWithTake/semicolon.kt b/idea/testData/inspectionsLocal/replaceSubstring/withTake/semicolon.kt similarity index 100% rename from idea/testData/intentions/replaceSubstringWithTake/semicolon.kt rename to idea/testData/inspectionsLocal/replaceSubstring/withTake/semicolon.kt diff --git a/idea/testData/intentions/replaceSubstringWithTake/semicolon.kt.after b/idea/testData/inspectionsLocal/replaceSubstring/withTake/semicolon.kt.after similarity index 100% rename from idea/testData/intentions/replaceSubstringWithTake/semicolon.kt.after rename to idea/testData/inspectionsLocal/replaceSubstring/withTake/semicolon.kt.after diff --git a/idea/testData/intentions/replaceSubstringWithDropLast/.intention b/idea/testData/intentions/replaceSubstringWithDropLast/.intention deleted file mode 100644 index d1b3ab76c5d..00000000000 --- a/idea/testData/intentions/replaceSubstringWithDropLast/.intention +++ /dev/null @@ -1 +0,0 @@ -org.jetbrains.kotlin.idea.intentions.ReplaceSubstringWithDropLastIntention \ No newline at end of file diff --git a/idea/testData/intentions/replaceSubstringWithIndexingOperation/.intention b/idea/testData/intentions/replaceSubstringWithIndexingOperation/.intention deleted file mode 100644 index f9ec534107d..00000000000 --- a/idea/testData/intentions/replaceSubstringWithIndexingOperation/.intention +++ /dev/null @@ -1 +0,0 @@ -org.jetbrains.kotlin.idea.intentions.ReplaceSubstringWithIndexingOperationIntention \ No newline at end of file diff --git a/idea/testData/intentions/replaceSubstringWithSubstringAfter/.intention b/idea/testData/intentions/replaceSubstringWithSubstringAfter/.intention deleted file mode 100644 index 4bf5c8420bc..00000000000 --- a/idea/testData/intentions/replaceSubstringWithSubstringAfter/.intention +++ /dev/null @@ -1 +0,0 @@ -org.jetbrains.kotlin.idea.intentions.ReplaceSubstringWithSubstringAfterIntention \ No newline at end of file diff --git a/idea/testData/intentions/replaceSubstringWithSubstringBefore/.intention b/idea/testData/intentions/replaceSubstringWithSubstringBefore/.intention deleted file mode 100644 index d65912abba3..00000000000 --- a/idea/testData/intentions/replaceSubstringWithSubstringBefore/.intention +++ /dev/null @@ -1 +0,0 @@ -org.jetbrains.kotlin.idea.intentions.ReplaceSubstringWithSubstringBeforeIntention \ No newline at end of file diff --git a/idea/testData/intentions/replaceSubstringWithTake/.intention b/idea/testData/intentions/replaceSubstringWithTake/.intention deleted file mode 100644 index 8cc60dcc852..00000000000 --- a/idea/testData/intentions/replaceSubstringWithTake/.intention +++ /dev/null @@ -1 +0,0 @@ -org.jetbrains.kotlin.idea.intentions.ReplaceSubstringWithTakeIntention \ 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 10c91fd22c1..372c7beed7f 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -8211,6 +8211,194 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { } } + @TestMetadata("idea/testData/inspectionsLocal/replaceSubstring") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class ReplaceSubstring extends AbstractLocalInspectionTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInReplaceSubstring() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/replaceSubstring"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + } + + @TestMetadata("idea/testData/inspectionsLocal/replaceSubstring/withDropLast") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class WithDropLast extends AbstractLocalInspectionTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInWithDropLast() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/replaceSubstring/withDropLast"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + } + + @TestMetadata("immutableProperty.kt") + public void testImmutableProperty() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceSubstring/withDropLast/immutableProperty.kt"); + } + + @TestMetadata("methodCallReceiver.kt") + public void testMethodCallReceiver() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceSubstring/withDropLast/methodCallReceiver.kt"); + } + + @TestMetadata("nonZeroFirstArgument.kt") + public void testNonZeroFirstArgument() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceSubstring/withDropLast/nonZeroFirstArgument.kt"); + } + + @TestMetadata("replaceWithDropLast.kt") + public void testReplaceWithDropLast() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceSubstring/withDropLast/replaceWithDropLast.kt"); + } + + @TestMetadata("semicolon.kt") + public void testSemicolon() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceSubstring/withDropLast/semicolon.kt"); + } + } + + @TestMetadata("idea/testData/inspectionsLocal/replaceSubstring/withIndexingOperation") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class WithIndexingOperation extends AbstractLocalInspectionTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInWithIndexingOperation() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/replaceSubstring/withIndexingOperation"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + } + + @TestMetadata("oneFirstTwoSecondArgument.kt") + public void testOneFirstTwoSecondArgument() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceSubstring/withIndexingOperation/oneFirstTwoSecondArgument.kt"); + } + + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceSubstring/withIndexingOperation/simple.kt"); + } + + @TestMetadata("zeroFirstTenSecondArgument.kt") + public void testZeroFirstTenSecondArgument() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceSubstring/withIndexingOperation/zeroFirstTenSecondArgument.kt"); + } + } + + @TestMetadata("idea/testData/inspectionsLocal/replaceSubstring/withSubstringAfter") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class WithSubstringAfter extends AbstractLocalInspectionTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInWithSubstringAfter() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/replaceSubstring/withSubstringAfter"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + } + + @TestMetadata("immutableProperty.kt") + public void testImmutableProperty() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceSubstring/withSubstringAfter/immutableProperty.kt"); + } + + @TestMetadata("methodCallReceiver.kt") + public void testMethodCallReceiver() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceSubstring/withSubstringAfter/methodCallReceiver.kt"); + } + + @TestMetadata("replaceWithSubstringAfter.kt") + public void testReplaceWithSubstringAfter() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceSubstring/withSubstringAfter/replaceWithSubstringAfter.kt"); + } + + @TestMetadata("semicolon.kt") + public void testSemicolon() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceSubstring/withSubstringAfter/semicolon.kt"); + } + } + + @TestMetadata("idea/testData/inspectionsLocal/replaceSubstring/withSubstringBefore") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class WithSubstringBefore extends AbstractLocalInspectionTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInWithSubstringBefore() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/replaceSubstring/withSubstringBefore"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + } + + @TestMetadata("immutableProperty.kt") + public void testImmutableProperty() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceSubstring/withSubstringBefore/immutableProperty.kt"); + } + + @TestMetadata("methodCallReceiver.kt") + public void testMethodCallReceiver() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceSubstring/withSubstringBefore/methodCallReceiver.kt"); + } + + @TestMetadata("nonZeroFirstArgument.kt") + public void testNonZeroFirstArgument() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceSubstring/withSubstringBefore/nonZeroFirstArgument.kt"); + } + + @TestMetadata("replaceWithSubstringBefore.kt") + public void testReplaceWithSubstringBefore() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceSubstring/withSubstringBefore/replaceWithSubstringBefore.kt"); + } + + @TestMetadata("semicolon.kt") + public void testSemicolon() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceSubstring/withSubstringBefore/semicolon.kt"); + } + } + + @TestMetadata("idea/testData/inspectionsLocal/replaceSubstring/withTake") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class WithTake extends AbstractLocalInspectionTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInWithTake() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/replaceSubstring/withTake"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + } + + @TestMetadata("constantAsFirstArgument.kt") + public void testConstantAsFirstArgument() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceSubstring/withTake/constantAsFirstArgument.kt"); + } + + @TestMetadata("expressionAsFirstArgument.kt") + public void testExpressionAsFirstArgument() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceSubstring/withTake/expressionAsFirstArgument.kt"); + } + + @TestMetadata("nonZeroFirstArgument.kt") + public void testNonZeroFirstArgument() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceSubstring/withTake/nonZeroFirstArgument.kt"); + } + + @TestMetadata("replaceWithTake.kt") + public void testReplaceWithTake() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceSubstring/withTake/replaceWithTake.kt"); + } + + @TestMetadata("semicolon.kt") + public void testSemicolon() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceSubstring/withTake/semicolon.kt"); + } + } + } + @TestMetadata("idea/testData/inspectionsLocal/replaceToStringWithStringTemplate") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java index b1468709663..d992c1eddd1 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -15115,181 +15115,6 @@ public class IntentionTestGenerated extends AbstractIntentionTest { } } - @TestMetadata("idea/testData/intentions/replaceSubstringWithDropLast") - @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class ReplaceSubstringWithDropLast extends AbstractIntentionTest { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); - } - - public void testAllFilesPresentInReplaceSubstringWithDropLast() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/replaceSubstringWithDropLast"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true); - } - - @TestMetadata("immutableProperty.kt") - public void testImmutableProperty() throws Exception { - runTest("idea/testData/intentions/replaceSubstringWithDropLast/immutableProperty.kt"); - } - - @TestMetadata("methodCallReceiver.kt") - public void testMethodCallReceiver() throws Exception { - runTest("idea/testData/intentions/replaceSubstringWithDropLast/methodCallReceiver.kt"); - } - - @TestMetadata("nonZeroFirstArgument.kt") - public void testNonZeroFirstArgument() throws Exception { - runTest("idea/testData/intentions/replaceSubstringWithDropLast/nonZeroFirstArgument.kt"); - } - - @TestMetadata("replaceWithDropLast.kt") - public void testReplaceWithDropLast() throws Exception { - runTest("idea/testData/intentions/replaceSubstringWithDropLast/replaceWithDropLast.kt"); - } - - @TestMetadata("semicolon.kt") - public void testSemicolon() throws Exception { - runTest("idea/testData/intentions/replaceSubstringWithDropLast/semicolon.kt"); - } - } - - @TestMetadata("idea/testData/intentions/replaceSubstringWithIndexingOperation") - @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class ReplaceSubstringWithIndexingOperation extends AbstractIntentionTest { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); - } - - 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 { - runTest("idea/testData/intentions/replaceSubstringWithIndexingOperation/oneFirstTwoSecondArgument.kt"); - } - - @TestMetadata("simple.kt") - public void testSimple() throws Exception { - runTest("idea/testData/intentions/replaceSubstringWithIndexingOperation/simple.kt"); - } - - @TestMetadata("zeroFirstTenSecondArgument.kt") - public void testZeroFirstTenSecondArgument() throws Exception { - runTest("idea/testData/intentions/replaceSubstringWithIndexingOperation/zeroFirstTenSecondArgument.kt"); - } - } - - @TestMetadata("idea/testData/intentions/replaceSubstringWithSubstringAfter") - @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class ReplaceSubstringWithSubstringAfter extends AbstractIntentionTest { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); - } - - public void testAllFilesPresentInReplaceSubstringWithSubstringAfter() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/replaceSubstringWithSubstringAfter"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true); - } - - @TestMetadata("immutableProperty.kt") - public void testImmutableProperty() throws Exception { - runTest("idea/testData/intentions/replaceSubstringWithSubstringAfter/immutableProperty.kt"); - } - - @TestMetadata("methodCallReceiver.kt") - public void testMethodCallReceiver() throws Exception { - runTest("idea/testData/intentions/replaceSubstringWithSubstringAfter/methodCallReceiver.kt"); - } - - @TestMetadata("replaceWithSubstringAfter.kt") - public void testReplaceWithSubstringAfter() throws Exception { - runTest("idea/testData/intentions/replaceSubstringWithSubstringAfter/replaceWithSubstringAfter.kt"); - } - - @TestMetadata("semicolon.kt") - public void testSemicolon() throws Exception { - runTest("idea/testData/intentions/replaceSubstringWithSubstringAfter/semicolon.kt"); - } - } - - @TestMetadata("idea/testData/intentions/replaceSubstringWithSubstringBefore") - @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class ReplaceSubstringWithSubstringBefore extends AbstractIntentionTest { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); - } - - public void testAllFilesPresentInReplaceSubstringWithSubstringBefore() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/replaceSubstringWithSubstringBefore"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true); - } - - @TestMetadata("immutableProperty.kt") - public void testImmutableProperty() throws Exception { - runTest("idea/testData/intentions/replaceSubstringWithSubstringBefore/immutableProperty.kt"); - } - - @TestMetadata("methodCallReceiver.kt") - public void testMethodCallReceiver() throws Exception { - runTest("idea/testData/intentions/replaceSubstringWithSubstringBefore/methodCallReceiver.kt"); - } - - @TestMetadata("nonZeroFirstArgument.kt") - public void testNonZeroFirstArgument() throws Exception { - runTest("idea/testData/intentions/replaceSubstringWithSubstringBefore/nonZeroFirstArgument.kt"); - } - - @TestMetadata("replaceWithSubstringBefore.kt") - public void testReplaceWithSubstringBefore() throws Exception { - runTest("idea/testData/intentions/replaceSubstringWithSubstringBefore/replaceWithSubstringBefore.kt"); - } - - @TestMetadata("semicolon.kt") - public void testSemicolon() throws Exception { - runTest("idea/testData/intentions/replaceSubstringWithSubstringBefore/semicolon.kt"); - } - } - - @TestMetadata("idea/testData/intentions/replaceSubstringWithTake") - @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class ReplaceSubstringWithTake extends AbstractIntentionTest { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); - } - - public void testAllFilesPresentInReplaceSubstringWithTake() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/replaceSubstringWithTake"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true); - } - - @TestMetadata("constantAsFirstArgument.kt") - public void testConstantAsFirstArgument() throws Exception { - runTest("idea/testData/intentions/replaceSubstringWithTake/constantAsFirstArgument.kt"); - } - - @TestMetadata("expressionAsFirstArgument.kt") - public void testExpressionAsFirstArgument() throws Exception { - runTest("idea/testData/intentions/replaceSubstringWithTake/expressionAsFirstArgument.kt"); - } - - @TestMetadata("nonZeroFirstArgument.kt") - public void testNonZeroFirstArgument() throws Exception { - runTest("idea/testData/intentions/replaceSubstringWithTake/nonZeroFirstArgument.kt"); - } - - @TestMetadata("replaceWithTake.kt") - public void testReplaceWithTake() throws Exception { - runTest("idea/testData/intentions/replaceSubstringWithTake/replaceWithTake.kt"); - } - - @TestMetadata("semicolon.kt") - public void testSemicolon() throws Exception { - runTest("idea/testData/intentions/replaceSubstringWithTake/semicolon.kt"); - } - } - @TestMetadata("idea/testData/intentions/replaceUnderscoreWithParameterName") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)