/** * Verify method parameter type(s). * * @param method the method to check * @param expected expected parameter types * @throws IllegalArgumentException if has an invalid parameter type(s) */ protected void checkParameterTypes(Method method, List<TypeToken<?>> expected) { final List<TypeToken<?>> actual = this.getParameterTypeTokens(method); if (!actual.equals(expected)) { throw new IllegalArgumentException(this.getErrorPrefix(method) + "method is required to take " + (expected.isEmpty() ? "zero parameters" : expected.size() + " parameter(s) of type " + expected)); } }
/** * Verify method takes a single parameter of the specified type. * * @param method the method to check * @param choices allowed parameter types * @throws IllegalArgumentException if parameter type does not match */ protected void checkSingleParameterType(Method method, List<TypeToken<?>> choices) { final List<TypeToken<?>> actuals = this.getParameterTypeTokens(method); if (actuals.size() != 1 || !choices.contains(actuals.get(0))) { throw new IllegalArgumentException(this.getErrorPrefix(method) + "method is required to take a single parameter" + " with type " + (choices.size() != 1 ? "one of " + choices : choices.get(0))); } }
/** * Verify a specific method parameter's type. * * @param method the method to check * @param index parameter index * @param choices allowed parameter types * @throws IllegalArgumentException if parameter type does not match */ protected void checkParameterType(Method method, int index, List<TypeToken<?>> choices) { final List<TypeToken<?>> actuals = this.getParameterTypeTokens(method); if (actuals.size() <= index || !choices.contains(actuals.get(index))) { throw new IllegalArgumentException(this.getErrorPrefix(method) + "method parameter #" + (index + 1) + " is required to have type " + (choices.size() != 1 ? "one of " + choices : choices.get(0))); } }