8173073: jshell tool: blank lines removed from multi-line snippets
authorrfield
Fri, 20 Jan 2017 11:05:48 -0800
changeset 43274 6b5ed4f9fb81
parent 43273 2614e1907a0b
child 43276 0f8dd574fa0a
8173073: jshell tool: blank lines removed from multi-line snippets Reviewed-by: jlahoda
langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java
langtools/test/jdk/jshell/ToolSimpleTest.java
--- a/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java	Fri Jan 20 08:29:59 2017 -0800
+++ b/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java	Fri Jan 20 11:05:48 2017 -0800
@@ -987,7 +987,7 @@
                     break;
                 }
                 String trimmed = trimEnd(raw);
-                if (!trimmed.isEmpty()) {
+                if (!trimmed.isEmpty() || !incomplete.isEmpty()) {
                     String line = incomplete + trimmed;
 
                     // No commands in the middle of unprocessed source
--- a/langtools/test/jdk/jshell/ToolSimpleTest.java	Fri Jan 20 08:29:59 2017 -0800
+++ b/langtools/test/jdk/jshell/ToolSimpleTest.java	Fri Jan 20 11:05:48 2017 -0800
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8153716 8143955 8151754 8150382 8153920 8156910 8131024 8160089 8153897 8167128 8154513 8170015 8170368 8172102 8172103  8165405
+ * @bug 8153716 8143955 8151754 8150382 8153920 8156910 8131024 8160089 8153897 8167128 8154513 8170015 8170368 8172102 8172103  8165405 8173073
  * @summary Simple jshell tool tests
  * @modules jdk.compiler/com.sun.tools.javac.api
  *          jdk.compiler/com.sun.tools.javac.main
@@ -496,6 +496,35 @@
     }
 
     @Test
+    public void testBlankLinesInSnippetContinuation() {
+        test(Locale.ROOT, false, new String[]{"--no-startup"}, "",
+                a -> assertCommand(a, "class C {",
+                        ""),
+                a -> assertCommand(a, "",
+                        ""),
+                a -> assertCommand(a, "",
+                        ""),
+                a -> assertCommand(a, "  int x;",
+                        ""),
+                a -> assertCommand(a, "",
+                        ""),
+                a -> assertCommand(a, "",
+                        ""),
+                a -> assertCommand(a, "}",
+                        "|  created class C"),
+                a -> assertCommand(a, "/list",
+                        "\n" +
+                        "   1 : class C {\n" +
+                        "       \n" +
+                        "       \n" +
+                        "         int x;\n" +
+                        "       \n" +
+                        "       \n" +
+                        "       }")
+        );
+    }
+
+    @Test
     public void testCompoundStart() {
         test(new String[]{"--startup", "DEFAULT", "--startup", "PRINTING"},
                 (a) -> assertCommand(a, "printf(\"%4.2f\", Math.PI)",