/** * Wraps the annotation into a proxy so that the returned object will also implement * {@link Locatable}. */ public static <A extends Annotation> A create( A annotation, Locatable parentSourcePos ) { if(annotation==null) return null; Class<? extends Annotation> type = annotation.annotationType(); if(quicks.containsKey(type)) { // use the existing proxy implementation if available return (A)quicks.get(type).newInstance(parentSourcePos,annotation); } // otherwise take the slow route ClassLoader cl = SecureLoader.getClassClassLoader(LocatableAnnotation.class); try { Class loadableT = Class.forName(type.getName(), false, cl); if(loadableT !=type) return annotation; // annotation type not loadable from this class loader return (A)Proxy.newProxyInstance(cl, new Class[]{ type, Locatable.class }, new LocatableAnnotation(annotation,parentSourcePos)); } catch (ClassNotFoundException e) { // annotation not loadable return annotation; } catch (IllegalArgumentException e) { // Proxy.newProxyInstance throws this if it cannot resolve this annotation // in this classloader return annotation; } }
/** * Wraps the annotation into a proxy so that the returned object will also implement * {@link Locatable}. */ public static <A extends Annotation> A create( A annotation, Locatable parentSourcePos ) { if(annotation==null) return null; Class<? extends Annotation> type = annotation.annotationType(); if(quicks.containsKey(type)) { // use the existing proxy implementation if available return (A)quicks.get(type).newInstance(parentSourcePos,annotation); } // otherwise take the slow route ClassLoader cl = SecureLoader.getClassClassLoader(LocatableAnnotation.class); try { Class loadableT = Class.forName(type.getName(), false, cl); if(loadableT !=type) return annotation; // annotation type not loadable from this class loader return (A)Proxy.newProxyInstance(cl, new Class[]{ type, Locatable.class }, new LocatableAnnotation(annotation,parentSourcePos)); } catch (ClassNotFoundException e) { // annotation not loadable return annotation; } catch (IllegalArgumentException e) { // Proxy.newProxyInstance throws this if it cannot resolve this annotation // in this classloader return annotation; } }
/** * Wraps the annotation into a proxy so that the returned object will also implement * {@link Locatable}. */ public static <A extends Annotation> A create( A annotation, Locatable parentSourcePos ) { if(annotation==null) return null; Class<? extends Annotation> type = annotation.annotationType(); if(quicks.containsKey(type)) { // use the existing proxy implementation if available return (A)quicks.get(type).newInstance(parentSourcePos,annotation); } // otherwise take the slow route ClassLoader cl = SecureLoader.getClassClassLoader(LocatableAnnotation.class); try { Class loadableT = Class.forName(type.getName(), false, cl); if(loadableT !=type) return annotation; // annotation type not loadable from this class loader return (A)Proxy.newProxyInstance(cl, new Class[]{ type, Locatable.class }, new LocatableAnnotation(annotation,parentSourcePos)); } catch (ClassNotFoundException e) { // annotation not loadable return annotation; } catch (IllegalArgumentException e) { // Proxy.newProxyInstance throws this if it cannot resolve this annotation // in this classloader return annotation; } }
/** * Wraps the annotation into a proxy so that the returned object will also implement * {@link Locatable}. */ public static <A extends Annotation> A create( A annotation, Locatable parentSourcePos ) { if(annotation==null) return null; Class<? extends Annotation> type = annotation.annotationType(); if(quicks.containsKey(type)) { // use the existing proxy implementation if available return (A)quicks.get(type).newInstance(parentSourcePos,annotation); } // otherwise take the slow route ClassLoader cl = SecureLoader.getClassClassLoader(LocatableAnnotation.class); try { Class loadableT = Class.forName(type.getName(), false, cl); if(loadableT !=type) return annotation; // annotation type not loadable from this class loader return (A)Proxy.newProxyInstance(cl, new Class[]{ type, Locatable.class }, new LocatableAnnotation(annotation,parentSourcePos)); } catch (ClassNotFoundException e) { // annotation not loadable return annotation; } catch (IllegalArgumentException e) { // Proxy.newProxyInstance throws this if it cannot resolve this annotation // in this classloader return annotation; } }