public int getArgumentCount() { int count = 0; int variable = 1; for (Parameter<?> argument : args) { if (argument.getMinOccurs() != argument.getMaxOccurs()) { variable = -1; // flag for variable arguments } count += argument.getMinOccurs(); } return variable * count; }
Parameter<?> parameter = getFunctionName().getArguments().get(argumentIndex); if (params.size() <= argumentIndex) { if (parameter.getMinOccurs() == 0) { return null; } else { String.format( "No arguments specified for arg " + "%s, minOccurs = %d", parameter.getName().toString(), parameter.getMinOccurs()));
if (args.get(0).getMinOccurs() != 0) { throw new IllegalArgumentException( String.format( "No arguments specified for arg " + "%s, minOccurs = %d", last.getName().toString(), last.getMinOccurs()));
void check(Parameter p, String name, Class type, int min, int max) { assertEquals(name, p.getName()); assertEquals(type, p.getType()); assertEquals(min, p.getMinOccurs()); assertEquals(max, p.getMaxOccurs()); } }
/** * Validates the structure of arguments, basically enforcing java conventions for variable * level arguments. */ private void validateArguments() throws IllegalArgumentException { List<Parameter<?>> args = getFunctionName().getArguments(); for (int i = 0; i < args.size(); i++) { Parameter<?> arg = args.get(i); if (arg.getMaxOccurs() == 0) { throw new IllegalArgumentException(String.format("Argument %s has zero max")); } if (arg.getMinOccurs() != 1 || arg.getMaxOccurs() != 1) { //this can only happen for the last argument if (i != args.size()-1) { throw new IllegalArgumentException(String.format("Argument %s(%d,%d) invalid." + " Variable arguments must be the last argument of function.", arg.getName(), arg.getMinOccurs(), arg.getMaxOccurs())); } } } }
if (args.get(0).getMinOccurs() != 0) { throw new IllegalArgumentException(String.format("No arguments specified for arg " + "%s, minOccurs = %d", last.getName().toString(), last.getMinOccurs()));
for (int index = 0; index < param.getMinOccurs(); index++) { params.add(null);
/** * Sets the function fixed. * * @param functionExpression the function expression * @param overallIndex the overall index * @param param the param * @return the int */ private int setFunctionFixed( Function functionExpression, int overallIndex, Parameter<?> param) { for (int index = 0; index < param.getMinOccurs(); index++) { ExpressionNode childNode = new ExpressionNode(); childNode.setParameter(param); if (index < functionExpression.getParameters().size()) { if (overallIndex < functionExpression.getParameters().size()) { childNode.setExpression(functionExpression.getParameters().get(overallIndex)); } else { childNode.setExpression(null); } } overallIndex++; this.insert(childNode, this.getChildCount()); } return overallIndex; }
+ function.getArguments().get(index).getType().getName() + "\t\t" + function.getArguments().get(index).getMinOccurs() + "\t" + function.getArguments().get(index).getMaxOccurs());
/** Sets the function. */ private void setFunction() { Function functionExpression = (Function) this.expression; FunctionName functionName = functionExpression.getFunctionName(); TypeManager.getInstance().setDataType(functionName.getReturn().getType()); int overallIndex = 0; for (Parameter<?> param : functionName.getArguments()) { if (param.getMinOccurs() == 0) { overallIndex = setFunctionOptional(functionExpression, overallIndex, param); } else { overallIndex = setFunctionFixed(functionExpression, overallIndex, param); } } }
value.setDataType(parameter.getType().getSimpleName()); value.setMinOccurences(parameter.getMinOccurs()); value.setMaxOccurences(parameter.getMaxOccurs());