termPrefix = "";
}
//
log.log(Level.FINE, "Retained term prefix is " + termPrefix);
CompletionMatch completion;
int pos = termPrefix.indexOf(' ');
if (pos == -1) {
Completion.Builder builder = Completion.builder(termPrefix);
for (Map.Entry<String, String> command : session.getCommands()) {
String name = command.getKey();
if (name.startsWith(termPrefix)) {
builder.add(name.substring(termPrefix.length()), true);
}
}
completion = new CompletionMatch(Delimiter.EMPTY, builder.build());
} else {
String commandName = termPrefix.substring(0, pos);
termPrefix = termPrefix.substring(pos);
try {
Command<?> command = session.getCommand(commandName);
if (command != null) {
completion = command.complete(new RuntimeContextImpl(session, session.getContext().getAttributes()), termPrefix);
} else {
completion = new CompletionMatch(Delimiter.EMPTY, Completion.create());
}
}
catch (CommandException e) {
log.log(Level.FINE, "Could not create command for completion of " + prefix, e);
completion = new CompletionMatch(Delimiter.EMPTY, Completion.create());
}
}
//
return completion;