use of org.apache.karaf.shell.commands.CompleterValues in project karaf by apache.
the class ArgumentCompleter method getCompleterValues.
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;
}
use of org.apache.karaf.shell.commands.CompleterValues in project karaf by apache.
the class ArgumentCompleter method getCompleterValues.
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;
}
Aggregations