shell/console/src/main/java/org/apache/karaf/shell/compat/ArgumentCompleter.java [164:254]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                if (completer == null) {
                    completer = NullCompleter.INSTANCE;
                }
                argsCompleters.add(completer);
            }
            if (argsCompleters.isEmpty() || !multi) {
                argsCompleters.add(NullCompleter.INSTANCE);
            }
            optionalCompleters = new HashMap<>();
            for (Option option : fields.keySet()) {
                Completer completer = null;
                Field field = fields.get(option);
                if (field != null) {
                    org.apache.karaf.shell.commands.Completer ann = field.getAnnotation(org.apache.karaf.shell.commands.Completer.class);
                    if (ann != null) {
                        Class clazz = ann.value();
                        String[] value = ann.values();
                        if (clazz != null) {
                            if (value.length > 0 && clazz == StringsCompleter.class) {
                                completer = new StringsCompleter(value, ann.caseSensitive());
                            } else {
                                BundleContext context = FrameworkUtil.getBundle(function.getClass()).getBundleContext();
                                completer = new ProxyServiceCompleter(context, clazz);
                            }
                        }
                    }
                }
                if (completer == null) {
                    completer = NullCompleter.INSTANCE;
                }
                optionalCompleters.put(option.name(), completer);
                if (option.aliases() != null) {
                    for (String alias : option.aliases()) {
                        optionalCompleters.put(alias, completer);
                    }
                }
            }
        }
        this.argsCompleters = argsCompleters;
        this.optionalCompleters = optionalCompleters;
    }

    private Map<Integer, Object> getCompleterValues(CommandWithAction function) {
        final Map<Integer, Object> values = new HashMap<>();
        Action action = null;
        try {
            for (Class<?> type = function.getActionClass(); type != null; type = type.getSuperclass()) {
                for (Method method : type.getDeclaredMethods()) {
                    CompleterValues completerMethod = method.getAnnotation(CompleterValues.class);
                    if (completerMethod != null) {
                        int index = completerMethod.index();
                        Integer key = index;
                        if (index >= arguments.size() || index < 0) {
                            LOGGER.warn("Index out of range on @CompleterValues on class " + type.getName() + " for index: " + key + " see: " + method);
                        } else if (values.containsKey(key)) {
                            LOGGER.warn("Duplicate @CompleterMethod annotations on class " + type.getName() + " for index: " + key + " see: " + method);
                        } else {
                            try {
                                Object value;
                                if (Modifier.isStatic(method.getModifiers())) {
                                    value = method.invoke(null);
                                } else {
                                    if (action == null) {
                                        action = function.createNewAction();
                                    }
                                    value = method.invoke(action);
                                }
                                values.put(key, value);
                            } catch (IllegalAccessException e) {
                                LOGGER.warn("Could not invoke @CompleterMethod on " + function + ". " + e, e);
                            } catch (InvocationTargetException e) {
                                Throwable target = e.getTargetException();
                                if (target == null) {
                                    target = e;
                                }
                                LOGGER.warn("Could not invoke @CompleterMethod on " + function + ". " + target, target);
                            }
                        }
                    }
                }
            }
        } finally {
            if (action != null) {
                try {
                    function.releaseAction(action);
                } catch (Exception e) {
                    LOGGER.warn("Failed to release action: " + action + ". " + e, e);
                }
            }
        }
        return values;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



shell/console/src/main/java/org/apache/karaf/shell/console/completer/ArgumentCompleter.java [159:249]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                if (completer == null) {
                    completer = NullCompleter.INSTANCE;
                }
                argsCompleters.add(completer);
            }
            if (argsCompleters.isEmpty() || !multi) {
                argsCompleters.add(NullCompleter.INSTANCE);
            }
            optionalCompleters = new HashMap<>();
            for (Option option : fields.keySet()) {
                Completer completer = null;
                Field field = fields.get(option);
                if (field != null) {
                    org.apache.karaf.shell.commands.Completer ann = field.getAnnotation(org.apache.karaf.shell.commands.Completer.class);
                    if (ann != null) {
                        Class clazz = ann.value();
                        String[] value = ann.values();
                        if (clazz != null) {
                            if (value.length > 0 && clazz == StringsCompleter.class) {
                                completer = new StringsCompleter(value, ann.caseSensitive());
                            } else {
                                BundleContext context = FrameworkUtil.getBundle(function.getClass()).getBundleContext();
                                completer = new ProxyServiceCompleter(context, clazz);
                            }
                        }
                    }
                }
                if (completer == null) {
                    completer = NullCompleter.INSTANCE;
                }
                optionalCompleters.put(option.name(), completer);
                if (option.aliases() != null) {
                    for (String alias : option.aliases()) {
                        optionalCompleters.put(alias, completer);
                    }
                }
            }
        }
        this.argsCompleters = argsCompleters;
        this.optionalCompleters = optionalCompleters;
    }

    private Map<Integer, Object> getCompleterValues(CommandWithAction function) {
        final Map<Integer, Object> values = new HashMap<>();
        Action action = null;
        try {
            for (Class<?> type = function.getActionClass(); type != null; type = type.getSuperclass()) {
                for (Method method : type.getDeclaredMethods()) {
                    CompleterValues completerMethod = method.getAnnotation(CompleterValues.class);
                    if (completerMethod != null) {
                        int index = completerMethod.index();
                        Integer key = index;
                        if (index >= arguments.size() || index < 0) {
                            LOGGER.warn("Index out of range on @CompleterValues on class " + type.getName() + " for index: " + key + " see: " + method);
                        } else if (values.containsKey(key)) {
                            LOGGER.warn("Duplicate @CompleterMethod annotations on class " + type.getName() + " for index: " + key + " see: " + method);
                        } else {
                            try {
                                Object value;
                                if (Modifier.isStatic(method.getModifiers())) {
                                    value = method.invoke(null);
                                } else {
                                    if (action == null) {
                                        action = function.createNewAction();
                                    }
                                    value = method.invoke(action);
                                }
                                values.put(key, value);
                            } catch (IllegalAccessException e) {
                                LOGGER.warn("Could not invoke @CompleterMethod on " + function + ". " + e, e);
                            } catch (InvocationTargetException e) {
                                Throwable target = e.getTargetException();
                                if (target == null) {
                                    target = e;
                                }
                                LOGGER.warn("Could not invoke @CompleterMethod on " + function + ". " + target, target);
                            }
                        }
                    }
                }
            }
        } finally {
            if (action != null) {
                try {
                    function.releaseAction(action);
                } catch (Exception e) {
                    LOGGER.warn("Failed to release action: " + action + ". " + e, e);
                }
            }
        }
        return values;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



