public JiraClassMap(@Nonnull final Class<?> clazz) { this.methodMap = new JiraMethodMap(clazz); }
private Iterable<Method> loadMethodsForName(final String methodName) { return deduplicateByNameAndArgumentTypes( publicMethodsWithName(allClassesAndInterfaces(), methodName)); }
@Override public Method findMethod(final String name, final Object[] params) throws MethodMap.AmbiguousException { return methodMap.find(name, params); } }
private Iterable<Class<?>> allClassesAndInterfaces() { return filter(concat(transform(getSuperClasses(clazz), GET_CLASS_AND_ALL_INTERFACES)), IS_PUBLIC_CLASS); }
@Override public Method find(final String methodName, final Object[] args) throws AmbiguousException { Preconditions.checkNotNull(args, "params cannot not be null"); //first try direct matches final Class<?>[] parametersTypes = VelocityTypesUtil.getParametersTypes(args); final Collection<Method> methods = copyOf(Iterables.filter(get(methodName), new Predicate<Method>() { @Override public boolean apply(final Method method) { return Arrays.equals(VelocityTypesUtil.getMethodArgsTypes(method), parametersTypes); } })); if (methods.size() == 1) { return Iterables.getOnlyElement(methods); } else if (methods.isEmpty()) { return super.find(methodName, args); } else { throw new MethodMap.AmbiguousException(); } }