changeset 4031:5a620c54268e

8176412: jshell tool: automatic imports are excluded on /reload causing it to fail Reviewed-by: jlahoda
author rfield
date Thu, 09 Mar 2017 08:45:21 -0800
parents a60be0cc160b
children e9e81bd49607
files src/jdk.jshell/share/classes/jdk/internal/jshell/tool/ConsoleIOContext.java src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java
diffstat 2 files changed, 10 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/ConsoleIOContext.java	Thu Mar 09 06:34:06 2017 -0800
+++ b/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/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java	Thu Mar 09 06:34:06 2017 -0800
+++ b/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;