changeset 49119:ca22f8cb0c9b

8198573: JShell: class replace loses instances Reviewed-by: jlahoda
author rfield
date Fri, 23 Feb 2018 10:49:56 -0800
parents ba545e52b932
children 4f11514fe783
files src/jdk.jshell/share/classes/jdk/jshell/DeclarationSnippet.java src/jdk.jshell/share/classes/jdk/jshell/OuterWrapMap.java src/jdk.jshell/share/classes/jdk/jshell/VarSnippet.java test/langtools/jdk/jshell/StartOptionTest.java test/langtools/jdk/jshell/ToolSimpleTest.java
diffstat 5 files changed, 17 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.jshell/share/classes/jdk/jshell/DeclarationSnippet.java	Fri Feb 23 10:25:22 2018 -0800
+++ b/src/jdk.jshell/share/classes/jdk/jshell/DeclarationSnippet.java	Fri Feb 23 10:49:56 2018 -0800
@@ -87,6 +87,6 @@
 
     @Override
     String importLine(JShell state) {
-        return "import static " + classFullName() + "." + name() + ";\n";
+        return "import static " + classFullName() + "." + name() + ";  ";
     }
 }
--- a/src/jdk.jshell/share/classes/jdk/jshell/OuterWrapMap.java	Fri Feb 23 10:25:22 2018 -0800
+++ b/src/jdk.jshell/share/classes/jdk/jshell/OuterWrapMap.java	Fri Feb 23 10:49:56 2018 -0800
@@ -64,7 +64,7 @@
 
     private CompoundWrap wrappedInClass(String className, String imports, List<Wrap> wraps) {
         List<Object> elems = new ArrayList<>(wraps.size() + 2);
-        elems.add(imports +
+        elems.add(imports + "\n" +
                 "class " + className + " {\n");
         elems.addAll(wraps);
         elems.add("}\n");
--- a/src/jdk.jshell/share/classes/jdk/jshell/VarSnippet.java	Fri Feb 23 10:25:22 2018 -0800
+++ b/src/jdk.jshell/share/classes/jdk/jshell/VarSnippet.java	Fri Feb 23 10:49:56 2018 -0800
@@ -79,9 +79,9 @@
 
     @Override
     String importLine(JShell state) {
-        return "import static " + classFullName() + "." + name() + ";\n" +
+        return "import static " + classFullName() + "." + name() + ";   " +
                anonymousClasses.stream()
-                               .map(c -> "import static " + classFullName() + "." + c + ";\n")
+                               .map(c -> "import static " + classFullName() + "." + c + ";   ")
                                .collect(Collectors.joining());
     }
 
--- a/test/langtools/jdk/jshell/StartOptionTest.java	Fri Feb 23 10:25:22 2018 -0800
+++ b/test/langtools/jdk/jshell/StartOptionTest.java	Fri Feb 23 10:49:56 2018 -0800
@@ -230,7 +230,7 @@
             startCo(s -> {
                 assertTrue(s.split("\n").length >= 5, "Not enough help-extra lines: " + s);
                 assertTrue(s.contains("--add-exports"), "Expected --add-exports: " + s);
-                assertTrue(s.contains("--execution"), "Expected --add-exports: " + s);
+                assertTrue(s.contains("--execution"), "Expected --execution: " + s);
                 assertFalse(s.contains("Welcome"), "Unexpected start: " + s);
             }, opt);
         }
--- a/test/langtools/jdk/jshell/ToolSimpleTest.java	Fri Feb 23 10:25:22 2018 -0800
+++ b/test/langtools/jdk/jshell/ToolSimpleTest.java	Fri Feb 23 10:49:56 2018 -0800
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8153716 8143955 8151754 8150382 8153920 8156910 8131024 8160089 8153897 8167128 8154513 8170015 8170368 8172102 8172103  8165405 8173073 8173848 8174041 8173916 8174028 8174262 8174797 8177079 8180508 8177466 8172154 8192979 8191842
+ * @bug 8153716 8143955 8151754 8150382 8153920 8156910 8131024 8160089 8153897 8167128 8154513 8170015 8170368 8172102 8172103  8165405 8173073 8173848 8174041 8173916 8174028 8174262 8174797 8177079 8180508 8177466 8172154 8192979 8191842 8198573
  * @summary Simple jshell tool tests
  * @modules jdk.compiler/com.sun.tools.javac.api
  *          jdk.compiler/com.sun.tools.javac.main
@@ -793,4 +793,15 @@
                 (a) -> assertCommandOutputContains(a, "/vars list", "|    List<<anonymous class extending Object>> list = ")
         );
     }
+
+    // This is mainly interesting in the TestLocalSimpleTest case (8198573)
+    @Test
+    public void testUpdateFalsePositive() {
+        test(
+                a -> assertClass(a, "class A { int a() { int error = 0; return error; } }", "class", "A"),
+                a -> assertVariable(a, "A", "a", "new A()", "A@.+"),
+                a -> assertVariable(a, "int", "error", "4711", "4711"),
+                a -> assertCommandOutputContains(a, "a", "A@")
+        );
+    }
 }