本文整理汇总了Java中org.jline.reader.ParsedLine类的典型用法代码示例。如果您正苦于以下问题:Java ParsedLine类的具体用法?Java ParsedLine怎么用?Java ParsedLine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ParsedLine类属于org.jline.reader包,在下文中一共展示了ParsedLine类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: complete
import org.jline.reader.ParsedLine; //导入依赖的package包/类
@Override
public void complete(LineReader reader, ParsedLine line, List<Candidate> candidates) {
if (line.words().size() == 2) {
String cmd = line.words().get(0);
String word = line.word();
if (COMMANDS.contains(cmd)) {
// group is already specified; only provide artifacts now
if (word.contains(":")) {
String group = word.split(":")[0] + ":";
archivesFromCache().stream().filter(a -> a.startsWith(group))
.collect(Collectors.toSet())
.forEach(a -> candidates.add(new Candidate(a)));
}
// sill completing group
else {
archivesFromCache().stream().map(a -> a.split(":")[0])
.collect(Collectors.toSet()).forEach(a -> candidates
.add(new Candidate(a + ":", a, null, null, null, null, false)));
}
}
}
}
示例2: parse
import org.jline.reader.ParsedLine; //导入依赖的package包/类
public ParsedLine parse(String line, int cursor,
ParseContext context) throws SyntaxError {
if (context == ParseContext.COMPLETE)
return parseForComplete(line, cursor);
CharArrayInPort cin = CharArrayInPort.make(line, "\n");
cin.setLineNumber(this.getLineNumber());
cin.setPath(this.getPath());
try {
Lexer lexer = language.getLexer(cin, this.messages);
lexer.setInteractive(true);
Compilation comp =
language.parse(lexer,
Language.PARSE_FOR_EVAL|Language.PARSE_INTERACTIVE_MODULE,
null);
if (comp == null)
throw new EndOfFileException();
if (comp.getState() == Compilation.ERROR_SEEN && cin.eofSeen()) {
messages.clear();
throw new EOFError(-1, -1, "unexpected end-of-file", "");
}
return new KawaParsedLine(this, comp, line, cursor);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
示例3: parse
import org.jline.reader.ParsedLine; //导入依赖的package包/类
@Override
public ParsedLine parse(String line, int cursor, ParseContext context) throws SyntaxError {
String input = line.trim();
DefaultParsedLine defaultResult = new DefaultParsedLine(line, cursor);
if (input.startsWith(Command.PREFIX)) {
return defaultResult;
}
if (!input.endsWith(";")) {
throw new EOFError(-1, -1, "Query not terminated");
}
return defaultResult;
}
示例4: statements_end_with_semicolon
import org.jline.reader.ParsedLine; //导入依赖的package包/类
@Test
public void statements_end_with_semicolon() {
thrown.expect(EOFError.class);
ParsedLine parsedLine = parser.parse("MATCH (n)", 4);
parser.parse("RETURN n;", 8);
assertThat(parsedLine.cursor()).isEqualTo(8);
assertThat(parsedLine.words()).containsExactly("MATCH (n)\nRETURN n;");
assertThat(parsedLine.word()).isEqualTo("MATCH (n)\nRETURN n;");
assertThat(parsedLine.wordCursor()).isEqualTo(8);
}
示例5: complete
import org.jline.reader.ParsedLine; //导入依赖的package包/类
@Override
public void complete(LineReader reader, ParsedLine commandLine, List<Candidate> candidates) {
if (commandLine.words().size() > 1) {
String word = commandLine.words().get(commandLine.words().size() - 2);
if ("-C".equals(word) || "--change-dir".equals(word)) {
super.complete(reader, commandLine, candidates);
}
else if (commandLine.line().startsWith(Constants.SHELL_ESCAPE)) {
super.complete(reader, commandLine, candidates);
}
}
}
示例6: reserved_commands_are_handled
import org.jline.reader.ParsedLine; //导入依赖的package包/类
@Test
public void reserved_commands_are_handled() {
ParsedLine line = parser.parse(":special-command", 15);
assertThat(line.cursor()).isEqualTo(15);
}
示例7: complete
import org.jline.reader.ParsedLine; //导入依赖的package包/类
@Override
public void complete(LineReader reader, ParsedLine line, List<Candidate> candidates) {
if (line.words().size() >= 1) {
String command = line.words().get(0);
if (COMMANDS.contains(command)) {
init();
switch (command) {
case "edit":
case "ed":
completeBasedOnJsonpathMatches("editors", line.words(), candidates);
break;
case "generate":
case "gen":
completeBasedOnJsonpathMatches("generators", line.words(), candidates);
break;
case "command":
completeBasedOnJsonpathMatches("command_handlers", line.words(), candidates);
break;
case "trigger":
completeBasedOnJsonpathMatches("event_handlers", line.words(), candidates);
break;
case "describe":
case "desc":
if (line.words().size() >= 2) {
String subCommand = line.words().get(1);
switch (subCommand) {
case "editor":
completeBasedOnJsonpathMatches("editors", line.words(), candidates);
break;
case "generator":
completeBasedOnJsonpathMatches("generators", line.words(), candidates);
break;
case "reviewer":
completeBasedOnJsonpathMatches("reviewers", line.words(), candidates);
break;
case "command-handler":
completeBasedOnJsonpathMatches("command_handlers", line.words(),
candidates);
break;
case "event-handler":
completeBasedOnJsonpathMatches("event_handlers", line.words(),
candidates);
break;
case "response-handler":
completeBasedOnJsonpathMatches("response_handlers", line.words(),
candidates);
break;
}
}
break;
}
}
}
}
示例8: complete
import org.jline.reader.ParsedLine; //导入依赖的package包/类
@Override
public void complete(LineReader reader, ParsedLine line, List<Candidate> candidates) {
List<String> words = line.words();
if (words.size() == 1) {
registry.commands().forEach(c -> {
candidates.add(new Candidate(c.name(), c.name(), null, null, null, c.name(), true));
c.aliases().forEach(
a -> candidates.add(new Candidate(a, a, null, null, null, c.name(), true)));
});
candidates.add(new Candidate("exit", "exit", null, null, null, "q", true));
candidates.add(new Candidate("quit", "quit", null, null, null, "q", true));
candidates.add(new Candidate("q", "q", null, null, null, "q", true));
candidates.add(new Candidate("/clear", "/clear", null, null, null, "cls", true));
candidates.add(new Candidate("/cls", "/cls", null, null, null, "cls", true));
candidates.add(new Candidate("/echo", "/echo", null, null, null, "echo", true));
}
else if (words.size() > 1) {
String word = words.get(0);
String l = StringUtils.join(words, " ");
Optional<CommandInfo> info = registry.commands().stream()
.filter(c -> c.name().startsWith(word) || c.aliases().contains(word))
.findFirst();
if (info.isPresent()) {
String remaining = ShellUtils.removePrefix(info.get().name(), words);
if (remaining != null && remaining.length() > 0
&& !info.get().aliases().contains(word)) {
candidates.add(new Candidate(remaining, info.get().name(), null, null, null,
null, true));
}
info.get().subCommands().stream()
.filter(s -> (info.get().name() + " " + s).startsWith(l) || info.get()
.aliases().stream().filter(a -> (a + " " + s).startsWith(l))
.findAny().isPresent())
.forEach(
s -> candidates.add(new Candidate(ShellUtils.removePrefix(s, words),
info.get().name() + " " + s, null, null, null, null,
true)));
completeOptions(info.get().globalOptions().getOptions(), candidates, words, false);
completeOptions(info.get().options().getOptions(), candidates, words, true);
}
}
}