/** * Turns an annotation AST node into an actual instance of an annotation class provided you already know its type. * <strong>NB: non-literal compile-time constants cannot be converted, and you should avoid querying classes; * instead call {@code resolver.getAnnotationClassAsString(objectReturnedByThisMethod, "annotation method name")}. * * @see #getAnnotationClassesAsStrings(java.lang.annotation.Annotation, String) * @see #getAnnotationClassAsString(java.lang.annotation.Annotation, String) */ public <A extends java.lang.annotation.Annotation> A toAnnotationInstance(Class<A> type, Annotation node) { return type.cast(Proxy.newProxyInstance(type.getClassLoader(), new Class[] { type }, new AnnotationProxy(this, node))); }
/** * Turns an annotation AST node into an actual instance of an annotation class provided you already know its type. * <strong>NB: non-literal compile-time constants cannot be converted, and you should avoid querying classes; * instead call {@code resolver.getAnnotationClassAsString(objectReturnedByThisMethod, "annotation method name")}. * * @see #getAnnotationClassesAsStrings(java.lang.annotation.Annotation, String) * @see #getAnnotationClassAsString(java.lang.annotation.Annotation, String) */ public <A extends java.lang.annotation.Annotation> A toAnnotationInstance(Class<A> type, Annotation node) { return type.cast(Proxy.newProxyInstance(type.getClassLoader(), new Class[] { type }, new AnnotationProxy(this, node))); }
/** * Turns an annotation AST node into an actual instance of an annotation class provided you already know its type. * <strong>NB: non-literal compile-time constants cannot be converted, and you should avoid querying classes; * instead call {@code resolver.getAnnotationClassAsString(objectReturnedByThisMethod, "annotation method name")}. * * @see #getAnnotationClassesAsStrings(java.lang.annotation.Annotation, String) * @see #getAnnotationClassAsString(java.lang.annotation.Annotation, String) */ public <A extends java.lang.annotation.Annotation> A toAnnotationInstance(Class<A> type, Annotation node) { return type.cast(Proxy.newProxyInstance(type.getClassLoader(), new Class[] { type }, new AnnotationProxy(this, node))); }