JLine2:如何将完成者组合在一个组中?

时间:2015-02-14 17:19:27

标签: java autocomplete jline

我认为这个问题会更加具体和清晰。

这是我的代码,它执行简单的自动完成操作(排序)。

public class JLineExample {
    public static void main(String[] args) throws IOException {
        String line;
        ConsoleReader console = new ConsoleReader();
        console.setPrompt("> ");

        // Quit
        Completer quit = new StringsCompleter("quit");

        // Group #1
        Completer start = new StringsCompleter("start");
        Completer stop = new StringsCompleter("stop");

        // Group #2
        Completer propetry = new StringsCompleter("property");
        Completer hide = new StringsCompleter("hide");

        // Joint groups
        Completer executionGroup = new ArgumentCompleter(start, stop);
        Completer propertyGroup = new ArgumentCompleter(propetry, hide);
        Completer jointGroups = new ArgumentCompleter(executionGroup, propertyGroup);

        // Aggregator
        Completer aggregated = new AggregateCompleter(quit, jointGroups);

        console.addCompleter(aggregated);
        while ((line = console.readLine("> ")) != null) {
            if ("quit".equals(line.trim())) exit(1);
        }
    }
}

问题在于将完成者组合在一个组中。我得到了

Exception in thread "main" java.lang.NullPointerException
        at jline.console.completer.ArgumentCompleter$AbstractArgumentDelimiter.delimit(ArgumentCompleter.java:283)
        at jline.console.completer.ArgumentCompleter.complete(ArgumentCompleter.java:116)
        at jline.console.completer.ArgumentCompleter.complete(ArgumentCompleter.java:152)
        at jline.console.completer.AggregateCompleter$Completion.complete(AggregateCompleter.java:121)
        at jline.console.completer.AggregateCompleter.complete(AggregateCompleter.java:80)
        at jline.console.ConsoleReader.complete(ConsoleReader.java:3261)
        at jline.console.ConsoleReader.readLine(ConsoleReader.java:2621)
        at jline.console.ConsoleReader.readLine(ConsoleReader.java:2269)
        at com.test.jline.JLineExample.main(JLineExample.java:52)
按下TAB键时

任何想法如何解决这个问题?

0 个答案:

没有答案