@Test(expected=IllegalStateException.class) public void testGetPossibleArgTypesWithABadArg() { final Class<?>[] singleArgArgList = { List.class }; sf.getPossibleArgTypes(singleArgArgList); }
public final List<Class<?>> getPossibleArgTypes(final Class[] leadingArgs) { int i = 0; int currentArgCount = 0; ArgDescriptor currentArgDescriptor = null; for (final Class leadingArg : leadingArgs) { if (currentArgCount == 0) { if (i == argDescriptors.length) throw new IllegalStateException("number of arguments is too large."); currentArgDescriptor = argDescriptors[i++]; } if (!currentArgDescriptor.isCompatibleWith(leadingArg)) { throw new IllegalStateException("incompatible argument type."); } else if (currentArgDescriptor.acceptsMultipleArgs()) ++currentArgCount; else currentArgCount = 0; } if (currentArgCount == 0 && i == argDescriptors.length) return null; final List<Class<?>> possibleNextArgs = new LinkedList<Class<?>>(); if (currentArgCount > 0) { for (final Class type : currentArgDescriptor.getCompatibleTypes()) possibleNextArgs.add(type); if (i == argDescriptors.length) possibleNextArgs.add(null); } if (i < argDescriptors.length) { final ArgDescriptor nextArgDesc = argDescriptors[i]; for (final Class type : nextArgDesc.getCompatibleTypes()) possibleNextArgs.add(type); if (nextArgDesc.isOptional()) possibleNextArgs.add(null); } return possibleNextArgs; }
AbstractFunction implements Function { public final List<Class<?>> getPossibleArgTypes(final Class[] leadingArgs) { int i = 0; int currentArgCount = 0; ArgDescriptor currentArgDescriptor = null; for (final Class leadingArg : leadingArgs) { if (currentArgCount == 0) { if (i == argDescriptors.length) throw new IllegalStateException("number of arguments is too large."); currentArgDescriptor = argDescriptors[i++]; } if (!currentArgDescriptor.isCompatibleWith(leadingArg)) { throw new IllegalStateException("incompatible argument type."); } else if (currentArgDescriptor.acceptsMultipleArgs()) ++currentArgCount; else currentArgCount = 0; } if (currentArgCount == 0 && i == argDescriptors.length) return null; final List<Class<?>> possibleNextArgs = new LinkedList<Class<?>>(); if (currentArgCount > 0) { for (final Class type : currentArgDescriptor.getCompatibleTypes()) possibleNextArgs.add(type); if (i == argDescriptors.length) possibleNextArgs.add(null); } if (i < argDescriptors.length) { final ArgDescriptor nextArgDesc = argDescriptors[i]; for (final Class type : nextArgDesc.getCompatibleTypes()) possibleNextArgs.add(type); if (nextArgDesc.isOptional()) possibleNextArgs.add(null); } return possibleNextArgs; } }
AbstractFunction implements Function { public final List<Class<?>> getPossibleArgTypes(final Class[] leadingArgs) { int i = 0; int currentArgCount = 0; ArgDescriptor currentArgDescriptor = null; for (final Class leadingArg : leadingArgs) { if (currentArgCount == 0) { if (i == argDescriptors.length) throw new IllegalStateException("number of arguments is too large."); currentArgDescriptor = argDescriptors[i++]; } if (!currentArgDescriptor.isCompatibleWith(leadingArg)) { throw new IllegalStateException("incompatible argument type."); } else if (currentArgDescriptor.acceptsMultipleArgs()) ++currentArgCount; else currentArgCount = 0; } if (currentArgCount == 0 && i == argDescriptors.length) return null; final List<Class<?>> possibleNextArgs = new LinkedList<Class<?>>(); if (currentArgCount > 0) { for (final Class type : currentArgDescriptor.getCompatibleTypes()) possibleNextArgs.add(type); if (i == argDescriptors.length) possibleNextArgs.add(null); } if (i < argDescriptors.length) { final ArgDescriptor nextArgDesc = argDescriptors[i]; for (final Class type : nextArgDesc.getCompatibleTypes()) possibleNextArgs.add(type); if (nextArgDesc.isOptional()) possibleNextArgs.add(null); } return possibleNextArgs; } protected  AbstractFunction(final ArgDescriptor[] argDescriptors); }
AbstractFunction implements Function { public final List<Class<?>> getPossibleArgTypes(final Class[] leadingArgs) { int i = 0; int currentArgCount = 0; ArgDescriptor currentArgDescriptor = null; for (final Class leadingArg : leadingArgs) { if (currentArgCount == 0) { if (i == argDescriptors.length) throw new IllegalStateException("number of arguments is too large."); currentArgDescriptor = argDescriptors[i++]; } if (!currentArgDescriptor.isCompatibleWith(leadingArg)) { throw new IllegalStateException("incompatible argument type."); } else if (currentArgDescriptor.acceptsMultipleArgs()) ++currentArgCount; else currentArgCount = 0; } if (currentArgCount == 0 && i == argDescriptors.length) return null; final List<Class<?>> possibleNextArgs = new LinkedList<Class<?>>(); if (currentArgCount > 0) { for (final Class type : currentArgDescriptor.getCompatibleTypes()) possibleNextArgs.add(type); if (i == argDescriptors.length) possibleNextArgs.add(null); } if (i < argDescriptors.length) { final ArgDescriptor nextArgDesc = argDescriptors[i]; for (final Class type : nextArgDesc.getCompatibleTypes()) possibleNextArgs.add(type); if (nextArgDesc.isOptional()) possibleNextArgs.add(null); } return possibleNextArgs; } protected  AbstractFunction(final ArgDescriptor[] argDescriptors); abstract String getName(); abstract String getFunctionSummary(); final String getUsageDescription(); abstract Class getReturnType(); Class validateArgTypes(final Class[] argTypes); abstract Object evaluateFunction(final Object[] args); final List<Class<?>> getPossibleArgTypes(final Class[] leadingArgs); }
AbstractFunction implements Function { public final List<Class<?>> getPossibleArgTypes(final Class[] leadingArgs) { int i = 0; int currentArgCount = 0; ArgDescriptor currentArgDescriptor = null; for (final Class leadingArg : leadingArgs) { if (currentArgCount == 0) { if (i == argDescriptors.length) throw new IllegalStateException("number of arguments is too large."); currentArgDescriptor = argDescriptors[i++]; } if (!currentArgDescriptor.isCompatibleWith(leadingArg)) { throw new IllegalStateException("incompatible argument type."); } else if (currentArgDescriptor.acceptsMultipleArgs()) ++currentArgCount; else currentArgCount = 0; } if (currentArgCount == 0 && i == argDescriptors.length) return null; final List<Class<?>> possibleNextArgs = new LinkedList<Class<?>>(); if (currentArgCount > 0) { for (final Class type : currentArgDescriptor.getCompatibleTypes()) possibleNextArgs.add(type); if (i == argDescriptors.length) possibleNextArgs.add(null); } if (i < argDescriptors.length) { final ArgDescriptor nextArgDesc = argDescriptors[i]; for (final Class type : nextArgDesc.getCompatibleTypes()) possibleNextArgs.add(type); if (nextArgDesc.isOptional()) possibleNextArgs.add(null); } return possibleNextArgs; } protected  AbstractFunction(final ArgDescriptor[] argDescriptors); abstract String getName(); abstract String getFunctionSummary(); final String getUsageDescription(); abstract Class getReturnType(); Class validateArgTypes(final Class[] argTypes); abstract Object evaluateFunction(final Object[] args); final List<Class<?>> getPossibleArgTypes(final Class[] leadingArgs);  }