diff --git a/idea/resources/intentionDescriptions/ConvertToRawStringTemplateIntention/after.kt.template b/idea/resources/intentionDescriptions/ConvertToRawStringTemplateIntention/after.kt.template
new file mode 100644
index 00000000000..5018f3ae1eb
--- /dev/null
+++ b/idea/resources/intentionDescriptions/ConvertToRawStringTemplateIntention/after.kt.template
@@ -0,0 +1,2 @@
+val x = "World"
+val y = """Hello $x"""
diff --git a/idea/resources/intentionDescriptions/ConvertToRawStringTemplateIntention/before.kt.template b/idea/resources/intentionDescriptions/ConvertToRawStringTemplateIntention/before.kt.template
new file mode 100644
index 00000000000..aa02c31e6cd
--- /dev/null
+++ b/idea/resources/intentionDescriptions/ConvertToRawStringTemplateIntention/before.kt.template
@@ -0,0 +1,2 @@
+val x = "World"
+val y = "Hello " + x
diff --git a/idea/resources/intentionDescriptions/ConvertToRawStringTemplateIntention/description.html b/idea/resources/intentionDescriptions/ConvertToRawStringTemplateIntention/description.html
new file mode 100644
index 00000000000..013ac7367ca
--- /dev/null
+++ b/idea/resources/intentionDescriptions/ConvertToRawStringTemplateIntention/description.html
@@ -0,0 +1,5 @@
+
+
+Converts a statement that builds a String using '+' to one that builds a String using a raw String
+
+
diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml
index 5256681c30e..afbce5a6333 100644
--- a/idea/src/META-INF/plugin.xml
+++ b/idea/src/META-INF/plugin.xml
@@ -1169,6 +1169,11 @@
Kotlin
+
+ org.jetbrains.kotlin.idea.intentions.ConvertToRawStringTemplateIntention
+ Kotlin
+
+
org.jetbrains.kotlin.idea.intentions.OperatorToFunctionIntention
Kotlin
diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToRawStringTemplateIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToRawStringTemplateIntention.kt
new file mode 100644
index 00000000000..dff6fd6e2db
--- /dev/null
+++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToRawStringTemplateIntention.kt
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2010-2017 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 org.jetbrains.kotlin.idea.core.replaced
+import org.jetbrains.kotlin.psi.KtBinaryExpression
+
+class ConvertToRawStringTemplateIntention : ConvertToStringTemplateIntention() {
+ init {
+ text = "Convert concatenation to raw string"
+ }
+
+ override fun applyTo(element: KtBinaryExpression, editor: Editor?) {
+ val replaced = element.replaced(buildReplacement(element))
+ ToRawStringLiteralIntention().applyTo(replaced, editor)
+ }
+}
\ No newline at end of file
diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToStringTemplateIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToStringTemplateIntention.kt
index ab77b68cee3..1af13f92f91 100644
--- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToStringTemplateIntention.kt
+++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToStringTemplateIntention.kt
@@ -1,5 +1,5 @@
/*
- * Copyright 2010-2015 JetBrains s.r.o.
+ * Copyright 2010-2017 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.
@@ -33,7 +33,7 @@ class ConvertToStringTemplateInspection : IntentionBasedInspection ConvertToStringTemplateIntention.shouldSuggestToConvert(it) }
)
-class ConvertToStringTemplateIntention : SelfTargetingOffsetIndependentIntention(KtBinaryExpression::class.java, "Convert concatenation to template") {
+open class ConvertToStringTemplateIntention : SelfTargetingOffsetIndependentIntention(KtBinaryExpression::class.java, "Convert concatenation to template") {
override fun isApplicableTo(element: KtBinaryExpression): Boolean {
if (!isApplicableToNoParentCheck(element)) return false
@@ -56,7 +56,8 @@ class ConvertToStringTemplateIntention : SelfTargetingOffsetIndependentIntention
&& !expression.textContains('\n')
}
- private fun buildReplacement(expression: KtBinaryExpression): KtStringTemplateExpression {
+ @JvmStatic
+ protected fun buildReplacement(expression: KtBinaryExpression): KtStringTemplateExpression {
val rightText = buildText(expression.right, false)
return fold(expression.left, rightText, KtPsiFactory(expression))
}
diff --git a/idea/testData/intentions/convertToRawStringTemplate/.intention b/idea/testData/intentions/convertToRawStringTemplate/.intention
new file mode 100644
index 00000000000..954d2d5d7b1
--- /dev/null
+++ b/idea/testData/intentions/convertToRawStringTemplate/.intention
@@ -0,0 +1 @@
+org.jetbrains.kotlin.idea.intentions.ConvertToRawStringTemplateIntention
diff --git a/idea/testData/intentions/convertToRawStringTemplate/basic.kt b/idea/testData/intentions/convertToRawStringTemplate/basic.kt
new file mode 100644
index 00000000000..eefc1364f37
--- /dev/null
+++ b/idea/testData/intentions/convertToRawStringTemplate/basic.kt
@@ -0,0 +1,2 @@
+val foo = "abc\n" +
+ "xyz"
\ No newline at end of file
diff --git a/idea/testData/intentions/convertToRawStringTemplate/basic.kt.after b/idea/testData/intentions/convertToRawStringTemplate/basic.kt.after
new file mode 100644
index 00000000000..821e2b7b361
--- /dev/null
+++ b/idea/testData/intentions/convertToRawStringTemplate/basic.kt.after
@@ -0,0 +1,2 @@
+val foo = """abc
+xyz"""
\ 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 ffc4c60c7d6..a5838cfcae8 100644
--- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java
+++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java
@@ -6570,6 +6570,21 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
}
}
+ @TestMetadata("idea/testData/intentions/convertToRawStringTemplate")
+ @TestDataPath("$PROJECT_ROOT")
+ @RunWith(JUnit3RunnerWithInners.class)
+ public static class ConvertToRawStringTemplate extends AbstractIntentionTest {
+ public void testAllFilesPresentInConvertToRawStringTemplate() throws Exception {
+ KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/convertToRawStringTemplate"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true);
+ }
+
+ @TestMetadata("basic.kt")
+ public void testBasic() throws Exception {
+ String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertToRawStringTemplate/basic.kt");
+ doTest(fileName);
+ }
+ }
+
@TestMetadata("idea/testData/intentions/convertToRun")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)