private AnnotationBuilder<T> set(String name, Object value, Class<?> type) { try { Method attr = this.type.getMethod(name); if (!attr.getReturnType().isAssignableFrom(type)) { throw new IllegalArgumentException("Attribute named: " + name + " expects a type of " + attr.getReturnType() + ", but got " + type); } // if valid, save for later attributes.put(name, AnnotationProxy.copyAnnotationValue(value)); return this; } catch (SecurityException e) { throw new RuntimeException(e); } catch (NoSuchMethodException e) { throw new IllegalArgumentException("Annotation type " + this.type + " does not have an attribute named: " + name); } }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (isHashCode(method)) { return proxyHashCode(proxy); } else if (isEquals(method)) { return proxyEquals(proxy, args[0]); } else if (isAnnotationType(method)) { return proxyAnnotationType(); } else if (isToString(method)) { return proxyToString(proxy); } else if (attributes.containsKey(method.getName()) && method.getParameterTypes().length == 0) { return copyAnnotationValue(attributes.get(method.getName())); } else { // fall back to the default return copyAnnotationValue(method.getDefaultValue()); } // wait() and other Object methods do not get sent to the InvocationHandler // so we don't have any other cases }