/** * Return the number of arguments this binding consumes. * * @return -1 if unknown or unavailable */ int getConsumedCount() { return getBinding().getConsumedCount(this); }
/** * 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; }
/** * 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(); }
BindingBehavior behavior = getBinding().getBehavior(this); boolean indeterminate = (behavior == BindingBehavior.INDETERMINATE); if (!isValueFlag() && indeterminate) { "@Switch missing for indeterminate consumer\n\n" + "Notably:\nFor the type " + type + ", the binding " + getBinding().getClass().getCanonicalName() + "\nmay or may not consume parameters (isIndeterminateConsumer(" + type + ") = true)" + "\nand therefore @Switch(flag) is required for parameter #" + parameterIndex + " of \n" + throw new ParametricException( "getConsumedCount() does not return -1 for binding " + getBinding().getClass().getCanonicalName() + "\neven though its behavior type is " + behavior.name() + "\nfor parameter #" + parameterIndex + " of \n" + throw new ParametricException( "getConsumedCount() must not return 0 for binding " + getBinding().getClass().getCanonicalName() + "\nwhen its behavior type is " + behavior.name() + " and not PROVIDES " + "\nfor parameter #" + parameterIndex + " of \n" +
/** * 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; }
@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)"); } } }
} else if (parameter.getBinding() == null) { parameter.setBinding(builder.getBindings().get(annotation.annotationType())); parameter.setClassifier(annotation); if (parameter.getBinding() == null) { parameter.setBinding(builder.getBindings().get(type)); if (parameter.getBinding() == null) { throw new ParametricException("Don't know how to handle the parameter type '" + type + "' in\n" + method.toGenericString()); throw new ParametricException( "Found an parameter using the binding " + parameter.getBinding().getClass().getCanonicalName() + "\nthat does not know how many arguments it consumes, but " + "it follows an optional parameter\nMethod: " +
args[i] = parameter.getBinding().bind(parameter, usedArguments, false); } catch (MissingParameterException e) {