/** * Get the right {@link ArgumentStack}. * * @param parameter the parameter * @param existing the existing scoped context * @return the context to use */ private static ArgumentStack getScopedContext(Parameter parameter, ArgumentStack existing) { if (parameter.getFlag() != null) { CommandContext context = existing.getContext(); if (parameter.isValueFlag()) { return new StringArgumentStack(context, context.getFlag(parameter.getFlag()), false); } else { String v = context.hasFlag(parameter.getFlag()) ? "true" : "false"; return new StringArgumentStack(context, v, true); } } return existing; }
/** * Get the default value for a parameter. * * @param i the index of the parameter * @param scoped the scoped context * @return a value * @throws ParameterException on an error * @throws CommandException on an error */ private Object getDefaultValue(int i, ContextArgumentStack scoped) throws ParameterException, CommandException, InvocationTargetException { CommandContext context = scoped.getContext(); ParameterData parameter = parameters[i]; String[] defaultValue = parameter.getDefaultValue(); if (defaultValue != null) { try { return parameter.getBinding().bind(parameter, new StringArgumentStack(context, defaultValue, false), false); } catch (MissingParameterException e) { throw new ParametricException( "The default value of the parameter using the binding " + parameter.getBinding().getClass() + " in the method\n" + method.toGenericString() + "\nis invalid"); } } return null; }