langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java
changeset 37389 9c137b83a8b8
parent 37007 6023a9a9d58a
child 37745 4b6b59f8e327
equal deleted inserted replaced
37011:c84d0cce090e 37389:9c137b83a8b8
  1075                     String n;
  1075                     String n;
  1076                     while ((n = at.next()) != null) {
  1076                     while ((n = at.next()) != null) {
  1077                         ed.add(n);
  1077                         ed.add(n);
  1078                     }
  1078                     }
  1079                     editor = ed.toArray(new String[ed.size()]);
  1079                     editor = ed.toArray(new String[ed.size()]);
  1080                     fluffmsg("jshell.msg.set.editor.set", arg);
  1080                     fluffmsg("jshell.msg.set.editor.set", prog);
  1081                     return true;
  1081                     return true;
  1082                 }
  1082                 }
  1083             }
  1083             }
  1084             case "start": {
  1084             case "start": {
  1085                 String init = readFile(at.next(), "'/set start'");
  1085                 String init = readFile(at.next(), "/set start");
  1086                 if (init == null) {
  1086                 if (init == null) {
  1087                     return false;
  1087                     return false;
  1088                 } else {
  1088                 } else {
  1089                     prefs.put(STARTUP_KEY, init);
  1089                     prefs.put(STARTUP_KEY, init);
  1090                     return true;
  1090                     return true;
  1349         }
  1349         }
  1350         List<Snippet> snippets = stream
  1350         List<Snippet> snippets = stream
  1351                 .filter(sn -> state.status(sn).isActive && sn instanceof PersistentSnippet)
  1351                 .filter(sn -> state.status(sn).isActive && sn instanceof PersistentSnippet)
  1352                 .collect(toList());
  1352                 .collect(toList());
  1353         if (snippets.isEmpty()) {
  1353         if (snippets.isEmpty()) {
  1354             errormsg("jshell.err.drop.active");
  1354             errormsg("jshell.err.drop.not.active");
  1355             return false;
  1355             return false;
  1356         }
  1356         }
  1357         if (snippets.size() > 1) {
  1357         if (snippets.size() > 1) {
  1358             errormsg("jshell.err.drop.ambiguous");
  1358             errormsg("jshell.err.drop.ambiguous");
  1359             fluffmsg("jshell.msg.use.one.of", snippets.stream()
  1359             fluffmsg("jshell.msg.use.one.of", snippets.stream()
  1497         });
  1497         });
  1498         return true;
  1498         return true;
  1499     }
  1499     }
  1500 
  1500 
  1501     private boolean cmdOpen(String filename) {
  1501     private boolean cmdOpen(String filename) {
  1502         return runFile(filename, "'/open'");
  1502         return runFile(filename, "/open");
  1503     }
  1503     }
  1504 
  1504 
  1505     private boolean runFile(String filename, String context) {
  1505     private boolean runFile(String filename, String context) {
  1506         if (!filename.isEmpty()) {
  1506         if (!filename.isEmpty()) {
  1507             try {
  1507             try {
  1531                 byte[] encoded = Files.readAllBytes(Paths.get(filename));
  1531                 byte[] encoded = Files.readAllBytes(Paths.get(filename));
  1532                 return new String(encoded);
  1532                 return new String(encoded);
  1533             } catch (AccessDeniedException e) {
  1533             } catch (AccessDeniedException e) {
  1534                 errormsg("jshell.err.file.not.accessible", context, filename, e.getMessage());
  1534                 errormsg("jshell.err.file.not.accessible", context, filename, e.getMessage());
  1535             } catch (NoSuchFileException e) {
  1535             } catch (NoSuchFileException e) {
  1536                 errormsg("jshell.err.file.not.found", context, filename, e.getMessage());
  1536                 errormsg("jshell.err.file.not.found", context, filename);
  1537             } catch (Exception e) {
  1537             } catch (Exception e) {
  1538                 errormsg("jshell.err.file.exception", context, filename, e);
  1538                 errormsg("jshell.err.file.exception", context, filename, e);
  1539             }
  1539             }
  1540         } else {
  1540         } else {
  1541             errormsg("jshell.err.file.filename", context);
  1541             errormsg("jshell.err.file.filename", context);