8198573: JShell: class replace loses instances

Reviewed-by: jlahoda
This commit is contained in:
Robert Field 2018-02-23 10:49:56 -08:00
parent f23f23fc76
commit b2ed2bda60
5 changed files with 17 additions and 6 deletions

View File

@ -87,6 +87,6 @@ public abstract class DeclarationSnippet extends PersistentSnippet {
@Override
String importLine(JShell state) {
return "import static " + classFullName() + "." + name() + ";\n";
return "import static " + classFullName() + "." + name() + "; ";
}
}

View File

@ -64,7 +64,7 @@ class OuterWrapMap {
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");

View File

@ -79,9 +79,9 @@ public class VarSnippet extends DeclarationSnippet {
@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());
}

View File

@ -230,7 +230,7 @@ public class StartOptionTest {
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);
}

View File

@ -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 @@ public class ToolSimpleTest extends ReplToolTesting {
(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@")
);
}
}