/** * Discover if a Class <b>c</b> has been annotated with <b>type</b>. This also discovers annotations defined through * a @{@link Stereotype}. * * @param c The class to inspect. * @param type The targeted annotation class * @return True if annotation is present either on class, false if the annotation is not present. */ public static boolean isAnnotationPresent(final Class<?> c, final Class<? extends Annotation> type) { return getAnnotation(c, type) != null; }
if (isAnnotationPresent(a, type)) result = isAnnotationPresent(m.getDeclaringClass(), type);
result = getAnnotationFromType(c, type); if (result == null) while (superclass != null) result = getAnnotation(superclass, type); if (result != null) break; for (Class<?> i : interfaces) result = getAnnotation(i, type); if (result != null) break;
@Override public Object call() throws Exception { Bean<R> bean = (Bean<R>) manager.resolve(manager.getBeans(actualType, Annotations.getQualifiersFrom(actualType))); context = manager.createCreationalContext(bean); Object delegate = manager.getInjectableReference(injectionPoint, context); return Proxies.enhance(loader, delegate, new ClassLoaderInterceptor(loader, delegate)); } };
private static boolean isAnnotationPresent(final Annotation a, final Class<? extends Annotation> type) { boolean result = false; if (a.annotationType().isAnnotationPresent(type)) { result = true; } else { for (Annotation nested : a.getClass().getAnnotations()) { if (isAnnotationPresent(nested, type)) { result = true; break; } } } return result; }
Set<Bean<?>> beans = manager.getBeans(type, Annotations.getQualifiersFrom(type)); Class<? extends T> assignableClass = (Class<? extends T>) type; result.add(new ExportedInstanceImpl<T>(
@SuppressWarnings("unchecked") private void invokeBefore(Class<?> clazz, Object instance) throws Exception { if (clazz.getSuperclass() != null && !Object.class.equals(clazz.getSuperclass())) invokeBefore(clazz.getSuperclass(), instance); for (Method m : clazz.getMethods()) { if (Annotations.isAnnotationPresent(m, (Class<? extends Annotation>) clazz.getClassLoader().loadClass("org.junit.Before"))) { m.invoke(instance); } } }
private Exported getExported(Class<?> clazz) { return Annotations.getAnnotation(clazz, Exported.class); } }
@SuppressWarnings("unchecked") private void invokeAfter(Class<?> clazz, Object instance) throws Exception { for (Method m : clazz.getMethods()) { if (Annotations.isAnnotationPresent(m, (Class<? extends Annotation>) clazz.getClassLoader().loadClass("org.junit.After"))) { m.invoke(instance); } } if (clazz.getSuperclass() != null && !Object.class.equals(clazz.getSuperclass())) invokeAfter(clazz.getSuperclass(), instance); }
/** * Inspect annotation <b>a</b> for a specific <b>type</b> of annotation. This also discovers annotations defined * through a @ {@link Stereotype}. * * @param m The method to inspect. * @param type The targeted annotation class * @return The annotation instance found on this method or enclosing class, or null if no matching annotation was * found. */ public static <A extends Annotation> A getAnnotation(final Annotation a, final Class<A> type) { Set<Annotation> seen = new HashSet<Annotation>(); return getAnnotation(seen, a, type); }
public void processRemotes(@Observes ProcessAnnotatedType<?> event) throws InstantiationException, IllegalAccessException { Class<?> type = event.getAnnotatedType().getJavaClass(); if (Annotations.isAnnotationPresent(type, Exported.class) && !(Modifier.isAbstract(type.getModifiers()) || Modifier.isInterface(type.getModifiers()))) { if (type.getClassLoader().equals(Thread.currentThread().getContextClassLoader())) { services.put(event.getAnnotatedType().getJavaClass(), event.getAnnotatedType()); } } }
/** * Inspect method <b>m</b> for a specific <b>type</b> of annotation. This also discovers annotations defined through * a @ {@link Stereotype}. * * @param m The method to inspect. * @param type The targeted annotation class * @return The annotation instance found on this method or enclosing class, or null if no matching annotation was * found. */ public static <A extends Annotation> A getAnnotation(final Method m, final Class<A> type) { A result = m.getAnnotation(type); if (result == null) { for (Annotation a : m.getAnnotations()) { result = getAnnotation(a, type); if (result != null) { break; } } } if (result == null) { result = getAnnotation(m.getDeclaringClass(), type); } return result; }
public void processProducerHooks(@Observes ProcessProducer<?, ?> event, BeanManager manager) { Class<?> type = Types.toClass(event.getAnnotatedMember().getJavaMember()); ClassLoader classLoader = type.getClassLoader(); if (classLoader != null && classLoader.equals(Thread.currentThread().getContextClassLoader())) { if (Annotations.isAnnotationPresent(type, Exported.class)) { services.put(type, manager.createAnnotatedType(type)); } } }
result = getAnnotation(a.annotationType().getDeclaringClass(), type); result = getAnnotation(seen, nested, type);
public void handleEvent(@Observes @Any Object event, EventMetadata metadata) if (Annotations.isAnnotationPresent(event.getClass(), Exported.class))