diff --git a/builtins/src/main/java/org/jline/builtins/Commands.java b/builtins/src/main/java/org/jline/builtins/Commands.java index 6ab5d84ad..23a068394 100644 --- a/builtins/src/main/java/org/jline/builtins/Commands.java +++ b/builtins/src/main/java/org/jline/builtins/Commands.java @@ -240,13 +240,13 @@ public static void history(LineReader reader, PrintStream out, PrintStream err, } else if (opt.isSet("save")) { history.save(); } else if (opt.isSet("A")) { - Path file = opt.args().size() > 0 ? currentDir.resolve(opt.args().get(0)) : null; + Path file = !opt.args().isEmpty() ? currentDir.resolve(opt.args().get(0)) : null; history.append(file, increment); } else if (opt.isSet("R")) { - Path file = opt.args().size() > 0 ? currentDir.resolve(opt.args().get(0)) : null; + Path file = !opt.args().isEmpty() ? currentDir.resolve(opt.args().get(0)) : null; history.read(file, increment); } else if (opt.isSet("W")) { - Path file = opt.args().size() > 0 ? currentDir.resolve(opt.args().get(0)) : null; + Path file = !opt.args().isEmpty() ? currentDir.resolve(opt.args().get(0)) : null; history.write(file, increment); } else { done = false; @@ -361,7 +361,7 @@ public ReExecute(History history, Options opt) throws IOException { if (edit) { cmdFile = File.createTempFile("jline-history-", null); cmdWriter = new FileWriter(cmdFile); - } else if (opt.args().size() > 0) { + } else if (!opt.args().isEmpty()) { String[] s = opt.args().get(argId).split("="); if (s.length == 2) { argId = argId + 1; @@ -640,7 +640,7 @@ public static void keymap(LineReader reader, PrintStream out, PrintStream err, S if (opt.isSet("l")) { boolean commands = opt.isSet("L"); // TODO: handle commands - if (opt.args().size() > 0) { + if (!opt.args().isEmpty()) { for (String arg : opt.args()) { KeyMap map = keyMaps.get(arg); if (map == null) { @@ -704,7 +704,7 @@ public static void keymap(LineReader reader, PrintStream out, PrintStream err, S err.println("keymap: keymap can not be selected with -N"); return; } - if (opt.args().size() > 0) { + if (!opt.args().isEmpty()) { err.println("keymap: too many arguments for -d"); return; } @@ -869,9 +869,9 @@ public static void keymap(LineReader reader, PrintStream out, PrintStream err, S err.println("keymap: option -p requires a prefix string"); return; } - if (opt.args().size() > 0 || !opt.isSet("e") && !opt.isSet("v")) { + if (!opt.args().isEmpty() || !opt.isSet("e") && !opt.isSet("v")) { Map bound = map.getBoundKeys(); - String seq = opt.args().size() > 0 ? KeyMap.translate(opt.args().get(0)) : null; + String seq = !opt.args().isEmpty() ? KeyMap.translate(opt.args().get(0)) : null; Map.Entry begin = null; String last = null; Iterator> iterator = bound.entrySet().iterator(); diff --git a/builtins/src/main/java/org/jline/builtins/Nano.java b/builtins/src/main/java/org/jline/builtins/Nano.java index bfa231d8d..d278bdc8f 100644 --- a/builtins/src/main/java/org/jline/builtins/Nano.java +++ b/builtins/src/main/java/org/jline/builtins/Nano.java @@ -1450,7 +1450,7 @@ public String up(String hint) { } boolean found = false; for (int pid = patternId; pid < patterns.size(); pid++) { - if (hint.length() == 0 || patterns.get(pid).startsWith(hint)) { + if (hint.isEmpty() || patterns.get(pid).startsWith(hint)) { patternId = pid + 1; out = patterns.get(pid); found = true; @@ -1467,7 +1467,7 @@ public String up(String hint) { public String down(String hint) { String out = hint; - if (patterns.size() > 0) { + if (!patterns.isEmpty()) { if (lastMoveUp) { patternId--; } @@ -1493,7 +1493,7 @@ public String down(String hint) { } public void add(String pattern) { - if (pattern.trim().length() == 0) { + if (pattern.trim().isEmpty()) { return; } patterns.remove(pattern); @@ -1512,7 +1512,7 @@ public void persist() { try (BufferedWriter writer = Files.newBufferedWriter( historyFile.toAbsolutePath(), StandardOpenOption.WRITE, StandardOpenOption.CREATE)) { for (String s : patterns) { - if (s.trim().length() > 0) { + if (!s.trim().isEmpty()) { writer.append(s); writer.newLine(); } @@ -2151,7 +2151,7 @@ private boolean save(String name) throws IOException { setMessage("Wrote " + buffer.lines.size() + " lines"); return true; } catch (IOException e) { - setMessage("Error writing " + name + ": " + e.toString()); + setMessage("Error writing " + name + ": " + e); return false; } finally { Files.deleteIfExists(t); @@ -2312,7 +2312,7 @@ private String getReadMessage() { return sb.toString(); } - void gotoLine() throws IOException { + void gotoLine() { KeyMap readKeyMap = new KeyMap<>(); readKeyMap.setUnicode(Operation.INSERT); for (char i = 32; i < 256; i++) { @@ -2786,12 +2786,7 @@ String replace() throws IOException { if (editBuffer.length() > 0) { replaceTerm = editBuffer.toString(); } - if (replaceTerm == null) { - setMessage("Cancelled"); - throw new IllegalArgumentException(); - } else { - patternHistory.add(replaceTerm); - } + patternHistory.add(replaceTerm); return replaceTerm; case HELP: help("nano-replace-help.txt"); @@ -2965,7 +2960,7 @@ void smoothScrolling() { setMessage("Smooth scrolling " + (smoothScrolling ? "enabled" : "disabled")); } - void mouseSupport() throws IOException { + void mouseSupport() { mouseSupport = !mouseSupport; setMessage("Mouse support " + (mouseSupport ? "enabled" : "disabled")); terminal.trackMouse(mouseSupport ? Terminal.MouseTracking.Normal : Terminal.MouseTracking.Off); diff --git a/demo/src/main/java/org/jline/demo/Repl.java b/demo/src/main/java/org/jline/demo/Repl.java index 362e0bd06..895aee212 100644 --- a/demo/src/main/java/org/jline/demo/Repl.java +++ b/demo/src/main/java/org/jline/demo/Repl.java @@ -62,6 +62,7 @@ */ public class Repl { + @SuppressWarnings("resource") protected static class MyCommands extends JlineCommandRegistry implements CommandRegistry { private LineReader reader; private final Supplier workDir; @@ -95,7 +96,7 @@ private void tput(CommandInput input) { try { Options opt = parseOptions(usage, input.xargs()); List argv = opt.args(); - if (argv.size() > 0) { + if (!argv.isEmpty()) { Capability vcap = Capability.byName(argv.get(0)); if (vcap != null) { terminal() @@ -161,7 +162,7 @@ private void echo(CommandInput input) { List argv = opt.args(); if (opt.isSet("version")) { terminal().writer().println("echo version: v0.1"); - } else if (opt.args().size() >= 1) { + } else if (!opt.args().isEmpty()) { terminal().writer().println(String.join(" ", opt.args())); } } catch (Exception e) {