From eb12cfd444934a6a7be03b036fb195e3cef697f8 Mon Sep 17 00:00:00 2001 From: Toshiaki Kameyama Date: Wed, 3 Jan 2018 19:27:16 +0900 Subject: [PATCH] KT-18674 Join Lines should join strings (#1305) * Join Lines should join strings #KT-18674 Fixed * #KT-18674 Fixed --- idea/src/META-INF/plugin.xml | 1 + .../ConvertToStringTemplateIntention.kt | 4 +- .../joinLines/JoinToStringTemplateHandler.kt | 50 +++++++++++++++++++ .../stringTemplate/firstLineVariable.kt | 5 ++ .../stringTemplate/firstLineVariable.kt.after | 4 ++ .../stringTemplate/secondLineVariable.kt | 5 ++ .../secondLineVariable.kt.after | 4 ++ .../joinLines/stringTemplate/simple.kt | 4 ++ .../joinLines/stringTemplate/simple.kt.after | 3 ++ .../joinLines/stringTemplate/threeLines.kt | 5 ++ .../stringTemplate/threeLines.kt.after | 4 ++ .../declarations/JoinLinesTestGenerated.java | 33 ++++++++++++ 12 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 idea/src/org/jetbrains/kotlin/idea/joinLines/JoinToStringTemplateHandler.kt create mode 100644 idea/testData/joinLines/stringTemplate/firstLineVariable.kt create mode 100644 idea/testData/joinLines/stringTemplate/firstLineVariable.kt.after create mode 100644 idea/testData/joinLines/stringTemplate/secondLineVariable.kt create mode 100644 idea/testData/joinLines/stringTemplate/secondLineVariable.kt.after create mode 100644 idea/testData/joinLines/stringTemplate/simple.kt create mode 100644 idea/testData/joinLines/stringTemplate/simple.kt.after create mode 100644 idea/testData/joinLines/stringTemplate/threeLines.kt create mode 100644 idea/testData/joinLines/stringTemplate/threeLines.kt.after diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index b5bc7f9af0f..7d3ee5a2907 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -727,6 +727,7 @@ + + "bar" +} \ No newline at end of file diff --git a/idea/testData/joinLines/stringTemplate/firstLineVariable.kt.after b/idea/testData/joinLines/stringTemplate/firstLineVariable.kt.after new file mode 100644 index 00000000000..588d2b2e799 --- /dev/null +++ b/idea/testData/joinLines/stringTemplate/firstLineVariable.kt.after @@ -0,0 +1,4 @@ +fun test() { + val foo = "1" + val s = foo + "bar" +} \ No newline at end of file diff --git a/idea/testData/joinLines/stringTemplate/secondLineVariable.kt b/idea/testData/joinLines/stringTemplate/secondLineVariable.kt new file mode 100644 index 00000000000..188610ddb4d --- /dev/null +++ b/idea/testData/joinLines/stringTemplate/secondLineVariable.kt @@ -0,0 +1,5 @@ +fun test() { + val foo = "1" + val s = "bar" + + foo +} \ No newline at end of file diff --git a/idea/testData/joinLines/stringTemplate/secondLineVariable.kt.after b/idea/testData/joinLines/stringTemplate/secondLineVariable.kt.after new file mode 100644 index 00000000000..68df4130f30 --- /dev/null +++ b/idea/testData/joinLines/stringTemplate/secondLineVariable.kt.after @@ -0,0 +1,4 @@ +fun test() { + val foo = "1" + val s = "bar" + foo +} \ No newline at end of file diff --git a/idea/testData/joinLines/stringTemplate/simple.kt b/idea/testData/joinLines/stringTemplate/simple.kt new file mode 100644 index 00000000000..30709391ee6 --- /dev/null +++ b/idea/testData/joinLines/stringTemplate/simple.kt @@ -0,0 +1,4 @@ +fun test() { + val s = "foo" + + "bar" +} \ No newline at end of file diff --git a/idea/testData/joinLines/stringTemplate/simple.kt.after b/idea/testData/joinLines/stringTemplate/simple.kt.after new file mode 100644 index 00000000000..53f0a7490a2 --- /dev/null +++ b/idea/testData/joinLines/stringTemplate/simple.kt.after @@ -0,0 +1,3 @@ +fun test() { + val s = "foobar" +} \ No newline at end of file diff --git a/idea/testData/joinLines/stringTemplate/threeLines.kt b/idea/testData/joinLines/stringTemplate/threeLines.kt new file mode 100644 index 00000000000..260502316c3 --- /dev/null +++ b/idea/testData/joinLines/stringTemplate/threeLines.kt @@ -0,0 +1,5 @@ +fun test() { + val s = "foo" + + "bar" + + "baz" +} \ No newline at end of file diff --git a/idea/testData/joinLines/stringTemplate/threeLines.kt.after b/idea/testData/joinLines/stringTemplate/threeLines.kt.after new file mode 100644 index 00000000000..ae29b808428 --- /dev/null +++ b/idea/testData/joinLines/stringTemplate/threeLines.kt.after @@ -0,0 +1,4 @@ +fun test() { + val s = "foobar" + + "baz" +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/declarations/JoinLinesTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/intentions/declarations/JoinLinesTestGenerated.java index d17ebbc20a1..120efc43ab3 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/declarations/JoinLinesTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/declarations/JoinLinesTestGenerated.java @@ -425,4 +425,37 @@ public class JoinLinesTestGenerated extends AbstractJoinLinesTest { doTest(fileName); } } + + @TestMetadata("idea/testData/joinLines/stringTemplate") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class StringTemplate extends AbstractJoinLinesTest { + public void testAllFilesPresentInStringTemplate() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/joinLines/stringTemplate"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("firstLineVariable.kt") + public void testFirstLineVariable() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/joinLines/stringTemplate/firstLineVariable.kt"); + doTest(fileName); + } + + @TestMetadata("secondLineVariable.kt") + public void testSecondLineVariable() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/joinLines/stringTemplate/secondLineVariable.kt"); + doTest(fileName); + } + + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/joinLines/stringTemplate/simple.kt"); + doTest(fileName); + } + + @TestMetadata("threeLines.kt") + public void testThreeLines() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/joinLines/stringTemplate/threeLines.kt"); + doTest(fileName); + } + } }