From 7a6d457e71f8757bc62b1565e6505174a6dec4e8 Mon Sep 17 00:00:00 2001 From: guang384 Date: Thu, 8 Sep 2022 03:14:06 +0800 Subject: [PATCH] Wraps ExtendedArgumentList into CompletingParsedLine prevent WARNING during startup. - Idea/hack copied from jline LineReaderImpl - Backport #526 - Fixes #594 --- .../shell/jline/ExtendedDefaultParser.java | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/spring-shell-core/src/main/java/org/springframework/shell/jline/ExtendedDefaultParser.java b/spring-shell-core/src/main/java/org/springframework/shell/jline/ExtendedDefaultParser.java index fd71edba..5e6dc26e 100644 --- a/spring-shell-core/src/main/java/org/springframework/shell/jline/ExtendedDefaultParser.java +++ b/spring-shell-core/src/main/java/org/springframework/shell/jline/ExtendedDefaultParser.java @@ -142,7 +142,7 @@ public class ExtendedDefaultParser implements Parser { } String openingQuote = quoteStart >= 0 ? line.substring(quoteStart, quoteStart + 1) : null; - return new ExtendedArgumentList(line, words, wordIndex, wordCursor, cursor, openingQuote); + return wrap(new ExtendedArgumentList(line, words, wordIndex, wordCursor, cursor, openingQuote)); } /** @@ -321,4 +321,46 @@ public class ExtendedDefaultParser implements Parser { return false; } + /** + * Another copy from JLine's {@link org.jline.reader.impl.LineReaderImpl} + * + * Used to wrap {@link org.jline.reader.ParsedLine} into {@link org.jline.reader.CompletingParsedLine} + */ + private static org.jline.reader.CompletingParsedLine wrap(ParsedLine line) { + if (line instanceof org.jline.reader.CompletingParsedLine) { + return (org.jline.reader.CompletingParsedLine) line; + } + else { + return new org.jline.reader.CompletingParsedLine() { + public String word() { + return line.word(); + } + public int wordCursor() { + return line.wordCursor(); + } + public int wordIndex() { + return line.wordIndex(); + } + public List words() { + return line.words(); + } + public String line() { + return line.line(); + } + public int cursor() { + return line.cursor(); + } + public CharSequence escape(CharSequence candidate, boolean complete) { + return candidate; + } + public int rawWordCursor() { + return wordCursor(); + } + public int rawWordLength() { + return word().length(); + } + }; + } + } + }