Skip to content

Commit

Permalink
Make sure no exception is thrown when using
Browse files Browse the repository at this point in the history
old commands that do not implement the new method on the CompletableFunction interface

git-svn-id: https://svn.apache.org/repos/asf/karaf/branches/karaf-2.2.x@1213776 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
gnodet committed Dec 13, 2011
1 parent 0860418 commit f708310
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,17 @@ public ArgumentCompleter(CommandSession session, AbstractCommand function, Strin
optionsCompleter = new StringsCompleter(options.keySet());
// Build arguments completers
argsCompleters = new ArrayList<Completer>();
optionalCompleters = new HashMap<String, Completer>();

if (function instanceof CompletableFunction) {
optionalCompleters = ((CompletableFunction) function).getOptionalCompleters();
try {
Map completers = ((CompletableFunction) function).getOptionalCompleters();
if (completers != null) {
optionalCompleters.putAll(completers);
}
} catch (AbstractMethodError err) {
// Allow old commands to not break the completers
}
List<Completer> fcl = ((CompletableFunction) function).getCompleters();
if (fcl != null) {
for (Completer c : fcl) {
Expand All @@ -111,7 +119,6 @@ public ArgumentCompleter(CommandSession session, AbstractCommand function, Strin
argsCompleters.add(NullCompleter.INSTANCE);
}
} else {
optionalCompleters = new HashMap<String, Completer>();
final Map<Integer, Method> methods = new HashMap<Integer, Method>();
for (Class type = function.getActionClass(); type != null; type = type.getSuperclass()) {
for (Method method : type.getDeclaredMethods()) {
Expand Down Expand Up @@ -267,7 +274,7 @@ public int complete(final String buffer, final int cursor,
if (option != null) {
Completer optionValueCompleter = null;
String name = option.name();
if (optionalCompleters != null && name != null) {
if (name != null) {
optionValueCompleter = optionalCompleters.get(name);
if (optionValueCompleter == null) {
String[] aliases = option.aliases();
Expand Down

0 comments on commit f708310

Please sign in to comment.