/** * Get whether this parameter is entered by the user. * * @return true if this parameter is entered by the user. */ boolean isUserInput() { return getBinding().getBehavior(this) != BindingBehavior.PROVIDES; }
/** * Return the number of arguments this binding consumes. * * @return -1 if unknown or unavailable */ int getConsumedCount() { return getBinding().getConsumedCount(this); }
/** * Add a binding for a given type or classifier (annotation). * * <p>Whenever a method parameter is encountered, a binding must be found for it * so that it can be called later to consume the stack of arguments provided by * the user and return an object that is later passed to * {@link Method#invoke(Object, Object...)}.</p> * * <p>Normally, a {@link Type} is used to discern between different bindings, but * if this is not specific enough, an annotation can be defined and used. This * makes it a "classifier" and it will take precedence over the base type. For * example, even if there is a binding that handles {@link String} parameters, * a special {@code @MyArg} annotation can be assigned to a {@link String} * parameter, which will cause the {@link Builder} to consult the {@link Binding} * associated with {@code @MyArg} rather than with the binding for * the {@link String} type.</p> * * @param binding the binding * @param type a list of types (if specified) to override the binding's types */ public void addBinding(Binding binding, Type... type) { if (type == null || type.length == 0) { type = binding.getTypes(); } for (Type t : type) { bindings.put(t, binding); } }
BindingBehavior behavior = getBinding().getBehavior(this); boolean indeterminate = (behavior == BindingBehavior.INDETERMINATE); if (!isValueFlag() && indeterminate) { if (behavior != BindingBehavior.CONSUMES && binding.getConsumedCount(this) != -1) { throw new ParametricException( "getConsumedCount() does not return -1 for binding " + if (behavior != BindingBehavior.PROVIDES && binding.getConsumedCount(this) == 0) { throw new ParametricException( "getConsumedCount() must not return 0 for binding " +
/** * 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; }
args[i] = parameter.getBinding().bind(parameter, usedArguments, false); } catch (MissingParameterException e) {
/** * Get whether this parameter consumes non-flag arguments. * * @return true if this parameter consumes non-flag arguments */ boolean isNonFlagConsumer() { return getBinding().getBehavior(this) != BindingBehavior.PROVIDES && !isValueFlag(); }
@Override public void updateDescription(Object object, Method method, ParameterData[] parameters, SimpleDescription description) { Command annotation = method.getAnnotation(Command.class); // Handle the case for old commands where no usage is set and all of its // parameters are provider bindings, so its usage information would // be blank and would imply that there were no accepted parameters if (annotation != null && annotation.usage().isEmpty() && (annotation.min() > 0 || annotation.max() > 0)) { boolean hasUserParameters = false; for (ParameterData parameter : parameters) { if (parameter.getBinding().getBehavior(parameter) != BindingBehavior.PROVIDES) { hasUserParameters = true; break; } } if (!hasUserParameters) { description.overrideUsage("(unknown usage information)"); } } }