/** * 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))); }
if (!(elem.astName() == null && name.equals("value")) && !name.equals(elem.astName())) continue; for (Node val : elem.getValues()) { if (tryAsNumeric(val, expectedType, returnValues)) continue; if (tryAsBoolean(val, expectedType, returnValues)) continue; if (tryAsString(val, expectedType, returnValues)) continue; if (tryAsEnum(val, expectedType, returnValues)) continue; if (expectedType == Class.class) { if (val instanceof ClassLiteral) {
if (!(elem.astName() == null && name.equals("value")) && !name.equals(elem.astName())) continue; for (Node val : elem.getValues()) { if (tryAsNumeric(val, expectedType, returnValues)) continue; if (tryAsBoolean(val, expectedType, returnValues)) continue; if (tryAsString(val, expectedType, returnValues)) continue; if (tryAsEnum(val, expectedType, returnValues)) continue; if (expectedType == Class.class) { if (val instanceof ClassLiteral) {
if (!(elem.astName() == null && name.equals("value")) && !name.equals(elem.astName())) continue; for (Node val : elem.getValues()) { if (tryAsNumeric(val, expectedType, returnValues)) continue; if (tryAsBoolean(val, expectedType, returnValues)) continue; if (tryAsString(val, expectedType, returnValues)) continue; if (tryAsEnum(val, expectedType, returnValues)) continue; if (expectedType == Class.class) { if (val instanceof ClassLiteral) {
/** * 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))); }