8176412: jshell tool: automatic imports are excluded on /reload causing it to fail
authorrfield
Thu, 09 Mar 2017 08:45:21 -0800
changeset 44188 3f2047e62102
parent 44187 c56d85ea6c89
child 44189 dd311cfb920b
8176412: jshell tool: automatic imports are excluded on /reload causing it to fail Reviewed-by: jlahoda
langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/ConsoleIOContext.java
langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java
--- a/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/ConsoleIOContext.java	Thu Mar 09 06:34:06 2017 -0800
+++ b/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/ConsoleIOContext.java	Thu Mar 09 08:45:21 2017 -0800
@@ -43,7 +43,6 @@
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
-import java.util.Objects;
 import java.util.Optional;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.function.Function;
@@ -82,7 +81,7 @@
 
     ConsoleIOContext(JShellTool repl, InputStream cmdin, PrintStream cmdout) throws Exception {
         this.repl = repl;
-        this.input = new StopDetectingInputStream(() -> repl.state.stop(), ex -> repl.hard("Error on input: %s", ex));
+        this.input = new StopDetectingInputStream(() -> repl.stop(), ex -> repl.hard("Error on input: %s", ex));
         Terminal term;
         if (System.getProperty("test.jdk") != null) {
             term = new TestTerminal(input);
@@ -617,7 +616,7 @@
 
                             @Override
                             public void perform(ConsoleReader in) throws IOException {
-                                repl.state.eval("import " + type + ";");
+                                repl.processCompleteSource("import " + type + ";");
                                 in.println("Imported: " + type);
                                 performToVar(in, stype);
                             }
@@ -641,7 +640,7 @@
 
                         @Override
                         public void perform(ConsoleReader in) throws IOException {
-                            repl.state.eval("import " + fqn + ";");
+                            repl.processCompleteSource("import " + fqn + ";");
                             in.println("Imported: " + fqn);
                             in.redrawLine();
                         }
--- a/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java	Thu Mar 09 06:34:06 2017 -0800
+++ b/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java	Thu Mar 09 08:45:21 2017 -0800
@@ -187,7 +187,7 @@
     private Options options;
 
     SourceCodeAnalysis analysis;
-    JShell state = null;
+    private JShell state = null;
     Subscription shutdownSubscription = null;
 
     static final EditorSetting BUILT_IN_EDITOR = new EditorSetting(null, false);
@@ -1704,6 +1704,11 @@
         return null;
     }
 
+    // Attempt to stop currently running evaluation
+    void stop() {
+        state.stop();
+    }
+
     // --- Command implementations ---
 
     private static final String[] SET_SUBCOMMANDS = new String[]{
@@ -2857,7 +2862,7 @@
         }
     }
     //where
-    private boolean processCompleteSource(String source) throws IllegalStateException {
+    boolean processCompleteSource(String source) throws IllegalStateException {
         debug("Compiling: %s", source);
         boolean failed = false;
         boolean isActive = false;