final Method[] methods = keyObject.getClass().getDeclaredMethods();
Method targetMethod = null;
for (final Method method : methods) {
if (method != null && method.getAnnotation(CacheKeyMethod.class) != null) {
if (method.getParameterTypes().length > 0) {
throw new InvalidAnnotationException(String.format(
"Method [%s] must have 0 arguments to be annotated with [%s]",
method.toString(),
CacheKeyMethod.class.getName()));
}
if (!String.class.equals(method.getReturnType())) {
throw new InvalidAnnotationException(String.format(
"Method [%s] must return a String to be annotated with [%s]",
method.toString(),
CacheKeyMethod.class.getName()));
}
if (targetMethod != null) {
throw new InvalidAnnotationException(String.format(
"Class [%s] should have only one method annotated with [%s]. See [%s] and [%s]",
keyObject.getClass().getName(),
CacheKeyMethod.class.getName(),
targetMethod.getName(),
method.getName()));